Skip to content
This repository was archived by the owner on Apr 16, 2020. It is now read-only.

Commit e221be8

Browse files
committed
specify exports main
1 parent a4955e2 commit e221be8

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

doc/api/esm.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,30 @@ PACKAGE_RESOLVE(_packageSpecifier_, _parentURL_)
235235
PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
236236
> 1. If _pjson_ is **null**, then
237237
> 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_.
245248
> 1. Let _legacyMainURL_ be the result applying the legacy
246249
> **LOAD_AS_DIRECTORY** CommonJS resolver to _packageURL_, throwing a
247250
> _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.
250255
> 1. Return _legacyMainURL_.
251256
252257
**ESM_FORMAT(_url_, _isMain_)**
253258
> 1. Assert: _url_ corresponds to an existing file.
254259
> 1. If _isMain_ is **true** and the `--type` flag is _"module"_, then
255260
> 1. If _url_ ends with _".cjs"_, then
256-
> 1. Throw an _Invalid File Extension_ error.
261+
> 1. Throw an _Unsupported Module Format_ error.
257262
> 1. Return _"module"_.
258263
> 1. Let _pjson_ be the result of **READ_PACKAGE_BOUNDARY**(_url_).
259264
> 1. If _pjson_ is **null** and _isMain_ is **true**, then
@@ -267,8 +272,9 @@ PACKAGE_MAIN_RESOLVE(_packageURL_, _pjson_)
267272
> 1. Otherwise,
268273
> 1. If _url_ ends in _".mjs"_, then
269274
> 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"_.
272278
273279
READ_PACKAGE_BOUNDARY(_url_)
274280
> 1. Let _boundaryURL_ be _url_.

0 commit comments

Comments
 (0)