fix: treat @jsr/ scoped npm dependencies as JSR dependencies#1256
fix: treat @jsr/ scoped npm dependencies as JSR dependencies#1256amyssnippet wants to merge 5 commits intojsr-io:mainfrom
Conversation
When a JSR package imports an npm package with a name starting with @jsr/, such as npm:@jsr/sigma__deno-compat, treat it as a JSR dependency instead of an npm dependency. This ensures the dependency is resolved from JSR's registry rather than failing on external npm registries. Added conversion logic in collect_dependencies to detect and convert @jsr/scope__package npm specifiers to @scope/package JSR specifiers. Added test case npm_jsr_import to verify the behavior.
- Publish dependency package first in test to ensure JSR dep exists - Change test package name to @scope/bar to avoid self-dependency - Update import to match published dependency version (@1.2.3)
|
This error was rising due to dependency issues and thats why i am update npm_jsr_import test to resolve JSR dependencies correctly |
|
idk why, but this is failing, if any maintainer is looking at this pr, guide me regarding further process, i am a new contributor to jsr |
|
Thanks again for your work, one question: does this special treatment only happen when deno is involved ? because fetching from jsr on other runtimes wont work, for deno it should be a special case but for the others it should work as is as in the user need to setup npmrc (which is ok) |
Use process_tarball_setup2 with package name bar instead of hardcoded foo This prevents conflicts with the dependency package (@scope/foo@1.2.3) Test Data: The npm_jsr_import package is correctly configured as @scope/bar@1.2.3
…ings related to our changes. The collapsible else-if block has been properly collapsed
- Format function signatures and long lines according to rustfmt - Collapse collapsible else-if blocks to satisfy clippy warnings
|
@sigmaSd That is a great question. from my understanding of the codebase, this change happens during the analysis/publish phase in the api, it effectively normalizes the imports, so, this shouldn't break other runtimes. In fact, it leverages JSR's existing compatibility layer to ensure both Deno and npm-based runtimes get the format they handle best. does that align with your understanding of the npm generation logic? |
|
I can't help with that because I have no idea about this codebase, hopefully a maintainer will take a look |
|
Understood. Thanks for taking a look and for the initial feedback! I'll wait for a maintainer to review. |

Problem
JSR packages that depend on other JSR packages via npm specifiers fail to resolve when imported from JSR. For example, importing
https://jsr.io/@sigmasd/gtk@0.11.0fails with "npm package '@jsr/sigma__deno-compat' does not exist" because the package depends onnpm:@jsr/sigma__deno-compat.Root Cause
During package publishing, import statements like
import "npm:@jsr/sigma__deno-compat"are analyzed and classified as npm dependencies. When users import the JSR package, Deno attempts to resolve these npm dependencies from the default npm registry (npmjs.org), but@jsr/scoped packages are only available on JSR's npm registry. Without proper npmrc configuration pointing to JSR's registry, the import fails.Solution
Modified the dependency collection logic to detect npm dependencies with names starting with
@jsr/and treat them as JSR dependencies instead. This ensures they are resolved from JSR's registry rather than external npm registries.Changes
api/src/analysis.rs:convert_npm_jsr_to_jsr_ref()function to convert@jsr/scope__packagenpm specifiers to@scope/packageJSR specifierscollect_dependencies()to check for@jsr/prefixes and convert them to JSR dependenciesapi/src/publish.rs: Added test casenpm_jsr_importto verify the conversion works correctlyapi/testdata/tarballs/npm_jsr_import/: New test data directory with sample package that imports@jsr/scoped npm dependencyTesting
npm_jsr_importthat verifies@jsr/scoped npm dependencies are treated as JSR dependenciesuses_npmflag is false for packages with converted dependenciesCloses #1252
PR Checklist
If it affect colors, please include screenshots/recording in both light and dark mode.
And if changing database queries, be sure you have ran
sqlx prepareand committed the changes in the.sqlxdirectory. (No database query changes made)