| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1bde0ef commit b3cfb55
66 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1148,6 +1148,27 @@ added: | |||
| 1148 | 1148 | ||
| 1149 | 1149 | Enable experimental support for the network inspection with Chrome DevTools. | |
| 1150 | 1150 | ||
| 1151 | + ### `--experimental-package-map=<path>` | ||
| 1152 | + | ||
| 1153 | + <!-- YAML | ||
| 1154 | + added: REPLACEME | ||
| 1155 | + --> | ||
| 1156 | + | ||
| 1157 | + > Stability: 1 - Experimental | ||
| 1158 | + | ||
| 1159 | + Enable experimental package map resolution. The `path` argument specifies the | ||
| 1160 | + location of a JSON configuration file that defines package resolution mappings. | ||
| 1161 | + | ||
| 1162 | + ```bash | ||
| 1163 | + node --experimental-package-map=./package-map.json app.js | ||
| 1164 | + ``` | ||
| 1165 | + | ||
| 1166 | + When enabled, bare specifier resolution consults the package map for resolution. | ||
| 1167 | + This allows explicit control over which packages can import which dependencies. | ||
| 1168 | + | ||
| 1169 | + See [Package maps][] for details on the configuration file format and | ||
| 1170 | + resolution algorithm. | ||
| 1171 | + | ||
| 1151 | 1172 | ### `--experimental-print-required-tla` | |
| 1152 | 1173 | ||
| 1153 | 1174 | <!-- YAML | |
@@ -3579,6 +3600,7 @@ one is included in the list below. | |||
| 3579 | 3600 | * `--experimental-json-modules` | |
| 3580 | 3601 | * `--experimental-loader` | |
| 3581 | 3602 | * `--experimental-modules` | |
| 3603 | + * `--experimental-package-map` | ||
| 3582 | 3604 | * `--experimental-print-required-tla` | |
| 3583 | 3605 | * `--experimental-quic` | |
| 3584 | 3606 | * `--experimental-require-module` | |
@@ -4170,6 +4192,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12 | |||
| 4170 | 4192 | [Navigator API]: globals.md#navigator | |
| 4171 | 4193 | [Node.js issue tracker]: https://github.com/nodejs/node/issues | |
| 4172 | 4194 | [OSSL_PROVIDER-legacy]: https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html | |
| 4195 | + [Package maps]: packages.md#package-maps | ||
| 4173 | 4196 | [Permission Model]: permissions.md#permission-model | |
| 4174 | 4197 | [REPL]: repl.md | |
| 4175 | 4198 | [ScriptCoverage]: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2499,6 +2499,77 @@ A given value is out of the accepted range. | |||
| 2499 | 2499 | The `package.json` [`"imports"`][] field does not define the given internal | |
| 2500 | 2500 | package specifier mapping. | |
| 2501 | 2501 | ||
| 2502 | + <a id="ERR_PACKAGE_MAP_EXTERNAL_FILE"></a> | ||
| 2503 | + | ||
| 2504 | + ### `ERR_PACKAGE_MAP_EXTERNAL_FILE` | ||
| 2505 | + | ||
| 2506 | + <!-- YAML | ||
| 2507 | + added: REPLACEME | ||
| 2508 | + --> | ||
| 2509 | + | ||
| 2510 | + A module attempted to resolve a bare specifier using the [package map][], but | ||
| 2511 | + the importing file is not located within any package defined in the map. | ||
| 2512 | + | ||
| 2513 | + ```console | ||
| 2514 | + $ node --experimental-package-map=./package-map.json /tmp/script.js | ||
| 2515 | + Error [ERR_PACKAGE_MAP_EXTERNAL_FILE]: Cannot resolve "dep-a" from "/tmp/script.js": file is not within any package defined in /path/to/package-map.json | ||
| 2516 | + ``` | ||
| 2517 | + | ||
| 2518 | + To fix this error, ensure the importing file is inside one of the package | ||
| 2519 | + directories listed in the package map, or add a new package entry whose `url` | ||
| 2520 | + covers the importing file. | ||
| 2521 | + | ||
| 2522 | + <a id="ERR_PACKAGE_MAP_INVALID"></a> | ||
| 2523 | + | ||
| 2524 | + ### `ERR_PACKAGE_MAP_INVALID` | ||
| 2525 | + | ||
| 2526 | + <!-- YAML | ||
| 2527 | + added: REPLACEME | ||
| 2528 | + --> | ||
| 2529 | + | ||
| 2530 | + The [package map][] configuration file is invalid. This can occur when: | ||
| 2531 | + | ||
| 2532 | + * The file does not exist at the specified path. | ||
| 2533 | + * The file contains invalid JSON. | ||
| 2534 | + * The file is missing the required `packages` object. | ||
| 2535 | + * A package entry is missing the required `url` field. | ||
| 2536 | + * Two package entries have the same `url` value. | ||
| 2537 | + | ||
| 2538 | + ```console | ||
| 2539 | + $ node --experimental-package-map=./missing.json app.js | ||
| 2540 | + Error [ERR_PACKAGE_MAP_INVALID]: Invalid package map at "./missing.json": file not found | ||
| 2541 | + ``` | ||
| 2542 | + | ||
| 2543 | + <a id="ERR_PACKAGE_MAP_KEY_NOT_FOUND"></a> | ||
| 2544 | + | ||
| 2545 | + ### `ERR_PACKAGE_MAP_KEY_NOT_FOUND` | ||
| 2546 | + | ||
| 2547 | + <!-- YAML | ||
| 2548 | + added: REPLACEME | ||
| 2549 | + --> | ||
| 2550 | + | ||
| 2551 | + A package's `dependencies` object in the [package map][] references a package | ||
| 2552 | + key that is not defined in the `packages` object. | ||
| 2553 | + | ||
| 2554 | + ```json | ||
| 2555 | + { | ||
| 2556 | + "packages": { | ||
| 2557 | + "app": { | ||
| 2558 | + "url": "./app", | ||
| 2559 | + "dependencies": { | ||
| 2560 | + "foo": "nonexistent" | ||
| 2561 | + } | ||
| 2562 | + } | ||
| 2563 | + } | ||
| 2564 | + } | ||
| 2565 | + ``` | ||
| 2566 | + | ||
| 2567 | + In this example, `"nonexistent"` is referenced as a dependency target but not | ||
| 2568 | + defined in `packages`, which will throw this error. | ||
| 2569 | + | ||
| 2570 | + To fix this error, ensure all package keys referenced in `dependencies` values | ||
| 2571 | + are defined in the `packages` object. | ||
| 2572 | + | ||
| 2502 | 2573 | <a id="ERR_PACKAGE_PATH_NOT_EXPORTED"></a> | |
| 2503 | 2574 | ||
| 2504 | 2575 | ### `ERR_PACKAGE_PATH_NOT_EXPORTED` | |
@@ -4531,6 +4602,7 @@ An error occurred trying to allocate memory. This should never happen. | |||
| 4531 | 4602 | [domains]: domain.md | |
| 4532 | 4603 | [event emitter-based]: events.md#class-eventemitter | |
| 4533 | 4604 | [file descriptors]: https://en.wikipedia.org/wiki/File_descriptor | |
| 4605 | + [package map]: packages.md#package-maps | ||
| 4534 | 4606 | [relative URL]: https://url.spec.whatwg.org/#relative-url-string | |
| 4535 | 4607 | [self-reference a package using its name]: packages.md#self-referencing-a-package-using-its-name | |
| 4536 | 4608 | [special scheme]: https://url.spec.whatwg.org/#special-scheme | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -949,6 +949,12 @@ The default loader has the following properties | |||
| 949 | 949 | * Fails on unknown extensions for `file:` loading | |
| 950 | 950 | (supports only `.cjs`, `.js`, and `.mjs`) | |
| 951 | 951 | ||
| 952 | + When the [`--experimental-package-map`][] flag is enabled, bare specifier | ||
| 953 | + resolution first consults the package map configuration. If the importing | ||
| 954 | + module is within a mapped package and the specifier matches a declared | ||
| 955 | + dependency, the package map resolution takes precedence. See [Package maps][] | ||
| 956 | + for details. | ||
| 957 | + | ||
| 952 | 958 | ### Resolution algorithm | |
| 953 | 959 | ||
| 954 | 960 | The algorithm to load an ES module specifier is given through the | |
@@ -1312,13 +1318,15 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][]. | |||
| 1312 | 1318 | [Loading ECMAScript modules using `require()`]: modules.md#loading-ecmascript-modules-using-require | |
| 1313 | 1319 | [Module customization hooks]: module.md#customization-hooks | |
| 1314 | 1320 | [Node.js Module Resolution And Loading Algorithm]: #resolution-algorithm-specification | |
| 1321 | + [Package maps]: packages.md#package-maps | ||
| 1315 | 1322 | [Source Phase Imports]: https://github.com/tc39/proposal-source-phase-imports | |
| 1316 | 1323 | [Terminology]: #terminology | |
| 1317 | 1324 | [Text modules]: #text-modules | |
| 1318 | 1325 | [URL]: https://url.spec.whatwg.org/ | |
| 1319 | 1326 | [WebAssembly JS String Builtins Proposal]: https://github.com/WebAssembly/js-string-builtins | |
| 1320 | 1327 | [`"exports"`]: packages.md#exports | |
| 1321 | 1328 | [`"type"`]: packages.md#type | |
| 1329 | + [`--experimental-package-map`]: cli.md#--experimental-package-mappath | ||
| 1322 | 1330 | [`--input-type`]: cli.md#--input-typetype | |
| 1323 | 1331 | [`data:` URLs]: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/data | |
| 1324 | 1332 | [`export`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -353,8 +353,12 @@ require(X) from module at path Y | |||
| 353 | 353 | 4. If X begins with '#' | |
| 354 | 354 | a. LOAD_PACKAGE_IMPORTS(X, dirname(Y)) | |
| 355 | 355 | 5. LOAD_PACKAGE_SELF(X, dirname(Y)) | |
| 356 | - 6. LOAD_NODE_MODULES(X, dirname(Y)) | ||
| 357 | - 7. THROW "not found" | ||
| 356 | + 6. If a package map PACKAGE_MAP exists, | ||
| 357 | + a. Find the package ID for the package owning Y | ||
| 358 | + 1. Let PARENT_PACKAGE_ID be FIND_PACKAGE_ID(dirname(Y), PACKAGE_MAP) | ||
| 359 | + b. LOAD_PACKAGE_MAP(X, PARENT_PACKAGE_ID, PACKAGE_MAP) | ||
| 360 | + 7. LOAD_NODE_MODULES(X, dirname(Y)) | ||
| 361 | + 8. THROW "not found" | ||
| 358 | 362 | ||
| 359 | 363 | MAYBE_DETECT_AND_LOAD(X) | |
| 360 | 364 | 1. If X parses as a CommonJS module, load X as a CommonJS module. STOP. | |
@@ -398,9 +402,11 @@ LOAD_AS_DIRECTORY(X) | |||
| 398 | 402 | 2. LOAD_INDEX(X) | |
| 399 | 403 | ||
| 400 | 404 | LOAD_NODE_MODULES(X, START) | |
| 401 | - 1. let DIRS = NODE_MODULES_PATHS(START) | ||
| 402 | - 2. for each DIR in DIRS: | ||
| 403 | - a. LOAD_PACKAGE_EXPORTS(X, DIR) | ||
| 405 | + 1. Try to interpret X as a combination of NAME and SUBPATH where the name | ||
| 406 | + may have a @scope/ prefix and the subpath begins with a slash (`/`). | ||
| 407 | + 2. let DIRS = NODE_MODULES_PATHS(START) | ||
| 408 | + 3. for each DIR in DIRS: | ||
| 409 | + a. LOAD_PACKAGE_EXPORTS(SUBPATH, DIR/NAME) | ||
| 404 | 410 | b. LOAD_AS_FILE(DIR/X) | |
| 405 | 411 | c. LOAD_AS_DIRECTORY(DIR/X) | |
| 406 | 412 | ||
@@ -415,6 +421,25 @@ NODE_MODULES_PATHS(START) | |||
| 415 | 421 | d. let I = I - 1 | |
| 416 | 422 | 5. return DIRS + GLOBAL_FOLDERS | |
| 417 | 423 | ||
| 424 | + FIND_PACKAGE_ID(PATH, PACKAGE_MAP) | ||
| 425 | + 1. Find the PACKAGE_ID for the entry whose "path" is a parent directory of PATH | ||
| 426 | + 2. If multiple entries are found, THROW "ambiguous resolution" | ||
| 427 | + 3. If no entry was found, THROW "external file". | ||
| 428 | + 4. return PACKAGE_ID | ||
| 429 | + | ||
| 430 | + LOAD_PACKAGE_MAP(X, PARENT_PACKAGE_ID, PACKAGE_MAP) | ||
| 431 | + 1. Try to interpret X as a combination of NAME and SUBPATH where the name | ||
| 432 | + may have a @scope/ prefix and the subpath begins with a slash (`/`). | ||
| 433 | + 2. Find the package map entry for key PARENT_PACKAGE_ID | ||
| 434 | + 3. Look up NAME in the entry's "dependencies" map. | ||
| 435 | + 4. If NAME is not found, THROW "not found". | ||
| 436 | + 5. Let TARGET be PACKAGE_MAP.packages[dependencies[name]] | ||
| 437 | + 6. Let PACKAGE_PATH be the resolved path of TARGET. | ||
| 438 | + 7. LOAD_PACKAGE_EXPORTS(SUBPATH, PACKAGE_PATH) | ||
| 439 | + 8. LOAD_AS_FILE(PACKAGE_PATH/SUBPATH) | ||
| 440 | + 9. LOAD_AS_DIRECTORY(PACKAGE_PATH/SUBPATH) | ||
| 441 | + 10. THROW "not found" | ||
| 442 | + | ||
| 418 | 443 | LOAD_PACKAGE_IMPORTS(X, DIR) | |
| 419 | 444 | 1. Find the closest package scope SCOPE to DIR. | |
| 420 | 445 | 2. If no scope was found, return. | |
@@ -426,19 +451,15 @@ LOAD_PACKAGE_IMPORTS(X, DIR) | |||
| 426 | 451 | CONDITIONS) defined in the ESM resolver. | |
| 427 | 452 | 6. RESOLVE_ESM_MATCH(MATCH). | |
| 428 | 453 | ||
| 429 | - LOAD_PACKAGE_EXPORTS(X, DIR) | ||
| 430 | - 1. Try to interpret X as a combination of NAME and SUBPATH where the name | ||
| 431 | - may have a @scope/ prefix and the subpath begins with a slash (`/`). | ||
| 432 | - 2. If X does not match this pattern or DIR/NAME/package.json is not a file, | ||
| 433 | - return. | ||
| 434 | - 3. Parse DIR/NAME/package.json, and look for "exports" field. | ||
| 435 | - 4. If "exports" is null or undefined, return. | ||
| 436 | - 5. If `--no-require-module` is not enabled | ||
| 454 | + LOAD_PACKAGE_EXPORTS(SUBPATH, PACKAGE_DIR) | ||
| 455 | + 1. Parse PACKAGE_DIR/package.json, and look for "exports" field. | ||
| 456 | + 2. If "exports" is null or undefined, return. | ||
| 457 | + 3. If `--no-require-module` is not enabled | ||
| 437 | 458 | a. let CONDITIONS = ["node", "require", "module-sync"] | |
| 438 | 459 | b. Else, let CONDITIONS = ["node", "require"] | |
| 439 | - 6. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(DIR/NAME), "." + SUBPATH, | ||
| 460 | + 4. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(PACKAGE_DIR), "." + SUBPATH, | ||
| 440 | 461 | `package.json` "exports", CONDITIONS) defined in the ESM resolver. | |
| 441 | - 7. RESOLVE_ESM_MATCH(MATCH) | ||
| 462 | + 5. RESOLVE_ESM_MATCH(MATCH) | ||
| 442 | 463 | ||
| 443 | 464 | LOAD_PACKAGE_SELF(X, DIR) | |
| 444 | 465 | 1. Find the closest package scope SCOPE to DIR. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments