Skip to content

Commit

Permalink
Change warning to be specific to --experimental-loader
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Sep 13, 2023
1 parent 3cf4e71 commit 601890e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ class CustomizedModuleLoader {
}
}

let emittedLoaderFlagWarning = false;
/**
* A loader instance is used as the main entry point for loading ES modules. Currently, this is a singleton; there is
* only one used for loading the main module and everything in its dependency graph, though separate instances of this
Expand All @@ -513,6 +514,13 @@ function createModuleLoader(useCustomLoadersIfPresent = true) {
!require('internal/modules/esm/utils').isLoaderWorker()) {
const userLoaderPaths = getOptionValue('--experimental-loader');
if (userLoaderPaths.length > 0) {
if (!emittedLoaderFlagWarning) {
process.emitWarning(
'`--experimental-loader` may be removed in the future; instead use `--import` to reference a file that calls `register()`',
'ExperimentalWarning',
);
emittedLoaderFlagWarning = true;
}
customizations = new CustomizedModuleLoader();
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/es-module/test-esm-experimental-warnings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ describe('ESM: warn for obsolete hooks provided', { concurrency: true }, () => {
describe('experimental warnings for enabled experimental feature', () => {
for (
const [experiment, arg] of [
[
/`--experimental-loader` may be removed in the future/,
`--experimental-loader=${fileURL('es-module-loaders', 'hooks-custom.mjs')}`
],
[/Network Imports/, '--experimental-network-imports'],
]
) {
Expand Down

0 comments on commit 601890e

Please sign in to comment.