@@ -1076,59 +1076,63 @@ The resolver can throw the following errors:
10761076> 1. Note: _specifier_ is now a bare specifier.
10771077> 2. Set _resolved_ the result of
10781078> ** PACKAGE \_RESOLVE ** (_specifier_, _parentURL_).
1079- > 6. If _resolved_ contains any percent encodings of _" /" _ or _" \\ " _ (_" %2f" _
1080- > and _" %5C" _ respectively), then
1081- > 1. Throw an _Invalid Module Specifier_ error.
1082- > 7. If the file at _resolved_ is a directory, then
1083- > 1. Throw an _Unsupported Directory Import_ error.
1084- > 8. If the file at _resolved_ does not exist, then
1085- > 1. Throw a _Module Not Found_ error.
1086- > 9. Set _resolved_ to the real path of _resolved_.
1087- > 10. Let _format_ be the result of ** ESM \_FORMAT ** (_resolved_).
1088- > 11. Load _resolved_ as module format, _format_.
1089- > 12. Return _resolved_.
1079+ > 6. Let _format_ be ** undefined ** .
1080+ > 7. If _resolved_ is a _" file:" _ URL , then
1081+ > 1. If _resolved_ contains any percent encodings of _" /" _ or _" \\ " _ (_" %2F" _
1082+ > and _" %5C" _ respectively), then
1083+ > 1. Throw an _Invalid Module Specifier_ error.
1084+ > 2. If the file at _resolved_ is a directory, then
1085+ > 1. Throw an _Unsupported Directory Import_ error.
1086+ > 3. If the file at _resolved_ does not exist, then
1087+ > 1. Throw a _Module Not Found_ error.
1088+ > 4. Set _resolved_ to the real path of _resolved_, maintaining the
1089+ > same URL querystring and fragment components.
1090+ > 5. Set _format_ to the result of ** ESM \_FILE \_FORMAT ** (_resolved_).
1091+ > 8. Otherwise,
1092+ > 1. Set _format_ the module format of the content type associated with the
1093+ > URL _resolved_.
1094+ > 9. Load _resolved_ as module format, _format_.
10901095
10911096** PACKAGE \_RESOLVE ** (_packageSpecifier_, _parentURL_)
10921097
10931098> 1. Let _packageName_ be ** undefined ** .
10941099> 2. If _packageSpecifier_ is an empty string, then
10951100> 1. Throw an _Invalid Module Specifier_ error.
1096- > 3. If _packageSpecifier_ does not start with _" @" _, then
1101+ > 3. If _packageSpecifier_ is a Node .js builtin module name, then
1102+ > 1. Return the string _" node:" _ concatenated with _packageSpecifier_.
1103+ > 4. If _packageSpecifier_ does not start with _" @" _, then
10971104> 1. Set _packageName_ to the substring of _packageSpecifier_ until the first
10981105> _" /" _ separator or the end of the string.
1099- > 4 . Otherwise,
1106+ > 5 . Otherwise,
11001107> 1. If _packageSpecifier_ does not contain a _" /" _ separator, then
11011108> 1. Throw an _Invalid Module Specifier_ error.
11021109> 2. Set _packageName_ to the substring of _packageSpecifier_
11031110> until the second _" /" _ separator or the end of the string.
1104- > 5 . If _packageName_ starts with _" ." _ or contains _" \\ " _ or _" %" _, then
1111+ > 6 . If _packageName_ starts with _" ." _ or contains _" \\ " _ or _" %" _, then
11051112> 1. Throw an _Invalid Module Specifier_ error.
1106- > 6 . Let _packageSubpath_ be _" ." _ concatenated with the substring of
1113+ > 7 . Let _packageSubpath_ be _" ." _ concatenated with the substring of
11071114> _packageSpecifier_ from the position at the length of _packageName_.
1108- > 7 . If _packageSubpath_ ends in _" /" _, then
1115+ > 8 . If _packageSubpath_ ends in _" /" _, then
11091116> 1. Throw an _Invalid Module Specifier_ error.
1110- > 8 . Let _selfUrl_ be the result of
1117+ > 9 . Let _selfUrl_ be the result of
11111118> ** PACKAGE \_SELF \_RESOLVE ** (_packageName_, _packageSubpath_, _parentURL_).
1112- > 9. If _selfUrl_ is not ** undefined ** , return _selfUrl_.
1113- > 10. If _packageSubpath_ is _" ." _ and _packageName_ is a Node .js builtin
1114- > module , then
1115- > 1. Return the string _" node:" _ concatenated with _packageSpecifier_.
1119+ > 10. If _selfUrl_ is not ** undefined ** , return _selfUrl_.
11161120> 11. While _parentURL_ is not the file system root,
1117- > 1. Let _packageURL_ be the URL resolution of _" node \_ modules /" _
1118- > concatenated with _packageSpecifier_, relative to _parentURL_.
1119- > 2. Set _parentURL_ to the parent folder URL of _parentURL_.
1120- > 3. If the folder at _packageURL_ does not exist, then
1121- > 1. Continue the next loop iteration.
1122- > 4. Let _pjson_ be the result of ** READ \_PACKAGE \_JSON ** (_packageURL_).
1123- > 5. If _pjson_ is not ** null ** and _pjson_ ._exports_ is not ** null ** or
1124- > ** undefined ** , then
1125- > 1. Return the result of ** PACKAGE \_EXPORTS \_RESOLVE ** (_packageURL_,
1126- > _packageSubpath_, _pjson .exports_ , _defaultConditions_).
1127- > 6. Otherwise, if _packageSubpath_ is equal to _" ." _, then
1128- > 1. If _pjson .main_ is a string, then
1129- > 1. Return the URL resolution of _main_ in _packageURL_.
1130- > 7. Otherwise,
1131- > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
1121+ > 1. Let _packageURL_ be the URL resolution of _" node_modules /" _
1122+ > concatenated with _packageSpecifier_, relative to _parentURL_.
1123+ > 2. Set _parentURL_ to the parent folder URL of _parentURL_.
1124+ > 3. If the folder at _packageURL_ does not exist, then
1125+ > 1. Continue the next loop iteration.
1126+ > 4. Let _pjson_ be the result of ** READ \_PACKAGE \_JSON ** (_packageURL_).
1127+ > 5. If _pjson_ is not ** null ** and _pjson_ ._exports_ is not ** null ** or
1128+ > ** undefined ** , then
1129+ > 1. Return the result of ** PACKAGE \_EXPORTS \_RESOLVE ** (_packageURL_,
1130+ > _packageSubpath_, _pjson .exports_ , _defaultConditions_).
1131+ > 6. Otherwise, if _packageSubpath_ is equal to _" ." _, then
1132+ > 1. If _pjson .main_ is a string, then
1133+ > 1. Return the URL resolution of _main_ in _packageURL_.
1134+ > 7. Otherwise,
1135+ > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
11321136> 12. Throw a _Module Not Found_ error.
11331137
11341138** PACKAGE \_SELF \_RESOLVE ** (_packageName_, _packageSubpath_, _parentURL_)
@@ -1238,18 +1242,20 @@ _internal_, _conditions_)
12381242> _"/"_ and is not a valid URL, then
12391243> 1. If _pattern_ is **true**, then
12401244> 1. Return **PACKAGE\_RESOLVE**(_target_ with every instance of
1241- > _"\*"_ replaced by _subpath_, _packageURL_ + _"/"_)\_ .
1245+ > _"\*"_ replaced by _subpath_, _packageURL_ + _"/"_).
12421246> 2. Return **PACKAGE\_RESOLVE**(_target_ + _subpath_,
1243- > _packageURL_ + _"/"_)\ _.
1247+ > _packageURL_ + _"/"_)_.
12441248> 2. Otherwise, throw an _Invalid Package Target_ error.
12451249> 3. If _target_ split on _"/"_ or _"\\"_ contains any _"."_, _".."_ or
1246- > _"node\_modules"_ segments after the first segment, throw an
1247- > _Invalid Package Target_ error.
1250+ > _"node\_modules"_ segments after the first segment, case insensitive and
1251+ > including percent encoded variants, throw an _Invalid Package Target_
1252+ > error.
12481253> 4. Let _resolvedTarget_ be the URL resolution of the concatenation of
12491254> _packageURL_ and _target_.
12501255> 5. Assert: _resolvedTarget_ is contained in _packageURL_.
12511256> 6. If _subpath_ split on _"/"_ or _"\\"_ contains any _"."_, _".."_ or
1252- > _"node\_modules"_ segments, throw an _Invalid Module Specifier_ error.
1257+ > _"node\_modules"_ segments, case insensitive and including percent
1258+ > encoded variants, throw an _Invalid Module Specifier_ error.
12531259> 7. If _pattern_ is **true**, then
12541260> 1. Return the URL resolution of _resolvedTarget_ with every instance of
12551261> _"\*"_ replaced with _subpath_.
@@ -1282,19 +1288,21 @@ _internal_, _conditions_)
12821288> 4. Otherwise, if _target_ is _null_, return **null**.
12831289> 5. Otherwise throw an _Invalid Package Target_ error.
12841290
1285- **ESM\_FORMAT**(_url_)
1291+ **ESM\_FILE\ _FORMAT**(_url_)
12861292
12871293> 1. Assert: _url_ corresponds to an existing file.
12881294> 2. Let _pjson_ be the result of **READ\_PACKAGE\_SCOPE**(_url_).
12891295> 3. If _url_ ends in _".mjs"_, then
12901296> 1. Return _"module"_.
12911297> 4. If _url_ ends in _".cjs"_, then
12921298> 1. Return _"commonjs"_.
1293- > 5. If _pjson?.type_ exists and is _"module"_, then
1299+ > 5. If _url_ ends in _".json"_, then
1300+ > 1. Return _"json"_.
1301+ > 6. If _pjson?.type_ exists and is _"module"_, then
12941302> 1. If _url_ ends in _".js"_, then
12951303> 1. Return _"module"_.
12961304> 2. Throw an _Unsupported File Extension_ error.
1297- > 6 . Otherwise,
1305+ > 7 . Otherwise,
12981306> 1. Throw an _Unsupported File Extension_ error.
12991307
13001308**READ\_PACKAGE\_SCOPE**(_url_)
0 commit comments