Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
doc: include "exports" resolver specification
  • Loading branch information
guybedford committed Jul 30, 2019
commit 0e6af4777a496be243aca4ef7933ddf1c8f24655
26 changes: 25 additions & 1 deletion doc/api/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,10 @@ _isMain_ is **true** when resolving the Node.js application entry point.
> 1. Return the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_,
> _pjson_).
> 1. Otherwise,
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
> 1. If _pjson_ is not **null** and _pjson.exports_ is an Object, then
> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packagePath_,
> _pjson_).
> 1. Return the URL resolution of _packagePath_ in _packageURL_.
> 1. Throw a _Module Not Found_ error.

**PACKAGE_MAIN_RESOLVE**(_packageURL_, _pjson_)
Expand All @@ -743,6 +746,27 @@ _isMain_ is **true** when resolving the Node.js application entry point.
> 1. Throw an _Unsupported File Extension_ error.
> 1. Return _legacyMainURL_.

**PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packagePath_, _pjson_)
> 1. Assert: _pjson_ is not **null**.
> 1. Assert: _pjson.exports_ is an Object.
Comment thread
guybedford marked this conversation as resolved.
Outdated
> 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
> 1. If _packagePath_ is a key of _pjson.exports_, then
> 1. Let _target_ be the value of _pjson.exports[packagePath]_.
> 1. If _target_ is not a String, continue the loop.
> 1. Return the URL resolution of the concatenation of _packageURL_ and
> _target_.
> 1. Let _directoryKeys_ be the list of keys of _pjson.exports_ ending in
> _"/"_, sorted by length descending.
> 1. For each key _directory_ in _directoryKeys_, do
> 1. If _packagePath_ starts with _directory_, then
> 1. Let _target_ be the value of _pjson.exports[directory]_.
> 1. If _target_ is not a String, continue the loop.
> 1. Let _subpath_ be the substring of _target_ starting at the index of
> the length of _directory_.
> 1. Return the URL resolution of the concatenation of _packageURL_,
> _target_ and _subpath_.
> 1. Throw a _Module Not Found_ error.

**ESM_FORMAT**(_url_, _isMain_)
> 1. Assert: _url_ corresponds to an existing file.
> 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_).
Expand Down