Skip to content

Commit

Permalink
WIP: switch specifier resolution warning to custom message
Browse files Browse the repository at this point in the history
IRL, both internal and external instances of ESMLoader happen. in the test, only 1 external happens and then the test fails.
  • Loading branch information
JakobJingleheimer committed Mar 20, 2022
1 parent bfe82dc commit cc6202a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
10 changes: 8 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ class ESMLoader {
*/
translators = translators;

constructor() {
constructor(isInternal = false) {
console.log({ isInternal })
if (isInternal) return;

if (getOptionValue('--experimental-loader')) {
emitExperimentalWarning('Custom ESM Loaders');
}
if (getOptionValue('--experimental-network-imports')) {
emitExperimentalWarning('Network Imports');
}
if (getOptionValue('--experimental-specifier-resolution') === 'node') {
emitExperimentalWarning('Specifier Resolution');
process.emitWarning(
'The Node.js specifier resolution flag is experimental. It could change or be removed at any time.',
'ExperimentalWarning'
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/esm_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async function importModuleDynamicallyCallback(wrap, specifier, assertions) {
throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING();
};

const esmLoader = new ESMLoader();
const esmLoader = new ESMLoader(true);

exports.esmLoader = esmLoader;

Expand Down
13 changes: 10 additions & 3 deletions test/es-module/test-esm-experimental-warnings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,30 @@ for (
const [experiment, arg] of [
[/Custom ESM Loaders/, `--experimental-loader=${fileURL('es-module-loaders', 'hooks-custom.mjs')}`],
[/Network Imports/, '--experimental-network-imports'],
[/Specifier Resolution/, '--experimental-specifier-resolution=node'],
[/specifier resolution/, '--experimental-specifier-resolution=node'],
]
) {
const input = `import ${JSON.stringify(fileURL('es-module-loaders','module-named-exports.mjs'))}`;
console.log({ input })
const child = spawn(execPath, [
arg,
'--input-type=module',
'--eval',
'const foo = "a"',
input,
]);

let stderr = '';
child.stderr.setEncoding('utf8');
child.stderr.on('data', (data) => { stderr += data; });

let stdout = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (data) => { stdout += data; });
child.on('close', mustCall((code, signal) => {
console.log({ experiment, code, signal, stderr, stdout })
strictEqual(code, 0);
strictEqual(signal, null);
match(stderr, /ExperimentalWarning:/);
match(stderr, /ExperimentalWarning/);
match(stderr, experiment);
}));
}

0 comments on commit cc6202a

Please sign in to comment.