Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ Note: This function is directly invoked by the CommonJS resolution algorithm.
Note: This function is directly invoked by the CommonJS resolution algorithm.

> 1. Assert: _specifier_ begins with _"#"_.
> 2. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then
> 2. If _specifier_ is exactly equal to _"#"_, then
> 1. Throw an _Invalid Module Specifier_ error.
> 3. Let _packageURL_ be the result of **LOOKUP\_PACKAGE\_SCOPE**(_parentURL_).
> 4. If _packageURL_ is not **null**, then
Expand Down
4 changes: 4 additions & 0 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ can be written:
added:
- v14.6.0
- v12.19.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/60864
description: Allow subpath imports that start with `#/`.
-->

In addition to the [`"exports"`][] field, there is a package `"imports"` field
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,7 @@ function patternKeyCompare(a, b) {
* @returns {URL} The resolved import URL.
*/
function packageImportsResolve(name, base, conditions) {
if (name === '#' || StringPrototypeStartsWith(name, '#/') ||
StringPrototypeEndsWith(name, '/')) {
if (name === '#' || StringPrototypeEndsWith(name, '/')) {
const reason = 'is not a valid internal imports specifier name';
throw new ERR_INVALID_MODULE_SPECIFIER(name, reason, fileURLToPath(base));
}
Expand Down
6 changes: 4 additions & 2 deletions test/es-module/test-esm-imports.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const { requireImport, importImport } = importer;
const internalImports = new Map([
// Base case
['#test', maybeWrapped({ default: 'test' })],
// Root wildcard import
['#/foo', maybeWrapped({ default: 'foo' })],
// Explicit #/ mapping
['#/initialslash', maybeWrapped({ default: 'test' })],
// import / require conditions
['#branch', maybeWrapped({ default: isRequire ? 'requirebranch' : 'importbranch' })],
// Subpath imports
Expand Down Expand Up @@ -64,8 +68,6 @@ const { requireImport, importImport } = importer;
['#external/subpath/x%5Cy', 'must not include encoded "/" or "\\"'],
// Target must have a name
['#', '#'],
// Initial slash target must have a leading name
['#/initialslash', '#/initialslash'],
// Percent-encoded target paths
['#encodedslash', 'must not include encoded "/" or "\\"'],
['#encodedbackslash', 'must not include encoded "/" or "\\"'],
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es-modules/pkgimports/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"imports": {
"#/*": "./src/*.js",
"#branch": {
"import": "./importbranch.js",
"require": "./requirebranch.js"
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/es-modules/pkgimports/src/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'foo';
Loading