Open-Source Wikis

/

Tauri

/

Packages

/

@tauri-apps/cli

tauri-apps/tauri

@tauri-apps/cli

Active contributors: Lucas Fernandes Nogueira, Amr Bashir, Fabian-Lars

Purpose

packages/cli repackages tauri-cli as a Node.js module so users can run the CLI without a Rust toolchain in scope (e.g. via npx tauri, or as a tauri script in package.json). It is a napi-rs native addon: crate-type = ["cdylib"] plus a thin JS shim.

When you npm install @tauri-apps/cli, npm picks the right platform-specific subpackage (@tauri-apps/cli-linux-x64-gnu, @tauri-apps/cli-darwin-arm64, @tauri-apps/cli-win32-x64-msvc, etc.) — each one ships a prebuilt .node addon. The platform packages live under packages/cli/npm/ and are published by .github/workflows/publish-cli-js.yml.

Directory layout

packages/cli/
├── Cargo.toml              # crate name "tauri-cli-node"; crate-type = ["cdylib"]
├── package.json            # exports the JS shim, postinstall picks the right native addon
├── build.rs                # napi-rs build helper
├── append-headers.js       # postprocess the generated index.js
├── index.js                # 24 KB napi-rs-generated JS bridge
├── index.d.ts              # generated TypeScript types
├── main.js / main.d.ts     # public entry: import + run
├── tauri.js                # CLI shim that npm uses as the bin entry
├── src/                    # tiny Rust src that re-exports tauri-cli through napi
├── npm/                    # per-platform npm subpackages (Linux/macOS/Windows × x64/arm64/musl)
└── __tests__/              # JS smoke tests

How it works

graph LR
    User["npm/yarn/pnpm script: tauri ..."] --> Tauri["tauri.js"]
    Tauri --> MainJS["main.js"]
    MainJS --> NapiBridge["index.js<br/>(napi-rs JS shim)"]
    NapiBridge --> Native[".node addon (cdylib)"]
    Native --> CliRust["tauri_cli::run"]

packages/cli/src/lib.rs defines a single napi-exported function that calls into tauri_cli::run(args, Some("tauri".into())). The native addon is built per-platform via pnpm build:cli (which invokes napi build), and the package.json optionalDependencies plus postinstall script select the addon that matches the user's platform.

Build

pnpm build:cli           # release
pnpm build:cli:debug     # faster
pnpm test                # smoke

CI workflow .github/workflows/publish-cli-js.yml is the most complex publishing job in the repo: it spawns build matrices for Linux (gnu, musl, x64, arm64, armv7), macOS (x64, arm64), Windows (msvc, gnu) and FreeBSD; signs each native module; and runs npm publish for all the per-platform packages plus the umbrella @tauri-apps/cli package.

Integration points

  • Up: npm install -D @tauri-apps/cli is the canonical install path for non-Rust developers. The tauri-action CI workflow uses it.
  • Down: depends on crates/tauri-cli directly via tauri-cli = { path = "../../crates/tauri-cli", default-features = false }.

Cargo features

  • default = ["tauri-cli/default"] — pull in the same defaults as the Rust binary.
  • native-tls / native-tls-vendored — propagate TLS choice into tauri-cli.

Entry points for modification

Goal Start here
Change CLI behaviour The Rust crate at tauri-cli (almost everything is there).
Tweak the JS shim or argv handling packages/cli/main.js / tauri.js
Adjust napi-rs binding code packages/cli/src/
Add a new platform target packages/cli/npm/<target>/ plus .github/workflows/publish-cli-js.yml

See tauri-cli for the actual command implementations.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

@tauri-apps/cli – Tauri wiki | Factory