doc: module resolution pseudocode corrections

PR-URL: https://github.com/nodejs/node/pull/57080
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
This commit is contained in:
Marcel Laverdet 2025-03-22 11:34:29 -05:00 committed by GitHub
parent ffc1cf6205
commit 86d8540773
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View File

@ -899,14 +899,12 @@ 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 _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.
@ -920,7 +918,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_)
@ -938,6 +936,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
@ -961,6 +961,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.
@ -977,14 +979,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_ and does not contain _"\*"_, 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
@ -999,7 +1003,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_)

View File

@ -349,7 +349,7 @@ require(X) from module at path Y
b. STOP
2. If X begins with '/'
a. set Y to the file system root
3. If X begins with './' or '/' or '../'
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"