From cc6202a3ed2cdbde209d28bd0a178376b5bbe25d Mon Sep 17 00:00:00 2001 From: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:13:47 +0100 Subject: [PATCH] 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. --- lib/internal/modules/esm/loader.js | 10 ++++++++-- lib/internal/process/esm_loader.js | 2 +- test/es-module/test-esm-experimental-warnings.mjs | 13 ++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index f05d7ba5d432fa..608c5b1875b7b4 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -108,7 +108,10 @@ class ESMLoader { */ translators = translators; - constructor() { + constructor(isInternal = false) { +console.log({ isInternal }) + if (isInternal) return; + if (getOptionValue('--experimental-loader')) { emitExperimentalWarning('Custom ESM Loaders'); } @@ -116,7 +119,10 @@ class ESMLoader { 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' + ); } } diff --git a/lib/internal/process/esm_loader.js b/lib/internal/process/esm_loader.js index 20021134ce40f3..ee20f2badf6621 100644 --- a/lib/internal/process/esm_loader.js +++ b/lib/internal/process/esm_loader.js @@ -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; diff --git a/test/es-module/test-esm-experimental-warnings.mjs b/test/es-module/test-esm-experimental-warnings.mjs index 3d849b4810968c..2d9a976c1896fd 100644 --- a/test/es-module/test-esm-experimental-warnings.mjs +++ b/test/es-module/test-esm-experimental-warnings.mjs @@ -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); })); }