From e1d83e3d2774b9d5771e63ea64548b47228a0f64 Mon Sep 17 00:00:00 2001 From: guybedford Date: Mon, 5 Nov 2018 13:28:40 +0200 Subject: [PATCH] move package parsing into package_resolve --- doc/api/esm.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index 373f7c15ba..e8c31674e9 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -202,16 +202,7 @@ The algorithm to resolve an ES module specifier is provided through _ESM_RESOLVE > 1. Let _resolvedURL_ be the URL resolution of _specifier_ to _parentURL_. > 1. Return the result of **PATH_RESOLVE**(_resolvedURL_). > 1. Note: _specifier_ is now a bare specifier. -> 1. Let _packageName_ be _undefined_. -> 1. Let _packagePath_ be _undefined_. -> 1. If _name_ does not start with _"@"_ then, -> 1. Set _packageName_ to the substring of _specifier_ until the first _"/"_ separator or the end of the string. -> 1. If _name_ starts with _"@"_ then, -> 1. If _name_ does not contain a _"/"_ separator then, -> 1. Throw a _Invalid Package Name_ error. -> 1. Set _packageName_ to the substring of _specifier_ until the second _"/"_ separator or the end of the string. -> 1. Let _packagePath_ be the substring of _specifier_ from the position at the length of _packageName_ plus one, if any. -> 1. Return the result of **PACKAGE_RESOLVE**(_packageName_, _packagePath_, _parentURL_), or propagating any errors thrown. +> 1. Return the result of **PACKAGE_RESOLVE**(_specifier_). **PATH_RESOLVE**(_resolvedURL_) > 1. If the file at _resolvedURL_ exists then, @@ -221,9 +212,19 @@ The algorithm to resolve an ES module specifier is provided through _ESM_RESOLVE > 1. Return _packageMainURL_. > 1. Throw a _Module Not Found_ error. -**PACKAGE_RESOLVE**(_packageName_, _packagePath_, _parentURL_) -> 1. Assert: _packagePath_ is either empty, or a path without a leading separator. +**PACKAGE_RESOLVE**(_packageSpecifier_) +> 1. Assert: _packageSpecifier_ is a valid bare specifier. +> 1. Let _packageName_ be _undefined_. +> 1. Let _packagePath_ be _undefined_. +> 1. If _packageSpecifier_ does not start with _"@"_ then, +> 1. Set _packageName_ to the substring of _packageSpecifier_ until the first _"/"_ separator or the end of the string. +> 1. If _packageSpecifier_ starts with _"@"_ then, +> 1. If _packageSpecifier_ does not contain a _"/"_ separator then, +> 1. Throw a _Invalid Package Name_ error. +> 1. Set _packageName_ to the substring of _packageSpecifier_ until the second _"/"_ separator or the end of the string. +> 1. Let _packagePath_ be the substring of _packageSpecifier_ from the position at the length of _packageName_ plus one, if any. > 1. Assert: _packageName_ is a valid package name or scoped package name. +> 1. Assert: _packagePath_ is either empty, or a path without a leading separator. > 1. Note: Further package name encoding validations can be added here. > 1. If _packagePath_ is empty and _packageName_ is a Node.js builtin module then, > 1. Return _"node:${packageName}"_.