-
Couldn't load subscription status.
- Fork 46
feat: add JSR protocol support for package specifiers #214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
It seems that parsing a jsr: protocol entry is identical to parsing a scoped package range after you've sliced off the |
|
Thank you for pointing that out. I should have noticed that I've now updated the code accordingly. Thanks for the helpful feedback and review :) |
| if (!spec) { | ||
| return false | ||
| } | ||
| return spec.toLowerCase().startsWith('jsr:') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it intentional that JsR and JSR and jSR etc are all supported? It seems better to only allow the lowercase form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was probably copied from the alias code, and yes it is best to just not support it at the outset. That is, provided it is not supported already in jsr et al.
|
|
||
| function fromJsr (res, where) { | ||
| // Remove 'jsr:' prefix | ||
| const jsrSpec = res.rawSpec.substr(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| const jsrSpec = res.rawSpec.substr(4) | |
| const jsrSpec = res.rawSpec.slice(4) |
substr is legacy
Motivation
Given that JSR is an MIT-licensed open-source solution and is already supported by other package managers such as Volt and pnpm, I believe npm should also adopt this feature to maintain consistency within the JavaScript ecosystem and provide a seamless user experience.
Current Behavior
Before this change, installing JSR packages is possible by adding the following to the
package.json:{ "dependencies": { "@scope/package": "npm:@jsr/[email protected]" } }This approach is rather messy and relies on the npm compatibility registry API to download packages from the JSR registry.
Proposed Solution
The proposed solution would be to handle installing packages from JSR natively. Installing a package from JSR would be simplified to:
Which then installs a JSR package into the
package.jsonas follows:{ "dependencies": { "@scope/package": "jsr:@scope/[email protected]" } }Reference
This implementation is based on the approach discussed in pnpm/pnpm#8941.