Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bun-lockfile-not-detected-in-detectpm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@generata/core": patch
---

fix(cli): detect bun lockfile in detectPm
27 changes: 27 additions & 0 deletions packages/core/src/cli/pm.test.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
1 change: 1 addition & 0 deletions packages/core/src/cli/pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading