From bd047e827719805a709f62bddcf627634ef64440 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 17 Dec 2019 01:58:19 -0500 Subject: module: self resolve bug fix and esm ordering PR-URL: https://github.com/nodejs/node/pull/31009 Reviewed-By: Jan Krems --- doc/api/esm.md | 36 ++++++++++++++++++------------------ doc/api/modules.md | 13 +++++++------ 2 files changed, 25 insertions(+), 24 deletions(-) (limited to 'doc') diff --git a/doc/api/esm.md b/doc/api/esm.md index 4898edfc3a9..9fb9f60b289 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -1207,6 +1207,9 @@ _defaultEnv_ is the conditional environment name priority array, > 1. If _packageSubpath_ contains any _"."_ or _".."_ segments or percent > encoded strings for _"/"_ or _"\\"_, then > 1. Throw an _Invalid Specifier_ error. +> 1. Set _selfUrl_ to the result of +> **SELF_REFERENCE_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_). +> 1. If _selfUrl_ isn't empty, return _selfUrl_. > 1. If _packageSubpath_ is _undefined_ and _packageName_ is a Node.js builtin > module, then > 1. Return the string _"node:"_ concatenated with _packageSpecifier_. @@ -1228,30 +1231,27 @@ _defaultEnv_ is the conditional environment name priority array, > 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, > _packageSubpath_, _pjson.exports_). > 1. Return the URL resolution of _packageSubpath_ in _packageURL_. -> 1. Set _selfUrl_ to the result of -> **SELF_REFERENCE_RESOLE**(_packageSpecifier_, _parentURL_). -> 1. If _selfUrl_ isn't empty, return _selfUrl_. > 1. Throw a _Module Not Found_ error. -**SELF_REFERENCE_RESOLVE**(_specifier_, _parentURL_) +**SELF_REFERENCE_RESOLVE**(_packageName_, _packageSubpath_, _parentURL_) > 1. Let _packageURL_ be the result of **READ_PACKAGE_SCOPE**(_parentURL_). > 1. If _packageURL_ is **null**, then -> 1. Return an empty result. +> 1. Return **undefined**. > 1. Let _pjson_ be the result of **READ_PACKAGE_JSON**(_packageURL_). -> 1. Set _name_ to _pjson.name_. -> 1. If _name_ is empty, then return an empty result. -> 1. If _name_ is equal to _specifier_, then -> 1. Return the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_, _pjson_). -> 1. If _specifier_ starts with _name_ followed by "/", then -> 1. Set _subpath_ to everything after the "/". -> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then -> 1. Let _exports_ be _pjson.exports_. -> 1. If _exports_ is not **null** or **undefined**, then -> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_, -> _pjson.exports_). -> 1. Return the URL resolution of _subpath_ in _packageURL_. -> 1. Otherwise return an empty result. +> 1. If _pjson_ does not include an _"exports"_ property, then +> 1. Return **undefined**. +> 1. If _pjson.name_ is equal to _packageName_, then +> 1. If _packageSubpath_ is _undefined_, then +> 1. Return the result of **PACKAGE_MAIN_RESOLVE**(_packageURL_, _pjson_). +> 1. Otherwise, +> 1. If _pjson_ is not **null** and _pjson_ has an _"exports"_ key, then +> 1. Let _exports_ be _pjson.exports_. +> 1. If _exports_ is not **null** or **undefined**, then +> 1. Return **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _subpath_, +> _pjson.exports_). +> 1. Return the URL resolution of _subpath_ in _packageURL_. +> 1. Otherwise, return **undefined**. **PACKAGE_MAIN_RESOLVE**(_packageURL_, _pjson_) diff --git a/doc/api/modules.md b/doc/api/modules.md index 9dc5cd22248..bac8b21d775 100644 --- a/doc/api/modules.md +++ b/doc/api/modules.md @@ -160,9 +160,9 @@ require(X) from module at path Y a. LOAD_AS_FILE(Y + X) b. LOAD_AS_DIRECTORY(Y + X) c. THROW "not found" -4. LOAD_NODE_MODULES(X, dirname(Y)) -5. LOAD_SELF_REFERENCE(X, dirname(Y)) -6. THROW "not found" +4. LOAD_SELF_REFERENCE(X, dirname(Y)) +5. LOAD_NODE_MODULES(X, dirname(Y)) +7. THROW "not found" LOAD_AS_FILE(X) 1. If X is a file, load X as JavaScript text. STOP @@ -205,9 +205,10 @@ NODE_MODULES_PATHS(START) LOAD_SELF_REFERENCE(X, START) 1. Find the closest package scope to START. -2. If no scope was found, throw "not found". -3. If the name in `package.json` isn't a prefix of X, throw "not found". -4. Otherwise, resolve the remainder of X relative to this package as if it +2. If no scope was found, return. +3. If the `package.json` has no "exports", return. +4. If the name in `package.json` isn't a prefix of X, throw "not found". +5. Otherwise, resolve the remainder of X relative to this package as if it was loaded via `LOAD_NODE_MODULES` with a name in `package.json`. ``` -- cgit v1.2.3