LinuxCommandLibrary

bun-publish

TLDR

Publish the current package to the npm registry

$ bun publish
copy

Publish a package from a specific directory
$ bun publish [path/to/package_directory]
copy

Publish a scoped package with specific access level
$ bun publish --access [public|restricted]
copy

Publish a package to a custom registry
$ bun publish --registry [registry]
copy

Run a dry run to see what would be published without uploading
$ bun publish --dry-run
copy

Publish a package with a specific distribution tag
$ bun publish --tag [tag_name]
copy

Publish with a one-time password for 2FA-enabled accounts
$ bun publish --otp [one_time_password]
copy

Publish using a specific authentication type
$ bun publish --auth-type [web|legacy]
copy

SYNOPSIS

bun publish [<dir>] [--registry <url>] [--otp <code>] [--dry-run] [--tag <tag>] [--access <public|restricted>]

PARAMETERS

--registry <url>
    npm registry URL (default: https://registry.npmjs.org)

--otp <code>
    One-time password for 2FA on scoped packages

--dry-run
    Simulate publish without uploading

--tag <tag>
    Dist-tag like latest, next (default: latest)

--access <public|restricted>
    Package visibility (default: public)

<dir>
    Directory to publish from (default: current)

DESCRIPTION

The bun publish command (invoked as bun publish) is part of Bun's built-in package manager, designed for speed and simplicity. It uploads your JavaScript/TypeScript package to the npm registry, similar to npm publish or yarn publish, but leverages Bun's rapid performance for bundling, transpiling, and tarball creation.

It automatically handles package.json validation, generates a gzipped tarball, and pushes it to the specified registry. Bun publish is up to 20x faster than npm due to its Zig-based runtime and native optimizations. Use it in monorepos or for quick iterations.

Prerequisites: Authenticate with bun login or set NPM_TOKEN. Supports scoped packages with OTP for 2FA. Ideal for modern JS workflows with ESM, TypeScript, and JSX out-of-the-box.

CAVEATS

Requires bun login or NPM_TOKEN env var. Does not support prepublish scripts by default. Scoped private packages need --access restricted. Tarball size optimized but verify with --dry-run.

AUTHENTICATION

Run bun login or export NPM_TOKEN=your_token. For scoped: bun publish --otp $(bunx @jsdevtools/otp-auth).

EXAMPLES

bun publish # Current dir to latest
bun publish ./my-pkg --tag beta --registry https://registry.npmjs.org

HISTORY

Introduced in Bun 0.1.0 (Sept 2022) by Jarred Sumner. Evolved with Bun 1.0 (2023) for full npm compatibility. Widely adopted for its speed in CI/CD pipelines.

SEE ALSO

npm(1), yarn(1), pnpm(1)

Copied to clipboard