# Shared: Package manager (npm, pnpm or Bun)

The references write commands for npm, as `npx …` and `npm …`. That is the
guidance for npm and pnpm projects, unchanged. A **Bun project** gets Bun commands
only: run each command in its Bun form from the table below, and never fall back to
`npx`, `npm`, `pnpm`, `yarn`, `node` or `tsx` there. The CLI, its MCP server and
Playwright's workers then run on Bun, whether or not Node is installed.

## Which manager

Decide once per invocation, from the test project root (the usage line in
SKILL.md applies the same rule from the working folder):

1. **The user's choice comes first.** When the user names a manager ("use Bun"),
   record it before you run the CLI: set `packageManager` in the test project's
   `package.json` to `<manager>@<version>`, with the version that manager prints:
   `bun@` and `bun --version`, `npm@` and `npm --version`, `pnpm@` and
   `pnpm --version`, `yarn@` and `yarn --version`. With no `package.json` yet,
   write a minimal one that holds only that field (`{ "packageManager": "…" }`)
   before running the scaffold; the scaffold merges into it and follows it, so a
   lockfile of another kind in the folder cannot override the choice. When the choice leaves a lockfile of another kind in the test
   project root (say Bun, with a `package-lock.json`), say that it is now stale
   and ask whether to delete it, and whether CI that installs with it should
   change too; never leave two lockfile kinds there without asking.

   **The two named exceptions.** Recording `packageManager`, and deleting a
   lockfile of another kind with the user's consent, are the only `package.json`
   and lockfile changes any subcommand may make outside `update` and dependency
   changes (`update.md`, and the edit contract in `project-layout.md`).
2. **Otherwise walk up** from the test project root to the filesystem root. The
   first folder with a signal decides:
   1. a `packageManager` field in its `package.json` (`bun@…` means Bun). A
      `package.json` without the field is not a signal; keep walking.
   2. otherwise its lockfiles, when there is exactly one kind: `bun.lock` or
      `bun.lockb` (Bun), `package-lock.json` (npm), `pnpm-lock.yaml` (pnpm),
      `yarn.lock` (Yarn).
3. **Several lockfile kinds in that folder is a conflict.** Ask the user which
   manager the project uses, record the answer as in step 1 (whichever manager
   it is), then go on.
4. **No signal at all** is not a Bun project: use the commands as written.

**Scaffolding (`init`) looks at the target folder only**, with no walk up, in
this order:

1. the user's explicit choice (step 1; a lockfile of another kind left in the
   target then gets the stale-lockfile question);
2. the target's own `packageManager` field, or its single lockfile kind
   (several kinds is a conflict, as in step 3);
3. the manager whose launcher `init` runs `create` with: npm (`npx`) as written,
   or Bun (`bunx`) when npm is not installed.

A lockfile in a parent folder (a stray `~/bun.lock` or `~/package-lock.json`)
never picks the scaffold's manager. **After scaffolding**, when `package.json`
still has no `packageManager` (the npm scaffold writes none), record the manager
it scaffolded with as in step 1, npm, pnpm and Yarn included, so every later
walk-up stops at the project.

## Run the project CLI

Set `SKILL_DIR` to the absolute directory containing this skill's `SKILL.md`.
Use the launcher from the test project root.

| Operation | npm, pnpm or Yarn | Bun |
|---|---|---|
| Run any installed CLI command | `node "$SKILL_DIR/scripts/cli.cjs" run <args>` | `bun "$SKILL_DIR/scripts/cli.cjs" run <args>` |
| Scaffold | `node "$SKILL_DIR/scripts/cli.cjs" init . --json` | `bun "$SKILL_DIR/scripts/cli.cjs" init . --json` |
| Read selected package name and version as JSON | `node "$SKILL_DIR/scripts/cli.cjs" info` | `bun "$SKILL_DIR/scripts/cli.cjs" info` |
| Check its latest version | `node "$SKILL_DIR/scripts/cli.cjs" latest` | `bun "$SKILL_DIR/scripts/cli.cjs" latest` |
| Update the selected package | `node "$SKILL_DIR/scripts/cli.cjs" update` | `bun "$SKILL_DIR/scripts/cli.cjs" update` |

In this skill, `npx shiplight …`, `bun run --bun shiplight …` and scripts that
delegate to Shiplight describe project CLI arguments. For commands the agent
executes, use the launcher with those arguments. For example, run
`node "$SKILL_DIR/scripts/cli.cjs" run transpile --strict tests/login.test.yaml`
or the Bun equivalent. Commands for installing browsers, running the MCP
server, and refreshing skills use their own executables.

The launcher prefers an installed `shiplight` and also supports `shiplightai`.
It launches the exact package executable. It restores declared dependencies
when needed and bootstraps `shiplight` only for a fresh init. Confirm a deliberate
migration before changing a project's dependency or Playwright imports. Commit
a newly generated lockfile with the project when appropriate.

## Bun forms

| Command as written | In a Bun project |
|---|---|
| `npm install` | `bun install` |
| `npm ci` | `bun install --frozen-lockfile` |
| `npm test` (the Shiplight tests) | `bun run --bun shiplight test` |
| `npm run test:headed` (the same, headed) | `bun run --bun shiplight test --headed` |
| `npx shiplight <args>` (any CLI command) | `bun run --bun shiplight <args>` |
| `npx playwright install <args>` (e.g. chromium; --with-deps chromium in CI) | `bun run --bun playwright install <args>` |
| `npx -y skills@latest update -y` | `bunx --bun skills@latest update -y` |
| `npx -y @shiplightai/mcp@latest` (MCP server) | `bunx --bun --package @shiplightai/mcp@latest shiplight-mcp` |
| `tsx <file>.ts` (in a package script) | `bun <file>.ts` |
| `pnpm agent:verify <args>`, `npm run <script> <args>` | `bun run agent:verify <args>`, `bun run <script> <args>` |

Notes:

- Bare `bun test` is Bun's own test runner, not Shiplight. Run the Shiplight
  tests with `bun run --bun shiplight test`; `bun run <script>` runs the
  project's own script, which may be another runner, or an old `shiplight test`
  that would run on Node.
- `--bun` is needed because the published executables start with a Node line;
  without it, `bun run` and `bunx` hand them to Node when Node is installed.
- **The Bun lockfile** means `bun.lock`, or `bun.lockb` in older projects; the
  references use that phrase. Never create a `package-lock.json` in a Bun
  project.
- The browser install runs the project's own Playwright, so a Bun project needs
  `@playwright/test` as a direct dependency (the Bun scaffold adds it). Its row
  above is the source. It is also spelled in `ci/github-hosted.md`,
  `create-agent-verification/runner.md`, the Bun CI template
  (`ci/assets/e2e-github-hosted-bun.yml`) and the agent-verification runner
  (`create-agent-verification/assets/run-agent-verification.ts`); the skills'
  tests check that every copy matches it.
- CI for a Bun project: only the GitHub-hosted workflow (`ci/github-hosted.md`).
  The Shiplight-hosted and autofix workflows are not available for Bun projects
  yet.
