diff options
author | Geoffrey Booth <webmaster@geoffreybooth.com> | 2019-04-15 10:29:56 -0700 |
---|---|---|
committer | Myles Borins <mylesborins@google.com> | 2019-04-16 12:41:59 -0400 |
commit | 96e46d37c458ab3d6cf1148a471cfd1aac7aafe6 (patch) | |
tree | a037559ded34f2450af5c9a41c74463bb89cd56c /lib/internal/modules/esm | |
parent | f85ef977e6e9f0f655a8ff6aa4796d80ae94010e (diff) | |
download | android-node-v8-96e46d37c458ab3d6cf1148a471cfd1aac7aafe6.tar.gz android-node-v8-96e46d37c458ab3d6cf1148a471cfd1aac7aafe6.tar.bz2 android-node-v8-96e46d37c458ab3d6cf1148a471cfd1aac7aafe6.zip |
esm: replace --entry-type with --input-type
New flag is for string input only
PR-URL: https://github.com/nodejs/node/pull/27184
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'lib/internal/modules/esm')
-rw-r--r-- | lib/internal/modules/esm/default_resolve.js | 32 |
1 files changed, 11 insertions, 21 deletions
diff --git a/lib/internal/modules/esm/default_resolve.js b/lib/internal/modules/esm/default_resolve.js index 8b8c5a2b5a..a83cf9c675 100644 --- a/lib/internal/modules/esm/default_resolve.js +++ b/lib/internal/modules/esm/default_resolve.js @@ -9,12 +9,12 @@ const { getOptionValue } = require('internal/options'); const preserveSymlinks = getOptionValue('--preserve-symlinks'); const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main'); const experimentalJsonModules = getOptionValue('--experimental-json-modules'); -const typeFlag = getOptionValue('--entry-type'); +const typeFlag = getOptionValue('--input-type'); const { resolve: moduleWrapResolve, getPackageType } = internalBinding('module_wrap'); const { pathToFileURL, fileURLToPath } = require('internal/url'); -const { ERR_ENTRY_TYPE_MISMATCH, +const { ERR_INPUT_TYPE_NOT_ALLOWED, ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes; const { @@ -25,7 +25,7 @@ const { const realpathCache = new SafeMap(); // const TYPE_NONE = 0; -const TYPE_COMMONJS = 1; +// const TYPE_COMMONJS = 1; const TYPE_MODULE = 2; const extensionFormatMap = { @@ -86,26 +86,16 @@ function resolve(specifier, parentURL) { let format = extMap[ext]; if (isMain && typeFlag) { - // Conflict between explicit extension (.mjs, .cjs) and --entry-type - if (ext === '.cjs' && typeFlag === 'module' || - ext === '.mjs' && typeFlag === 'commonjs') { - throw new ERR_ENTRY_TYPE_MISMATCH( - fileURLToPath(url), ext, typeFlag, 'extension'); - } - - // Conflict between package scope type and --entry-type - if (ext === '.js') { - if (type === TYPE_MODULE && typeFlag === 'commonjs' || - type === TYPE_COMMONJS && typeFlag === 'module') { - throw new ERR_ENTRY_TYPE_MISMATCH( - fileURLToPath(url), ext, typeFlag, 'scope'); - } - } + // This is the initial entry point to the program, and --input-type has + // been passed as an option; but --input-type can only be used with + // --eval, --print or STDIN string input. It is not allowed with file + // input, to avoid user confusion over how expansive the effect of the + // flag should be (i.e. entry point only, package scope surrounding the + // entry point, etc.). + throw new ERR_INPUT_TYPE_NOT_ALLOWED(); } if (!format) { - if (isMain && typeFlag) - format = typeFlag; - else if (isMain) + if (isMain) format = type === TYPE_MODULE ? 'module' : 'commonjs'; else throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url), |