Buckets:
| // Copyright (c) 2026 the Zuke contributors | |
| // SPDX-License-Identifier: MIT | |
| /** | |
| * `JsrTasks` — typed task functions for the [JSR](https://jsr.io) CLI, in the | |
| * settings-lambda style: configure a fluent settings object in a lambda, and | |
| * the task function builds the command line and executes it. | |
| * | |
| * ```ts | |
| * import { JsrTasks } from "@zuke/jsr"; | |
| * await JsrTasks.publish((s) => s.dryRun().allowSlowTypes()); | |
| * await JsrTasks.add((s) => s.packages("@std/assert")); | |
| * ``` | |
| * | |
| * The binary is `jsr` from PATH. Arguments stay a discrete argv array | |
| * end-to-end — never a concatenated shell string — so command construction is | |
| * injection-free. | |
| * | |
| * @module | |
| */ | |
| import { type Configure, runSettings, ToolSettings } from "@zuke/core/tooling"; | |
| import type { CommandOutput } from "@zuke/core/shell"; | |
| /** Base for all `jsr` subcommand settings: the binary is `jsr`. */ | |
| export abstract class JsrSettings extends ToolSettings { | |
| /** The tool binary is `jsr`. */ | |
| protected override defaultTool(): string { | |
| return "jsr"; | |
| } | |
| } | |
| /** Settings for `jsr publish`. */ | |
| export class JsrPublishSettings extends JsrSettings { | |
| #dryRun = false; | |
| #allowSlowTypes = false; | |
| #allowDirty = false; | |
| #noCheck = false; | |
| #provenance = false; | |
| #token?: string; | |
| /** Validate without publishing (`--dry-run`). */ | |
| dryRun(): this { | |
| this.#dryRun = true; | |
| return this; | |
| } | |
| /** Permit slow types in the published package (`--allow-slow-types`). */ | |
| allowSlowTypes(): this { | |
| this.#allowSlowTypes = true; | |
| return this; | |
| } | |
| /** Publish even with an uncommitted working tree (`--allow-dirty`). */ | |
| allowDirty(): this { | |
| this.#allowDirty = true; | |
| return this; | |
| } | |
| /** Skip type-checking before publishing (`--no-check`). */ | |
| noCheck(): this { | |
| this.#noCheck = true; | |
| return this; | |
| } | |
| /** Attach provenance attestation in CI (`--provenance`). */ | |
| provenance(): this { | |
| this.#provenance = true; | |
| return this; | |
| } | |
| /** | |
| * Authenticate with a token instead of the interactive flow (`--token`). | |
| * | |
| * Registered with the run's redactor, so every *rendering* of the command | |
| * masks it — a dry-run echo, a failure message. That is as far as it goes: | |
| * `jsr publish` accepts the token only as a flag, so the value still reaches | |
| * the child's argv, where `ps` and `/proc/<pid>/cmdline` expose it to every | |
| * other user on the host and to every process the build starts. There is no | |
| * environment variable to move it to. | |
| * | |
| * On GitHub Actions, prefer OIDC and pass no token at all: the publish is | |
| * authenticated by the workflow's identity, so there is no credential to | |
| * expose. This is for the cases where that is not available. | |
| */ | |
| token(value: string): this { | |
| this.#token = value; | |
| this.markSecret(value); | |
| return this; | |
| } | |
| /** Assemble the `jsr publish` argv. */ | |
| protected override buildArgs(): string[] { | |
| const argv = ["publish"]; | |
| if (this.#dryRun) argv.push("--dry-run"); | |
| if (this.#allowSlowTypes) argv.push("--allow-slow-types"); | |
| if (this.#allowDirty) argv.push("--allow-dirty"); | |
| if (this.#noCheck) argv.push("--no-check"); | |
| if (this.#provenance) argv.push("--provenance"); | |
| if (this.#token !== undefined) argv.push("--token", this.#token); | |
| return argv; | |
| } | |
| } | |
| /** Settings for `jsr add` (install a JSR dependency). */ | |
| export class JsrAddSettings extends JsrSettings { | |
| #packages: string[] = []; | |
| #dev = false; | |
| /** Package specs to add, e.g. `@std/assert` (required). */ | |
| packages(...specs: string[]): this { | |
| this.#packages.push(...specs); | |
| return this; | |
| } | |
| /** Add as a development dependency (`--save-dev`). */ | |
| dev(): this { | |
| this.#dev = true; | |
| return this; | |
| } | |
| /** Assemble the `jsr add` argv. */ | |
| protected override buildArgs(): string[] { | |
| if (this.#packages.length === 0) { | |
| throw new Error("JsrTasks.add: .packages() requires at least one spec."); | |
| } | |
| const argv = ["add"]; | |
| if (this.#dev) argv.push("--save-dev"); | |
| argv.push(...this.#packages); | |
| return argv; | |
| } | |
| } | |
| /** Settings for `jsr remove`. */ | |
| export class JsrRemoveSettings extends JsrSettings { | |
| #packages: string[] = []; | |
| /** Package names to remove (required). */ | |
| packages(...names: string[]): this { | |
| this.#packages.push(...names); | |
| return this; | |
| } | |
| /** Assemble the `jsr remove` argv. */ | |
| protected override buildArgs(): string[] { | |
| if (this.#packages.length === 0) { | |
| throw new Error( | |
| "JsrTasks.remove: .packages() requires at least one name.", | |
| ); | |
| } | |
| return ["remove", ...this.#packages]; | |
| } | |
| } | |
| /** The shape of {@link JsrTasks}. */ | |
| export interface JsrTasksApi { | |
| /** Publish the package: `jsr publish`. */ | |
| publish(configure?: Configure<JsrPublishSettings>): Promise<CommandOutput>; | |
| /** Add a JSR dependency: `jsr add`. */ | |
| add(configure?: Configure<JsrAddSettings>): Promise<CommandOutput>; | |
| /** Remove a dependency: `jsr remove`. */ | |
| remove(configure?: Configure<JsrRemoveSettings>): Promise<CommandOutput>; | |
| } | |
| /** Typed task functions for the `jsr` CLI. */ | |
| export const JsrTasks: JsrTasksApi = { | |
| publish(configure?: Configure<JsrPublishSettings>): Promise<CommandOutput> { | |
| return runSettings(new JsrPublishSettings(), configure); | |
| }, | |
| add(configure?: Configure<JsrAddSettings>): Promise<CommandOutput> { | |
| return runSettings(new JsrAddSettings(), configure); | |
| }, | |
| remove(configure?: Configure<JsrRemoveSettings>): Promise<CommandOutput> { | |
| return runSettings(new JsrRemoveSettings(), configure); | |
| }, | |
| }; | |
Xet Storage Details
- Size:
- 5.52 kB
- Xet hash:
- 9e773c8ab1f3430eb64f6d051e9db47def2927a19b460a643e9894d9d556d01f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.