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

Commit 1b0695b

Browse files
jdaltonnodejs-ci
authored andcommitted
esm: Remove --loader.
PR-URL: #6 Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Myles Borins <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent b1d91ba commit 1b0695b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2
-467
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module.exports = {
3939
files: [
4040
'doc/api/esm.md',
4141
'*.mjs',
42-
'test/es-module/test-esm-example-loader.js',
4342
],
4443
parserOptions: { sourceType: 'module' },
4544
},

doc/api/cli.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,6 @@ default) is not firewall-protected.**
249249

250250
See the [debugging security implications][] section for more information.
251251

252-
### `--loader=file`
253-
<!-- YAML
254-
added: v9.0.0
255-
-->
256-
257-
Specify the `file` of the custom [experimental ECMAScript Module][] loader.
258-
259252
### `--max-http-header-size=size`
260253
<!-- YAML
261254
added: v11.6.0
@@ -691,7 +684,6 @@ Node.js options that are allowed are:
691684
- `--inspect`
692685
- `--inspect-brk`
693686
- `--inspect-port`
694-
- `--loader`
695687
- `--max-http-header-size`
696688
- `--napi-modules`
697689
- `--no-deprecation`
@@ -879,7 +871,6 @@ greater than `4` (its current default value). For more information, see the
879871
[debugger]: debugger.html
880872
[debugging security implications]: https://nodejs.org/en/docs/guides/debugging-getting-started/#security-implications
881873
[emit_warning]: process.html#process_process_emitwarning_warning_type_code_ctor
882-
[experimental ECMAScript Module]: esm.html#esm_loader_hooks
883874
[libuv threadpool documentation]: http://docs.libuv.org/en/latest/threadpool.html
884875
[remote code execution]: https://www.owasp.org/index.php/Code_Injection
885876
[secureProtocol]: tls.html#tls_tls_createsecurecontext_options

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
@@ -48,7 +48,6 @@ const manifest = getOptionValue('--experimental-policy') ?
4848
require('internal/process/policy').manifest :
4949
null;
5050
const { compileFunction } = internalBinding('contextify');
51-
const hasLoader = getOptionValue('--loader');
5251

5352
const {
5453
ERR_INVALID_ARG_VALUE,
@@ -863,7 +862,7 @@ Module.runMain = function() {
863862
const ext = path.extname(base);
864863
const isESM = ext === '.mjs';
865864

866-
if (experimentalModules && (isESM || hasLoader)) {
865+
if (experimentalModules && isESM) {
867866
if (asyncESM === undefined) lazyLoadESM();
868867
asyncESM.loaderPromise.then((loader) => {
869868
return loader.import(pathToFileURL(process.argv[1]).pathname);

lib/internal/process/esm_loader.js

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

7-
const { pathToFileURL } = require('internal/url');
87
const Loader = require('internal/modules/esm/loader');
98
const {
109
wrapToModuleMap,
@@ -41,15 +40,8 @@ exports.loaderPromise = new Promise((resolve, reject) => {
4140
exports.ESMLoader = undefined;
4241

4342
exports.initializeLoader = function(cwd, userLoader) {
44-
let ESMLoader = new Loader();
43+
const ESMLoader = new Loader();
4544
const loaderPromise = (async () => {
46-
if (userLoader) {
47-
const hooks = await ESMLoader.import(
48-
userLoader, pathToFileURL(`${cwd}/`).href);
49-
ESMLoader = new Loader();
50-
ESMLoader.hook(hooks);
51-
exports.ESMLoader = ESMLoader;
52-
}
5345
return ESMLoader;
5446
})();
5547
loaderResolve(loaderPromise);

src/node_options.cc

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

9797
void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
98-
if (!userland_loader.empty() && !experimental_modules) {
99-
errors->push_back("--loader requires --experimental-modules be enabled");
100-
}
101-
10298
if (syntax_check_only && has_eval_string) {
10399
errors->push_back("either --check or --eval can be used, not both");
104100
}
@@ -236,11 +232,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
236232
"(default: llhttp).",
237233
&EnvironmentOptions::http_parser,
238234
kAllowedInEnvironment);
239-
AddOption("--loader",
240-
"(with --experimental-modules) use the specified file as a "
241-
"custom loader",
242-
&EnvironmentOptions::userland_loader,
243-
kAllowedInEnvironment);
244235
AddOption("--no-deprecation",
245236
"silence deprecation warnings",
246237
&EnvironmentOptions::no_deprecation,

src/node_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class EnvironmentOptions : public Options {
103103
bool trace_deprecation = false;
104104
bool trace_sync_io = false;
105105
bool trace_warnings = false;
106-
std::string userland_loader;
107106

108107
bool syntax_check_only = false;
109108
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.

test/es-module/test-esm-loader-invalid-format.mjs

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

0 commit comments

Comments
 (0)