@@ -1446,6 +1446,17 @@ of these top-level routines unless stated otherwise.
1446
1446
_defaultEnv_ is the conditional environment name priority array,
1447
1447
` [" node" , " import" ]` .
1448
1448
1449
+ The resolver can throw the following errors:
1450
+ * _Invalid Module Specifier_: Module specifier is an invalid URL, package name
1451
+ or package subpath specifier.
1452
+ * _Invalid Package Configuration_: package.json configuration is invalid or
1453
+ contains an invalid configuration.
1454
+ * _Invalid Package Target_: Package exports define a target module within the
1455
+ package that is an invalid type or string target.
1456
+ * _Package Path Not Exported_: Package exports do not define or permit a target
1457
+ subpath in the package for the given module.
1458
+ * _Module Not Found_: The package or module requested does not exist.
1459
+
1449
1460
<details>
1450
1461
<summary>Resolver algorithm specification</summary>
1451
1462
@@ -1456,7 +1467,7 @@ _defaultEnv_ is the conditional environment name priority array,
1456
1467
> 1. Set _resolvedURL_ to the result of parsing and reserializing
1457
1468
> _specifier_ as a URL.
1458
1469
> 1. Otherwise, if _specifier_ starts with _"/"_, then
1459
- > 1. Throw an _Invalid Specifier_ error.
1470
+ > 1. Throw an _Invalid Module Specifier_ error.
1460
1471
> 1. Otherwise, if _specifier_ starts with _"./"_ or _"../"_, then
1461
1472
> 1. Set _resolvedURL_ to the URL resolution of _specifier_ relative to
1462
1473
> _parentURL_.
@@ -1466,7 +1477,7 @@ _defaultEnv_ is the conditional environment name priority array,
1466
1477
> **PACKAGE_RESOLVE**(_specifier_, _parentURL_).
1467
1478
> 1. If _resolvedURL_ contains any percent encodings of _"/"_ or _"\\ "_ (_"%2f"_
1468
1479
> and _"%5C"_ respectively), then
1469
- > 1. Throw an _Invalid Specifier_ error.
1480
+ > 1. Throw an _Invalid Module Specifier_ error.
1470
1481
> 1. If _resolvedURL_ does not end with a trailing _"/"_ and the file at
1471
1482
> _resolvedURL_ does not exist, then
1472
1483
> 1. Throw a _Module Not Found_ error.
@@ -1480,22 +1491,22 @@ _defaultEnv_ is the conditional environment name priority array,
1480
1491
> 1. Let _packageName_ be *undefined*.
1481
1492
> 1. Let _packageSubpath_ be *undefined*.
1482
1493
> 1. If _packageSpecifier_ is an empty string, then
1483
- > 1. Throw an _Invalid Specifier_ error.
1494
+ > 1. Throw an _Invalid Module Specifier_ error.
1484
1495
> 1. Otherwise,
1485
1496
> 1. If _packageSpecifier_ does not contain a _"/"_ separator, then
1486
- > 1. Throw an _Invalid Specifier_ error.
1497
+ > 1. Throw an _Invalid Module Specifier_ error.
1487
1498
> 1. Set _packageName_ to the substring of _packageSpecifier_
1488
1499
> until the second _"/"_ separator or the end of the string.
1489
1500
> 1. If _packageName_ starts with _"."_ or contains _"\\ "_ or _"%"_, then
1490
- > 1. Throw an _Invalid Specifier_ error.
1501
+ > 1. Throw an _Invalid Module Specifier_ error.
1491
1502
> 1. Let _packageSubpath_ be _undefined_.
1492
1503
> 1. If the length of _packageSpecifier_ is greater than the length of
1493
1504
> _packageName_, then
1494
1505
> 1. Set _packageSubpath_ to _"."_ concatenated with the substring of
1495
1506
> _packageSpecifier_ from the position at the length of _packageName_.
1496
1507
> 1. If _packageSubpath_ contains any _"."_ or _".."_ segments or percent
1497
1508
> encoded strings for _"/"_ or _"\\ "_, then
1498
- > 1. Throw an _Invalid Specifier_ error.
1509
+ > 1. Throw an _Invalid Module Specifier_ error.
1499
1510
> 1. Set _selfUrl_ to the result of
1500
1511
> **SELF_REFERENCE_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_).
1501
1512
> 1. If _selfUrl_ isn't empty, return _selfUrl_.
@@ -1552,7 +1563,7 @@ _defaultEnv_ is the conditional environment name priority array,
1552
1563
> 1. Throw a _Module Not Found_ error.
1553
1564
> 1. If _pjson.exports_ is not **null** or **undefined**, then
1554
1565
> 1. If _exports_ is an Object with both a key starting with _"."_ and a key
1555
- > not starting with _"."_, throw an "Invalid Package Configuration" error.
1566
+ > not starting with _"."_, throw an _Invalid Package Configuration_ error.
1556
1567
> 1. If _pjson.exports_ is a String or Array, or an Object containing no
1557
1568
> keys starting with _"."_, then
1558
1569
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
@@ -1561,6 +1572,7 @@ _defaultEnv_ is the conditional environment name priority array,
1561
1572
> 1. Let _mainExport_ be the _"."_ property in _pjson.exports_.
1562
1573
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
1563
1574
> _mainExport_, _""_).
1575
+ > 1. Throw a _Package Path Not Exported_ error.
1564
1576
> 1. If _pjson.main_ is a String, then
1565
1577
> 1. Let _resolvedMain_ be the URL resolution of _packageURL_, "/", and
1566
1578
> _pjson.main_.
@@ -1575,7 +1587,7 @@ _defaultEnv_ is the conditional environment name priority array,
1575
1587
1576
1588
**PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packagePath_, _exports_)
1577
1589
> 1. If _exports_ is an Object with both a key starting with _"."_ and a key not
1578
- > starting with _"."_, throw an "Invalid Package Configuration" error.
1590
+ > starting with _"."_, throw an _Invalid Package Configuration_ error.
1579
1591
> 1. If _exports_ is an Object and all keys of _exports_ start with _"."_, then
1580
1592
> 1. Set _packagePath_ to _"./"_ concatenated with _packagePath_.
1581
1593
> 1. If _packagePath_ is a key of _exports_, then
@@ -1591,43 +1603,44 @@ _defaultEnv_ is the conditional environment name priority array,
1591
1603
> of the length of _directory_.
1592
1604
> 1. Return **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_,
1593
1605
> _subpath_, _defaultEnv_).
1594
- > 1. Throw a _Module Not Found_ error.
1606
+ > 1. Throw a _Package Path Not Exported_ error.
1595
1607
1596
1608
**PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _env_)
1597
1609
1598
- > 1. If _target_ is a String, then
1599
- > 1. If _target_ does not start with _"./"_, throw a _Module Not Found_
1600
- > error.
1601
- > 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
1602
- > throw a _Module Not Found_ error.
1603
- > 1. If _target_ or _subpath_ contain any _"node_modules"_ segments including
1604
- > _"node_modules"_ percent-encoding, throw a _Module Not Found_ error.
1610
+ > 1.If _target_ is a String, then
1611
+ > 1. If _target_ does not start with _"./"_ or contains any _"node_modules"_
1612
+ > segments including _"node_modules"_ percent-encoding, throw an
1613
+ > _Invalid Package Target_ error.
1605
1614
> 1. Let _resolvedTarget_ be the URL resolution of the concatenation of
1606
1615
> _packageURL_ and _target_.
1607
- > 1. If _resolvedTarget_ is contained in _packageURL_, then
1608
- > 1. Let _resolved_ be the URL resolution of the concatenation of
1609
- > _subpath_ and _resolvedTarget_.
1610
- > 1. If _resolved_ is contained in _resolvedTarget_, then
1611
- > 1. Return _resolved_.
1616
+ > 1. If _resolvedTarget_ is not contained in _packageURL_, throw an
1617
+ > _Invalid Package Target_ error.
1618
+ > 1. If _subpath_ has non-zero length and _target_ does not end with _"/"_,
1619
+ > throw an _Invalid Module Specifier_ error.
1620
+ > 1. Let _resolved_ be the URL resolution of the concatenation of
1621
+ > _subpath_ and _resolvedTarget_.
1622
+ > 1. If _resolved_ is not contained in _resolvedTarget_, throw an
1623
+ > _Invalid Module Specifier_ error.
1624
+ > 1. Return _resolved_.
1612
1625
> 1. Otherwise, if _target_ is a non-null Object, then
1613
1626
> 1. If _exports_ contains any index property keys, as defined in ECMA-262
1614
1627
> [6.1.7 Array Index][], throw an _Invalid Package Configuration_ error.
1615
1628
> 1. For each property _p_ of _target_, in object insertion order as,
1616
1629
> 1. If _env_ contains an entry for _p_, then
1617
1630
> 1. Let _targetValue_ be the value of the _p_ property in _target_.
1618
- > 1. Let _resolved_ be the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**
1619
- > ( _packageURL_, _targetValue_, _subpath_, _env_).
1620
- > 1. Assert: _resolved_ is a String .
1621
- > 1. Return _resolved_ .
1631
+ > 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(
1632
+ > _packageURL_, _targetValue_, _subpath_, _env_), continuing the
1633
+ > loop on any _Package Path Not Exported_ error .
1634
+ > 1. Throw a _Package Path Not Exported_ error .
1622
1635
> 1. Otherwise, if _target_ is an Array, then
1636
+ > 1. If _target.length is zero, throw an _Invalid Package Target_ error.
1623
1637
> 1. For each item _targetValue_ in _target_, do
1624
1638
> 1. If _targetValue_ is an Array, continue the loop.
1625
- > 1. Let _resolved_ be the result of
1626
- > **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_, _targetValue_,
1627
- > _subpath_, _env_), continuing the loop on abrupt completion.
1628
- > 1. Assert: _resolved_ is a String.
1629
- > 1. Return _resolved_.
1630
- > 1. Throw a _Module Not Found_ error.
1639
+ > 1. Return the result of **PACKAGE_EXPORTS_TARGET_RESOLVE**(_packageURL_,
1640
+ > _targetValue_, _subpath_, _env_), continuing the loop on any
1641
+ > _Package Path Not Exported_ or _Invalid Package Target_ error.
1642
+ > 1. Throw the last fallback resolution error.
1643
+ > 1. Otherwise throw an _Invalid Package Target_ error.
1631
1644
1632
1645
**ESM_FORMAT**(_url_)
1633
1646
0 commit comments