From c461d2dfa02b46820ea1dba6dec08615366e5bf9 Mon Sep 17 00:00:00 2001 From: Ben Rogerson Date: Wed, 13 May 2026 23:18:16 +0930 Subject: [PATCH 1/2] fix(cli): detect bun lockfile in detectPm Added check for `bun.lockb` in the detectPm function to correctly identify bun projects. Previously, bun-only projects with no other lockfile would silently downgrade to pnpm. Includes test coverage for the detection logic. --- packages/core/src/cli/pm.test.ts | 27 +++++++++++++++++++++++++++ packages/core/src/cli/pm.ts | 1 + 2 files changed, 28 insertions(+) create mode 100644 packages/core/src/cli/pm.test.ts diff --git a/packages/core/src/cli/pm.test.ts b/packages/core/src/cli/pm.test.ts new file mode 100644 index 0000000..5e97894 --- /dev/null +++ b/packages/core/src/cli/pm.test.ts @@ -0,0 +1,27 @@ +import { strictEqual } from "node:assert/strict"; +import { describe, it, before, after } from "node:test"; +import { mkdtempSync, writeFileSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { detectPm } from "./pm.js"; + +let dir: string; +const originalUa = process.env.npm_config_user_agent; + +describe("detectPm", () => { + before(() => { + dir = mkdtempSync(join(tmpdir(), "pm-detect-")); + }); + after(() => { + rmSync(dir, { recursive: true, force: true }); + if (originalUa === undefined) delete process.env.npm_config_user_agent; + else process.env.npm_config_user_agent = originalUa; + }); + + it("returns 'bun' when bun.lockb is present, even if user-agent is pnpm", () => { + const dest = mkdtempSync(join(dir, "bun-")); + writeFileSync(join(dest, "bun.lockb"), ""); + process.env.npm_config_user_agent = "pnpm/9.0.0 npm/? node/v20.0.0 darwin arm64"; + strictEqual(detectPm(dest), "bun"); + }); +}); diff --git a/packages/core/src/cli/pm.ts b/packages/core/src/cli/pm.ts index 0de5c67..054fe23 100644 --- a/packages/core/src/cli/pm.ts +++ b/packages/core/src/cli/pm.ts @@ -5,6 +5,7 @@ export function detectPm(dest: string): string { if (existsSync(join(dest, "pnpm-lock.yaml"))) return "pnpm"; if (existsSync(join(dest, "yarn.lock"))) return "yarn"; if (existsSync(join(dest, "package-lock.json"))) return "npm"; + if (existsSync(join(dest, "bun.lockb"))) return "bun"; // Fresh init: match whatever PM invoked us (npx -> npm, pnpm dlx -> pnpm, etc.) const ua = process.env.npm_config_user_agent ?? ""; if (ua.startsWith("pnpm")) return "pnpm"; From f8f3bf062d7b4c93e1a4de2e9d288e37948045c1 Mon Sep 17 00:00:00 2001 From: Ben Rogerson Date: Wed, 13 May 2026 23:18:16 +0930 Subject: [PATCH 2/2] chore: add changeset --- .changeset/bun-lockfile-not-detected-in-detectpm.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/bun-lockfile-not-detected-in-detectpm.md diff --git a/.changeset/bun-lockfile-not-detected-in-detectpm.md b/.changeset/bun-lockfile-not-detected-in-detectpm.md new file mode 100644 index 0000000..544c338 --- /dev/null +++ b/.changeset/bun-lockfile-not-detected-in-detectpm.md @@ -0,0 +1,5 @@ +--- +"@generata/core": patch +--- + +fix(cli): detect bun lockfile in detectPm