Skip to content

Conversation

@eser
Copy link

@eser eser commented Oct 22, 2025

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:

npm i jsr:@scope/package

Which then installs a JSR package into the package.json as follows:

{
  "dependencies": {
    "@scope/package": "jsr:@scope/[email protected]"
  }
}

Reference

This implementation is based on the approach discussed in pnpm/pnpm#8941.

@wraithgar
Copy link
Member

It seems that parsing a jsr: protocol entry is identical to parsing a scoped package range after you've sliced off the jsr: part. If that's so we don't need to re-implement a scoped package parser. Much like how fromAlias works, it parses the reference without npm: and then tweaks the response object. We can do something similar, but probably skip straight to the fromRegistry part.

@eser
Copy link
Author

eser commented Oct 22, 2025

Thank you for pointing that out.

I should have noticed that fromAlias redirects this way earlier.

I've now updated the code accordingly. Thanks for the helpful feedback and review :)

if (!spec) {
return false
}
return spec.toLowerCase().startsWith('jsr:')
Copy link
Contributor

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.

Copy link
Member

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const jsrSpec = res.rawSpec.substr(4)
const jsrSpec = res.rawSpec.slice(4)

substr is legacy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants