From 0ce99ad8884d61cd681c34f83fd405fede4ca029 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 18 Feb 2020 12:43:10 +0200 Subject: [PATCH 1/3] module: disable conditional exports, self resolve warnings --- lib/internal/modules/cjs/loader.js | 4 +-- lib/internal/modules/esm/loader.js | 2 +- lib/internal/process/esm_loader.js | 10 +------- src/module_wrap.cc | 3 --- test/es-module/test-esm-dynamic-import.js | 3 --- test/es-module/test-esm-nowarn-exports.mjs | 25 +++++++++++++++++++ .../es-modules/import-resolve-exports.mjs | 10 ++++++++ test/message/async_error_sync_esm.out | 1 - test/message/esm_display_syntax_error.out | 1 - .../esm_display_syntax_error_import.out | 1 - ...esm_display_syntax_error_import_module.out | 1 - .../esm_display_syntax_error_module.out | 1 - test/message/esm_loader_not_found.out | 1 - test/message/esm_loader_syntax_error.out | 1 - 14 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 test/es-module/test-esm-nowarn-exports.mjs create mode 100644 test/fixtures/es-modules/import-resolve-exports.mjs diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index c0c565f12308f4..a73101aa1feaf1 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -51,7 +51,7 @@ const { rekeySourceMap } = require('internal/source_map/source_map_cache'); const { pathToFileURL, fileURLToPath, URL } = require('internal/url'); -const { deprecate, emitExperimentalWarning } = require('internal/util'); +const { deprecate } = require('internal/util'); const vm = require('vm'); const assert = require('internal/assert'); const fs = require('fs'); @@ -614,7 +614,6 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) { case 'node': case 'require': try { - emitExperimentalWarning('Conditional exports'); return resolveExportsTarget(baseUrl, target[p], subpath, mappingKey); } catch (e) { @@ -1008,7 +1007,6 @@ Module._resolveFilename = function(request, parent, isMain, options) { if (parent && parent.filename) { const filename = trySelf(parent.filename, isMain, request); if (filename) { - emitExperimentalWarning('Package name self resolution'); const cacheKey = request + '\x00' + (paths.length === 1 ? paths[0] : paths.join('\x00')); Module._pathCache[cacheKey] = filename; diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index 5a27f4be7c9d1a..ecc43d4e94b45b 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -3,7 +3,7 @@ const { FunctionPrototypeBind, ObjectSetPrototypeOf, - SafeMap, + SafeMap } = primordials; const { diff --git a/lib/internal/process/esm_loader.js b/lib/internal/process/esm_loader.js index 404be77338bfe1..49895ef4dda54a 100644 --- a/lib/internal/process/esm_loader.js +++ b/lib/internal/process/esm_loader.js @@ -24,12 +24,7 @@ exports.initializeImportMetaObject = function(wrap, meta) { exports.importModuleDynamicallyCallback = async function(wrap, specifier) { assert(calledInitialize === true || !userLoader); - if (!calledInitialize) { - process.emitWarning( - 'The ESM module loader is experimental.', - 'ExperimentalWarning', undefined); - calledInitialize = true; - } + calledInitialize = true; const { callbackMap } = internalBinding('module_wrap'); if (callbackMap.has(wrap)) { const { importModuleDynamically } = callbackMap.get(wrap); @@ -48,9 +43,6 @@ let calledInitialize = false; exports.initializeLoader = initializeLoader; async function initializeLoader() { assert(calledInitialize === false); - process.emitWarning( - 'The ESM module loader is experimental.', - 'ExperimentalWarning', undefined); calledInitialize = true; if (!userLoader) return; diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 436a6e98e73fe5..a1e1fb5b088f0f 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -1073,7 +1073,6 @@ Maybe ResolveExportsTarget(Environment* env, return Nothing(); } CHECK(!try_catch.HasCaught()); - ProcessEmitExperimentalWarning(env, "Conditional exports"); return resolved; } } else if (key_str == "default") { @@ -1094,7 +1093,6 @@ Maybe ResolveExportsTarget(Environment* env, return Nothing(); } CHECK(!try_catch.HasCaught()); - ProcessEmitExperimentalWarning(env, "Conditional exports"); return resolved; } } @@ -1310,7 +1308,6 @@ Maybe PackageResolve(Environment* env, } } if (found_pjson && pcfg->name == pkg_name && !pcfg->exports.IsEmpty()) { - ProcessEmitExperimentalWarning(env, "Package name self resolution"); if (pkg_subpath == "./") { return Just(URL("./", pjson_url)); } else if (!pkg_subpath.length()) { diff --git a/test/es-module/test-esm-dynamic-import.js b/test/es-module/test-esm-dynamic-import.js index e01b86eed143ed..e72922d31c0b18 100644 --- a/test/es-module/test-esm-dynamic-import.js +++ b/test/es-module/test-esm-dynamic-import.js @@ -42,9 +42,6 @@ function expectFsNamespace(result) { // For direct use of import expressions inside of CJS or ES modules, including // via eval, all kinds of specifiers should work without issue. (function testScriptOrModuleImport() { - common.expectWarning('ExperimentalWarning', - 'The ESM module loader is experimental.'); - // Importing another file, both direct & via eval // expectOkNamespace(import(relativePath)); expectOkNamespace(eval(`import("${relativePath}")`)); diff --git a/test/es-module/test-esm-nowarn-exports.mjs b/test/es-module/test-esm-nowarn-exports.mjs new file mode 100644 index 00000000000000..5e0927f4674f84 --- /dev/null +++ b/test/es-module/test-esm-nowarn-exports.mjs @@ -0,0 +1,25 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { strictEqual, ok } from 'assert'; +import { spawn } from 'child_process'; + +const child = spawn(process.execPath, [ + '--experimental-import-meta-resolve', + path('/es-modules/import-resolve-exports.mjs') +]); + +let stderr = ''; +child.stderr.setEncoding('utf8'); +child.stderr.on('data', (data) => { + stderr += data; +}); +child.on('close', (code, signal) => { + strictEqual(code, 0); + strictEqual(signal, null); + ok(!stderr.toString().includes( + 'ExperimentalWarning: The ESM module loader is experimental' + )); + ok(!stderr.toString().includes( + 'ExperimentalWarning: Conditional exports' + )); +}); diff --git a/test/fixtures/es-modules/import-resolve-exports.mjs b/test/fixtures/es-modules/import-resolve-exports.mjs new file mode 100644 index 00000000000000..0bbce4fbc5efc0 --- /dev/null +++ b/test/fixtures/es-modules/import-resolve-exports.mjs @@ -0,0 +1,10 @@ +import { strictEqual } from 'assert'; + +(async () => { + const resolved = await import.meta.resolve('pkgexports-sugar'); + strictEqual(typeof resolved, 'string'); +})() +.catch((e) => { + console.error(e); + process.exit(1); +}); diff --git a/test/message/async_error_sync_esm.out b/test/message/async_error_sync_esm.out index 6577fff6944723..6054fc7cc22de0 100644 --- a/test/message/async_error_sync_esm.out +++ b/test/message/async_error_sync_esm.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. Error: test at one (*fixtures*async-error.js:4:9) at two (*fixtures*async-error.js:17:9) diff --git a/test/message/esm_display_syntax_error.out b/test/message/esm_display_syntax_error.out index 778d901129fa95..b7d2008540adf3 100644 --- a/test/message/esm_display_syntax_error.out +++ b/test/message/esm_display_syntax_error.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/message/esm_display_syntax_error.mjs:2 await async () => 0; ^^^^^ diff --git a/test/message/esm_display_syntax_error_import.out b/test/message/esm_display_syntax_error_import.out index e39744a049b59b..387a63a734b512 100644 --- a/test/message/esm_display_syntax_error_import.out +++ b/test/message/esm_display_syntax_error_import.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/message/esm_display_syntax_error_import.mjs:5 notfound ^^^^^^^^ diff --git a/test/message/esm_display_syntax_error_import_module.out b/test/message/esm_display_syntax_error_import_module.out index 0daaeff5b95daf..ae8b99d55fef20 100644 --- a/test/message/esm_display_syntax_error_import_module.out +++ b/test/message/esm_display_syntax_error_import_module.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1 import { foo, notfound } from './module-named-exports.mjs'; ^^^^^^^^ diff --git a/test/message/esm_display_syntax_error_module.out b/test/message/esm_display_syntax_error_module.out index a1498f72c94d57..708257fcaf5792 100644 --- a/test/message/esm_display_syntax_error_module.out +++ b/test/message/esm_display_syntax_error_module.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/fixtures/es-module-loaders/syntax-error.mjs:2 await async () => 0; ^^^^^ diff --git a/test/message/esm_loader_not_found.out b/test/message/esm_loader_not_found.out index 770ffdc1cb3559..3bb6d5e23ca30c 100644 --- a/test/message/esm_loader_not_found.out +++ b/test/message/esm_loader_not_found.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. (node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time internal/modules/esm/resolve.js:* let url = moduleWrapResolve(specifier, parentURL); diff --git a/test/message/esm_loader_syntax_error.out b/test/message/esm_loader_syntax_error.out index 9767a9c86c6bc2..7dd1c01fbcc1bf 100644 --- a/test/message/esm_loader_syntax_error.out +++ b/test/message/esm_loader_syntax_error.out @@ -1,4 +1,3 @@ -(node:*) ExperimentalWarning: The ESM module loader is experimental. (node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time file://*/test/fixtures/es-module-loaders/syntax-error.mjs:2 await async () => 0; From 98b1f93d23ad2a4de8ac2d29079c8ca887de14f1 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 26 Feb 2020 22:32:08 +0200 Subject: [PATCH 2/3] fixup: disable experimental-modules flag removal --- lib/internal/process/esm_loader.js | 9 +++++++++ test/es-module/test-esm-dynamic-import.js | 2 ++ test/es-module/test-esm-nowarn-exports.mjs | 2 +- test/message/async_error_sync_esm.out | 1 + test/message/esm_display_syntax_error.out | 1 + test/message/esm_display_syntax_error_import.out | 1 + test/message/esm_display_syntax_error_module.out | 1 + test/message/esm_loader_not_found.out | 1 + test/message/esm_loader_syntax_error.out | 1 + 9 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/internal/process/esm_loader.js b/lib/internal/process/esm_loader.js index 49895ef4dda54a..17375dd2fc3c85 100644 --- a/lib/internal/process/esm_loader.js +++ b/lib/internal/process/esm_loader.js @@ -24,6 +24,12 @@ exports.initializeImportMetaObject = function(wrap, meta) { exports.importModuleDynamicallyCallback = async function(wrap, specifier) { assert(calledInitialize === true || !userLoader); + if (!calledInitialize) { + process.emitWarning( + 'The ESM module loader is experimental.', + 'ExperimentalWarning', undefined); + calledInitialize = true; + } calledInitialize = true; const { callbackMap } = internalBinding('module_wrap'); if (callbackMap.has(wrap)) { @@ -43,6 +49,9 @@ let calledInitialize = false; exports.initializeLoader = initializeLoader; async function initializeLoader() { assert(calledInitialize === false); + process.emitWarning( + 'The ESM module loader is experimental.', + 'ExperimentalWarning', undefined); calledInitialize = true; if (!userLoader) return; diff --git a/test/es-module/test-esm-dynamic-import.js b/test/es-module/test-esm-dynamic-import.js index e72922d31c0b18..43867826aa932a 100644 --- a/test/es-module/test-esm-dynamic-import.js +++ b/test/es-module/test-esm-dynamic-import.js @@ -42,6 +42,8 @@ function expectFsNamespace(result) { // For direct use of import expressions inside of CJS or ES modules, including // via eval, all kinds of specifiers should work without issue. (function testScriptOrModuleImport() { + common.expectWarning('ExperimentalWarning', + 'The ESM module loader is experimental.'); // Importing another file, both direct & via eval // expectOkNamespace(import(relativePath)); expectOkNamespace(eval(`import("${relativePath}")`)); diff --git a/test/es-module/test-esm-nowarn-exports.mjs b/test/es-module/test-esm-nowarn-exports.mjs index 5e0927f4674f84..13bfaf9b4f3527 100644 --- a/test/es-module/test-esm-nowarn-exports.mjs +++ b/test/es-module/test-esm-nowarn-exports.mjs @@ -16,7 +16,7 @@ child.stderr.on('data', (data) => { child.on('close', (code, signal) => { strictEqual(code, 0); strictEqual(signal, null); - ok(!stderr.toString().includes( + ok(stderr.toString().includes( 'ExperimentalWarning: The ESM module loader is experimental' )); ok(!stderr.toString().includes( diff --git a/test/message/async_error_sync_esm.out b/test/message/async_error_sync_esm.out index 6054fc7cc22de0..6577fff6944723 100644 --- a/test/message/async_error_sync_esm.out +++ b/test/message/async_error_sync_esm.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. Error: test at one (*fixtures*async-error.js:4:9) at two (*fixtures*async-error.js:17:9) diff --git a/test/message/esm_display_syntax_error.out b/test/message/esm_display_syntax_error.out index b7d2008540adf3..778d901129fa95 100644 --- a/test/message/esm_display_syntax_error.out +++ b/test/message/esm_display_syntax_error.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/message/esm_display_syntax_error.mjs:2 await async () => 0; ^^^^^ diff --git a/test/message/esm_display_syntax_error_import.out b/test/message/esm_display_syntax_error_import.out index 387a63a734b512..e39744a049b59b 100644 --- a/test/message/esm_display_syntax_error_import.out +++ b/test/message/esm_display_syntax_error_import.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/message/esm_display_syntax_error_import.mjs:5 notfound ^^^^^^^^ diff --git a/test/message/esm_display_syntax_error_module.out b/test/message/esm_display_syntax_error_module.out index 708257fcaf5792..a1498f72c94d57 100644 --- a/test/message/esm_display_syntax_error_module.out +++ b/test/message/esm_display_syntax_error_module.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/fixtures/es-module-loaders/syntax-error.mjs:2 await async () => 0; ^^^^^ diff --git a/test/message/esm_loader_not_found.out b/test/message/esm_loader_not_found.out index 3bb6d5e23ca30c..770ffdc1cb3559 100644 --- a/test/message/esm_loader_not_found.out +++ b/test/message/esm_loader_not_found.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. (node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time internal/modules/esm/resolve.js:* let url = moduleWrapResolve(specifier, parentURL); diff --git a/test/message/esm_loader_syntax_error.out b/test/message/esm_loader_syntax_error.out index 7dd1c01fbcc1bf..9767a9c86c6bc2 100644 --- a/test/message/esm_loader_syntax_error.out +++ b/test/message/esm_loader_syntax_error.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. (node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time file://*/test/fixtures/es-module-loaders/syntax-error.mjs:2 await async () => 0; From fd2c05b2a980450f07d4c9f62243283cb71b2bb9 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 26 Feb 2020 22:39:29 +0200 Subject: [PATCH 3/3] fixup: various --- lib/internal/modules/esm/loader.js | 2 +- lib/internal/process/esm_loader.js | 1 - test/es-module/test-esm-dynamic-import.js | 1 + test/message/esm_display_syntax_error_import_module.out | 1 + 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index ecc43d4e94b45b..5a27f4be7c9d1a 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -3,7 +3,7 @@ const { FunctionPrototypeBind, ObjectSetPrototypeOf, - SafeMap + SafeMap, } = primordials; const { diff --git a/lib/internal/process/esm_loader.js b/lib/internal/process/esm_loader.js index 17375dd2fc3c85..404be77338bfe1 100644 --- a/lib/internal/process/esm_loader.js +++ b/lib/internal/process/esm_loader.js @@ -30,7 +30,6 @@ exports.importModuleDynamicallyCallback = async function(wrap, specifier) { 'ExperimentalWarning', undefined); calledInitialize = true; } - calledInitialize = true; const { callbackMap } = internalBinding('module_wrap'); if (callbackMap.has(wrap)) { const { importModuleDynamically } = callbackMap.get(wrap); diff --git a/test/es-module/test-esm-dynamic-import.js b/test/es-module/test-esm-dynamic-import.js index 43867826aa932a..e01b86eed143ed 100644 --- a/test/es-module/test-esm-dynamic-import.js +++ b/test/es-module/test-esm-dynamic-import.js @@ -44,6 +44,7 @@ function expectFsNamespace(result) { (function testScriptOrModuleImport() { common.expectWarning('ExperimentalWarning', 'The ESM module loader is experimental.'); + // Importing another file, both direct & via eval // expectOkNamespace(import(relativePath)); expectOkNamespace(eval(`import("${relativePath}")`)); diff --git a/test/message/esm_display_syntax_error_import_module.out b/test/message/esm_display_syntax_error_import_module.out index ae8b99d55fef20..0daaeff5b95daf 100644 --- a/test/message/esm_display_syntax_error_import_module.out +++ b/test/message/esm_display_syntax_error_import_module.out @@ -1,3 +1,4 @@ +(node:*) ExperimentalWarning: The ESM module loader is experimental. file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1 import { foo, notfound } from './module-named-exports.mjs'; ^^^^^^^^