From 781c02f5b4ac9dbf6e696b7aea0eb359bb8b726a Mon Sep 17 00:00:00 2001 From: Marcel Laverdet Date: Sat, 15 Feb 2025 17:18:47 -0600 Subject: [PATCH 1/3] doc: module resolution pseudocode corrections --- doc/api/esm.md | 5 +++-- doc/api/modules.md | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 8b371941c42cdc..300459f7c53359 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -876,7 +876,7 @@ The resolver can throw the following errors: > 10. If _selfUrl_ is not **undefined**, return _selfUrl_. > 11. While _parentURL_ is not the file system root, > 1. Let _packageURL_ be the URL resolution of _"node\_modules/"_ -> concatenated with _packageSpecifier_, relative to _parentURL_. +> concatenated with _packageName_, relative to _parentURL_. > 2. Set _parentURL_ to the parent folder URL of _parentURL_. > 3. If the folder at _packageURL_ does not exist, then > 1. Continue the next loop iteration. @@ -947,7 +947,8 @@ 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 contain _"\*"_, then +> 1. If _matchKey_ is a key of _matchObj_, does not contain _"\*"_, and does not +> end with _"/"_ then > 1. Let _target_ be the value of _matchObj_\[_matchKey_]. > 2. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_, > _target_, **null**, _isImports_, _conditions_). diff --git a/doc/api/modules.md b/doc/api/modules.md index 1647bcaede2e9a..4ad239633005d1 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -346,8 +346,8 @@ require(X) from module at path Y a. return the core module b. STOP 2. If X begins with '/' - a. set Y to the file system root -3. If X begins with './' or '/' or '../' + a. set Y to be the file system root +3. If X is equal to '.', or X begins with './', '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) c. THROW "not found" From d885678cbe3aaa5567860a8554e2b281349b921c Mon Sep 17 00:00:00 2001 From: Marcel Laverdet Date: Wed, 19 Feb 2025 17:13:51 -0600 Subject: [PATCH 2/3] doc: Fix merge error See: ecf803daca --- doc/api/modules.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/modules.md b/doc/api/modules.md index 4ad239633005d1..adc6bc3f712b18 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -346,7 +346,7 @@ require(X) from module at path Y a. return the core module b. STOP 2. If X begins with '/' - a. set Y to be the file system root + a. set Y to the file system root 3. If X is equal to '.', or X begins with './', '/' or '../' a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) From 43055379b04e32ddba551f54303159d818f4d7bf Mon Sep 17 00:00:00 2001 From: Marcel Laverdet Date: Sun, 23 Feb 2025 16:38:56 -0600 Subject: [PATCH 3/3] doc: Further resolver tweaks --- doc/api/esm.md | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 300459f7c53359..c5cd3c366694e6 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -869,12 +869,10 @@ The resolver can throw the following errors: > 1. Throw an _Invalid Module Specifier_ error. > 7. Let _packageSubpath_ be _"."_ concatenated with the substring of > _packageSpecifier_ from the position at the length of _packageName_. -> 8. If _packageSubpath_ ends in _"/"_, then -> 1. Throw an _Invalid Module Specifier_ error. -> 9. Let _selfUrl_ be the result of +> 8. Let _selfUrl_ be the result of > **PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_). -> 10. If _selfUrl_ is not **undefined**, return _selfUrl_. -> 11. While _parentURL_ is not the file system root, +> 9. If _selfUrl_ is not **undefined**, return _selfUrl_. +> 10. While _parentURL_ is not the file system root, > 1. Let _packageURL_ be the URL resolution of _"node\_modules/"_ > concatenated with _packageName_, relative to _parentURL_. > 2. Set _parentURL_ to the parent folder URL of _parentURL_. @@ -890,7 +888,7 @@ The resolver can throw the following errors: > 1. Return the URL resolution of _main_ in _packageURL_. > 7. Otherwise, > 1. Return the URL resolution of _packageSubpath_ in _packageURL_. -> 12. Throw a _Module Not Found_ error. +> 11. Throw a _Module Not Found_ error. **PACKAGE\_SELF\_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_) @@ -908,6 +906,8 @@ The resolver can throw the following errors: **PACKAGE\_EXPORTS\_RESOLVE**(_packageURL_, _subpath_, _exports_, _conditions_) +Note: This function is directly invoked by the CommonJS resolution algorithm. + > 1. If _exports_ is an Object with both a key starting with _"."_ and a key not > starting with _"."_, throw an _Invalid Package Configuration_ error. > 2. If _subpath_ is equal to _"."_, then @@ -931,6 +931,8 @@ The resolver can throw the following errors: **PACKAGE\_IMPORTS\_RESOLVE**(_specifier_, _parentURL_, _conditions_) +Note: This function is directly invoked by the CommonJS resolution algorithm. + > 1. Assert: _specifier_ begins with _"#"_. > 2. If _specifier_ is exactly equal to _"#"_ or starts with _"#/"_, then > 1. Throw an _Invalid Module Specifier_ error. @@ -947,15 +949,16 @@ The resolver can throw the following errors: **PACKAGE\_IMPORTS\_EXPORTS\_RESOLVE**(_matchKey_, _matchObj_, _packageURL_, _isImports_, _conditions_) -> 1. If _matchKey_ is a key of _matchObj_, does not contain _"\*"_, and does not -> end with _"/"_ then +> 1. If _matchKey_ ends in _"/"_, then +> 1. Throw an _Invalid Module Specifier_ error. +> 2. If _matchKey_ is a key of _matchObj_ and does not contain _"\*"_, then > 1. Let _target_ be the value of _matchObj_\[_matchKey_]. > 2. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_, > _target_, **null**, _isImports_, _conditions_). -> 2. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a +> 3. Let _expansionKeys_ be the list of keys of _matchObj_ containing only a > single _"\*"_, sorted by the sorting function **PATTERN\_KEY\_COMPARE** > which orders in descending order of specificity. -> 3. For each key _expansionKey_ in _expansionKeys_, do +> 4. For each key _expansionKey_ in _expansionKeys_, do > 1. Let _patternBase_ be the substring of _expansionKey_ up to but excluding > the first _"\*"_ character. > 2. If _matchKey_ starts with but is not equal to _patternBase_, then @@ -970,7 +973,7 @@ _isImports_, _conditions_) > _matchKey_ minus the length of _patternTrailer_. > 3. Return the result of **PACKAGE\_TARGET\_RESOLVE**(_packageURL_, > _target_, _patternMatch_, _isImports_, _conditions_). -> 4. Return **null**. +> 5. Return **null**. **PATTERN\_KEY\_COMPARE**(_keyA_, _keyB_)