@@ -1068,62 +1068,64 @@ The resolver can throw the following errors:
10681068> 1. Note: _specifier_ is now a bare specifier.
10691069> 2. Set _resolved_ the result of
10701070> ** PACKAGE \_RESOLVE ** (_specifier_, _parentURL_).
1071- > 6. If _resolved_ contains any percent encodings of _" /" _ or _" \\ " _ (_" %2f" _
1072- > and _" %5C" _ respectively), then
1073- > 1. Throw an _Invalid Module Specifier_ error.
1074- > 7. If the file at _resolved_ is a directory, then
1075- > 1. Throw an _Unsupported Directory Import_ error.
1076- > 8. If the file at _resolved_ does not exist, then
1077- > 1. Throw a _Module Not Found_ error.
1078- > 9. Set _resolved_ to the real path of _resolved_.
1079- > 10. Let _format_ be the result of ** ESM \_FORMAT ** (_resolved_).
1080- > 11. Load _resolved_ as module format, _format_.
1081- > 12. Return _resolved_.
1071+ > 6. Let _format_ be ** undefined ** .
1072+ > 7. If _resolved_ is a _" file:" _ URL , then
1073+ > 1. If _resolved_ contains any percent encodings of _" /" _ or _" \\ " _ (_" %2F" _
1074+ > and _" %5C" _ respectively), then
1075+ > 1. Throw an _Invalid Module Specifier_ error.
1076+ > 2. If the file at _resolved_ is a directory, then
1077+ > 1. Throw an _Unsupported Directory Import_ error.
1078+ > 3. If the file at _resolved_ does not exist, then
1079+ > 1. Throw a _Module Not Found_ error.
1080+ > 4. Set _resolved_ to the real path of _resolved_, maintaining the
1081+ > same URL querystring and fragment components.
1082+ > 5. Set _format_ to the result of ** ESM \_FILE \_FORMAT ** (_resolved_).
1083+ > 8. Otherwise,
1084+ > 1. Set _format_ the module format of the content type associated with the
1085+ > URL _resolved_.
1086+ > 9. Load _resolved_ as module format, _format_.
10821087
10831088** PACKAGE \_RESOLVE ** (_packageSpecifier_, _parentURL_)
10841089
10851090> 1. Let _packageName_ be ** undefined ** .
10861091> 2. If _packageSpecifier_ is an empty string, then
10871092> 1. Throw an _Invalid Module Specifier_ error.
1088- > 3. If _packageSpecifier_ does not start with _" @" _, then
1093+ > 3. If _packageSpecifier_ is a Node .js builtin module name, then
1094+ > 1. Return the string _" node:" _ concatenated with _packageSpecifier_.
1095+ > 4. If _packageSpecifier_ does not start with _" @" _, then
10891096> 1. Set _packageName_ to the substring of _packageSpecifier_ until the first
10901097> _" /" _ separator or the end of the string.
1091- > 4 . Otherwise,
1098+ > 5 . Otherwise,
10921099> 1. If _packageSpecifier_ does not contain a _" /" _ separator, then
10931100> 1. Throw an _Invalid Module Specifier_ error.
10941101> 2. Set _packageName_ to the substring of _packageSpecifier_
10951102> until the second _" /" _ separator or the end of the string.
1096- > 5 . If _packageName_ starts with _" ." _ or contains _" \\ " _ or _" %" _, then
1103+ > 6 . If _packageName_ starts with _" ." _ or contains _" \\ " _ or _" %" _, then
10971104> 1. Throw an _Invalid Module Specifier_ error.
1098- > 6 . Let _packageSubpath_ be _" ." _ concatenated with the substring of
1105+ > 7 . Let _packageSubpath_ be _" ." _ concatenated with the substring of
10991106> _packageSpecifier_ from the position at the length of _packageName_.
1100- > 7. Let _selfUrl_ be the result of
1107+ > 8. If _packageSubpath_ ends in _" /" _, then
1108+ > 1. Throw an _Invalid Module Specifier_ error.
1109+ > 9. Let _selfUrl_ be the result of
11011110> ** PACKAGE \_SELF \_RESOLVE ** (_packageName_, _packageSubpath_, _parentURL_).
1102- > 8. If _selfUrl_ is not ** undefined ** , return _selfUrl_.
1103- > 9. If _packageSubpath_ is _" ." _ and _packageName_ is a Node .js builtin
1104- > module , then
1105- > 1. Return the string _" node:" _ concatenated with _packageSpecifier_.
1106- > 10. While _parentURL_ is not the file system root,
1107- > 1. Let _packageURL_ be the URL resolution of _" node\_ modules/" _
1108- > concatenated with _packageSpecifier_, relative to _parentURL_.
1109- > 2. Set _parentURL_ to the parent folder URL of _parentURL_.
1110- > 3. If the folder at _packageURL_ does not exist, then
1111- > 1. Set _parentURL_ to the parent URL path of _parentURL_.
1112- > 2. Continue the next loop iteration.
1113- > 4. Let _pjson_ be the result of ** READ \_PACKAGE \_JSON ** (_packageURL_).
1114- > 5. If _pjson_ is not ** null ** and _pjson_ ._exports_ is not ** null ** or
1115- > ** undefined ** , then
1116- > 1. Let _exports_ be _pjson .exports_ .
1117- > 2. Return the _resolved_ destructured value of the result of
1118- > ** PACKAGE \_EXPORTS \_RESOLVE ** (_packageURL_, _packageSubpath_,
1119- > _pjson .exports_ , _defaultConditions_).
1120- > 6. Otherwise, if _packageSubpath_ is equal to _" ." _, then
1121- > 1. Return the result applying the legacy ** LOAD \_AS \_DIRECTORY **
1122- > CommonJS resolver to _packageURL_, throwing a _Module Not Found_
1123- > error for no resolution.
1124- > 7. Otherwise,
1125- > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
1126- > 11. Throw a _Module Not Found_ error.
1111+ > 10. If _selfUrl_ is not ** undefined ** , return _selfUrl_.
1112+ > 11. While _parentURL_ is not the file system root,
1113+ > 1. Let _packageURL_ be the URL resolution of _" node_modules/" _
1114+ > concatenated with _packageSpecifier_, relative to _parentURL_.
1115+ > 2. Set _parentURL_ to the parent folder URL of _parentURL_.
1116+ > 3. If the folder at _packageURL_ does not exist, then
1117+ > 1. Continue the next loop iteration.
1118+ > 4. Let _pjson_ be the result of ** READ \_PACKAGE \_JSON ** (_packageURL_).
1119+ > 5. If _pjson_ is not ** null ** and _pjson_ ._exports_ is not ** null ** or
1120+ > ** undefined ** , then
1121+ > 1. Return the result of ** PACKAGE \_EXPORTS \_RESOLVE ** (_packageURL_,
1122+ > _packageSubpath_, _pjson .exports_ , _defaultConditions_).
1123+ > 6. Otherwise, if _packageSubpath_ is equal to _" ." _, then
1124+ > 1. If _pjson .main_ is a string, then
1125+ > 1. Return the URL resolution of _main_ in _packageURL_.
1126+ > 7. Otherwise,
1127+ > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
1128+ > 12. Throw a _Module Not Found_ error.
11271129
11281130** PACKAGE \_SELF \_RESOLVE ** (_packageName_, _packageSubpath_, _parentURL_)
11291131
@@ -1253,18 +1255,20 @@ _internal_, _conditions_)
12531255> _" /" _ and is not a valid URL , then
12541256> 1. If _pattern_ is ** true ** , then
12551257> 1. Return ** PACKAGE \_RESOLVE ** (_target_ with every instance of
1256- > _" \* " _ replaced by _subpath_, _packageURL_ + _" /" _)\_ .
1258+ > _" \* " _ replaced by _subpath_, _packageURL_ + _" /" _).
12571259> 2. Return ** PACKAGE \_RESOLVE ** (_target_ + _subpath_,
1258- > _packageURL_ + _" /" _)\ _.
1260+ > _packageURL_ + _" /" _)_.
12591261> 2. Otherwise, throw an _Invalid Package Target_ error.
12601262> 3. If _target_ split on _" /" _ or _" \\ " _ contains any _" ." _, _" .." _ or
1261- > _" node\_ modules" _ segments after the first segment, throw an
1262- > _Invalid Package Target_ error.
1263+ > _" node\_ modules" _ segments after the first segment, case insensitive and
1264+ > including percent encoded variants, throw an _Invalid Package Target_
1265+ > error.
12631266> 4. Let _resolvedTarget_ be the URL resolution of the concatenation of
12641267> _packageURL_ and _target_.
12651268> 5. Assert: _resolvedTarget_ is contained in _packageURL_.
12661269> 6. If _subpath_ split on _" /" _ or _" \\ " _ contains any _" ." _, _" .." _ or
1267- > _" node\_ modules" _ segments, throw an _Invalid Module Specifier_ error.
1270+ > _" node\_ modules" _ segments, case insensitive and including percent
1271+ > encoded variants, throw an _Invalid Module Specifier_ error.
12681272> 7. If _pattern_ is ** true ** , then
12691273> 1. Return the URL resolution of _resolvedTarget_ with every instance of
12701274> _" \* " _ replaced with _subpath_.
@@ -1297,19 +1301,21 @@ _internal_, _conditions_)
12971301> 4. Otherwise, if _target_ is _null_, return ** null ** .
12981302> 5. Otherwise throw an _Invalid Package Target_ error.
12991303
1300- ** ESM \_FORMAT ** (_url_)
1304+ ** ESM \_FILE \ _FORMAT ** (_url_)
13011305
13021306> 1. Assert: _url_ corresponds to an existing file.
13031307> 2. Let _pjson_ be the result of ** READ \_PACKAGE \_SCOPE ** (_url_).
13041308> 3. If _url_ ends in _" .mjs" _, then
13051309> 1. Return _" module" _.
13061310> 4. If _url_ ends in _" .cjs" _, then
13071311> 1. Return _" commonjs" _.
1308- > 5. If _pjson? .type_ exists and is _" module" _, then
1312+ > 5. If _url_ ends in _" .json" _, then
1313+ > 1. Return _" json" _.
1314+ > 6. If _pjson? .type_ exists and is _" module" _, then
13091315> 1. If _url_ ends in _" .js" _, then
13101316> 1. Return _" module" _.
13111317> 2. Throw an _Unsupported File Extension_ error.
1312- > 6 . Otherwise,
1318+ > 7 . Otherwise,
13131319> 1. Throw an _Unsupported File Extension_ error.
13141320
13151321** READ \_PACKAGE \_SCOPE ** (_url_)
0 commit comments