From 359afac1f52ec7ad27491d905be059daca7181c8 Mon Sep 17 00:00:00 2001 From: Myles Borins Date: Mon, 18 Mar 2019 16:22:19 -0400 Subject: [PATCH] fixup: s/type/entry-type impl --- doc/node.1 | 6 +++--- lib/internal/errors.js | 10 +++++----- lib/internal/main/repl.js | 2 +- lib/internal/modules/esm/default_resolve.js | 4 ++-- lib/internal/process/esm_loader.js | 2 +- src/node_options.cc | 5 +++-- test/es-module/test-esm-no-extension.js | 2 +- test/es-module/test-esm-type-flag-errors.js | 16 ++++++++-------- test/es-module/test-esm-type-flag.mjs | 2 +- test/parallel/test-cli-syntax-piped-bad.js | 4 ++-- test/parallel/test-cli-syntax-piped-good.js | 4 ++-- 11 files changed, 29 insertions(+), 28 deletions(-) diff --git a/doc/node.1 b/doc/node.1 index 8b5560b1f1..2b742c4e3a 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -119,6 +119,9 @@ Enable FIPS-compliant crypto at startup. Requires Node.js to be built with .Sy ./configure --openssl-fips . . +.It Fl -entry-type Ns = Ns Ar type +Set the top-level module resolution type. +. .It Fl -experimental-modules Enable experimental ES module support and caching modules. . @@ -280,9 +283,6 @@ Print stack traces for process warnings (including deprecations). .It Fl -track-heap-objects Track heap object allocations for heap snapshots. . -.It Fl -type Ns = Ns Ar type -Set the top-level module resolution type. -. .It Fl -use-bundled-ca , Fl -use-openssl-ca Use bundled Mozilla CA store as supplied by current Node.js version or use OpenSSL's default CA store. The default store is selectable at build-time. diff --git a/lib/internal/errors.js b/lib/internal/errors.js index 4dd61ffd69..30e809a9ac 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -784,7 +784,7 @@ E('ERR_INVALID_PROTOCOL', E('ERR_INVALID_REPL_EVAL_CONFIG', 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL', TypeError); E('ERR_INVALID_REPL_TYPE', - 'Cannot specify --type for REPL', TypeError); + 'Cannot specify --entry-type for REPL', TypeError); E('ERR_INVALID_RETURN_PROPERTY', (input, name, prop, value) => { return `Expected a valid ${input} to be returned for the "${prop}" from the` + ` "${name}" function but got ${value}.`; @@ -816,7 +816,7 @@ E('ERR_INVALID_SYNC_FORK_INPUT', E('ERR_INVALID_THIS', 'Value of "this" must be of type %s', TypeError); E('ERR_INVALID_TUPLE', '%s must be an iterable %s tuple', TypeError); E('ERR_INVALID_TYPE_FLAG', - 'Type flag must be one of "module", "commonjs". Received --type=%s', + 'Type flag must be one of "module", "commonjs". Received --entry-type=%s', TypeError); E('ERR_INVALID_URI', 'URI malformed', URIError); E('ERR_INVALID_URL', 'Invalid URL: %s', TypeError); @@ -958,12 +958,12 @@ E('ERR_TRANSFORM_WITH_LENGTH_0', E('ERR_TTY_INIT_FAILED', 'TTY initialization failed', SystemError); E('ERR_TYPE_MISMATCH', (filename, ext, typeFlag, conflict) => { const typeString = - typeFlag === 'module' ? '--type=module' : '--type=commonjs'; - // --type mismatches file extension + typeFlag === 'module' ? '--entry-type=module' : '--entry-type=commonjs'; + // --entry-type mismatches file extension if (conflict === 'extension') return `Extension ${ext} is not supported for ` + `${typeString} loading ${filename}`; - // --type mismatches package.json "type" + // --entry-type mismatches package.json "type" else if (conflict === 'scope') return `Cannot use ${typeString} because nearest parent package.json ` + ((typeFlag === 'module') ? diff --git a/lib/internal/main/repl.js b/lib/internal/main/repl.js index 7656af46a3..cc15cda7fd 100644 --- a/lib/internal/main/repl.js +++ b/lib/internal/main/repl.js @@ -15,7 +15,7 @@ const { ERR_INVALID_REPL_TYPE } = require('internal/errors').codes; prepareMainThreadExecution(); -// --type flag not supported in REPL +// --entry-type flag not supported in REPL if (require('internal/process/esm_loader').typeFlag) { throw ERR_INVALID_REPL_TYPE(); } diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index 3abf4e04a9..7b6b6fd4a3 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -81,14 +81,14 @@ function resolve(specifier, parentURL) { let format = extMap[ext]; if (isMain && asyncESM.typeFlag) { - // Conflict between explicit extension (.mjs, .cjs) and --type + // Conflict between explicit extension (.mjs, .cjs) and --entry-type if (ext === '.cjs' && asyncESM.typeFlag === 'module' || ext === '.mjs' && asyncESM.typeFlag === 'commonjs') { throw new ERR_TYPE_MISMATCH( fileURLToPath(url), ext, asyncESM.typeFlag, 'extension'); } - // Conflict between package scope type and --type + // Conflict between package scope type and --entry-type if (ext === '.js') { if (type === TYPE_MODULE && asyncESM.typeFlag === 'commonjs' || type === TYPE_COMMONJS && asyncESM.typeFlag === 'module') { diff --git a/lib/internal/process/esm_loader.js b/lib/internal/process/esm_loader.js index 803c854d9a..b5475769c7 100644 --- a/lib/internal/process/esm_loader.js +++ b/lib/internal/process/esm_loader.js @@ -9,7 +9,7 @@ const { } = require('internal/errors').codes; const { emitExperimentalWarning } = require('internal/util'); -const type = require('internal/options').getOptionValue('--type'); +const type = require('internal/options').getOptionValue('--entry-type'); if (type && type !== 'commonjs' && type !== 'module') throw new ERR_INVALID_TYPE_FLAG(type); exports.typeFlag = type; diff --git a/src/node_options.cc b/src/node_options.cc index fc4eb985e2..ef240ef2c9 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -108,7 +108,8 @@ void EnvironmentOptions::CheckOptions(std::vector* errors) { } if (!module_type.empty() && !experimental_modules) { - errors->push_back("--type requires --experimental-modules be enabled"); + errors->push_back("--entry-type requires" + "--experimental-modules be enabled"); } if (experimental_json_modules && !experimental_modules) { @@ -332,7 +333,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "show stack traces on process warnings", &EnvironmentOptions::trace_warnings, kAllowedInEnvironment); - AddOption("--type", + AddOption("--entry-type", "top-level module type name", &EnvironmentOptions::module_type, kAllowedInEnvironment); diff --git a/test/es-module/test-esm-no-extension.js b/test/es-module/test-esm-no-extension.js index 36848eed0e..3e9ffb2bbc 100644 --- a/test/es-module/test-esm-no-extension.js +++ b/test/es-module/test-esm-no-extension.js @@ -12,7 +12,7 @@ const entry = fixtures.path('/es-modules/noext-esm'); const child = spawn(process.execPath, [ '--experimental-modules', - '--type=module', + '--entry-type=module', entry ]); diff --git a/test/es-module/test-esm-type-flag-errors.js b/test/es-module/test-esm-type-flag-errors.js index 4b75eabc0c..bbdd140482 100644 --- a/test/es-module/test-esm-type-flag-errors.js +++ b/test/es-module/test-esm-type-flag-errors.js @@ -19,16 +19,16 @@ expect('', packageTypeModuleMain, 'package-type-module'); expect('', packageTypeCommonJsMain, 'package-type-commonjs'); expect('', packageWithoutTypeMain, 'package-without-type'); -// Check that running with --type and no package.json "type" works -expect('--type=commonjs', packageWithoutTypeMain, 'package-without-type'); -expect('--type=module', packageWithoutTypeMain, 'package-without-type'); +// Check that running with --entry-type and no package.json "type" works +expect('--entry-type=commonjs', packageWithoutTypeMain, 'package-without-type'); +expect('--entry-type=module', packageWithoutTypeMain, 'package-without-type'); -// Check that running with conflicting --type flags throws errors -expect('--type=commonjs', mjsFile, 'ERR_TYPE_MISMATCH', true); -expect('--type=module', cjsFile, 'ERR_TYPE_MISMATCH', true); -expect('--type=commonjs', packageTypeModuleMain, +// Check that running with conflicting --entry-type flags throws errors +expect('--entry-type=commonjs', mjsFile, 'ERR_TYPE_MISMATCH', true); +expect('--entry-type=module', cjsFile, 'ERR_TYPE_MISMATCH', true); +expect('--entry-type=commonjs', packageTypeModuleMain, 'ERR_TYPE_MISMATCH', true); -expect('--type=module', packageTypeCommonJsMain, +expect('--entry-type=module', packageTypeCommonJsMain, 'ERR_TYPE_MISMATCH', true); function expect(opt = '', inputFile, want, wantsError = false) { diff --git a/test/es-module/test-esm-type-flag.mjs b/test/es-module/test-esm-type-flag.mjs index cf91580490..2f5d0b626a 100644 --- a/test/es-module/test-esm-type-flag.mjs +++ b/test/es-module/test-esm-type-flag.mjs @@ -1,4 +1,4 @@ -// Flags: --experimental-modules --type=module +// Flags: --experimental-modules --entry-type=module /* eslint-disable node-core/required-modules */ import cjs from '../fixtures/baz.js'; import '../common/index.mjs'; diff --git a/test/parallel/test-cli-syntax-piped-bad.js b/test/parallel/test-cli-syntax-piped-bad.js index ba93e13038..f342a7834f 100644 --- a/test/parallel/test-cli-syntax-piped-bad.js +++ b/test/parallel/test-cli-syntax-piped-bad.js @@ -34,12 +34,12 @@ syntaxArgs.forEach(function(arg) { assert.strictEqual(c.status, 1); }); -// Check --type=module +// Check --entry-type=module syntaxArgs.forEach(function(arg) { const stdin = 'export var p = 5; var foo bar;'; const c = spawnSync( node, - ['--experimental-modules', '--type=module', '--no-warnings', arg], + ['--experimental-modules', '--entry-type=module', '--no-warnings', arg], { encoding: 'utf8', input: stdin } ); diff --git a/test/parallel/test-cli-syntax-piped-good.js b/test/parallel/test-cli-syntax-piped-good.js index 8ee11226d9..b2b02172cb 100644 --- a/test/parallel/test-cli-syntax-piped-good.js +++ b/test/parallel/test-cli-syntax-piped-good.js @@ -25,12 +25,12 @@ syntaxArgs.forEach(function(arg) { assert.strictEqual(c.status, 0); }); -// Check --type=module +// Check --entry-type=module syntaxArgs.forEach(function(arg) { const stdin = 'export var p = 5; throw new Error("should not get run");'; const c = spawnSync( node, - ['--experimental-modules', '--no-warnings', '--type=module', arg], + ['--experimental-modules', '--no-warnings', '--entry-type=module', arg], { encoding: 'utf8', input: stdin } );