Skip to content

feat: add support for the jsr: protocol#9358

Merged
zkochan merged 58 commits into
mainfrom
jsr-8941
Apr 20, 2025
Merged

feat: add support for the jsr: protocol#9358
zkochan merged 58 commits into
mainfrom
jsr-8941

Conversation

@KSXGitHub

Copy link
Copy Markdown
Contributor

Resolves #8941

@KSXGitHub KSXGitHub marked this pull request as ready for review April 1, 2025 12:22
@KSXGitHub KSXGitHub requested a review from zkochan as a code owner April 1, 2025 12:22
Comment thread .changeset/silly-ravens-sink.md Outdated
Comment thread resolving/npm-resolver/src/index.ts Outdated
Comment thread resolving/npm-resolver/src/index.ts Outdated
@KSXGitHub KSXGitHub requested a review from zkochan April 2, 2025 08:28
zkochan

This comment was marked as resolved.

@zkochan

This comment was marked as resolved.

@KSXGitHub

This comment was marked as resolved.

@KSXGitHub KSXGitHub requested a review from zkochan April 4, 2025 06:30
zkochan

This comment was marked as resolved.

Comment thread resolving/npm-resolver/src/index.ts Outdated
Comment thread resolving/npm-resolver/src/index.ts Outdated
@zkochan

This comment was marked as resolved.

@zkochan zkochan requested a review from a team April 4, 2025 12:39
Comment thread resolving/npm-resolver/src/index.ts Outdated
@zkochan

This comment was marked as resolved.

@zkochan zkochan changed the title feat: jsr feat: add support for the jsr: protocol Apr 20, 2025
@zkochan zkochan merged commit 9c3dd03 into main Apr 20, 2025
@zkochan zkochan deleted the jsr-8941 branch April 20, 2025 09:51
@zkochan

zkochan commented Apr 21, 2025

Copy link
Copy Markdown
Member

🚢 10.9

@btea

btea commented Apr 21, 2025

Copy link
Copy Markdown
Member

I'm not sure if this is a problem with the parsing result. When I execute pnpm add jsr:@sxzz/tsdown, the corresponding dependencies can be installed, but the content in package.json is missing. https://jsr.io/@sxzz/tsdown/0.9.1/package.json

image

cc @KSXGitHub @zkochan

@KSXGitHub

Copy link
Copy Markdown
Contributor Author

@btea The JSR npm compatibility layer seems to generate its own package.json

package.json
{
  "name": "@jsr/sxzz__tsdown",
  "version": "0.9.1",
  "homepage": "https://jsr.io/@sxzz/tsdown",
  "type": "module",
  "dependencies": {
    "ansis": "^3.17.0",
    "chokidar": "^4.0.3",
    "consola": "^3.4.2",
    "debug": "^4.4.0",
    "find-up-simple": "^1.0.1",
    "pkg-types": "^2.1.0",
    "publint": "^0.3.12",
    "rolldown": "^1.0.0-beta.7",
    "rolldown-plugin-dts": "^0.8.0",
    "tinyexec": "^1.0.1",
    "tinyglobby": "^0.2.12",
    "unconfig": "^7.3.1",
    "unplugin-unused": "^0.4.4",
    "vite": "^6.3.2"
  },
  "exports": {
    ".": {
      "types": "./_dist/src/index.d.ts",
      "default": "./src/index.js"
    }
  },
  "_jsr_revision": 11
}

The links to the tarballs is in https://npm.jsr.io/@jsr/sxzz__tsdown

@KSXGitHub

Copy link
Copy Markdown
Contributor Author

@btea npm jsr add @sxzz/tsdown also gives the same package.json:

screenshot

@btea

btea commented Apr 21, 2025

Copy link
Copy Markdown
Member

Looks a bit weird, I haven't used jsr before, so is this normal?

@KSXGitHub

Copy link
Copy Markdown
Contributor Author

Looks a bit weird, I haven't used jsr before, so is this normal?

We can't do anything about it because we don't control the jsr registry.

@btea

btea commented Apr 21, 2025

Copy link
Copy Markdown
Member

Got it.

zkochan added a commit that referenced this pull request Apr 29, 2026
 This is consistent with #9358, but implements support for the GitHub Packages npm registry and, more broadly, for vlt-style https://docs.vlt.sh/cli/registries for any registry.

This PR adds a built-in gh: specifier that resolves against the GitHub Packages npm registry, plus a namedRegistries config key so a project can map its own aliases to arbitrary registries. A project can mix public npm packages and private GitHub Packages (or self-hosted) ones without applying a scope-wide registry override to every @scope/* package.

- pnpm add gh:@acme/private writes "@acme/private": "gh:^1.0.0" and resolves from https://npm.pkg.github.com/.
- pnpm add gh:@acme/private@^1.0.0 (with or without an alias) is also supported. Aliased form writes "my-alias": "gh:@acme/private@^1.0.0".
- Auth comes from the existing per-URL .npmrc mechanism, e.g. //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}. No new auth surface.
- @github is intentionally not defaulted to https://npm.pkg.github.com/ - hardcoding that would hijack installs of the public @github/* packages on npmjs.org (e.g. @github/relative-time-element) for users without a scope-wide override. Use gh: to install from GitHub Packages, or configure @github:registry=... yourself if that's really what you want.
- Additional named registries (a self-hosted proxy, GitHub Enterprise Server, etc.) can be configured in pnpm-workspace.yaml:

```yml
namedRegistries:
  gh: https://npm.pkg.github.example.com/   # optional: overrides the built-in `gh` alias for GHES
  work: https://npm.work.example.com/
```

- Then work:@corp/lib@^2.0.0 resolves against https://npm.work.example.com/, and the built-in gh alias can be redirected to a GHES host.
- Env-var substitution (${VAR}) is supported in namedRegistries values, mirroring the .npmrc convention.
- Reserved alias names (npm, jsr, github, workspace, catalog, file, git, http, https, link, patch, and related git host shorthands) cannot be redefined as user-named registries - the resolver throws ERR_PNPM_RESERVED_NAMED_REGISTRY_ALIAS at startup rather than silently shadowing another protocol. Malformed URLs throw ERR_PNPM_INVALID_NAMED_REGISTRY_URL at startup too, instead of failing as a confusing 404 during resolution.
- On publish, createExportableManifest strips any named-registry prefix (both the built-in gh: and any user-configured alias) so npm and yarn consumers can still resolve the dependency via their own scope-registry configuration - mirroring the user-facing requirement when installing such a dep without the prefix.

The prefix is gh: rather than github: because github: is reserved by npm-package-arg / hosted-git-info as a git host shorthand (e.g. github:owner/repo) - reusing it would be a deviation from the specs used by the npm CLI. gh: is  shorter, matches vlt's convention, and cannot collide with any existing npm scheme.

Unlike jsr:, gh: (and any other named-registry alias) does not rewrite the package name - gh:@acme/foo resolves @acme/foo from the GitHub Packages registry as-is. This also means npm/yarn consumers see the original name after the prefix is stripped on publish.

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
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.

Add support for installing JSR packages directly

5 participants