From b9f3bfe6c8c5c715fc40afd4fce2ee78584fd7df Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 18 Feb 2020 12:43:10 +0200 Subject: [PATCH] module: disable conditional exports, self resolve warnings PR-URL: https://github.com/nodejs/node/pull/31845 Reviewed-By: Jan Krems Reviewed-By: Geoffrey Booth --- lib/internal/modules/cjs/loader.js | 4 +-- src/module_wrap.cc | 3 --- test/es-module/test-esm-nowarn-exports.mjs | 25 +++++++++++++++++++ .../es-modules/import-resolve-exports.mjs | 10 ++++++++ 4 files changed, 36 insertions(+), 6 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 c2a8b2a3f7435b..92551236dc0aa4 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -48,7 +48,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'); @@ -610,7 +610,6 @@ function resolveExportsTarget(baseUrl, target, subpath, mappingKey) { case 'node': case 'require': try { - emitExperimentalWarning('Conditional exports'); return resolveExportsTarget(baseUrl, target[p], subpath, mappingKey); } catch (e) { @@ -953,7 +952,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/src/module_wrap.cc b/src/module_wrap.cc index 350e395ebf43a2..5d758bac620b54 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -1075,7 +1075,6 @@ Maybe ResolveExportsTarget(Environment* env, return Nothing(); } CHECK(!try_catch.HasCaught()); - ProcessEmitExperimentalWarning(env, "Conditional exports"); return resolved; } } else if (key_str == "default") { @@ -1096,7 +1095,6 @@ Maybe ResolveExportsTarget(Environment* env, return Nothing(); } CHECK(!try_catch.HasCaught()); - ProcessEmitExperimentalWarning(env, "Conditional exports"); return resolved; } } @@ -1312,7 +1310,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-nowarn-exports.mjs b/test/es-module/test-esm-nowarn-exports.mjs new file mode 100644 index 00000000000000..13bfaf9b4f3527 --- /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); +});