# Publish a TypeScript Library to JSR Alongside npm

Yes. An agent adds a jsr.json, makes the sources pass JSR's type checks, adds a workflow that publishes to JSR with GitHub OIDC on each release and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-jsr-publishing/typescript-library/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the library into its own cloud sandbox and reads how it ships today. In a package like sindresorhus/p-queue, `package.json` is `type: module` at version `10.0.0` with `exports` pointing `types` at `./dist/index.d.ts` and `default` at `./dist/index.js`, `files` of just `dist`, `sideEffects: false` and `engines.node >=22`. `build` runs `del-cli dist && tsc`, `test` chains `xo`, the Node test runner through `tsx` over `test/*.ts`, a fresh build and `nz` for the type tests in `test-d/`, and `prepublishOnly` runs the build. `tsconfig.json` extends `@sindresorhus/tsconfig` with `rootDir: source` and `outDir: dist`. The sources are five files under `source/`: `index.ts`, `queue.ts`, `priority-queue.ts`, `options.ts` and `lower-bound.ts`, importing each other with `.js` specifiers such as `./queue.js`. `index.ts` exports a default class `PQueue` that extends `EventTarget`, a `TimeoutError` that extends `DOMException`, the `PriorityQueue` class and the option types. `.npmrc` says `package-lock=false`, there is no `jsr.json` or `deno.json`, and the only workflow runs `npm install` and `npm test` on Node 22, 24 and 26.

JSR publishes TypeScript source rather than a build, so the agent writes `jsr.json` with the scoped name (`@sindresorhus/p-queue` here, under a scope the maintainer creates once on jsr.io), the version copied from `package.json`, `exports` set to `./source/index.ts`, and a `publish.include` list of `source/`, `readme.md` and `license` so tests and benchmarks stay out of the package. Two things in the sources need attention. JSR resolves relative imports to real files and does not map `./queue.js` onto `queue.ts`, so the agent rewrites the relative specifiers to `.ts` and turns on `rewriteRelativeImportExtensions` in `tsconfig.json`, which TypeScript 6 supports, so the `tsc` build for npm still emits `.js` imports in `dist/`. And JSR refuses "slow types": every exported function and method needs an explicit return type and every exported constant an explicit annotation, so `npx jsr publish --dry-run` becomes the check that lists each one, and the agent adds the annotations it names in `index.ts` and `priority-queue.ts` without changing any signature.

The release path is a second workflow, `.github/workflows/jsr.yml`, that runs when a GitHub release is published, with `permissions` of `contents: read` and `id-token: write`, checks out, sets up Node and runs `npx jsr publish`. No token is stored: JSR trusts GitHub's OIDC token once the repository is linked to the package on jsr.io, which is the one step the pull request asks the maintainer to do. A step before the publish compares `version` in `jsr.json` with `package.json` and fails on a mismatch, and the agent adds `npx jsr publish --dry-run` to the existing CI workflow so a pull request that introduces a slow type fails before release day.

Everything is run in the sandbox before the pull request exists: `npm install`, `npm test` (which exercises `xo`, the tests, the `tsc` build and `nz` with the rewritten import specifiers), `npx jsr publish --dry-run` until it reports no problems, and a read of `dist/` to show the emitted `.js` files still import `./queue.js`. The agent does not publish anything; the dry run is the proof that the package would be accepted.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Set up publishing to JSR for this TypeScript library, keeping the npm package unchanged. Read package.json, tsconfig.json, .npmrc, every file under source, test and test-d, and the existing workflow first. Write jsr.json with the scoped package name, the version from package.json, exports pointing at source/index.ts and a publish include list of the sources, readme and license. Rewrite relative imports in source to .ts specifiers and enable rewriteRelativeImportExtensions so tsc still emits .js imports; run npx jsr publish --dry-run and add the explicit return types and annotations it asks for without changing any public signature. Add .github/workflows/jsr.yml that publishes on a published GitHub release with id-token write and no stored token, with a step that fails when jsr.json and package.json versions differ, and add the dry run to the existing CI workflow. Run npm test and the dry run, confirm the dist output still imports .js files, and open a pull request that explains the one-time scope and repository link on jsr.io.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request adding `jsr.json` and `.github/workflows/jsr.yml`, changing `tsconfig.json` and the import specifiers in `source/`, adding the return types the dry run asked for, and adding one dry-run step to `.github/workflows/main.yml`. The description lists each annotation it added with its file and line, and the two manual steps: create the scope on jsr.io and link this repository to the package so OIDC publishing is allowed.

