@@ -1391,6 +1391,17 @@ of these top-level routines unless stated otherwise.
13911391_defaultEnv_ is the conditional environment name priority array,
13921392` [" node" , " import" ]` .
13931393
1394+ The resolver can throw the following errors:
1395+ * _Invalid Module Specifier_: Module specifier is an invalid URL, package name
1396+ or package subpath specifier.
1397+ * _Invalid Package Configuration_: package.json configuration is invalid or
1398+ contains an invalid configuration.
1399+ * _Invalid Package Target_: Package exports define a target module within the
1400+ package that is an invalid type or string target.
1401+ * _Package Path Not Exported_: Package exports do not define or permit a target
1402+ subpath in the package for the given module.
1403+ * _Module Not Found_: The package or module requested does not exist.
1404+
13941405<details>
13951406<summary>Resolver algorithm specification</summary>
13961407
@@ -1401,7 +1412,7 @@ _defaultEnv_ is the conditional environment name priority array,
14011412> 1. Set _resolvedURL_ to the result of parsing and reserializing
14021413> _specifier_ as a URL.
14031414> 1. Otherwise, if _specifier_ starts with _"/"_, then
1404- > 1. Throw an _Invalid Specifier_ error.
1415+ > 1. Throw an _Invalid Module Specifier_ error.
14051416> 1. Otherwise, if _specifier_ starts with _"./"_ or _"../"_, then
14061417> 1. Set _resolvedURL_ to the URL resolution of _specifier_ relative to
14071418> _parentURL_.
@@ -1411,7 +1422,7 @@ _defaultEnv_ is the conditional environment name priority array,
14111422> **PACKAGE_RESOLVE**(_specifier_, _parentURL_).
14121423> 1. If _resolvedURL_ contains any percent encodings of _"/"_ or _"\\ "_ (_"%2f"_
14131424> and _"%5C"_ respectively), then
1414- > 1. Throw an _Invalid Specifier_ error.
1425+ > 1. Throw an _Invalid Module Specifier_ error.
14151426> 1. If _resolvedURL_ does not end with a trailing _"/"_ and the file at
14161427> _resolvedURL_ does not exist, then
14171428> 1. Throw a _Module Not Found_ error.
@@ -1425,22 +1436,22 @@ _defaultEnv_ is the conditional environment name priority array,
14251436> 1. Let _packageName_ be *undefined*.
14261437> 1. Let _packageSubpath_ be *undefined*.
14271438> 1. If _packageSpecifier_ is an empty string, then
1428- > 1. Throw an _Invalid Specifier_ error.
1439+ > 1. Throw an _Invalid Module Specifier_ error.
14291440> 1. Otherwise,
14301441> 1. If _packageSpecifier_ does not contain a _"/"_ separator, then
1431- > 1. Throw an _Invalid Specifier_ error.
1442+ > 1. Throw an _Invalid Module Specifier_ error.
14321443> 1. Set _packageName_ to the substring of _packageSpecifier_
14331444> until the second _"/"_ separator or the end of the string.
14341445> 1. If _packageName_ starts with _"."_ or contains _"\\ "_ or _"%"_, then
1435- > 1. Throw an _Invalid Specifier_ error.
1446+ > 1. Throw an _Invalid Module Specifier_ error.
14361447> 1. Let _packageSubpath_ be _undefined_.
14371448> 1. If the length of _packageSpecifier_ is greater than the length of
14381449> _packageName_, then
14391450> 1. Set _packageSubpath_ to _"."_ concatenated with the substring of
14401451> _packageSpecifier_ from the position at the length of _packageName_.
14411452> 1. If _packageSubpath_ contains any _"."_ or _".."_ segments or percent
14421453> encoded strings for _"/"_ or _"\\ "_, then
1443- > 1. Throw an _Invalid Specifier_ error.
1454+ > 1. Throw an _Invalid Module Specifier_ error.
14441455> 1. Set _selfUrl_ to the result of
14451456> **SELF_REFERENCE_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
14461457> 1. If _selfUrl_ isn't empty, return _selfUrl_.
@@ -1497,7 +1508,7 @@ _defaultEnv_ is the conditional environment name priority array,
14971508> 1. Throw a _Module Not Found_ error.
14981509> 1. If _pjson.exports_ is not **null** or **undefined**, then
14991510> 1. If _exports_ is an Object with both a key starting with _"."_ and a key
1500- > not starting with _"."_, throw an "Invalid Package Configuration" error.
1511+ > not starting with _"."_, throw an _Invalid Package Configuration_ error.
15011512> 1. If _pjson.exports_ is a String or Array, or an Object containing no
15021513> keys starting with _"."_, then
15031514> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
@@ -1506,6 +1517,7 @@ _defaultEnv_ is the conditional environment name priority array,
15061517> 1. Let _mainExport_ be the _"."_ property in _pjson.exports_.
15071518> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
15081519> _mainExport_, _""_).
1520+ > 1. Throw a _Package Path Not Exported_ error.
15091521> 1. If _pjson.main_ is a String, then
15101522> 1. Let _resolvedMain_ be the URL resolution of _packageURL_, "/", and
15111523> _pjson.main_.
@@ -1520,7 +1532,7 @@ _defaultEnv_ is the conditional environment name priority array,
15201532
15211533**PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packagePath_, _exports_)
15221534> 1. If _exports_ is an Object with both a key starting with _"."_ and a key not
1523- > starting with _"."_, throw an "Invalid Package Configuration" error.
1535+ > starting with _"."_, throw an _Invalid Package Configuration_ error.
15241536> 1. If _exports_ is an Object and all keys of _exports_ start with _"."_, then
15251537> 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
15261538> 1. If _packagePath_ is a key of _exports_, then
@@ -1536,43 +1548,44 @@ _defaultEnv_ is the conditional environment name priority array,
15361548> of the length of _directory_.
15371549> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_,
15381550> _subpath_, _defaultEnv_).
1539- > 1. Throw a _Module Not Found_ error.
1551+ > 1. Throw a _Package Path Not Exported_ error.
15401552
15411553**PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _env_)
15421554
1543- > 1. If _target_ is a String, then
1544- > 1. If _target_ does not start with _"./"_, throw a _Module Not Found_
1545- > error.
1546- > 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
1547- > throw a _Module Not Found_ error.
1548- > 1. If _target_ or _subpath_ contain any _"node_modules"_ segments including
1549- > _"node_modules"_ percent-encoding, throw a _Module Not Found_ error.
1555+ > 1.If _target_ is a String, then
1556+ > 1. If _target_ does not start with _"./"_ or contains any _"node_modules"_
1557+ > segments including _"node_modules"_ percent-encoding, throw an
1558+ > _Invalid Package Target_ error.
15501559> 1. Let _resolvedTarget_ be the URL resolution of the concatenation of
15511560> _packageURL_ and _target_.
1552- > 1. If _resolvedTarget_ is contained in _packageURL_, then
1553- > 1. Let _resolved_ be the URL resolution of the concatenation of
1554- > _subpath_ and _resolvedTarget_.
1555- > 1. If _resolved_ is contained in _resolvedTarget_, then
1556- > 1. Return _resolved_.
1561+ > 1. If _resolvedTarget_ is not contained in _packageURL_, throw an
1562+ > _Invalid Package Target_ error.
1563+ > 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
1564+ > throw an _Invalid Module Specifier_ error.
1565+ > 1. Let _resolved_ be the URL resolution of the concatenation of
1566+ > _subpath_ and _resolvedTarget_.
1567+ > 1. If _resolved_ is not contained in _resolvedTarget_, throw an
1568+ > _Invalid Module Specifier_ error.
1569+ > 1. Return _resolved_.
15571570> 1. Otherwise, if _target_ is a non-null Object, then
15581571> 1. If _exports_ contains any index property keys, as defined in ECMA-262
15591572> [6.1.7 Array Index][], throw an _Invalid Package Configuration_ error.
15601573> 1. For each property _p_ of _target_, in object insertion order as,
15611574> 1. If _env_ contains an entry for _p_, then
15621575> 1. Let _targetValue_ be the value of the _p_ property in _target_.
1563- > 1. Let _resolved_ be the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**
1564- > ( _packageURL_, _targetValue_, _subpath_, _env_).
1565- > 1. Assert: _resolved_ is a String .
1566- > 1. Return _resolved_ .
1576+ > 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(
1577+ > _packageURL_, _targetValue_, _subpath_, _env_), continuing the
1578+ > loop on any _Package Path Not Exported_ error .
1579+ > 1. Throw a _Package Path Not Exported_ error .
15671580> 1. Otherwise, if _target_ is an Array, then
1581+ > 1. If _target.length is zero, throw an _Invalid Package Target_ error.
15681582> 1. For each item _targetValue_ in _target_, do
15691583> 1. If _targetValue_ is an Array, continue the loop.
1570- > 1. Let _resolved_ be the result of
1571- > **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _targetValue_,
1572- > _subpath_, _env_), continuing the loop on abrupt completion.
1573- > 1. Assert: _resolved_ is a String.
1574- > 1. Return _resolved_.
1575- > 1. Throw a _Module Not Found_ error.
1584+ > 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
1585+ > _targetValue_, _subpath_, _env_), continuing the loop on any
1586+ > _Package Path Not Exported_ or _Invalid Package Target_ error.
1587+ > 1. Throw the last fallback resolution error.
1588+ > 1. Otherwise throw an _Invalid Package Target_ error.
15761589
15771590**ESM_FORMAT**(_url_)
15781591
0 commit comments