Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: rename --loader to --experimental-loader #29752

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,13 @@ Specify ways of the inspector web socket url exposure.
By default inspector websocket url is available in stderr and under `/json/list`
endpoint on `http://host:port/json/list`.

### `--loader=file`
### `--experimental-loader=module`
<!-- YAML
added: v9.0.0
-->

Specify the `file` of the custom [experimental ECMAScript Module][] loader.
Specify the `module` of a custom [experimental ECMAScript Module][] loader.
`module` may be either a path to a file, or an ECMAScript Module name.

### `--max-http-header-size=size`
<!-- YAML
Expand Down Expand Up @@ -981,6 +982,7 @@ Node.js options that are allowed are:
* `--enable-fips`
* `--es-module-specifier-resolution`
* `--experimental-exports`
* `--experimental-loader`
* `--experimental-modules`
* `--experimental-policy`
* `--experimental-repl-await`
Expand All @@ -998,7 +1000,6 @@ Node.js options that are allowed are:
* `--inspect-port`, `--debug-port`
* `--inspect-publish-uid`
* `--inspect`
* `--loader`
* `--max-http-header-size`
* `--napi-modules`
* `--no-deprecation`
Expand Down
4 changes: 2 additions & 2 deletions doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ would provide the exports interface for the instantiation of `module.wasm`.
<!-- type=misc -->

To customize the default module resolution, loader hooks can optionally be
provided via a `--loader ./loader-name.mjs` argument to Node.js.
provided via a `--experimental-loader ./loader-name.mjs` argument to Node.js.

When hooks are used they only apply to ES module loading and not to any
CommonJS modules loaded.
Expand Down Expand Up @@ -731,7 +731,7 @@ export async function resolve(specifier,
With this loader, running:

```console
NODE_OPTIONS='--experimental-modules --loader ./custom-loader.mjs' node x.js
NODE_OPTIONS='--experimental-modules --experimental-loader ./custom-loader.mjs' node x.js
```

would load the module `x.js` as an ES module with relative resolution support
Expand Down
4 changes: 2 additions & 2 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ Default is
V8 Inspector integration allows attaching Chrome DevTools and IDEs to Node.js instances for debugging and profiling.
It uses the Chrome DevTools Protocol.
.
.It Fl -loader Ns = Ns Ar file
.It Fl -experimental-loader Ns = Ns Ar module
Specify the
.Ar file
.Ar module
as a custom loader, to load
.Fl -experimental-modules .
.
Expand Down
8 changes: 4 additions & 4 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,12 @@ function initializeESMLoader() {
// track of for different ESM modules.
setInitializeImportMetaObjectCallback(esm.initializeImportMetaObject);
setImportModuleDynamicallyCallback(esm.importModuleDynamicallyCallback);
const userLoader = getOptionValue('--loader');
// If --loader is specified, create a loader with user hooks. Otherwise
// create the default loader.
const userLoader = getOptionValue('--experimental-loader');
// If --experimental-loader is specified, create a loader with user hooks.
// Otherwise create the default loader.
if (userLoader) {
const { emitExperimentalWarning } = require('internal/util');
emitExperimentalWarning('--loader');
emitExperimentalWarning('--experimental-loader');
}
esm.initializeLoader(process.cwd(), userLoader);
}
Expand Down
14 changes: 8 additions & 6 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ void PerIsolateOptions::CheckOptions(std::vector<std::string>* errors) {

void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) {
if (!userland_loader.empty() && !experimental_modules) {
errors->push_back("--loader requires --experimental-modules be enabled");
errors->push_back("--experimental-loader requires "
"--experimental-modules be enabled");
}
if (has_policy_integrity_string && experimental_policy.empty()) {
errors->push_back("--policy-integrity requires "
Expand Down Expand Up @@ -311,6 +312,12 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"experimental support for exports in package.json",
&EnvironmentOptions::experimental_exports,
kAllowedInEnvironment);
AddOption("--experimental-loader",
"(with --experimental-modules) use the specified file as a "
"custom loader",
&EnvironmentOptions::userland_loader,
kAllowedInEnvironment);
AddAlias("--loader", "--experimental-loader");
AddOption("--experimental-modules",
"experimental ES Module support and caching modules",
&EnvironmentOptions::experimental_modules,
Expand Down Expand Up @@ -363,11 +370,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
"set module type for string input",
&EnvironmentOptions::module_type,
kAllowedInEnvironment);
AddOption("--loader",
"(with --experimental-modules) use the specified file as a "
"custom loader",
&EnvironmentOptions::userland_loader,
kAllowedInEnvironment);
AddOption("--es-module-specifier-resolution",
"Select extension resolution algorithm for es modules; "
"either 'explicit' (default) or 'node'",
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-example-loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/example-loader.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/example-loader.mjs
/* eslint-disable node-core/require-common-first, node-core/required-modules */
import assert from 'assert';
import ok from '../fixtures/es-modules/test-esm-ok.mjs';
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-dependency.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/loader-with-dep.mjs
/* eslint-disable node-core/require-common-first, node-core/required-modules */
import '../fixtures/es-modules/test-esm-ok.mjs';

Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-invalid-format.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-format.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/loader-invalid-format.mjs
import { expectsError, mustCall } from '../common/index.mjs';
import assert from 'assert';

Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-invalid-url.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs
import { expectsError, mustCall } from '../common/index.mjs';
import assert from 'assert';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/missing-dynamic-instantiate-hook.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/missing-dynamic-instantiate-hook.mjs
import { expectsError } from '../common/index.mjs';

import('test').catch(expectsError({
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-named-exports.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/builtin-named-exports-loader.mjs
import '../common/index.mjs';
import { readFile } from 'fs';
import assert from 'assert';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs
/* eslint-disable node-core/require-common-first, node-core/required-modules */
import './not-found.js';
2 changes: 1 addition & 1 deletion test/es-module/test-esm-preserve-symlinks-not-found.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/not-found-assert-loader.mjs
/* eslint-disable node-core/require-common-first, node-core/required-modules */
import './not-found.mjs';
2 changes: 1 addition & 1 deletion test/es-module/test-esm-resolve-hook.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/js-loader.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/js-loader.mjs
/* eslint-disable node-core/require-common-first, node-core/required-modules */
import { namedExport } from '../fixtures/es-module-loaders/js-as-esm.js';
import assert from 'assert';
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-shared-loader-dep.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-shared-dep.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/loader-shared-dep.mjs
import { createRequire } from '../common/index.mjs';

import assert from 'assert';
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-loaders-unknown-builtin-module.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs
import { expectsError, mustCall } from '../common/index.mjs';
import assert from 'assert';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const undocumented = difference(process.allowedNodeEnvironmentFlags,
assert(undocumented.delete('--debug-arraybuffer-allocations'));
assert(undocumented.delete('--experimental-worker'));
assert(undocumented.delete('--no-node-snapshot'));
assert(undocumented.delete('--loader'));

assert.strictEqual(undocumented.size, 0,
'The following options are not documented as allowed in ' +
Expand Down