diff options
author | Guy Bedford <guybedford@gmail.com> | 2020-06-28 08:09:24 +0300 |
---|---|---|
committer | Guy Bedford <guybedford@gmail.com> | 2020-07-10 05:19:35 +0300 |
commit | 1237955d4149ce0d9445ca707bc824322fc8c15c (patch) | |
tree | f1511ef9cde4ad416e7431f0cb955664da529b77 /lib/internal/errors.js | |
parent | 1198aebd2db710b22bfed003edcf8cca2db8a174 (diff) |
module: package "imports" field
PR-URL: https://github.com/nodejs/node/pull/34117
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Diffstat (limited to 'lib/internal/errors.js')
-rw-r--r-- | lib/internal/errors.js | 64 |
1 files changed, 23 insertions, 41 deletions
diff --git a/lib/internal/errors.js b/lib/internal/errors.js index bda1f3f4711..e99ae7c1c32 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -20,7 +20,6 @@ const { NumberIsInteger, ObjectDefineProperty, ObjectKeys, - StringPrototypeSlice, StringPrototypeStartsWith, Symbol, SymbolFor, @@ -1111,16 +1110,9 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError); E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError); E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError); E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError); -E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => { - if (subpath === undefined) { - return `Invalid package name '${pkgPath}' imported from ${base}`; - } else if (base === undefined) { - assert(subpath !== '.'); - return `Package subpath '${subpath}' is not a valid module request for ` + - `the "exports" resolution of ${pkgPath}${sep}package.json`; - } - return `Package subpath '${subpath}' is not a valid module request for ` + - `the "exports" resolution of ${pkgPath} imported from ${base}`; +E('ERR_INVALID_MODULE_SPECIFIER', (request, reason, base = undefined) => { + return `Invalid module "${request}" ${reason}${base ? + ` imported from ${base}` : ''}`; }, TypeError); E('ERR_INVALID_OPT_VALUE', (name, value) => `The value "${String(value)}" is invalid for option "${name}"`, @@ -1134,31 +1126,20 @@ E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => { return `Invalid JSON in ${path} imported from ${message}`; }, Error); E('ERR_INVALID_PACKAGE_TARGET', - (pkgPath, key, subpath, target, base = undefined) => { - const relError = typeof target === 'string' && + (pkgPath, key, target, isImport = false, base = undefined) => { + const relError = typeof target === 'string' && !isImport && target.length && !StringPrototypeStartsWith(target, './'); - if (key === null) { - if (subpath !== '') { - return `Invalid "exports" target ${JSONStringify(target)} defined ` + - `for '${subpath}' in the package config ${pkgPath} imported from ` + - `${base}.${relError ? '; targets must start with "./"' : ''}`; - } - return `Invalid "exports" main target ${target} defined in the ` + - `package config ${pkgPath} imported from ${base}${relError ? - '; targets must start with "./"' : ''}`; - } else if (key === '.') { + if (key === '.') { + assert(isImport === false); return `Invalid "exports" main target ${JSONStringify(target)} defined ` + - `in the package config ${pkgPath}${sep}package.json${relError ? - '; targets must start with "./"' : ''}`; - } else if (relError) { - return `Invalid "exports" target ${JSONStringify(target)} defined for '${ - StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` + - `package config ${pkgPath}${sep}package.json; ` + - 'targets must start with "./"'; + `in the package config ${pkgPath}package.json${base ? + ` imported from ${base}` : ''}${relError ? + '; targets must start with "./"' : ''}`; } - return `Invalid "exports" target ${JSONStringify(target)} defined for '${ - StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` + - `package config ${pkgPath}${sep}package.json`; + return `Invalid "${isImport ? 'imports' : 'exports'}" target ${ + JSONStringify(target)} defined for '${key}' in the package config ${ + pkgPath}package.json${base ? ` imported from ${base}` : ''}${relError ? + '; targets must start with "./"' : ''}`; }, Error); E('ERR_INVALID_PERFORMANCE_MARK', 'The "%s" performance mark has not been set', Error); @@ -1307,15 +1288,16 @@ E('ERR_OUT_OF_RANGE', msg += ` It must be ${range}. Received ${received}`; return msg; }, RangeError); +E('ERR_PACKAGE_IMPORT_NOT_DEFINED', (specifier, packagePath, base) => { + return `Package import specifier "${specifier}" is not defined${packagePath ? + ` in package ${packagePath}package.json` : ''} imported from ${base}`; +}, TypeError); E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => { - if (subpath === '.') { - return `No "exports" main resolved in ${pkgPath}${sep}package.json`; - } else if (base === undefined) { - return `Package subpath '${subpath}' is not defined by "exports" in ${ - pkgPath}${sep}package.json`; - } + if (subpath === '.') + return `No "exports" main defined in ${pkgPath}package.json${base ? + ` imported from ${base}` : ''}`; return `Package subpath '${subpath}' is not defined by "exports" in ${ - pkgPath} imported from ${base}`; + pkgPath}package.json${base ? ` imported from ${base}` : ''}`; }, Error); E('ERR_QUICCLIENTSESSION_FAILED', 'Failed to create a new QuicClientSession: %s', Error); @@ -1486,7 +1468,7 @@ E('ERR_UNKNOWN_FILE_EXTENSION', E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError); E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError); E('ERR_UNSUPPORTED_DIR_IMPORT', "Directory import '%s' is not supported " + -'resolving ES modules, imported from %s', Error); +'resolving ES modules imported from %s', Error); E('ERR_UNSUPPORTED_ESM_URL_SCHEME', 'Only file and data URLs are supported ' + 'by the default ESM loader', Error); |