Skip to content

Latest commit

 

History

History
105 lines (81 loc) · 2.94 KB

introduction.md

File metadata and controls

105 lines (81 loc) · 2.94 KB
title description
Introduction to JSR
JSR is a new modern package registry for JavaScript and TypeScript. It was designed to be fast, simple, and reliable. It is backwards compatible with npm, and natively supports TypeScript.

The JavaScript Registry (JSR) is a modern package registry for JavaScript and TypeScript. JSR works with many runtimes (Node.js, Deno, Bun, browsers, and more) and is backwards compatible with npm. Learn more about why we built JSR.

Using JSR packages

Add a package to your project using one of the commands below. This will add the most recent version of @luca/cases to your project.

# deno
deno add jsr:@luca/cases

# pnpm 10.9+
pnpm add jsr:@luca/cases

# yarn 4.9+
yarn add jsr:@luca/cases

# npm, bun, and older versions of yarn or pnpm
npx jsr add @luca/cases # replace npx with any of yarn dlx, pnpm dlx, or bunx

After adding the package, you can import and use it in ES modules like so:

import { camelCase } from "@luca/cases";

camelCase("hello world"); // "helloWorld"

In Deno, you can optionally use JSR packages without an install step using jsr: specifiers and Deno's native support for JSR.

import { camelCase } from "jsr:@luca/cases@1";

camelCase("hello world"); // "helloWorld"

You can find more packages on jsr.io. Each package on the JSR site also displays documentation, which is automatically generated from the package's source code. Learn more about using packages.

Publishing JSR packages

JSR packages are published using the jsr publish / deno publish command. You can publish packages from your local machine, or from CI.

First, write your code. JSR packages are written in JavaScript or TypeScript, and are published as ES modules.

// mod.ts
/**
 * A module providing a function to greet people.
 * @module
 */

/**
 * Greet a person.
 *
 * @param name The name of the person to greet.
 */
export function greet(name: string) {
  console.log(`Hello, ${name}!`);
}

Then, add a config file to your package. This file contains package metadata like the name, version, and entrypoint(s). The exports field tells JSR which modules should be importable by users of your package.

// jsr.json / deno.json
{
  "name": "@luca/greet",
  "version": "1.0.0",
  "exports": "./mod.ts"
}

Finally, run npx jsr publish, or deno publish to publish your package. You will be prompted to authenticate with JSR, and then your package will be published.

$ npx jsr publish
Visit https://jsr.io/auth?code=ABCD-EFGH to authorize publishing of @luca/greet
Waiting...
Authorization successful. Authenticated as Luca Casonato
Publishing @luca/[email protected] ...
Successfully published @luca/[email protected]
Visit https://jsr.io/@luca/[email protected] for details

Learn more about publishing packages.