@@ -235,25 +235,30 @@ PACKAGE_RESOLVE(_packageSpecifier_, _parentURL_)
235
235
PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
236
236
> 1. If _pjson_ is **null**, then
237
237
> 1. Throw a _Module Not Found_ error.
238
- > 1. If _pjson.main_ is a String, then
239
- > 1. Let _resolvedMain_ be the concatenation of _packageURL_, "/", and
240
- > _pjson.main_.
241
- > 1. If the file at _resolvedMain_ exists, then
242
- > 1. Return _resolvedMain_.
243
- > 1. If _pjson.type_ is equal to _"module"_, then
244
- > 1. Throw a _Module Not Found_ error.
238
+ > 1. Let _main_ be **undefined**.
239
+ > 1. If _pjson.exports_ is a String, then
240
+ > 1. Set _main_ to _pjson.exports_.
241
+ > 1. If _main_ ends in _".js"_ and _pjson.type_ is not equal to _"module"_,
242
+ > or _main_ ends in _".cjs"_, then
243
+ > 1. Throw an _Unsupported Module Format_ error.
244
+ > 1. Let _resolvedMain_ be the resolution of _main_ to _packageURL_.
245
+ > 1. If the file at _resolvedMain_ does not exist, then
246
+ > 1. Throw a _Module Not Found_ error.
247
+ > 1. Return _resolvedMain_.
245
248
> 1. Let _legacyMainURL_ be the result applying the legacy
246
249
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
247
250
> _Module Not Found_ error for no resolution.
248
- > 1. If _legacyMainURL_ does not end in _".js"_ then,
249
- > 1. Throw an _Unsupported File Extension_ error.
251
+ > 1. If _pjson.type_ is _"module"_ and _legacyMainURL_ ends in _".js"_, then
252
+ > 1. Throw an _Unsupported Module Format_ error.
253
+ > 1. If _legacyMainURL_ ends in _".mjs"_, then
254
+ > 1. Throw an _Unsupported Module Format_ error.
250
255
> 1. Return _legacyMainURL_.
251
256
252
257
**ESM_FORMAT(_url_, _isMain_)**
253
258
> 1. Assert: _url_ corresponds to an existing file.
254
259
> 1. If _isMain_ is **true** and the ` -- type` flag is _"module"_, then
255
260
> 1. If _url_ ends with _".cjs"_, then
256
- > 1. Throw an _Invalid File Extension_ error.
261
+ > 1. Throw an _Unsupported Module Format_ error.
257
262
> 1. Return _"module"_.
258
263
> 1. Let _pjson_ be the result of **READ_PACKAGE_BOUNDARY**(_url_).
259
264
> 1. If _pjson_ is **null** and _isMain_ is **true**, then
@@ -267,8 +272,9 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
267
272
> 1. Otherwise,
268
273
> 1. If _url_ ends in _".mjs"_, then
269
274
> 1. Return _"module"_.
270
- > 1. Otherwise,
271
- > 1. Return _"commonjs"_.
275
+ > 1. If _url_ does not end in _".js"_, then
276
+ > 1. Throw an _Unsupported File Extension_ error.
277
+ > 1. Return _"commonjs"_.
272
278
273
279
READ_PACKAGE_BOUNDARY(_url_)
274
280
> 1. Let _boundaryURL_ be _url_.
0 commit comments