Skip to content
Permalink
Browse files

esm: modify resolution order for specifier flag

Currently `--es-module-specifier-resolution=node` has an alternative
resolution order than the default in common.js, this causes
inconsistencies. As discussed in @nodejs/modules we want to preserve
resolution order between implementations.

PR-URL: #29974
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
MylesBorins authored and guybedford committed Oct 14, 2019
1 parent a6b030d commit 1e5ed9a5db7494d2e415e7937ee0caa4f68e5505
@@ -9,6 +9,8 @@ const { getOptionValue } = require('internal/options');
const preserveSymlinks = getOptionValue('--preserve-symlinks');
const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
const experimentalJsonModules = getOptionValue('--experimental-json-modules');
const esModuleSpecifierResolution =
getOptionValue('--es-module-specifier-resolution');
const typeFlag = getOptionValue('--input-type');
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
const { resolve: moduleWrapResolve,
@@ -110,6 +112,8 @@ function resolve(specifier, parentURL) {
if (!format) {
if (isMain)
format = type === TYPE_MODULE ? 'module' : 'commonjs';
else if (esModuleSpecifierResolution === 'node')
format = 'commonjs';
else
throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url));
}
@@ -48,11 +48,10 @@ using v8::Undefined;
using v8::Value;

static const char* const EXTENSIONS[] = {
".mjs",
".cjs",
".js",
".json",
".node"
".node",
".mjs"
};

ModuleWrap::ModuleWrap(Environment* env,
@@ -1,5 +1,5 @@
// Flags: --experimental-modules --es-module-specifier-resolution=node
import { mustNotCall } from '../common';
import { mustNotCall } from '../common/index.mjs';
import assert from 'assert';

// commonJS index.js
@@ -14,8 +14,8 @@ assert.strictEqual(commonjs, 'commonjs');
assert.strictEqual(module, 'module');
assert.strictEqual(success, 'success');
assert.strictEqual(explicit, 'esm');
assert.strictEqual(implicit, 'esm');
assert.strictEqual(implicitModule, 'esm');
assert.strictEqual(implicit, 'cjs');
assert.strictEqual(implicitModule, 'cjs');

async function main() {
try {

Some generated files are not rendered by default. Learn more.

0 comments on commit 1e5ed9a

Please sign in to comment.
You can’t perform that action at this time.