@@ -1077,59 +1077,63 @@ The resolver can throw the following errors:
1077
1077
> 1. Note: _specifier_ is now a bare specifier.
1078
1078
> 2. Set _resolved_ the result of
1079
1079
> ** PACKAGE \_RESOLVE ** (_specifier_, _parentURL_).
1080
- > 6. If _resolved_ contains any percent encodings of _" /" _ or _" \\ " _ (_" %2f" _
1081
- > and _" %5C" _ respectively), then
1082
- > 1. Throw an _Invalid Module Specifier_ error.
1083
- > 7. If the file at _resolved_ is a directory, then
1084
- > 1. Throw an _Unsupported Directory Import_ error.
1085
- > 8. If the file at _resolved_ does not exist, then
1086
- > 1. Throw a _Module Not Found_ error.
1087
- > 9. Set _resolved_ to the real path of _resolved_.
1088
- > 10. Let _format_ be the result of ** ESM \_FORMAT ** (_resolved_).
1089
- > 11. Load _resolved_ as module format, _format_.
1090
- > 12. Return _resolved_.
1080
+ > 6. Let _format_ be ** undefined ** .
1081
+ > 7. If _resolved_ is a _" file:" _ URL , then
1082
+ > 1. If _resolved_ contains any percent encodings of _" /" _ or _" \\ " _ (_" %2F" _
1083
+ > and _" %5C" _ respectively), then
1084
+ > 1. Throw an _Invalid Module Specifier_ error.
1085
+ > 2. If the file at _resolved_ is a directory, then
1086
+ > 1. Throw an _Unsupported Directory Import_ error.
1087
+ > 3. If the file at _resolved_ does not exist, then
1088
+ > 1. Throw a _Module Not Found_ error.
1089
+ > 4. Set _resolved_ to the real path of _resolved_, maintaining the
1090
+ > same URL querystring and fragment components.
1091
+ > 5. Set _format_ to the result of ** ESM \_FILE \_FORMAT ** (_resolved_).
1092
+ > 8. Otherwise,
1093
+ > 1. Set _format_ the module format of the content type associated with the
1094
+ > URL _resolved_.
1095
+ > 9. Load _resolved_ as module format, _format_.
1091
1096
1092
1097
** PACKAGE \_RESOLVE ** (_packageSpecifier_, _parentURL_)
1093
1098
1094
1099
> 1. Let _packageName_ be ** undefined ** .
1095
1100
> 2. If _packageSpecifier_ is an empty string, then
1096
1101
> 1. Throw an _Invalid Module Specifier_ error.
1097
- > 3. If _packageSpecifier_ does not start with _" @" _, then
1102
+ > 3. If _packageSpecifier_ is a Node .js builtin module name, then
1103
+ > 1. Return the string _" node:" _ concatenated with _packageSpecifier_.
1104
+ > 4. If _packageSpecifier_ does not start with _" @" _, then
1098
1105
> 1. Set _packageName_ to the substring of _packageSpecifier_ until the first
1099
1106
> _" /" _ separator or the end of the string.
1100
- > 4 . Otherwise,
1107
+ > 5 . Otherwise,
1101
1108
> 1. If _packageSpecifier_ does not contain a _" /" _ separator, then
1102
1109
> 1. Throw an _Invalid Module Specifier_ error.
1103
1110
> 2. Set _packageName_ to the substring of _packageSpecifier_
1104
1111
> until the second _" /" _ separator or the end of the string.
1105
- > 5 . If _packageName_ starts with _" ." _ or contains _" \\ " _ or _" %" _, then
1112
+ > 6 . If _packageName_ starts with _" ." _ or contains _" \\ " _ or _" %" _, then
1106
1113
> 1. Throw an _Invalid Module Specifier_ error.
1107
- > 6 . Let _packageSubpath_ be _" ." _ concatenated with the substring of
1114
+ > 7 . Let _packageSubpath_ be _" ." _ concatenated with the substring of
1108
1115
> _packageSpecifier_ from the position at the length of _packageName_.
1109
- > 7 . If _packageSubpath_ ends in _" /" _, then
1116
+ > 8 . If _packageSubpath_ ends in _" /" _, then
1110
1117
> 1. Throw an _Invalid Module Specifier_ error.
1111
- > 8 . Let _selfUrl_ be the result of
1118
+ > 9 . Let _selfUrl_ be the result of
1112
1119
> ** PACKAGE \_SELF \_RESOLVE ** (_packageName_, _packageSubpath_, _parentURL_).
1113
- > 9. If _selfUrl_ is not ** undefined ** , return _selfUrl_.
1114
- > 10. If _packageSubpath_ is _" ." _ and _packageName_ is a Node .js builtin
1115
- > module , then
1116
- > 1. Return the string _" node:" _ concatenated with _packageSpecifier_.
1120
+ > 10. If _selfUrl_ is not ** undefined ** , return _selfUrl_.
1117
1121
> 11. While _parentURL_ is not the file system root,
1118
- > 1. Let _packageURL_ be the URL resolution of _" node \_ modules /" _
1119
- > concatenated with _packageSpecifier_, relative to _parentURL_.
1120
- > 2. Set _parentURL_ to the parent folder URL of _parentURL_.
1121
- > 3. If the folder at _packageURL_ does not exist, then
1122
- > 1. Continue the next loop iteration.
1123
- > 4. Let _pjson_ be the result of ** READ \_PACKAGE \_JSON ** (_packageURL_).
1124
- > 5. If _pjson_ is not ** null ** and _pjson_ ._exports_ is not ** null ** or
1125
- > ** undefined ** , then
1126
- > 1. Return the result of ** PACKAGE \_EXPORTS \_RESOLVE ** (_packageURL_,
1127
- > _packageSubpath_, _pjson .exports_ , _defaultConditions_).
1128
- > 6. Otherwise, if _packageSubpath_ is equal to _" ." _, then
1129
- > 1. If _pjson .main_ is a string, then
1130
- > 1. Return the URL resolution of _main_ in _packageURL_.
1131
- > 7. Otherwise,
1132
- > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
1122
+ > 1. Let _packageURL_ be the URL resolution of _" node_modules /" _
1123
+ > concatenated with _packageSpecifier_, relative to _parentURL_.
1124
+ > 2. Set _parentURL_ to the parent folder URL of _parentURL_.
1125
+ > 3. If the folder at _packageURL_ does not exist, then
1126
+ > 1. Continue the next loop iteration.
1127
+ > 4. Let _pjson_ be the result of ** READ \_PACKAGE \_JSON ** (_packageURL_).
1128
+ > 5. If _pjson_ is not ** null ** and _pjson_ ._exports_ is not ** null ** or
1129
+ > ** undefined ** , then
1130
+ > 1. Return the result of ** PACKAGE \_EXPORTS \_RESOLVE ** (_packageURL_,
1131
+ > _packageSubpath_, _pjson .exports_ , _defaultConditions_).
1132
+ > 6. Otherwise, if _packageSubpath_ is equal to _" ." _, then
1133
+ > 1. If _pjson .main_ is a string, then
1134
+ > 1. Return the URL resolution of _main_ in _packageURL_.
1135
+ > 7. Otherwise,
1136
+ > 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
1133
1137
> 12. Throw a _Module Not Found_ error.
1134
1138
1135
1139
** PACKAGE \_SELF \_RESOLVE ** (_packageName_, _packageSubpath_, _parentURL_)
@@ -1239,18 +1243,20 @@ _internal_, _conditions_)
1239
1243
> _"/"_ and is not a valid URL, then
1240
1244
> 1. If _pattern_ is **true**, then
1241
1245
> 1. Return **PACKAGE\_RESOLVE**(_target_ with every instance of
1242
- > _"\*"_ replaced by _subpath_, _packageURL_ + _"/"_)\_ .
1246
+ > _"\*"_ replaced by _subpath_, _packageURL_ + _"/"_).
1243
1247
> 2. Return **PACKAGE\_RESOLVE**(_target_ + _subpath_,
1244
- > _packageURL_ + _"/"_)\ _.
1248
+ > _packageURL_ + _"/"_)_.
1245
1249
> 2. Otherwise, throw an _Invalid Package Target_ error.
1246
1250
> 3. If _target_ split on _"/"_ or _"\\"_ contains any _"."_, _".."_ or
1247
- > _"node\_modules"_ segments after the first segment, throw an
1248
- > _Invalid Package Target_ error.
1251
+ > _"node\_modules"_ segments after the first segment, case insensitive and
1252
+ > including percent encoded variants, throw an _Invalid Package Target_
1253
+ > error.
1249
1254
> 4. Let _resolvedTarget_ be the URL resolution of the concatenation of
1250
1255
> _packageURL_ and _target_.
1251
1256
> 5. Assert: _resolvedTarget_ is contained in _packageURL_.
1252
1257
> 6. If _subpath_ split on _"/"_ or _"\\"_ contains any _"."_, _".."_ or
1253
- > _"node\_modules"_ segments, throw an _Invalid Module Specifier_ error.
1258
+ > _"node\_modules"_ segments, case insensitive and including percent
1259
+ > encoded variants, throw an _Invalid Module Specifier_ error.
1254
1260
> 7. If _pattern_ is **true**, then
1255
1261
> 1. Return the URL resolution of _resolvedTarget_ with every instance of
1256
1262
> _"\*"_ replaced with _subpath_.
@@ -1283,19 +1289,21 @@ _internal_, _conditions_)
1283
1289
> 4. Otherwise, if _target_ is _null_, return **null**.
1284
1290
> 5. Otherwise throw an _Invalid Package Target_ error.
1285
1291
1286
- **ESM\_FORMAT**(_url_)
1292
+ **ESM\_FILE\ _FORMAT**(_url_)
1287
1293
1288
1294
> 1. Assert: _url_ corresponds to an existing file.
1289
1295
> 2. Let _pjson_ be the result of **READ\_PACKAGE\_SCOPE**(_url_).
1290
1296
> 3. If _url_ ends in _".mjs"_, then
1291
1297
> 1. Return _"module"_.
1292
1298
> 4. If _url_ ends in _".cjs"_, then
1293
1299
> 1. Return _"commonjs"_.
1294
- > 5. If _pjson?.type_ exists and is _"module"_, then
1300
+ > 5. If _url_ ends in _".json"_, then
1301
+ > 1. Return _"json"_.
1302
+ > 6. If _pjson?.type_ exists and is _"module"_, then
1295
1303
> 1. If _url_ ends in _".js"_, then
1296
1304
> 1. Return _"module"_.
1297
1305
> 2. Throw an _Unsupported File Extension_ error.
1298
- > 6 . Otherwise,
1306
+ > 7 . Otherwise,
1299
1307
> 1. Throw an _Unsupported File Extension_ error.
1300
1308
1301
1309
**READ\_PACKAGE\_SCOPE**(_url_)
0 commit comments