Skip to content

Commit 7c80963

Browse files
guybedfordtargos
authored andcommitted
doc: include "exports" resolver specification
PR-URL: #28899 Reviewed-By: Jan Krems <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent d601a0a commit 7c80963

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

doc/api/esm.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ _isMain_ is **true** when resolving the Node.js application entry point.
712712
> module, then
713713
> 1. Return the string _"node:"_ concatenated with _packageSpecifier_.
714714
> 1. While _parentURL_ is not the file system root,
715-
> 1. Let _packageURL_ be the URL resolution of "node_modules/"
715+
> 1. Let _packageURL_ be the URL resolution of _"node_modules/"_
716716
> concatenated with _packageSpecifier_, relative to _parentURL_.
717717
> 1. Set _parentURL_ to the parent folder URL of _parentURL_.
718718
> 1. If the folder at _packageURL_ does not exist, then
@@ -723,7 +723,12 @@ _isMain_ is **true** when resolving the Node.js application entry point.
723723
> 1. Return the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_,
724724
> _pjson_).
725725
> 1. Otherwise,
726-
> 1. Return the URL resolution of _packageSubpath_ in _packageURL_.
726+
> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then
727+
> 1. Let _exports_ be _pjson.exports_.
728+
> 1. If _exports_ is not **null** or **undefined**, then
729+
> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_,
730+
> _packagePath_, _pjson.exports_).
731+
> 1. Return the URL resolution of _packagePath_ in _packageURL_.
727732
> 1. Throw a _Module Not Found_ error.
728733
729734
**PACKAGE_MAIN_RESOLVE**(_packageURL_, _pjson_)
@@ -743,6 +748,26 @@ _isMain_ is **true** when resolving the Node.js application entry point.
743748
> 1. Throw an _Unsupported File Extension_ error.
744749
> 1. Return _legacyMainURL_.
745750
751+
**PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packagePath_, _exports_)
752+
> 1. If _exports_ is an Object, then
753+
> 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
754+
> 1. If _packagePath_ is a key of _exports_, then
755+
> 1. Let _target_ be the value of _exports[packagePath]_.
756+
> 1. If _target_ is not a String, continue the loop.
757+
> 1. Return the URL resolution of the concatenation of _packageURL_ and
758+
> _target_.
759+
> 1. Let _directoryKeys_ be the list of keys of _exports_ ending in
760+
> _"/"_, sorted by length descending.
761+
> 1. For each key _directory_ in _directoryKeys_, do
762+
> 1. If _packagePath_ starts with _directory_, then
763+
> 1. Let _target_ be the value of _exports[directory]_.
764+
> 1. If _target_ is not a String, continue the loop.
765+
> 1. Let _subpath_ be the substring of _target_ starting at the index
766+
> of the length of _directory_.
767+
> 1. Return the URL resolution of the concatenation of _packageURL_,
768+
> _target_ and _subpath_.
769+
> 1. Throw a _Module Not Found_ error.
770+
746771
**ESM_FORMAT**(_url_, _isMain_)
747772
> 1. Assert: _url_ corresponds to an existing file.
748773
> 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_).

0 commit comments

Comments
 (0)