Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Commit

Permalink
fixup: s/type/entry-type impl
Browse files Browse the repository at this point in the history
  • Loading branch information
MylesBorins authored and dummygithubaccount committed Mar 21, 2019
1 parent d9fc7d7 commit 359afac
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 28 deletions.
6 changes: 3 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
.
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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') ?
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/main/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/process/esm_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* 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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-no-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
]);

Expand Down
16 changes: 8 additions & 8 deletions test/es-module/test-esm-type-flag-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-type-flag.mjs
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-cli-syntax-piped-bad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);

Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-cli-syntax-piped-good.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
);

Expand Down

0 comments on commit 359afac

Please sign in to comment.