GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — esm: port loader code to JS · lerouxb/node@605615e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • errors.js
    • modules/esm
      • get_format.js
      • resolve.js
  • src
    • env.h
    • module_wrap.cc
    • module_wrap.h
    • node_errors.h
  • test
    • es-module
      • test-esm-exports.mjs
    • message
      • esm_loader_not_found.out
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+43-16Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,29 +1078,50 @@ E('ERR_INVALID_FILE_URL_PATH', 'File URL path %s', TypeError);
10781078
E('ERR_INVALID_HANDLE_TYPE', 'This handle type cannot be sent', TypeError);
10791079
E('ERR_INVALID_HTTP_TOKEN', '%s must be a valid HTTP token ["%s"]', TypeError);
10801080
E('ERR_INVALID_IP_ADDRESS', 'Invalid IP address: %s', TypeError);
1081-
E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath) => {
1082-
assert(subpath !== '.');
1083-
return `Package subpath '${subpath}' is not a valid module request for the ` +
1084-
`"exports" resolution of ${pkgPath}${sep}package.json`;
1081+
E('ERR_INVALID_MODULE_SPECIFIER', (pkgPath, subpath, base = undefined) => {
1082+
if (subpath === undefined) {
1083+
return `Invalid package name '${pkgPath}' imported from ${base}`;
1084+
} else if (base === undefined) {
1085+
assert(subpath !== '.');
1086+
return `Package subpath '${subpath}' is not a valid module request for ` +
1087+
`the "exports" resolution of ${pkgPath}${sep}package.json`;
1088+
} else {
1089+
return `Package subpath '${subpath}' is not a valid module request for ` +
1090+
`the "exports" resolution of ${pkgPath} imported from ${base}`;
1091+
}
10851092
}, TypeError);
10861093
E('ERR_INVALID_OPT_VALUE', (name, value) =>
10871094
`The value "${String(value)}" is invalid for option "${name}"`,
10881095
TypeError,
10891096
RangeError);
10901097
E('ERR_INVALID_OPT_VALUE_ENCODING',
10911098
'The value "%s" is invalid for option "encoding"', TypeError);
1092-
E('ERR_INVALID_PACKAGE_CONFIG',
1093-
`Invalid package config %s${sep}package.json, %s`, Error);
1094-
E('ERR_INVALID_PACKAGE_TARGET', (pkgPath, key, subpath, target) => {
1095-
if (key === '.') {
1096-
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
1099+
E('ERR_INVALID_PACKAGE_CONFIG', (path, message, hasMessage = true) => {
1100+
if (hasMessage)
1101+
return `Invalid package config ${path}${sep}package.json, ${message}`;
1102+
else
1103+
return `Invalid JSON in ${path} imported from ${message}`;
1104+
}, Error);
1105+
E('ERR_INVALID_PACKAGE_TARGET',
1106+
(pkgPath, key, subpath, target, base = undefined) => {
1107+
if (key === null) {
1108+
if (subpath !== '') {
1109+
return `Invalid "exports" target ${JSONStringify(target)} defined ` +
1110+
`for '${subpath}' in the package config ${pkgPath} imported from ` +
1111+
base;
1112+
} else {
1113+
return `Invalid "exports" main target ${target} defined in the ` +
1114+
`package config ${pkgPath} imported from ${base}.`;
1115+
}
1116+
} else if (key === '.') {
1117+
return `Invalid "exports" main target ${JSONStringify(target)} defined ` +
10971118
`in the package config ${pkgPath}${sep}package.json`;
1098-
} else {
1099-
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
1100-
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
1119+
} else {
1120+
return `Invalid "exports" target ${JSONStringify(target)} defined for '${
1121+
StringPrototypeSlice(key, 0, -subpath.length || key.length)}' in the ` +
11011122
`package config ${pkgPath}${sep}package.json`;
1102-
}
1103-
}, Error);
1123+
}
1124+
}, Error);
11041125
E('ERR_INVALID_PERFORMANCE_MARK',
11051126
'The "%s" performance mark has not been set', Error);
11061127
E('ERR_INVALID_PROTOCOL',
@@ -1211,6 +1232,9 @@ E('ERR_MISSING_DYNAMIC_INSTANTIATE_HOOK',
12111232
'The ES Module loader may not return a format of \'dynamic\' when no ' +
12121233
'dynamicInstantiate function was provided', Error);
12131234
E('ERR_MISSING_OPTION', '%s is required', TypeError);
1235+
E('ERR_MODULE_NOT_FOUND', (path, base, type = 'package') => {
1236+
return `Cannot find ${type} '${path}' imported from ${base}`;
1237+
}, Error);
12141238
E('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times', Error);
12151239
E('ERR_NAPI_CONS_FUNCTION', 'Constructor must be a function', TypeError);
12161240
E('ERR_NAPI_INVALID_DATAVIEW_ARGS',
@@ -1245,12 +1269,15 @@ E('ERR_OUT_OF_RANGE',
12451269
msg += ` It must be ${range}. Received ${received}`;
12461270
return msg;
12471271
}, RangeError);
1248-
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath) => {
1272+
E('ERR_PACKAGE_PATH_NOT_EXPORTED', (pkgPath, subpath, base = undefined) => {
12491273
if (subpath === '.') {
12501274
return `No "exports" main resolved in ${pkgPath}${sep}package.json`;
1251-
} else {
1275+
} else if (base === undefined) {
12521276
return `Package subpath '${subpath}' is not defined by "exports" in ${
12531277
pkgPath}${sep}package.json`;
1278+
} else {
1279+
return `Package subpath '${subpath}' is not defined by "exports" in ${
1280+
pkgPath} imported from ${base}`;
12541281
}
12551282
}, Error);
12561283
E('ERR_REQUIRE_ESM',
Collapse file

‎lib/internal/modules/esm/get_format.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/get_format.js
+5-10Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
'use strict';
2-
2+
const { StringPrototypeStartsWith } = primordials;
33
const { extname } = require('path');
44
const { getOptionValue } = require('internal/options');
55

66
const experimentalJsonModules = getOptionValue('--experimental-json-modules');
77
const experimentalSpeciferResolution =
88
getOptionValue('--experimental-specifier-resolution');
99
const experimentalWasmModules = getOptionValue('--experimental-wasm-modules');
10-
const { getPackageType } = internalBinding('module_wrap');
10+
const { getPackageType } = require('internal/modules/esm/resolve');
1111
const { URL, fileURLToPath } = require('internal/url');
1212
const { ERR_UNKNOWN_FILE_EXTENSION } = require('internal/errors').codes;
1313

14-
// const TYPE_NONE = 0;
15-
// const TYPE_COMMONJS = 1;
16-
const TYPE_MODULE = 2;
17-
1814
const extensionFormatMap = {
1915
'__proto__': null,
2016
'.cjs': 'commonjs',
@@ -37,8 +33,8 @@ if (experimentalWasmModules)
3733
if (experimentalJsonModules)
3834
extensionFormatMap['.json'] = legacyExtensionFormatMap['.json'] = 'json';
3935

40-
function defaultGetFormat(url, context, defaultGetFormat) {
41-
if (url.startsWith('nodejs:')) {
36+
function defaultGetFormat(url, context, defaultGetFormatUnused) {
37+
if (StringPrototypeStartsWith(url, 'nodejs:')) {
4238
return { format: 'builtin' };
4339
}
4440
const parsed = new URL(url);
@@ -55,8 +51,7 @@ function defaultGetFormat(url, context, defaultGetFormat) {
5551
const ext = extname(parsed.pathname);
5652
let format;
5753
if (ext === '.js') {
58-
format = getPackageType(parsed.href) === TYPE_MODULE ?
59-
'module' : 'commonjs';
54+
format = getPackageType(parsed.href) === 'module' ? 'module' : 'commonjs';
6055
} else {
6156
format = extensionFormatMap[ext];
6257
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.