The run's record keeps the full `npm test` output with `xo`, the Node tests, the build and `nz` passing on the rewritten sources, the final clean `jsr publish --dry-run`, and the listing of `dist/index.js` showing `.js` imports, so a reviewer sees that npm consumers are unaffected.

Before merging, a reviewer reads the added type annotations to confirm they match what the implementation returns, checks the include list in `jsr.json` against what the npm package ships, creates the scope, links the repository, and lets the next GitHub release be the first JSR publish.

## Run it on every library release

A maintainer hands this off from the terminal once per library: one `POST /o/{org}/sessions` with this body and the repository in `resources`. Someone who maintains many packages sends one request per repository, each with a `request_id` that is a UUID v5 of the repository path so a retry returns the run it already started, and the key's `webhook_url` reports each run as it finishes with the pull request link.

After the merge, every published GitHub release publishes to JSR through the workflow, and the dry run in CI stops a slow type from reaching the release.

## Why run it on Rush?

JSR's rules are simple to state and tedious to satisfy by hand: real file extensions in imports, explicit types on everything exported, a version that matches npm's. The agent works through them in its own sandbox with the dry run as the judge, keeps the npm build green at every step, and the pull request arrives with the dry run already clean instead of with a guess about what jsr.io will say.

Because the sandbox keeps every command and its output, the reviewer sees the `tsc` emit with `.js` imports and the passing test suite for themselves. The change to a library's public surface is only annotations, and each one is listed by line for review.

## Frequently asked questions

### Does this change what npm users get?

No. The npm package still ships `dist/` built by `tsc`, and `rewriteRelativeImportExtensions` makes the emitted JavaScript import `./queue.js` as before. The dry run and the `dist/` listing in the run's record show both outputs side by side.

### Why rewrite imports to .ts instead of keeping .js?

Because JSR serves the TypeScript sources and resolves each import to a real file; `./queue.js` does not exist in `source/`. TypeScript 6 can emit `.js` from `.ts` specifiers with one compiler option, so both registries are served from the same files.

### Where is the JSR token stored?

Nowhere. The workflow requests a GitHub OIDC token with `id-token: write`, and JSR accepts it once the repository is linked to the package on jsr.io. Revoking access is unlinking the repository; there is no secret to rotate.

### What are slow types and why does the dry run reject them?

Exports whose types JSR would have to infer by running the compiler, such as a method with no return annotation. JSR requires explicit types on the public surface so it can generate documentation and type-check dependents quickly. The agent adds only the annotations the dry run names, and the pull request lists them.

### Can the same workflow publish to npm too?

It could, but this pull request does not touch the npm release, which may already be handled by `np` or another workflow. Keeping JSR in its own workflow means a JSR failure never blocks an npm release, and the version check keeps the two in step.

## More TypeScript library jobs

- [Add Knip to a TypeScript Library's CI](https://getrush.ai/run/add-knip-to-ci/typescript-library/)
- [Add Mutation Testing to a TypeScript Library](https://getrush.ai/run/add-mutation-testing/typescript-library/)
- [Publish a TypeScript Library to npm With Trusted Publishing](https://getrush.ai/run/add-npm-trusted-publishing/typescript-library/)

## More jobs like this: Hand off a long task

- [Add JWT Authentication to an Actix Web API](https://getrush.ai/run/add-jwt-auth/actix/)
- [Add JWT Authentication to a Ktor API](https://getrush.ai/run/add-jwt-auth/ktor/)
- [Add JWT Auth to a Quarkus API](https://getrush.ai/run/add-jwt-auth/quarkus/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
