fix(npm): support catalog: protocol in deno.json imports#35168
Merged
Conversation
Expand `catalog:`/`catalog:<name>` values in deno.json "imports" and "scopes" to the "npm:<name>@<version_req>" specifier from the workspace root catalog when building the synthetic import map, so resolution, deno install (including materializing the package and its bin entries into node_modules), the lockfile, and deno compile all see a regular npm specifier. Fixes #35165
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously
catalog:was only supported inpackage.jsondependencies. Using it in deno.jsonimportswas silently broken everywhere:deno runfailed withUnsupported scheme "catalog" for module "catalog:", anddeno installskipped the entry entirely, so the package was never materialized intonode_modules(and its CLI bin entries were never created).This PR makes
catalog:/catalog:<name>work in deno.jsonimports(andscopes):libs/resolver/workspace.rs): when building the synthetic import map,catalog:values are replaced with thenpm:<name>@<version_req>specifier from the workspace root catalog (package name taken from the import key, matching pnpm semantics). A trailing-slash entry is added so subpath imports work, mirroring the existingnpm:expansion. A missing catalog entry fails with the same error already used for package.json catalog deps:Package '<name>' not found in catalog. External import map files are not expanded, consistent with how the bare specifier expansion only applies to inline imports.libs/npm_installer/package_json.rs):NpmInstallDepsProviderresolvescatalog:values in deno.json imports sodeno installmaterializes the package (and its bin entries) intonode_modulesinautoandmanualmodes.libs/config,libs/resolver/lockfile.rs):ConfigFile::dependencies()now takes the workspace catalogs and resolvescatalog:import entries, so the resolved req is tracked under the lockfile'sworkspaceconfig (previously the entry was dropped). Linked packages pass empty catalogs since another workspace's catalog shouldn't apply to them.Verified that
deno run,deno install(none/auto/manual), subpath imports, workspace members referencing the root catalog, named catalogs, anddeno compileall work, with behavior matching plainnpm:import map entries.Spec tests added for install materialization in
manualmode (including a named catalog), running without a node_modules dir, and the missing-catalog-entry error.Fixes #35165