You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the resolver algorithm specification, READ_PACKAGE_SCOPE returns a parsed JSON value but is then used as a URL. Surely this is a mistake. In detail:
The READ_PACKAGE_JSON function either returns null, throws an error, or returns a parsed JSON value:
READ_PACKAGE_JSON(packageURL)
Let pjsonURL be the resolution of "package.json" within packageURL.
If the file at pjsonURL does not exist, then
Return null.
If the file at packageURL does not parse as valid JSON, then
Throw an Invalid Package Configuration error.
Return the parsed JSON source of the file at pjsonURL.
The READ_PACKAGE_SCOPE function either returns null or the result of calling READ_PACKAGE_JSON, so it also returns a parsed JSON value (called pjson below):
READ_PACKAGE_SCOPE(url)
Let scopeURL be url.
While scopeURL is not the file system root,
Set scopeURL to the parent URL of scopeURL.
If scopeURL ends in a "node_modules" path segment, return null.
Let pjson be the result of READ_PACKAGE_JSON(scopeURL).
If pjson is not null, then
Return pjson.
Return null.
The ESM_FORMAT function calls READ_PACKAGE_SCOPE and uses the result as a parsed JSON object (called pjson below):
ESM_FORMAT(url)
Assert: url corresponds to an existing file.
Let pjson be the result of READ_PACKAGE_SCOPE(url).
If url ends in ".mjs", then
Return "module".
If url ends in ".cjs", then
Return "commonjs".
If pjson?.type exists and is "module", then
If url ends in ".js", then
Return "module".
Throw an Unsupported File Extension error.
Otherwise,
Throw an Unsupported File Extension error.
However, both PACKAGE_SELF_RESOLVE and PACKAGE_IMPORTS_RESOLVE call READ_PACKAGE_SCOPE and use the result as a URL (called packageURL below). In particular, they pass the result to READ_PACKAGE_JSON again. I assume READ_PACKAGE_JSON is not meant to be called on its own result:
If specifier is exactly equal to "#" or starts with "#/", then
Throw an Invalid Module Specifier error.
Let packageURL be the result of READ_PACKAGE_SCOPE(parentURL).
If packageURL is not null, then
Let pjson be the result of READ_PACKAGE_JSON(packageURL).
If pjson.imports is a non-null Object, then
Let resolved be the result of PACKAGE_IMPORTS_EXPORTS_RESOLVE( specifier, pjson.imports, packageURL, true, conditions).
If resolved is not null or undefined, return resolved.
Throw a Package Import Not Defined error.
If this was type checked, this would be a type error. I'm not sure what the right fix is. Maybe READ_PACKAGE_SCOPE should return a URL instead? Anyway I think the docs should be updated even if it's possible to figure out what they actually mean, because the mismatch is unnecessarily confusing.
I would like to work on this issue and
submit a pull request.
The text was updated successfully, but these errors were encountered:
📗 API Reference Docs Problem
Location
Resolver Algorithm Specification
Affected URL(s):
Description
In the resolver algorithm specification,
READ_PACKAGE_SCOPE
returns a parsed JSON value but is then used as a URL. Surely this is a mistake. In detail:The
READ_PACKAGE_JSON
function either returns null, throws an error, or returns a parsed JSON value:The
READ_PACKAGE_SCOPE
function either returnsnull
or the result of callingREAD_PACKAGE_JSON
, so it also returns a parsed JSON value (called pjson below):The
ESM_FORMAT
function callsREAD_PACKAGE_SCOPE
and uses the result as a parsed JSON object (called pjson below):However, both
PACKAGE_SELF_RESOLVE
andPACKAGE_IMPORTS_RESOLVE
callREAD_PACKAGE_SCOPE
and use the result as a URL (called packageURL below). In particular, they pass the result toREAD_PACKAGE_JSON
again. I assumeREAD_PACKAGE_JSON
is not meant to be called on its own result:If this was type checked, this would be a type error. I'm not sure what the right fix is. Maybe
READ_PACKAGE_SCOPE
should return a URL instead? Anyway I think the docs should be updated even if it's possible to figure out what they actually mean, because the mismatch is unnecessarily confusing.submit a pull request.
The text was updated successfully, but these errors were encountered: