diff --git a/composer.mjs b/composer.mjs index 06b42e5..5002bbe 100644 --- a/composer.mjs +++ b/composer.mjs @@ -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)"]; } diff --git a/main.mjs b/main.mjs index ad1765a..57f3fc7 100644 --- a/main.mjs +++ b/main.mjs @@ -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 = [ diff --git a/tests/composer.test.mjs b/tests/composer.test.mjs index 0194d71..aa0525a 100644 --- a/tests/composer.test.mjs +++ b/tests/composer.test.mjs @@ -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", @@ -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)"); });