Skip to content
Closed
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
10 changes: 9 additions & 1 deletion composer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@
*
* @param {string} composerVersion - @prisma/composer-cli version to fetch via bunx when the local bin is absent.
* @param {boolean} binExists - Whether node_modules/.bin/prisma-composer exists in the working directory.
* @param {boolean} unifiedCliAvailable - Whether the local Prisma CLI mounts the Composer command family.
* @returns {[string, string[], string]}
*/
export function selectComposerCommand(composerVersion, binExists) {
export function selectComposerCommand(composerVersion, binExists, unifiedCliAvailable) {
if (unifiedCliAvailable) {
return [
"bun",
["run", "--bun", "prisma", "composer"],
"composer=local Prisma CLI (bun run --bun)",
];
}
if (binExists) {
return ["bun", ["run", "--bun", "prisma-composer"], "composer=local bin (bun run --bun)"];
}
Expand Down
15 changes: 10 additions & 5 deletions main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,20 @@ if (buildCommand === null) {
// The stage reaches the argv array straight from the environment; it is
// never interpolated into a shell string.
//
// The CLI bin is named prisma-composer. From 0.7.0 it ships inside
// @prisma/composer-cli (previously @prisma/composer); there is no npm package
// named prisma-composer, so `npx prisma-composer@v` 404s. The repo's own
// install already provides the bin, so prefer the local bin under Bun; fall
// back to bunx fetching the pinned package when the repo does not carry it.
// The unified Prisma CLI accepts every registered prisma.config.ts section,
// which lets ORM and Composer share one config file.
const localPrismaBin = join(workdir, "node_modules", ".bin", "prisma");
const unifiedCliAvailable =
existsSync(localPrismaBin) &&
spawnSync("bun", ["run", "--bun", "prisma", "composer", "--help"], {
cwd: workdir,
stdio: "ignore",
}).status === 0;
const localBin = join(workdir, "node_modules", ".bin", "prisma-composer");
const [composerCmd, composerLead, composerLabel] = selectComposerCommand(
composerVersion,
existsSync(localBin),
unifiedCliAvailable,
);
log(composerLabel);
const composerArgs = [
Expand Down
15 changes: 11 additions & 4 deletions tests/composer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { test } from "node:test";
import { selectComposerCommand } from "../composer.mjs";

test("runs the local bin with bun run --bun when it exists", () => {
const [cmd, lead, label] = selectComposerCommand("0.9.0", true);
const [cmd, lead, label] = selectComposerCommand("0.9.0", true, false);
assert.equal(cmd, "bun");
assert.deepEqual(lead, ["run", "--bun", "prisma-composer"]);
assert.equal(label, "composer=local bin (bun run --bun)");
});

test("prefers the unified Prisma CLI when it mounts Composer", () => {
const [cmd, lead, label] = selectComposerCommand("0.10.0", true, true);
assert.equal(cmd, "bun");
assert.deepEqual(lead, ["run", "--bun", "prisma", "composer"]);
assert.equal(label, "composer=local Prisma CLI (bun run --bun)");
});

test("falls back to bunx with --bun when the local bin is absent", () => {
const [cmd, lead, label] = selectComposerCommand("0.9.0", false);
const [cmd, lead, label] = selectComposerCommand("0.9.0", false, false);
assert.equal(cmd, "bunx");
assert.deepEqual(lead, [
"--bun",
Expand All @@ -22,11 +29,11 @@ test("falls back to bunx with --bun when the local bin is absent", () => {
});

test("bunx fallback log label includes the exact version", () => {
const [, , label] = selectComposerCommand("0.7.5", false);
const [, , label] = selectComposerCommand("0.7.5", false, false);
assert.equal(label, "composer=0.7.5 (bunx fallback)");
});

test("local bin label is always the same string regardless of version", () => {
const [, , label] = selectComposerCommand("0.7.5", true);
const [, , label] = selectComposerCommand("0.7.5", true, false);
assert.equal(label, "composer=local bin (bun run --bun)");
});
Loading