Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc/api
diff options
context:
space:
mode:
authorGuy Bedford <guybedford@gmail.com>2021-08-03 00:46:23 +0300
committerGuy Bedford <guybedford@gmail.com>2021-08-25 22:49:33 +0300
commit18bb2cef83a097902cca41af47868b5bf535e4af (patch)
treea7adde66bf73fb11f3c6f0144f90e66da9c9d001 /doc/api
parent95834d11a23b224f1abcc71a868d3cade4763717 (diff)
module: support pattern trailers
PR-URL: https://github.com/nodejs/node/pull/39635 Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Diffstat (limited to 'doc/api')
-rw-r--r--doc/api/esm.md55
-rw-r--r--doc/api/packages.md5
2 files changed, 43 insertions, 17 deletions
diff --git a/doc/api/esm.md b/doc/api/esm.md
index a5ad877d9e0..dc93e659b01 100644
--- a/doc/api/esm.md
+++ b/doc/api/esm.md
@@ -1176,25 +1176,36 @@ The resolver can throw the following errors:
**PACKAGE_IMPORTS_EXPORTS_RESOLVE**(_matchKey_, _matchObj_, _packageURL_,
_isImports_, _conditions_)
-> 1. If _matchKey_ is a key of _matchObj_, and does not end in _"*"_, then
+> 1. If _matchKey_ is a key of _matchObj_ and does not end in _"/"_ or contain
+> _"*"_, then
> 1. Let _target_ be the value of _matchObj_\[_matchKey_\].
> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
> _packageURL_, _target_, _""_, **false**, _isImports_, _conditions_).
> 1. Return the object _{ resolved, exact: **true** }_.
-> 1. Let _expansionKeys_ be the list of keys of _matchObj_ ending in _"/"_
-> or _"*"_, sorted by length descending.
+> 1. Let _expansionKeys_ be the list of keys of _matchObj_ either ending in
+> _"/"_ or containing only a single _"*"_, sorted by the sorting function
+> **PATTERN_KEY_COMPARE** which orders in descending order of specificity.
> 1. For each key _expansionKey_ in _expansionKeys_, do
-> 1. If _expansionKey_ ends in _"*"_ and _matchKey_ starts with but is
-> not equal to the substring of _expansionKey_ excluding the last _"*"_
-> character, then
-> 1. Let _target_ be the value of _matchObj_\[_expansionKey_\].
-> 1. Let _subpath_ be the substring of _matchKey_ starting at the
-> index of the length of _expansionKey_ minus one.
-> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
-> _packageURL_, _target_, _subpath_, **true**, _isImports_,
-> _conditions_).
-> 1. Return the object _{ resolved, exact: **true** }_.
-> 1. If _matchKey_ starts with _expansionKey_, then
+> 1. Let _patternBase_ be **null**.
+> 1. If _expansionKey_ contains _"*"_, set _patternBase_ to the substring of
+> _expansionKey_ up to but excluding the first _"*"_ character.
+> 1. If _patternBase_ is not **null** and _matchKey_ starts with but is not
+> equal to _patternBase_, then
+> 1. Let _patternTrailer_ be the substring of _expansionKey_ from the
+> index after the first _"*"_ character.
+> 1. If _patternTrailer_ has zero length, or if _matchKey_ ends with
+> _patternTrailer_ and the length of _matchKey_ is greater than or
+> equal to the length of _expansionKey_, then
+> 1. Let _target_ be the value of _matchObj_\[_expansionKey_\].
+> 1. Let _subpath_ be the substring of _matchKey_ starting at the
+> index of the length of _patternBase_ up to the length of
+> _matchKey_ minus the length of _patternTrailer_.
+> 1. Let _resolved_ be the result of **PACKAGE_TARGET_RESOLVE**(
+> _packageURL_, _target_, _subpath_, **true**, _isImports_,
+> _conditions_).
+> 1. Return the object _{ resolved, exact: **true** }_.
+> 1. Otherwise if _patternBase_ is **null** and _matchKey_ starts with
+> _expansionKey_, then
> 1. Let _target_ be the value of _matchObj_\[_expansionKey_\].
> 1. Let _subpath_ be the substring of _matchKey_ starting at the
> index of the length of _expansionKey_.
@@ -1204,6 +1215,22 @@ _isImports_, _conditions_)
> 1. Return the object _{ resolved, exact: **false** }_.
> 1. Return the object _{ resolved: **null**, exact: **true** }_.
+**PATTERN_KEY_COMPARE**(_keyA_, _keyB_)
+
+> 1. Assert: _keyA_ ends with _"/"_ or contains only a single _"*"_.
+> 1. Assert: _keyB_ ends with _"/"_ or contains only a single _"*"_.
+> 1. Let _baseLengthA_ be the index of _"*"_ in _keyA_ plus one, if _keyA_
+> contains _"*"_, or the length of _keyA_ otherwise.
+> 1. Let _baseLengthB_ be the index of _"*"_ in _keyB_ plus one, if _keyB_
+> contains _"*"_, or the length of _keyB_ otherwise.
+> 1. If _baseLengthA_ is greater than _baseLengthB_, return -1.
+> 1. If _baseLengthB_ is greater than _baseLengthA_, return 1.
+> 1. If _keyA_ does not contain _"*"_, return 1.
+> 1. If _keyB_ does not contain _"*"_, return -1.
+> 1. If the length of _keyA_ is greater than the length of _keyB_, return -1.
+> 1. If the length of _keyB_ is greater than the length of _keyA_, return 1.
+> 1. Return 0.
+
**PACKAGE_TARGET_RESOLVE**(_packageURL_, _target_, _subpath_, _pattern_,
_internal_, _conditions_)
diff --git a/doc/api/packages.md b/doc/api/packages.md
index 09acf5a5490..8817350b646 100644
--- a/doc/api/packages.md
+++ b/doc/api/packages.md
@@ -376,9 +376,8 @@ For these use cases, subpath export patterns can be used instead:
**`*` maps expose nested subpaths as it is a string replacement syntax
only.**
-The left hand matching pattern must always end in `*`. All instances of `*` on
-the right hand side will then be replaced with this value, including if it
-contains any `/` separators.
+All instances of `*` on the right hand side will then be replaced with this
+value, including if it contains any `/` separators.
```js
import featureX from 'es-module-package/features/x';