Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.

Commit 47e60ec

Browse files
jdaltondevsnek
authored andcommitted
esm: Remove --loader.
PR-URL: #6 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Myles Borins <mylesborins@google.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent ec83dee commit 47e60ec

40 files changed

Lines changed: 2 additions & 454 deletions

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ module.exports = {
3636
files: [
3737
'doc/api/esm.md',
3838
'*.mjs',
39-
'test/es-module/test-esm-example-loader.js',
4039
],
4140
parserOptions: { sourceType: 'module' },
4241
},

doc/api/cli.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ V8 inspector integration allows tools such as Chrome DevTools and IDEs to debug
155155
and profile Node.js instances. The tools attach to Node.js instances via a
156156
tcp port and communicate using the [Chrome DevTools Protocol][].
157157

158-
### `--loader=file`
159-
<!--
160-
added: v9.0.0
161-
-->
162-
163-
Specify the `file` of the custom [experimental ECMAScript Module][] loader.
164-
165158
### `--napi-modules`
166159
<!-- YAML
167160
added: v7.10.0
@@ -561,7 +554,6 @@ Node options that are allowed are:
561554
- `--inspect`
562555
- `--inspect-brk`
563556
- `--inspect-port`
564-
- `--loader`
565557
- `--napi-modules`
566558
- `--no-deprecation`
567559
- `--no-force-async-hooks-checks`
@@ -739,5 +731,4 @@ greater than `4` (its current default value). For more information, see the
739731
[V8 JavaScript code coverage]: https://v8project.blogspot.com/2017/12/javascript-code-coverage.html
740732
[debugger]: debugger.html
741733
[emit_warning]: process.html#process_process_emitwarning_warning_type_code_ctor
742-
[experimental ECMAScript Module]: esm.html#esm_loader_hooks
743734
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html

