### Start Next.js Development Server Source: https://jsr.io/docs/with/nextjs Run the command to start the local development server for your Next.js application. ```bash next dev ``` -------------------------------- ### Start Vite Development Server Source: https://jsr.io/docs/with/vite Run the 'vite' command to start the local development server for your Vite project. ```bash vite ``` -------------------------------- ### Install Deno Canary Build Source: https://jsr.io/docs/migrate-x-to-jsr Install the latest canary build of the Deno CLI to use the migration tool. ```bash deno upgrade --canary ``` -------------------------------- ### Including Examples in Module Documentation Source: https://jsr.io/docs/writing-docs You can include code examples within the module's JSDoc comment using the @example tag and a fenced code block. ```typescript /** * This module contains functions to search the database. * * @example * ```ts * import { search } from "@luca/search"; * * search("Alan") // ["Alan Turing", "Alan Kay", ...] * ``` * * @module */ ``` -------------------------------- ### Package Version Metadata Example Source: https://jsr.io/docs/api An example of the JSON structure for package version metadata. It details the files within the version, their sizes and checksums, and the package's exports. ```json { "manifest": { "/deno.json": { "size": 75, "checksum": "sha256-98719bf861369684be254b01f1427084dc6d16b506809719122890784542496b" }, "/LICENSE": { "size": 1070, "checksum": "sha256-c3f0644e8374585b209ea5206ab88055c1c503c202bff5d1f01bb29c07041fbb" }, "/README.md": { "size": 279, "checksum": "sha256-f544a1489e93e93957d6bd03f069e0db7a9bef4af6eeae46a86b4e3316e598c3" }, "/main.ts": { "size": 2989, "checksum": "sha256-a41796ceb0be1bca3aa446ddebebcd732492ccb2cdcb8912adbabef3375fafc8" } }, "moduleGraph1": { "/main.ts": {} }, "exports": { ".": "./main.ts" } } ``` -------------------------------- ### Package Metadata Example Source: https://jsr.io/docs/api An example of the JSON structure returned for package metadata. It includes the scope, name, and a map of versions, with each version potentially indicating if it's yanked. ```json { "scope": "luca", "name": "flag", "versions": { "1.0.0": { "yanked": true }, "1.0.1": {} } } ``` -------------------------------- ### Example .d.ts file for JavaScript Entrypoint Source: https://jsr.io/docs/about-slow-types This is an example of a TypeScript declaration file (`.d.ts`) that can be referenced by a JavaScript entrypoint to provide type information to JSR. ```typescript // index.d.ts export function foo(): string; ``` -------------------------------- ### Package Configuration (Single Entrypoint) Source: https://jsr.io/docs/publishing-packages Configure package metadata like name, version, and entrypoint using `jsr.json` or `deno.json(c)`. This example defines a single default entrypoint. ```json { "name": "@luca/greet", "version": "1.0.0", "exports": "./mod.ts" } ``` -------------------------------- ### Install JSR Package with vlt Source: https://jsr.io/docs/npm-compatibility Use `vlt install` to add JSR packages to your project if you are using vlt. ```bash vlt install jsr:@luca/cases ``` -------------------------------- ### Example Module URL Source: https://jsr.io/docs/api This is the URL format for directly accessing a module file from the JSR registry. Modules are immutable and can be cached indefinitely. ```text https://jsr.io/@/// ``` ```text https://jsr.io/@luca/flag/1.0.0/main.ts ``` -------------------------------- ### Dependency Manifest Example Source: https://jsr.io/docs/publishing-packages Simplify imports using a dependency manifest like `package.json` or `deno.json(c)`. `jsr publish` rewrites specifiers to fully qualified ones. ```json { "imports": { "@luca/greet": "jsr:@luca/greet@1", "@std/path": "jsr:@std/path@1" } } ``` ```typescript export { greet } from "@luca/greet"; export { join } from "@std/path"; ``` -------------------------------- ### Start local development server for Cloudflare Worker Source: https://jsr.io/docs/with/cloudflare-workers Run `wrangler dev` to start the local development server for your Cloudflare Worker. Access your worker at `http://localhost:8787`. ```bash wrangler dev ``` -------------------------------- ### Import and Use JSR Packages in Node.js Source: https://jsr.io/docs/with/node Import JSR packages into your Node.js code after installation. This example shows how to import and use a color formatting function. ```javascript import { red } from "@std/fmt/colors"; console.log(red("Hello, world!")); ``` -------------------------------- ### Install Pre-release Version Source: https://jsr.io/docs/packages Explicitly specify a pre-release version when importing from a package. This is necessary because Semver resolution excludes pre-release versions by default. ```typescript import { foo } from "jsr:@scope/my-package@2.0.0-beta.1"; ``` -------------------------------- ### Install JSR Package with pnpm Source: https://jsr.io/docs/npm-compatibility Use `pnpm install` to add JSR packages to your project if you are using pnpm version 10.9 or later. ```bash pnpm install jsr:@luca/cases ``` -------------------------------- ### Install JSR packages using npm, yarn, or pnpm Source: https://jsr.io/docs/npm-compatibility Manually install JSR packages using your preferred package manager by specifying the @jsr scope and the package name. ```bash npm install @jsr/luca__cases@1 # installs the @luca/cases package from JSR ``` ```bash yarn add @jsr/luca__cases@1 # installs the @luca/cases package from JSR ``` ```bash pnpm install @jsr/luca__cases@1 # installs the @luca/cases package from JSR ``` -------------------------------- ### Including Code Examples in JSDoc Comments Source: https://jsr.io/docs/writing-docs Embed code examples within JSDoc comments using fenced code blocks (```ts ... ```) to demonstrate how to use a function. These examples are rendered in the generated documentation. ```typescript /** * Search the database with the given query. * * ```ts * search("Alan") // ["Alan Turing", "Alan Kay", ...] * ``` */ export function search(query: string, limit: number = 20): string[]; ``` -------------------------------- ### Example .d.ts file for Imported JavaScript Module Source: https://jsr.io/docs/about-slow-types This is an example of a TypeScript declaration file (`.d.ts`) for a JavaScript module that is imported elsewhere. It provides type information for the imported function. ```typescript // bar.d.ts export function foo(): string; ``` -------------------------------- ### Import and Use JSR Package Source: https://jsr.io/docs After adding a package, import and use its functions in your ES modules. This example shows importing and using `camelCase` from `@luca/cases`. ```javascript import { camelCase } from "@luca/cases"; camelCase("hello world"); // "helloWorld" ``` -------------------------------- ### Download Module Source: https://jsr.io/docs/api Modules are served using standard HTTP GET requests. This endpoint allows direct download of module files. ```APIDOC ## GET /@/// ### Description Retrieves a specific module file from a package version. ### Method GET ### Endpoint https://jsr.io/@/// ### Parameters #### Path Parameters - **scope** (string) - Required - The scope of the package. - **package-name** (string) - Required - The name of the package. - **version** (string) - Required - The version of the package. - **path** (string) - Required - The path to the module within the package. ### Request Example ``` GET /@luca/flag/1.0.0/main.ts Host: jsr.io Accept: application/javascript ``` ### Response #### Success Response (200) - **(file content)** - The content of the requested module file. ``` -------------------------------- ### Install JSR Package with JSR CLI Source: https://jsr.io/docs/npm-compatibility Use the JSR CLI with `npx jsr add` for npm, older pnpm/Yarn versions, or Bun. The package manager is auto-detected, or can be specified with flags like `--npm`, `--yarn`, or `--pnpm`. ```bash npx jsr add @luca/cases ``` -------------------------------- ### Import JSR packages with the @jsr scope Source: https://jsr.io/docs/npm-compatibility Import packages directly using the @jsr scope after installation. ```javascript import { camelCase } from "@jsr/luca__cases"; ``` -------------------------------- ### Use JSR Packages in Deno with `jsr:` Specifiers Source: https://jsr.io/docs In Deno, you can use JSR packages directly with `jsr:` specifiers without an explicit install step, leveraging Deno's native support. ```javascript import { camelCase } from "jsr:@luca/cases@1"; camelCase("hello world"); // "helloWorld" ``` -------------------------------- ### Include specific files in jsr.json Source: https://jsr.io/docs/publishing-packages Configure the `publish.include` field in `jsr.json` to specify which files should be included in the package. This example includes LICENSE, README.md, and all TypeScript files in the src directory. ```json // jsr.json { "name": "@luca/greet", "version": "1.0.0", "exports": "./src/mod.ts", // note: this will be collapsed down to just include in the future "publish": { "include": [ "LICENSE", "README.md", "src/**/*.ts" ] } } ``` -------------------------------- ### Import JSR Package Directly with `jsr:` Specifier Source: https://jsr.io/docs/using-packages In Deno, you can import packages directly using `jsr:` specifiers without needing an install step or import map entry. ```javascript import { camelCase } from "jsr:@luca/cases@^1.0.1"; camelCase("hello world"); // "helloWorld" ``` -------------------------------- ### Install JSR Package with Yarn Source: https://jsr.io/docs/npm-compatibility Use `yarn add` to add JSR packages to your project if you are using Yarn version 4.9 or later. ```bash yarn add jsr:@luca/cases ``` -------------------------------- ### Configure Import Map for JSR Packages in Deno Source: https://jsr.io/docs/native-imports Use an import map in `deno.json(c)` to alias `jsr:` schemes for cleaner imports. This example maps `@luca/cases` to a specific JSR package version. ```json { "imports": { "@luca/cases": "jsr:@luca/cases@1" } } ``` -------------------------------- ### JSR Package Module Code Source: https://jsr.io/docs Write your JSR package code in JavaScript or TypeScript, exporting functions as ES modules. This example defines a `greet` function. ```typescript // 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}!`); } ``` -------------------------------- ### Create a New Vite Project Source: https://jsr.io/docs/with/vite Use npm, yarn, pnpm, or bun to initialize a new Vite project. ```bash npm init vite@latest ``` ```bash yarn create vite ``` ```bash pnpm create vite ``` ```bash bun create vite ``` -------------------------------- ### Publishing from Local Machine Source: https://jsr.io/docs/publishing-packages Publish packages from your local machine by navigating to the package root directory and running the `deno publish` command. Authentication is handled via browser. ```bash # deno deno publish ``` -------------------------------- ### Create a New Next.js Project Source: https://jsr.io/docs/with/nextjs Use your preferred package manager to initialize a new Next.js project. ```bash npx create-next-app@latest ``` ```bash yarn create next-app ``` ```bash pnpm create next-app ``` ```bash bun create next-app ``` -------------------------------- ### Package Configuration (Multiple Entrypoints) Source: https://jsr.io/docs/publishing-packages Configure multiple entrypoints for your package using the object syntax for `exports` in `jsr.json` or `deno.json(c)`. The `.` key specifies the default entrypoint. ```json { "name": "@luca/greet", "version": "1.0.0", "exports": { ".": "./mod.ts", "./greet": "./greet.ts", "./farewell": "./farewell.ts" } } ``` -------------------------------- ### Include a License File Source: https://jsr.io/docs/troubleshooting Place a recognized license file (e.g., LICENSE, LICENSE.md) in the root of your package. ```plaintext LICENSE LICENSE.md LICENSE.txt LICENCE LICENCE.md LICENCE.txt ``` -------------------------------- ### Run /x to JSR Migration Tool Source: https://jsr.io/docs/migrate-x-to-jsr Execute the automated migration tool from within your package directory. ```bash deno run -Ar jsr:@deno/x-to-jsr ``` -------------------------------- ### JSR Package Configuration File Source: https://jsr.io/docs Create a configuration file (e.g., `jsr.json` or `deno.json(c)`) for your package. This file includes metadata like name, version, and entrypoints, specifying which modules are importable via the `exports` field. ```json // jsr.json / deno.json(c) { "name": "@luca/greet", "version": "1.0.0", "exports": "./mod.ts" } ``` -------------------------------- ### Get Package Metadata Source: https://jsr.io/docs/api Retrieves metadata for a package, including its scope, name, and published versions. ```APIDOC ## GET /@//meta.json ### Description Retrieves metadata for a specific package, including a list of all published versions. ### Method GET ### Endpoint https://jsr.io/@//meta.json ### Parameters #### Path Parameters - **scope** (string) - Required - The scope of the package. - **package-name** (string) - Required - The name of the package. ### Response #### Success Response (200) - **scope** (string) - The scope of the package. - **name** (string) - The name of the package. - **versions** (object) - An object where keys are version numbers and values contain version-specific information (e.g., yanked status). ### Response Example ```json { "scope": "luca", "name": "flag", "versions": { "1.0.0": { "yanked": true }, "1.0.1": {} } } ``` ``` -------------------------------- ### Import npm packages Source: https://jsr.io/docs/publishing-packages Demonstrates importing an npm package ('chalk') with a bare specifier and another ('express') using the 'npm:' specifier. Ensure dependencies are correctly listed in package.json. ```typescript import * as chalk from "chalk"; import * as express from "npm:express@4"; ``` -------------------------------- ### Specify License in Configuration File Source: https://jsr.io/docs/licenses Add a `license` field to your `jsr.json` or `deno.json` with an SPDX license identifier. ```json { "name": "@scope/package", "version": "1.0.0", "license": "MIT" } ``` -------------------------------- ### Get Package Version Metadata Source: https://jsr.io/docs/api Retrieves metadata for a specific version of a package, including its file manifest and exports. ```APIDOC ## GET /@//_meta.json ### Description Retrieves metadata for a specific version of a package, including file details and export mappings. ### Method GET ### Endpoint https://jsr.io/@//_meta.json ### Parameters #### Path Parameters - **scope** (string) - Required - The scope of the package. - **package-name** (string) - Required - The name of the package. - **version** (string) - Required - The specific version of the package. ### Response #### Success Response (200) - **manifest** (object) - A map of file paths to their size and checksum. - **moduleGraph1** (object) - Information about the module graph. - **exports** (object) - Normalized export mappings for the package version. ### Response Example ```json { "manifest": { "/main.ts": { "size": 2989, "checksum": "sha256-a41796ceb0be1bca3aa446ddebebcd732492ccb2cdcb8912adbabef3375fafc8" } }, "moduleGraph1": { "/main.ts": {} }, "exports": { ".": "./main.ts" } } ``` ``` -------------------------------- ### Preview JSR package documentation Source: https://jsr.io/docs/with/deno Generate an HTML preview of your JSR package's documentation using `deno doc --html`. This helps visualize how documentation will appear on jsr.io. ```bash deno doc --html ``` -------------------------------- ### Publish using a token with Deno or npx Source: https://jsr.io/docs/publishing-packages For CI providers other than GitHub Actions, authenticate publishing by passing a JSR access token using the `--token` flag with either the `deno publish` command or `npx jsr publish`. ```bash # Using Deno deno publish --token $JSR_TOKEN ``` ```bash # Using npx npx jsr publish --token $JSR_TOKEN ``` -------------------------------- ### `jsr.json` with Multiple Exports Source: https://jsr.io/docs/package-configuration Specifies multiple entry points for a package, allowing users to import specific modules. The `.` entrypoint is the default. ```json // jsr.json / deno.json(c) { "name": "@luca/greet", "version": "1.0.0", "exports": { ".": "./mod.ts", "./greet": "./greet.ts" } } ``` -------------------------------- ### Import and Use JSR Packages in Vite Source: https://jsr.io/docs/with/vite Import functions from JSR packages directly into your JavaScript or TypeScript code. Ensure the package is installed and accessible. ```javascript import { encodeBase64 } from "@std/encoding/base64"; document.querySelector("#app")!.innerHTML = encodeBase64( "Hello World!", ); ``` -------------------------------- ### Import and use JSR packages in Cloudflare Workers Source: https://jsr.io/docs/with/cloudflare-workers Import JSR packages directly into your Worker code. Ensure the package is correctly installed and accessible. ```typescript import { encodeBase64 } from "@std/encoding/base64"; export default { async fetch(request: Request): Promise { return new Response(encodeBase64("Hello World!")); }, }; ``` -------------------------------- ### Exclude specific files in jsr.json Source: https://jsr.io/docs/publishing-packages Use the `publish.exclude` field in `jsr.json` to prevent specific files or directories from being included in the package. This example excludes the `src/tests` directory. ```json // jsr.json { "name": "@luca/greet", "version": "1.0.0", "exports": "./src/mod.ts", "publish": { "include": [ "LICENSE", "README.md", "src/**/*.ts" ], "exclude": [ "src/tests" ] } } ``` -------------------------------- ### Publish Pre-release Version Configuration Source: https://jsr.io/docs/packages Configure your package.json to publish a pre-release version. This is useful for testing new features before a stable release. ```json { "name": "@scope/my-package", "version": "2.0.0-beta.1", "exports": "./mod.ts" } ``` -------------------------------- ### Documenting Classes, Constructors, Properties, and Methods Source: https://jsr.io/docs/writing-docs Document classes, their constructors, properties, and methods using JSDoc comments. This includes specifying parameter constraints and providing explanations for each member. ```typescript /** * A class to represent a person. */ export class Person { /** The name of the person. */ name: string; /** The age of the person. */ age: number; /** * Create a new person with the given name and age. * @param name The name of the person. * @param age The age of the person. Must be non-negative. */ constructor(name: string, age: number) { if (age < 0) { throw new Error("Age cannot be negative"); } this.name = name; this.age = age; } /** Print a greeting to the console. */ greet() { console.log( `Hello, my name is ${this.name} and I am ${this.age} years old.`, ); } } ``` -------------------------------- ### Publish a package locally Source: https://jsr.io/docs/publishing-packages Use the `jsr publish` command with your preferred package manager (npm, yarn, or pnpm) to publish a package. This action will open a browser for authentication and approval. ```bash npx jsr publish ``` ```bash yarn dlx jsr publish ``` ```bash pnpm dlx jsr publish ``` -------------------------------- ### Add JSR packages to a Cloudflare Worker project Source: https://jsr.io/docs/with/cloudflare-workers Add JSR packages to your project using your package manager. This installs the package into `node_modules` and updates `package.json`. ```bash # pnpm 10.9+ and yarn 4.9+ pnpm add jsr:@std/encoding yarn add jsr:@std/encoding # npm, bun, and older versions of yarn or pnpm npx jsr add @std/encoding bunx jsr add @std/encoding yarn dlx jsr add @std/encoding pnpm dlx jsr add @std/encoding ``` -------------------------------- ### Publishing Commands Source: https://jsr.io/docs/publishing-packages Commands to publish packages to JSR. Use `deno publish` for Deno projects or `npx jsr publish` (and equivalents for yarn/pnpm) for npm-compatible projects. ```bash # deno deno publish # npm npx jsr publish # yarn yarn dlx jsr publish # pnpm pnpm dlx jsr publish ``` -------------------------------- ### Get npm compatible package metadata Source: https://jsr.io/docs/api Retrieve npm compatible package metadata for a given JSR package. This endpoint is part of the npm compatibility registry API. ```APIDOC ## GET /@jsr/:scope/:name ### Description Retrieves npm compatible package metadata for a specified JSR package. ### Method GET ### Endpoint https://npm.jsr.io/@jsr/:scope/:name ### Parameters #### Path Parameters - **scope** (string) - Required - The scope of the JSR package. - **name** (string) - Required - The name of the JSR package. ### Response #### Success Response (200) - **name** (string) - The npm compatibility name of the package. - **description** (string) - The package description. - **dist-tags** (object) - Contains the `latest` version of the package. - **versions** (object) - A map of versions to version metadata. - **time** (object) - A map of versions to publish timestamps. ### Response Example ```json { "name": "@jsr/luca__flag", "description": "A package for handling flags.", "dist-tags": { "latest": "1.0.0" }, "versions": { "1.0.0": { "name": "@jsr/luca__flag", "version": "1.0.0", "description": "A package for handling flags.", "dist": { "tarball": "https://example.com/tarball.tgz", "integrity": "sha512-example" }, "dependencies": { "some-dep": "^1.0.0" } } }, "time": { "1.0.0": "2023-01-01T12:00:00.000Z" } } ``` ``` -------------------------------- ### Publish JSR Package Source: https://jsr.io/docs Publish your JSR package using `npx jsr publish` or `deno publish`. You will be prompted to authenticate and confirm the publication. ```bash $ 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/greet@1.0.0 ... Successfully published @luca/greet@1.0.0 Visit https://jsr.io/@luca/greet@1.0.0 for details ``` -------------------------------- ### Vendor Dependencies Source: https://jsr.io/docs/migrate-x-to-jsr Configure Deno to vendor HTTPS dependencies locally by adding `"vendor": true` to `deno.json(c)`. ```json "vendor": true ``` -------------------------------- ### Deno import map entry for JSR package Source: https://jsr.io/docs/with/deno After running `deno add`, your `deno.json(c)` file will include an entry mapping the package name to its JSR URL, including the version specifier. ```json { "imports": { "@luca/flag": "jsr:@luca/flag@^1.0.1" } } ``` -------------------------------- ### Valid JSON(C) Exports Field Formats Source: https://jsr.io/docs/troubleshooting These examples show the two valid formats for the 'exports' field in a JSR configuration file. Ensure your 'exports' field matches one of these structures. ```json { "exports": "./mod.ts" } ``` ```json { "exports": { ".": "./mod.ts", "./greet": "./greet.ts" } } ``` -------------------------------- ### Specify Package License in Configuration Source: https://jsr.io/docs/troubleshooting Add a 'license' field with an SPDX identifier to your package.json or equivalent configuration file. ```json { "name": "@scope/pkg", "version": "1.0.0", "license": "MIT", "exports": "./mod.ts" } ``` -------------------------------- ### Get npm Compatible Package Metadata Source: https://jsr.io/docs/api Retrieve npm compatible package metadata for a JSR package. This endpoint is useful for tools that need to interact with JSR packages using npm conventions. ```bash https://npm.jsr.io/@jsr/luca__flag ``` -------------------------------- ### Add JSR Package to Project Source: https://jsr.io/docs/using-packages Use these commands to add the latest version of a JSR package. Deno, pnpm, and Yarn 4.9+ have first-class support. For npm, Bun, and older versions, use `npx`, `bunx`, or `yarn dlx` with the `jsr` command. ```bash # deno, pnpm 10.9+, and yarn 4.9+ with first class JSR support deno add jsr:@luca/cases pnpm add jsr:@luca/cases yarn add jsr:@luca/cases # npm, bun, and older versions of yarn or pnpm npx jsr add @luca/cases bunx jsr add @luca/cases yarn dlx jsr add @luca/cases pnpm dlx jsr add @luca/cases ``` -------------------------------- ### Create a new Cloudflare Worker project Source: https://jsr.io/docs/with/cloudflare-workers Use your preferred package manager to create a new Cloudflare Worker project. This sets up the basic project structure. ```bash npm create cloudflare@latest yarn create cloudflare pnpm create cloudflare bun create cloudflare ``` -------------------------------- ### Management API Authentication Tokens Source: https://jsr.io/docs/api Examples of Authorization headers for different token types used with the JSR Management API. Use 'Bearer' for device and personal access tokens, and 'githuboidc' for GitHub Actions OIDC tokens. ```http Authorization: Bearer jsrd_5gVEGU852nnRH2opZeP9uZ1UdNXog0fcvP8 ``` ```http Authorization: Bearer jsrp_Kj0yFdcksJqHPm04l5tic2WXVtaLS2292b2 ``` ```http Authorization: githuboidc eyJhbGciOiJSUzI1NiIsImtpZCI6IjEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMCJ9.eyJyZXBvIjoibHVjYWNhc29uYXRvL2ZsYWciLCJkaWQiOiAieW91IHJlYWxseSB0aGluayBpIHdhcyBnb2luZyB0byBnaXZlIHlvdSBhIHZhbGlkIHRva2VuPyJ9.ZXlKeVpYQnZJam9pYkhWallXTmhjMjl1WVhSdkwyWnNZV2NpTENKa2FXUWlPaUFpZVc5MU ``` -------------------------------- ### Single Export as String in `deno.jsonc` Source: https://jsr.io/docs/package-configuration A simplified way to define a single default export in `deno.jsonc`, equivalent to the object form with only the `.` entrypoint. ```json // deno.json(c) { "name": "@luca/greet", "version": "1.0.0", "exports": "./mod.ts" } ``` -------------------------------- ### Publish from GitHub Actions Source: https://jsr.io/docs/publishing-packages Automate package publishing from GitHub Actions by checking out the code and running `npx jsr publish`. Ensure your repository is linked to your JSR package and the workflow has the necessary permissions for OIDC authentication. ```yaml # .github/workflows/publish.yml name: Publish on: push: branches: - main jobs: publish: runs-on: ubuntu-latest permissions: contents: read id-token: write # The OIDC ID token is used for authentication with JSR. steps: - uses: actions/checkout@v6 - run: npx jsr publish ``` -------------------------------- ### Importing a Specific Entrypoint using an Import Map or package.json Source: https://jsr.io/docs/using-packages When using an import map or a `package.json` with path mappings, you can import specific entrypoints by specifying the entrypoint after the alias. This simplifies imports by abstracting the JSR specifier. ```typescript import { join } from "@std/path/join"; ``` -------------------------------- ### Publish from GitLab CI Source: https://jsr.io/docs/publishing-packages Publish packages from GitLab CI using a Deno image and a JSR access token stored as a secret. The `deno publish` command is used with the token for authentication. ```yaml # .gitlab-ci.yml publish: image: denoland/deno:latest stage: deploy script: - deno publish --token $JSR_TOKEN only: - main ``` -------------------------------- ### Embed Weekly Downloads Badge in HTML Source: https://jsr.io/docs/badges Use this HTML code to display the weekly downloads badge for a package. Replace `` and `` with your package's details. ```html ``` -------------------------------- ### Analyze JSR package dependencies Source: https://jsr.io/docs/with/deno The `deno info` command can analyze the dependencies of a JSR package, displaying a list of all direct and indirect dependencies along with their version constraints. ```bash deno info jsr:@std/fs ``` -------------------------------- ### Deno Import Map Entry for JSR Module Source: https://jsr.io/docs/using-packages When using `deno add`, an entry is added to your `deno.json(c)` file, mapping the package name to its JSR URL. ```json { "imports": { "@luca/cases": "jsr:@luca/cases@^1.0.1" } } ``` -------------------------------- ### Run Node.js Script Source: https://jsr.io/docs/with/node Execute your Node.js script containing JSR package imports using the `node` command. ```bash node main.js ``` -------------------------------- ### Embed Total Downloads Badge in HTML Source: https://jsr.io/docs/badges Use this HTML code to display the total downloads badge for a package. Replace `` and `` with your package's details. ```html ``` -------------------------------- ### Import JSR packages Source: https://jsr.io/docs/publishing-packages Shows how to import a JSR package ('@std/encoding') using a scoped package name and another ('@luca/cases') using the 'jsr:' specifier. Ensure packages are correctly declared as dependencies. ```typescript import * as encoding from "@std/encoding"; import { camelCase } from "jsr:@luca/cases@1"; ``` -------------------------------- ### Package Version Metadata URL Source: https://jsr.io/docs/api This URL is used to fetch metadata for a specific version of a package. It includes details like the file manifest, module graph, and exports. ```text https://jsr.io/@//_meta.json ``` ```text https://jsr.io/@luca/flag/1.0.0_meta.json ``` -------------------------------- ### Documenting Function Parameters and Return Values Source: https://jsr.io/docs/writing-docs Use `@param` and `@returns` tags within JSDoc comments to document function parameters and their return values. This improves clarity and editor assistance. ```typescript /** * Search the database with the given query. * * @param query This is the query to search with. It should be less than 50 chars to ensure good performance. * @param limit The number of items to return. If unspecified, defaults to 20. * @returns The array of matched items. */ export function search(query: string, limit: number = 20): string[]; ``` -------------------------------- ### Embed Weekly Downloads Badge in Markdown Source: https://jsr.io/docs/badges Use this Markdown code to display the weekly downloads badge for a package. Replace `` and `` with your package's details. ```markdown [![JSR](https://jsr.io/badges/@//weekly-downloads)](https://jsr.io/@/) ``` -------------------------------- ### Dry Run JSR Publish Source: https://jsr.io/docs/troubleshooting Use the '--dry-run' flag with 'jsr publish' or 'deno publish' to check which files are included in the package before publishing. ```bash npx jsr publish --dry-run ``` ```bash deno publish --dry-run ``` -------------------------------- ### Filter files in deno.json(c) for publishing Source: https://jsr.io/docs/publishing-packages Configure `publish.include` and `publish.exclude` within `deno.json(c)` to control file inclusion for publishing. These settings can be specific to publishing and do not affect other Deno commands. ```json // deno.json(c) { "name": "@luca/greet", "version": "1.0.0", "exports": "./dist/mod.ts", "publish": { "include": ["src"], "exclude": ["src/tests"] } } ``` -------------------------------- ### Package Metadata URL Source: https://jsr.io/docs/api This URL retrieves the metadata for a specific package, including its scope, name, and a list of published versions. This allows for version discovery and semantic versioning resolution. ```text https://jsr.io/@//meta.json ``` ```text https://jsr.io/@luca/flag/meta.json ``` -------------------------------- ### Embed Package Version Badge in HTML Source: https://jsr.io/docs/badges Use this HTML code to display the version badge for a package. Replace `` and `` with your package's details. ```html ``` -------------------------------- ### Importing a Specific Entrypoint from a JSR Package Source: https://jsr.io/docs/using-packages Import a specific module from a package by appending the entrypoint path after the version. This is useful when a package has multiple exportable modules. ```typescript import { join } from "jsr:@std/path@1/join"; ```