@@ -712,7 +712,7 @@ _isMain_ is **true** when resolving the Node.js application entry point.
712
712
> module, then
713
713
> 1. Return the string _"node:"_ concatenated with _packageSpecifier_.
714
714
> 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/"_
716
716
> concatenated with _packageSpecifier_, relative to _parentURL_.
717
717
> 1. Set _parentURL_ to the parent folder URL of _parentURL_.
718
718
> 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.
723
723
> 1. Return the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_,
724
724
> _pjson_).
725
725
> 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_.
727
732
> 1. Throw a _Module Not Found_ error.
728
733
729
734
**PACKAGE_MAIN_RESOLVE**(_packageURL_, _pjson_)
@@ -743,6 +748,26 @@ _isMain_ is **true** when resolving the Node.js application entry point.
743
748
> 1. Throw an _Unsupported File Extension_ error.
744
749
> 1. Return _legacyMainURL_.
745
750
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
+
746
771
**ESM_FORMAT**(_url_, _isMain_)
747
772
> 1. Assert: _url_ corresponds to an existing file.
748
773
> 1. Let _pjson_ be the result of **READ_PACKAGE_SCOPE**(_url_).
0 commit comments