doc/api/esm.md

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -146,125 +146,6 @@ fs.readFileSync = () => Buffer.from('Hello, ESM');
146146
fs.readFileSync === readFileSync;
147147
```
148148
149-
## Loader hooks
150-
151-
<!-- type=misc -->
152-
153-
To customize the default module resolution, loader hooks can optionally be
154-
provided via a `--loader ./loader-name.mjs` argument to Node.js.
155-
156-
When hooks are used they only apply to ES module loading and not to any
157-
CommonJS modules loaded.
158-
159-
### Resolve hook
160-
161-
The resolve hook returns the resolved file URL and module format for a
162-
given module specifier and parent file URL:
163-
164-
```js
165-
const baseURL = new URL('file://');
166-
baseURL.pathname = `${process.cwd()}/`;
167-
168-
export async function resolve(specifier,
169-
parentModuleURL = baseURL,
170-
defaultResolver) {
171-
return {
172-
url: new URL(specifier, parentModuleURL).href,
173-
format: 'esm'
174-
};
175-
}
176-
```
177-
178-
The `parentModuleURL` is provided as `undefined` when performing main Node.js
179-
load itself.
180-
181-
The default Node.js ES module resolution function is provided as a third
182-
argument to the resolver for easy compatibility workflows.
183-
184-
In addition to returning the resolved file URL value, the resolve hook also
185-
returns a `format` property specifying the module format of the resolved
186-
module. This can be one of the following:
187-
188-
| `format` | Description |
189-
| --- | --- |
190-
| `'esm'` | Load a standard JavaScript module |
191-
| `'builtin'` | Load a node builtin CommonJS module |
192-
| `'dynamic'` | Use a [dynamic instantiate hook][] |
193-
194-
For example, a dummy loader to load JavaScript restricted to browser resolution
195-
rules with only JS file extension and Node.js builtin modules support could
196-
be written:
197-
198-
```js
199-
import path from 'path';
200-
import process from 'process';
201-
import Module from 'module';
202-
203-
const builtins = Module.builtinModules;
204-
const JS_EXTENSIONS = new Set(['.js', '.mjs']);
205-
206-
const baseURL = new URL('file://');
207-
baseURL.pathname = `${process.cwd()}/`;
208-
209-
export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) {
210-
if (builtins.includes(specifier)) {
211-
return {
212-
url: specifier,
213-
format: 'builtin'
214-
};
215-
}
216-
if (/^\.{0,2}[/]/.test(specifier) !== true && !specifier.startsWith('file:')) {
217-
// For node_modules support:
218-
// return defaultResolve(specifier, parentModuleURL);
219-
throw new Error(
220-
`imports must begin with '/', './', or '../'; '${specifier}' does not`);
221-
}
222-
const resolved = new URL(specifier, parentModuleURL);
223-
const ext = path.extname(resolved.pathname);
224-
if (!JS_EXTENSIONS.has(ext)) {
225-
throw new Error(
226-
`Cannot load file with non-JavaScript file extension ${ext}.`);
227-
}
228-
return {
229-
url: resolved.href,
230-
format: 'esm'
231-
};
232-
}
233-
```
234-
235-
With this loader, running:
236-
237-
```console
238-
NODE_OPTIONS='--experimental-modules --loader ./custom-loader.mjs' node x.js
239-
```
240-
241-
would load the module `x.js` as an ES module with relative resolution support
242-
(with `node_modules` loading skipped in this example).
243-
244-
### Dynamic instantiate hook
245-
246-
To create a custom dynamic module that doesn't correspond to one of the
247-
existing `format` interpretations, the `dynamicInstantiate` hook can be used.
248-
This hook is called only for modules that return `format: 'dynamic'` from
249-
the `resolve` hook.
250-
251-
```js
252-
export async function dynamicInstantiate(url) {
253-
return {
254-
exports: ['customExportName'],
255-
execute: (exports) => {
256-
// get and set functions provided for pre-allocated export names
257-
exports.customExportName.set('value');
258-
}
259-
};
260-
}
261-
```
262-
263-
With the list of module exports provided upfront, the `execute` function will
264-
then be called at the exact point of module evaluation order for that module
265-
in the import tree.
266-
267149
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
268-
[dynamic instantiate hook]: #esm_dynamic_instantiate_hook
269150
[`module.createRequireFromPath()`]: modules.html#modules_module_createrequirefrompath_filename
270151
[ESM Minimal Kernel]: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md

lib/internal/modules/cjs/loader.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const {
4444
const preserveSymlinks = !!process.binding('config').preserveSymlinks;
4545
const preserveSymlinksMain = !!process.binding('config').preserveSymlinksMain;
4646
const experimentalModules = !!process.binding('config').experimentalModules;
47-
const hasLoader = !!process.binding('config').userLoader;
4847

4948
const {
5049
ERR_INVALID_ARG_TYPE,
@@ -760,7 +759,7 @@ Module.runMain = function() {
760759
const ext = path.extname(base);
761760
const isESM = ext === '.mjs';
762761

763-
if (experimentalModules && (isESM || hasLoader)) {
762+
if (experimentalModules && isESM) {
764763
if (asyncESM === undefined) lazyLoadESM();
765764
asyncESM.loaderPromise.then((loader) => {
766765
return loader.import(pathToFileURL(process.argv[1]).pathname);

lib/internal/process/esm_loader.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const {
66
callbackMap,
77
} = internalBinding('module_wrap');
88

9-
const { pathToFileURL } = require('internal/url');
109
const Loader = require('internal/modules/esm/loader');
1110
const {
1211
wrapToModuleMap,
@@ -46,16 +45,8 @@ exports.loaderPromise = new Promise((resolve, reject) => {
4645
exports.ESMLoader = undefined;
4746

4847
exports.setup = function() {
49-
let ESMLoader = new Loader();
48+
const ESMLoader = new Loader();
5049
const loaderPromise = (async () => {
51-
const userLoader = process.binding('config').userLoader;
52-
if (userLoader) {
53-
const hooks = await ESMLoader.import(
54-
userLoader, pathToFileURL(`${process.cwd()}/`).href);
55-
ESMLoader = new Loader();
56-
ESMLoader.hook(hooks);
57-
exports.ESMLoader = ESMLoader;
58-
}
5950
return ESMLoader;
6051
})();
6152
loaderResolve(loaderPromise);

src/node_config.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ static void Initialize(Local<Object> target,
8989

9090
if (env->options()->experimental_modules) {
9191
READONLY_BOOLEAN_PROPERTY("experimentalModules");
92-
const std::string& userland_loader = env->options()->userland_loader;
93-
if (!userland_loader.empty()) {
94-
READONLY_STRING_PROPERTY(target, "userLoader", userland_loader);
95-
}
9692
}
9793

9894
if (env->options()->experimental_vm_modules)

src/node_options.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {
3232
}
3333

3434
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
35-
if (!userland_loader.empty() && !experimental_modules) {
36-
errors->push_back("--loader requires --experimental-modules be enabled");
37-
}
38-
3935
if (syntax_check_only && has_eval_string) {
4036
errors->push_back("either --check or --eval can be used, not both");
4137
}
@@ -102,11 +98,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
10298
&EnvironmentOptions::experimental_worker,
10399
kAllowedInEnvironment);
104100
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
105-
AddOption("--loader",
106-
"(with --experimental-modules) use the specified file as a "
107-
"custom loader",
108-
&EnvironmentOptions::userland_loader,
109-
kAllowedInEnvironment);
110101
AddOption("--no-deprecation",
111102
"silence deprecation warnings",
112103
&EnvironmentOptions::no_deprecation,

src/node_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class EnvironmentOptions : public Options {
8484
bool trace_deprecation = false;
8585
bool trace_sync_io = false;
8686
bool trace_warnings = false;
87-
std::string userland_loader;
8887

8988
bool syntax_check_only = false;
9089
bool has_eval_string = false;

test/es-module/test-esm-example-loader.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/es-module/test-esm-loader-dependency.mjs

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)