Skip to content

Commit 59eff1f

Browse files
JakobJingleheimerGeoffreyBooth
authored andcommitted
WIP: switch specifier resolution warning to custom message
IRL, both internal and external instances of ESMLoader happen. in the test, only 1 external happens and then the test fails.
1 parent 463ae28 commit 59eff1f

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

lib/internal/modules/esm/loader.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,21 @@ class ESMLoader {
108108
*/
109109
translators = translators;
110110

111-
constructor() {
111+
constructor(isInternal = false) {
112+
console.log({ isInternal })
113+
if (isInternal) return;
114+
112115
if (getOptionValue('--experimental-loader')) {
113116
emitExperimentalWarning('Custom ESM Loaders');
114117
}
115118
if (getOptionValue('--experimental-network-imports')) {
116119
emitExperimentalWarning('Network Imports');
117120
}
118121
if (getOptionValue('--experimental-specifier-resolution') === 'node') {
119-
emitExperimentalWarning('Specifier Resolution');
122+
process.emitWarning(
123+
'The Node.js specifier resolution flag is experimental. It could change or be removed at any time.',
124+
'ExperimentalWarning'
125+
);
120126
}
121127
}
122128

lib/internal/process/esm_loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function importModuleDynamicallyCallback(wrap, specifier, assertions) {
3939
throw new ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING();
4040
};
4141

42-
const esmLoader = new ESMLoader();
42+
const esmLoader = new ESMLoader(true);
4343

4444
exports.esmLoader = esmLoader;
4545

test/es-module/test-esm-experimental-warnings.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@ for (
99
const [experiment, arg] of [
1010
[/Custom ESM Loaders/, `--experimental-loader=${fileURL('es-module-loaders', 'hooks-custom.mjs')}`],
1111
[/Network Imports/, '--experimental-network-imports'],
12-
[/Specifier Resolution/, '--experimental-specifier-resolution=node'],
12+
[/specifier resolution/, '--experimental-specifier-resolution=node'],
1313
]
1414
) {
15+
const input = `import ${JSON.stringify(fileURL('es-module-loaders','module-named-exports.mjs'))}`;
16+
console.log({ input })
1517
const child = spawn(execPath, [
1618
arg,
1719
'--input-type=module',
1820
'--eval',
19-
'const foo = "a"',
21+
input,
2022
]);
2123

2224
let stderr = '';
2325
child.stderr.setEncoding('utf8');
2426
child.stderr.on('data', (data) => { stderr += data; });
27+
28+
let stdout = '';
29+
child.stdout.setEncoding('utf8');
30+
child.stdout.on('data', (data) => { stdout += data; });
2531
child.on('close', mustCall((code, signal) => {
32+
console.log({ experiment, code, signal, stderr, stdout })
2633
strictEqual(code, 0);
2734
strictEqual(signal, null);
28-
match(stderr, /ExperimentalWarning:/);
35+
match(stderr, /ExperimentalWarning/);
2936
match(stderr, experiment);
3037
}));
3138
}

0 commit comments

Comments
 (0)