From f791eb007e280e38e27d71d346c90aed911cb2b0 Mon Sep 17 00:00:00 2001 From: willbot Date: Tue, 10 Nov 2026 15:55:00 +1100 Subject: [PATCH 1/2] fix: warn when local Bun is too old to run React 19.3 apps Bun 1.3.13 and older mis-transpile a labeled if after else in React 19.3's server renderer, so TanStack Start apps return HTTP 500 under Composer dev, which runs the app with the Bun on PATH. Prisma Compute runs Bun 1.4.4 and is not affected. create-prisma now warns at scaffold time when the local Bun is older than 1.3.14. A new e2e test serves a TanStack Start app under Composer dev, and a Linux CI job runs it on Compute's Bun version. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- .github/workflows/publish.yml | 42 ++++++++++++++++++++++- README.md | 2 ++ package.json | 2 +- src/tasks/prisma-setup/local-bun.ts | 18 ++++++++++ src/tasks/setup-prisma.ts | 8 +++++ src/utils/package-manager.ts | 4 +-- tests/e2e/create-prisma.e2e.test.ts | 53 ++++++++++++++++++++++++++--- tests/local-bun.test.ts | 37 ++++++++++++++++++++ 8 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 src/tasks/prisma-setup/local-bun.ts create mode 100644 tests/local-bun.test.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8c6303a..9da31ff 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -59,9 +59,49 @@ jobs: --test-name-pattern "builds a Next.js app with a TypeScript-authored contract" ./tests/e2e/create-prisma.e2e.test.ts + linux-composer-dev-smoke: + name: Linux Composer dev smoke + if: >- + github.event_name == 'pull_request' && + github.event.pull_request.head.repo.full_name == github.repository && + (github.event.action != 'labeled' || github.event.label.name == 'release:next') + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + steps: + - name: Checkout repository + uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: + node-version: "22.18.0" + + # The Bun in Prisma Compute's runtime image (oven/bun:1.4.4-distroless in + # prisma/project-compute spark/Dockerfile). Composer dev runs the app with it. + - name: Setup Bun + uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 + with: + bun-version: "1.4.4" + + - name: Install dependencies + run: bun install --frozen-lockfile + + - name: Serve a TanStack Start app under Composer dev + env: + CREATE_PRISMA_E2E_TIMEOUT_MS: "600000" + run: >- + bun test --timeout 600000 + --test-name-pattern "serves a TanStack Start app" + ./tests/e2e/create-prisma.e2e.test.ts + preview: name: Publish PR preview - needs: windows-smoke + needs: [windows-smoke, linux-composer-dev-smoke] if: >- github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && diff --git a/README.md b/README.md index 6e05e83..1d7ef3d 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Each supported Node.js release works with the npm it ships, including npm 10 on The one exception is the `nuxt` template. Nuxt itself requires Node.js `^22.22.3 || ^24.15.0 || >=26.0.0`, so Nuxt projects declare that narrower range. +Running the app locally with `dev:composer` needs Bun 1.3.14 or newer on your PATH, because Prisma Composer runs the app with that Bun, as Prisma Compute does. Older Bun fails on React 19.3 server rendering, so every page of the `tanstack-start` template returns HTTP 500. create-prisma warns when it finds an older Bun. + ## Quick start Use your package manager: diff --git a/package.json b/package.json index 38a1187..9f27d07 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "dev": "tsdown --watch", "start": "bun run ./dist/cli.mjs", "test": "bun run test:unit && bun run test:e2e", - "test:unit": "bun test ./tests/create-context.test.ts ./tests/dependencies.test.ts ./tests/deploy-with-composer.test.ts ./tests/initialize-git.test.ts ./tests/install.test.ts ./tests/json-output.test.ts ./tests/node-version.test.ts ./tests/package-manager-error-code.test.ts ./tests/pin-problems.test.ts ./tests/setup-prisma.test.ts ./tests/telemetry-client.test.ts ./tests/telemetry.test.ts", + "test:unit": "bun test ./tests/create-context.test.ts ./tests/dependencies.test.ts ./tests/deploy-with-composer.test.ts ./tests/initialize-git.test.ts ./tests/install.test.ts ./tests/json-output.test.ts ./tests/local-bun.test.ts ./tests/node-version.test.ts ./tests/package-manager-error-code.test.ts ./tests/pin-problems.test.ts ./tests/setup-prisma.test.ts ./tests/telemetry-client.test.ts ./tests/telemetry.test.ts", "test:e2e": "bun test --timeout 180000 ./tests/e2e/create-prisma.e2e.test.ts", "check": "bun run format:check && bun run lint", "lint": "oxlint . --deny-warnings", diff --git a/src/tasks/prisma-setup/local-bun.ts b/src/tasks/prisma-setup/local-bun.ts new file mode 100644 index 0000000..d34a420 --- /dev/null +++ b/src/tasks/prisma-setup/local-bun.ts @@ -0,0 +1,18 @@ +import { Effect } from "effect"; + +import { CommandRunner } from "../../services/command-runner"; +import { isOlderVersion, parsePackageManagerVersion } from "../../utils/package-manager"; + +// Bun 1.3.13 and older mis-transpile React 19.3's server renderer, so every SSR request fails. +export const MINIMUM_LOCAL_BUN_VERSION = [1, 3, 14] as const; + +export const checkLocalBunEffect = Effect.fn("PrismaSetup.checkLocalBun")(function* (cwd: string) { + const runner = yield* CommandRunner; + const result = yield* runner + .run({ command: "bun", args: ["--version"], cwd }) + .pipe(Effect.orElseSucceed(() => undefined)); + const version = + result?.exitCode === 0 ? parsePackageManagerVersion("bun", result.stdout.trim()) : undefined; + if (!version || !isOlderVersion(version.parts, MINIMUM_LOCAL_BUN_VERSION)) return undefined; + return `Bun ${version.version} is on your PATH. Prisma Composer runs your app locally with it, and Bun older than ${MINIMUM_LOCAL_BUN_VERSION.join(".")} cannot run some apps, such as React 19.3 server rendering. Run \`bun upgrade\` before \`dev:composer\`.`; +}); diff --git a/src/tasks/setup-prisma.ts b/src/tasks/setup-prisma.ts index 83a1364..6d4273d 100644 --- a/src/tasks/setup-prisma.ts +++ b/src/tasks/setup-prisma.ts @@ -17,6 +17,7 @@ import { initializeGitRepositoryEffect, type GitInitializationResult } from "./i import { installProjectDependenciesEffect, writePrismaDependenciesEffect } from "./install"; import { initializeAgentSkills, runPrismaCli, runPrismaInit } from "./prisma-setup/commands"; import { collectPrismaSetupContextEffect } from "./prisma-setup/context"; +import { checkLocalBunEffect } from "./prisma-setup/local-bun"; import { ensureComposerTypeScriptOptions, ensureGitignoreEntry, @@ -202,6 +203,13 @@ export const executePrismaSetupContextEffect = Effect.fn("PrismaSetup.execute")( gitInitialization?.status === "skipped" ? [`Could not initialize Git repository: ${gitInitialization.reason}`] : []; + if (options.includeDevNextStep && context.packageManager !== "deno") { + const bunWarning = yield* checkLocalBunEffect(projectDir); + if (bunWarning) { + warnings.push(bunWarning); + yield* Effect.sync(() => log.warn(bunWarning, { output: context.output })); + } + } const projectSummary = formatProjectSummary({ createdProjectPath: options.createdProjectPath, ...(deployment ? { deployment } : {}), diff --git a/src/utils/package-manager.ts b/src/utils/package-manager.ts index ac9e3f2..03800d1 100644 --- a/src/utils/package-manager.ts +++ b/src/utils/package-manager.ts @@ -89,7 +89,7 @@ const packageManagerChecks: Record< const PACKAGE_MANAGER_VERSION_PATTERN = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/; -function parsePackageManagerVersion( +export function parsePackageManagerVersion( packageManager: PackageManager, version: string, ): PackageManagerVersion | undefined { @@ -102,7 +102,7 @@ function parsePackageManagerVersion( return parts.every(Number.isSafeInteger) ? { version: match[0], parts } : undefined; } -function isOlderVersion(version: VersionParts, minimum: VersionParts): boolean { +export function isOlderVersion(version: VersionParts, minimum: VersionParts): boolean { for (const [index, part] of version.entries()) { if (part !== minimum[index]) return part < minimum[index]!; } diff --git a/tests/e2e/create-prisma.e2e.test.ts b/tests/e2e/create-prisma.e2e.test.ts index db114e0..1e1ff62 100644 --- a/tests/e2e/create-prisma.e2e.test.ts +++ b/tests/e2e/create-prisma.e2e.test.ts @@ -21,6 +21,9 @@ import type { CreateCommandResult } from "../../src/result"; import { scaffoldCreateTemplate } from "../../src/templates/render-create-template"; import { writeCreateTemplateDependencies, writePrismaDependencies } from "../../src/tasks/install"; +// `bun test` sets NODE_ENV=test; a Vite build under it emits development JSX +// that React's production runtime cannot run. +const { NODE_ENV: _testNodeEnv, ...appEnv } = Bun.env; const TEST_TIMEOUT = Number(process.env.CREATE_PRISMA_E2E_TIMEOUT_MS ?? 300_000); const tempRoots: string[] = []; const TEST_PSL_CONTRACT = `// use prisma-8 @@ -45,7 +48,7 @@ async function runCommand(projectDir: string, args: string[]) { const process = Bun.spawn({ cmd: args, cwd: projectDir, - env: { ...Bun.env, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1" }, + env: { ...appEnv, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1" }, stdout: "pipe", stderr: "pipe", }); @@ -175,12 +178,21 @@ async function verifyBuiltServer( return body; } -async function verifyComposerDev(projectDir: string, usersPath = "") { +async function expectSeededUsersJson(response: Response) { + const body = (await response.json()) as { users: Array<{ name: string }> }; + expect(body.users.map((user) => user.name)).toEqual(["Alice", "Bob", "Carol"]); +} + +async function verifyComposerDev( + projectDir: string, + usersPath = "", + expectUsers: (response: Response) => Promise = expectSeededUsersJson, +) { const process = Bun.spawn({ // A piped prisma command prints plain text; --json asks for the endpoint frames read below. cmd: ["bun", "run", "dev:composer", "--", "--json"], cwd: projectDir, - env: { ...Bun.env, CI: "1" }, + env: { ...appEnv, CI: "1" }, stdout: "pipe", stderr: "pipe", }); @@ -219,8 +231,7 @@ async function verifyComposerDev(projectDir: string, usersPath = "") { // retry connection refusals until the deadline. const response = await fetchUntilReady(`${appUrl}${usersPath}`, deadline); expect(response.status).toBe(200); - const body = (await response.json()) as { users: Array<{ name: string }> }; - expect(body.users.map((user) => user.name)).toEqual(["Alice", "Bob", "Carol"]); + await expectUsers(response); return; } } finally { @@ -544,6 +555,38 @@ describe("create-prisma e2e", () => { TEST_TIMEOUT, ); + test( + "serves a TanStack Start app's seeded users under Composer dev", + async () => { + const rootDir = await mkdtemp(path.join(tmpdir(), "create-prisma-tanstack-e2e-")); + tempRoots.push(rootDir); + const { result, exitCode } = await runCreatePrismaJson(rootDir, [ + "tanstack-app", + "--template", + "tanstack-start", + "--provider", + "postgres", + "--package-manager", + "bun", + "--skills", + "none", + "--no-deploy", + "--json", + ]); + expect(result).toMatchObject({ ok: true }); + expect(exitCode).toBe(0); + + const projectDir = path.join(rootDir, "tanstack-app"); + await runCommand(projectDir, ["bun", "run", "build"]); + await runCommand(projectDir, ["bunx", "tsc", "--noEmit"]); + await verifyComposerDev(projectDir, "/", async (response) => { + const html = await response.text(); + for (const name of ["Alice", "Bob", "Carol"]) expect(html).toContain(name); + }); + }, + TEST_TIMEOUT, + ); + test( "creates a project without agent skill files when --skills none is passed", async () => { diff --git a/tests/local-bun.test.ts b/tests/local-bun.test.ts new file mode 100644 index 0000000..e6af886 --- /dev/null +++ b/tests/local-bun.test.ts @@ -0,0 +1,37 @@ +import { expect, test } from "bun:test"; +import { Effect } from "effect"; + +import { CommandExecutionError, CommandRunner } from "../src/services/command-runner"; +import { checkLocalBunEffect } from "../src/tasks/prisma-setup/local-bun"; + +function checkWith(run: CommandRunner["Service"]["run"]) { + return Effect.runPromise( + checkLocalBunEffect(process.cwd()).pipe( + Effect.provideService(CommandRunner, { run, runChecked: run }), + ), + ); +} + +const bunVersion = (stdout: string) => () => Effect.succeed({ exitCode: 0, stdout, stderr: "" }); + +test("warns when the local Bun is older than 1.3.14", async () => { + expect(await checkWith(bunVersion("1.3.13\n"))).toContain("Bun 1.3.13 is on your PATH."); +}); + +test("accepts Bun 1.3.14 and newer", async () => { + expect(await checkWith(bunVersion("1.3.14\n"))).toBeUndefined(); + expect(await checkWith(bunVersion("1.4.4\n"))).toBeUndefined(); +}); + +test("stays silent when Bun is missing or prints no version", async () => { + expect( + await checkWith(() => + Effect.fail( + new CommandExecutionError({ command: "bun", args: ["--version"], stdout: "", stderr: "" }), + ), + ), + ).toBeUndefined(); + expect( + await checkWith(() => Effect.succeed({ exitCode: 127, stdout: "", stderr: "not found" })), + ).toBeUndefined(); +}); From 5573eade41e4425bd776d77839168019b8d6470e Mon Sep 17 00:00:00 2001 From: willbot Date: Tue, 10 Nov 2026 15:59:57 +1100 Subject: [PATCH 2/2] fix: address review of the Composer dev Bun check Move the check to src/tasks/composer/dev-bun.ts and name it for what it returns. Give up after 3 seconds if `bun --version` hangs. Warn when Bun is missing too. Name the dev command with the project's package manager. Derive "the next steps include Composer dev" once, for both the next steps and the check. Remove NODE_ENV=test from every e2e child process. Release 0.14.8. Co-Authored-By: Claude Opus 5.5 Signed-off-by: willbot Signed-off-by: Will Madden --- README.md | 2 +- package.json | 4 +- src/tasks/composer/dev-bun.ts | 45 ++++++++++++++ src/tasks/prisma-setup/local-bun.ts | 18 ------ src/tasks/prisma-setup/presentation.ts | 24 +++++--- src/tasks/setup-prisma.ts | 13 ++-- tests/composer-dev-bun.test.ts | 85 ++++++++++++++++++++++++++ tests/e2e/create-prisma.e2e.test.ts | 8 +-- tests/local-bun.test.ts | 37 ----------- 9 files changed, 161 insertions(+), 75 deletions(-) create mode 100644 src/tasks/composer/dev-bun.ts delete mode 100644 src/tasks/prisma-setup/local-bun.ts create mode 100644 tests/composer-dev-bun.test.ts delete mode 100644 tests/local-bun.test.ts diff --git a/README.md b/README.md index 1d7ef3d..7067e1d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Each supported Node.js release works with the npm it ships, including npm 10 on The one exception is the `nuxt` template. Nuxt itself requires Node.js `^22.22.3 || ^24.15.0 || >=26.0.0`, so Nuxt projects declare that narrower range. -Running the app locally with `dev:composer` needs Bun 1.3.14 or newer on your PATH, because Prisma Composer runs the app with that Bun, as Prisma Compute does. Older Bun fails on React 19.3 server rendering, so every page of the `tanstack-start` template returns HTTP 500. create-prisma warns when it finds an older Bun. +Running the app locally with `dev:composer` needs Bun 1.3.14 or newer on your PATH, because Prisma Composer runs the app with that Bun, as Prisma Compute does. Older Bun fails on React 19.3 server rendering, so every page of the `tanstack-start` template returns HTTP 500. create-prisma warns when Bun is missing or older. ## Quick start diff --git a/package.json b/package.json index 9f27d07..f835599 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-prisma", - "version": "0.14.7", + "version": "0.14.8", "private": false, "description": "Create Prisma 8 projects with first-party templates and great DX.", "homepage": "https://github.com/prisma/create-prisma", @@ -37,7 +37,7 @@ "dev": "tsdown --watch", "start": "bun run ./dist/cli.mjs", "test": "bun run test:unit && bun run test:e2e", - "test:unit": "bun test ./tests/create-context.test.ts ./tests/dependencies.test.ts ./tests/deploy-with-composer.test.ts ./tests/initialize-git.test.ts ./tests/install.test.ts ./tests/json-output.test.ts ./tests/local-bun.test.ts ./tests/node-version.test.ts ./tests/package-manager-error-code.test.ts ./tests/pin-problems.test.ts ./tests/setup-prisma.test.ts ./tests/telemetry-client.test.ts ./tests/telemetry.test.ts", + "test:unit": "bun test ./tests/composer-dev-bun.test.ts ./tests/create-context.test.ts ./tests/dependencies.test.ts ./tests/deploy-with-composer.test.ts ./tests/initialize-git.test.ts ./tests/install.test.ts ./tests/json-output.test.ts ./tests/node-version.test.ts ./tests/package-manager-error-code.test.ts ./tests/pin-problems.test.ts ./tests/setup-prisma.test.ts ./tests/telemetry-client.test.ts ./tests/telemetry.test.ts", "test:e2e": "bun test --timeout 180000 ./tests/e2e/create-prisma.e2e.test.ts", "check": "bun run format:check && bun run lint", "lint": "oxlint . --deny-warnings", diff --git a/src/tasks/composer/dev-bun.ts b/src/tasks/composer/dev-bun.ts new file mode 100644 index 0000000..cfe4e63 --- /dev/null +++ b/src/tasks/composer/dev-bun.ts @@ -0,0 +1,45 @@ +import { Effect, Option } from "effect"; + +import { CommandRunner } from "../../services/command-runner"; +import type { PackageManager } from "../../types"; +import type { ChildProcessFailure } from "../../utils/child-process-failure"; +import { + getRunScriptCommand, + isOlderVersion, + parsePackageManagerVersion, +} from "../../utils/package-manager"; + +// Composer dev runs the app with the Bun on PATH. Bun 1.3.13 and older mis-transpile +// React 19.3's server renderer, so every server-rendered request fails. +export const MINIMUM_COMPOSER_DEV_BUN_VERSION = [1, 3, 14] as const; + +const BUN_VERSION_TIMEOUT = "3 seconds"; + +type BunProbe = { installed: false } | { installed: true; version: string | undefined }; + +const probe = (failure: ChildProcessFailure | undefined, version?: string): BunProbe => + failure === "command_not_found" ? { installed: false } : { installed: true, version }; + +export const getComposerDevBunWarningEffect = Effect.fn("Composer.devBunWarning")(function* ( + cwd: string, + packageManager: PackageManager, +) { + const runner = yield* CommandRunner; + const bun = yield* runner.run({ command: "bun", args: ["--version"], cwd }).pipe( + Effect.map((result) => + probe(result.childProcessFailure, result.exitCode === 0 ? result.stdout.trim() : undefined), + ), + Effect.catch((error) => Effect.succeed(probe(error.childProcessFailure))), + Effect.timeoutOption(BUN_VERSION_TIMEOUT), + Effect.map(Option.getOrUndefined), + ); + const devCommand = `\`${getRunScriptCommand(packageManager, "dev:composer")}\``; + if (bun?.installed === false) { + return `Bun is not on your PATH. Prisma Composer runs your app locally with Bun. Install it from https://bun.sh before ${devCommand}.`; + } + const version = bun?.version ? parsePackageManagerVersion("bun", bun.version) : undefined; + if (!version || !isOlderVersion(version.parts, MINIMUM_COMPOSER_DEV_BUN_VERSION)) { + return undefined; + } + return `Bun ${version.version} is on your PATH. Prisma Composer runs your app locally with it, and Bun older than ${MINIMUM_COMPOSER_DEV_BUN_VERSION.join(".")} cannot run some apps, such as React 19.3 server rendering. Run \`bun upgrade\` before ${devCommand}.`; +}); diff --git a/src/tasks/prisma-setup/local-bun.ts b/src/tasks/prisma-setup/local-bun.ts deleted file mode 100644 index d34a420..0000000 --- a/src/tasks/prisma-setup/local-bun.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Effect } from "effect"; - -import { CommandRunner } from "../../services/command-runner"; -import { isOlderVersion, parsePackageManagerVersion } from "../../utils/package-manager"; - -// Bun 1.3.13 and older mis-transpile React 19.3's server renderer, so every SSR request fails. -export const MINIMUM_LOCAL_BUN_VERSION = [1, 3, 14] as const; - -export const checkLocalBunEffect = Effect.fn("PrismaSetup.checkLocalBun")(function* (cwd: string) { - const runner = yield* CommandRunner; - const result = yield* runner - .run({ command: "bun", args: ["--version"], cwd }) - .pipe(Effect.orElseSucceed(() => undefined)); - const version = - result?.exitCode === 0 ? parsePackageManagerVersion("bun", result.stdout.trim()) : undefined; - if (!version || !isOlderVersion(version.parts, MINIMUM_LOCAL_BUN_VERSION)) return undefined; - return `Bun ${version.version} is on your PATH. Prisma Composer runs your app locally with it, and Bun older than ${MINIMUM_LOCAL_BUN_VERSION.join(".")} cannot run some apps, such as React 19.3 server rendering. Run \`bun upgrade\` before \`dev:composer\`.`; -}); diff --git a/src/tasks/prisma-setup/presentation.ts b/src/tasks/prisma-setup/presentation.ts index 7485735..1f73eea 100644 --- a/src/tasks/prisma-setup/presentation.ts +++ b/src/tasks/prisma-setup/presentation.ts @@ -36,6 +36,13 @@ export function formatProjectSummary(options: { return lines.join("\n"); } +export function showsComposerDevStep( + context: PrismaSetupContext, + options: PrismaSetupRunOptions, +): boolean { + return options.includeDevNextStep === true && context.packageManager !== "deno"; +} + export function buildNextSteps( context: PrismaSetupContext, options: PrismaSetupRunOptions, @@ -47,16 +54,15 @@ export function buildNextSteps( description: "Composer uses this secret when deploying the MongoDB template.", }); } - if (options.includeDevNextStep) { + if (showsComposerDevStep(context, options)) { + nextSteps.push({ + command: getRunScriptCommand(context.packageManager, "dev:composer"), + description: "Build and start the app with Prisma Composer locally.", + }); + } else if (options.includeDevNextStep) { nextSteps.push({ - command: getRunScriptCommand( - context.packageManager, - context.packageManager === "deno" ? "dev" : "dev:composer", - ), - description: - context.packageManager === "deno" - ? "Start the Deno app after setting DATABASE_URL in .env." - : "Build and start the app with Prisma Composer locally.", + command: getRunScriptCommand(context.packageManager, "dev"), + description: "Start the Deno app after setting DATABASE_URL in .env.", }); } if (context.packageManager !== "deno") { diff --git a/src/tasks/setup-prisma.ts b/src/tasks/setup-prisma.ts index 6d4273d..bfb35af 100644 --- a/src/tasks/setup-prisma.ts +++ b/src/tasks/setup-prisma.ts @@ -12,18 +12,23 @@ import type { CreateTemplate, PrismaSetupCommandInput } from "../types"; import { getErrorMessage } from "../utils/errors"; import { getInstallCommand } from "../utils/package-manager"; import { atCreateStage } from "../workflow/failure"; +import { getComposerDevBunWarningEffect } from "./composer/dev-bun"; import { deployNewProjectWithComposerEffect } from "./deploy-with-composer"; import { initializeGitRepositoryEffect, type GitInitializationResult } from "./initialize-git"; import { installProjectDependenciesEffect, writePrismaDependenciesEffect } from "./install"; import { initializeAgentSkills, runPrismaCli, runPrismaInit } from "./prisma-setup/commands"; import { collectPrismaSetupContextEffect } from "./prisma-setup/context"; -import { checkLocalBunEffect } from "./prisma-setup/local-bun"; import { ensureComposerTypeScriptOptions, ensureGitignoreEntry, ensureMongoEnvironment, } from "./prisma-setup/project-files"; -import { buildNextSteps, formatNextSteps, formatProjectSummary } from "./prisma-setup/presentation"; +import { + buildNextSteps, + formatNextSteps, + formatProjectSummary, + showsComposerDevStep, +} from "./prisma-setup/presentation"; import type { PrismaSetupContext, PrismaSetupRunOptions, @@ -203,8 +208,8 @@ export const executePrismaSetupContextEffect = Effect.fn("PrismaSetup.execute")( gitInitialization?.status === "skipped" ? [`Could not initialize Git repository: ${gitInitialization.reason}`] : []; - if (options.includeDevNextStep && context.packageManager !== "deno") { - const bunWarning = yield* checkLocalBunEffect(projectDir); + if (showsComposerDevStep(context, options)) { + const bunWarning = yield* getComposerDevBunWarningEffect(projectDir, context.packageManager); if (bunWarning) { warnings.push(bunWarning); yield* Effect.sync(() => log.warn(bunWarning, { output: context.output })); diff --git a/tests/composer-dev-bun.test.ts b/tests/composer-dev-bun.test.ts new file mode 100644 index 0000000..a50f095 --- /dev/null +++ b/tests/composer-dev-bun.test.ts @@ -0,0 +1,85 @@ +import { expect, test } from "bun:test"; +import { Effect } from "effect"; + +import { CommandExecutionError, CommandRunner } from "../src/services/command-runner"; +import { getComposerDevBunWarningEffect } from "../src/tasks/composer/dev-bun"; +import { showsComposerDevStep } from "../src/tasks/prisma-setup/presentation"; +import type { PrismaSetupContext } from "../src/tasks/prisma-setup/types"; + +function warningWith(run: CommandRunner["Service"]["run"]) { + return Effect.runPromise( + getComposerDevBunWarningEffect(process.cwd(), "npm").pipe( + Effect.provideService(CommandRunner, { run, runChecked: run }), + ), + ); +} + +const bunPrints = + (stdout: string, exitCode = 0) => + () => + Effect.succeed({ exitCode, stdout, stderr: "" }); + +test("warns when the local Bun is older than 1.3.14", async () => { + const warning = await warningWith(bunPrints("1.3.13\n")); + expect(warning).toContain("Bun 1.3.13 is on your PATH."); + expect(warning).toContain("Run `bun upgrade` before `npm run dev:composer`."); +}); + +test("accepts Bun 1.3.14 and newer", async () => { + expect(await warningWith(bunPrints("1.3.14\n"))).toBeUndefined(); + expect(await warningWith(bunPrints("1.4.4\n"))).toBeUndefined(); +}); + +test("warns when Bun is not installed", async () => { + const missing = () => + Effect.fail( + new CommandExecutionError({ + command: "bun", + args: ["--version"], + stdout: "", + stderr: "", + childProcessFailure: "command_not_found", + }), + ); + expect(await warningWith(missing)).toContain("Bun is not on your PATH."); + expect( + await warningWith(() => + Effect.succeed({ + exitCode: 1, + stdout: "", + stderr: "", + childProcessFailure: "command_not_found" as const, + }), + ), + ).toContain("Bun is not on your PATH."); +}); + +test("stays silent when Bun's version cannot be read", async () => { + expect(await warningWith(bunPrints("not a version\n"))).toBeUndefined(); + expect(await warningWith(bunPrints("", 1))).toBeUndefined(); + expect( + await warningWith(() => + Effect.fail( + new CommandExecutionError({ + command: "bun", + args: ["--version"], + stdout: "", + stderr: "", + childProcessFailure: "permission_denied", + }), + ), + ), + ).toBeUndefined(); +}); + +test("gives up when bun --version hangs", async () => { + expect(await warningWith(() => Effect.never)).toBeUndefined(); +}, 10_000); + +test("checks Bun only when the next steps include Composer dev", () => { + const context = (packageManager: PrismaSetupContext["packageManager"]) => + ({ packageManager }) as PrismaSetupContext; + expect(showsComposerDevStep(context("npm"), { includeDevNextStep: true })).toBe(true); + expect(showsComposerDevStep(context("npm"), {})).toBe(false); + expect(showsComposerDevStep(context("deno"), { includeDevNextStep: true })).toBe(false); +}); diff --git a/tests/e2e/create-prisma.e2e.test.ts b/tests/e2e/create-prisma.e2e.test.ts index 1e1ff62..8f8a7a2 100644 --- a/tests/e2e/create-prisma.e2e.test.ts +++ b/tests/e2e/create-prisma.e2e.test.ts @@ -67,7 +67,7 @@ async function runCreatePrismaJson(rootDir: string, args: string[]) { const child = Bun.spawn({ cmd: [process.execPath, path.join(import.meta.dir, "../../src/cli.ts"), ...args], cwd: rootDir, - env: { ...Bun.env, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1" }, + env: { ...appEnv, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1" }, stdout: "pipe", stderr: "pipe", }); @@ -147,7 +147,7 @@ async function verifyBuiltServer( const process = Bun.spawn({ cmd: ["node", "dist/server.mjs"], cwd: projectDir, - env: { ...Bun.env, ...env, PORT: String(port) }, + env: { ...appEnv, ...env, PORT: String(port) }, stdout: "pipe", stderr: "pipe", }); @@ -352,7 +352,7 @@ describe("create-prisma e2e", () => { ], cwd: rootDir, env: { - ...Bun.env, + ...appEnv, PATH: emptyBinDir, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1", @@ -402,7 +402,7 @@ describe("create-prisma e2e", () => { "--json", ], cwd: rootDir, - env: { ...Bun.env, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1" }, + env: { ...appEnv, CI: "1", CREATE_PRISMA_DISABLE_TELEMETRY: "1" }, stdout: "pipe", stderr: "pipe", }); diff --git a/tests/local-bun.test.ts b/tests/local-bun.test.ts deleted file mode 100644 index e6af886..0000000 --- a/tests/local-bun.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { expect, test } from "bun:test"; -import { Effect } from "effect"; - -import { CommandExecutionError, CommandRunner } from "../src/services/command-runner"; -import { checkLocalBunEffect } from "../src/tasks/prisma-setup/local-bun"; - -function checkWith(run: CommandRunner["Service"]["run"]) { - return Effect.runPromise( - checkLocalBunEffect(process.cwd()).pipe( - Effect.provideService(CommandRunner, { run, runChecked: run }), - ), - ); -} - -const bunVersion = (stdout: string) => () => Effect.succeed({ exitCode: 0, stdout, stderr: "" }); - -test("warns when the local Bun is older than 1.3.14", async () => { - expect(await checkWith(bunVersion("1.3.13\n"))).toContain("Bun 1.3.13 is on your PATH."); -}); - -test("accepts Bun 1.3.14 and newer", async () => { - expect(await checkWith(bunVersion("1.3.14\n"))).toBeUndefined(); - expect(await checkWith(bunVersion("1.4.4\n"))).toBeUndefined(); -}); - -test("stays silent when Bun is missing or prints no version", async () => { - expect( - await checkWith(() => - Effect.fail( - new CommandExecutionError({ command: "bun", args: ["--version"], stdout: "", stderr: "" }), - ), - ), - ).toBeUndefined(); - expect( - await checkWith(() => Effect.succeed({ exitCode: 127, stdout: "", stderr: "not found" })), - ).toBeUndefined(); -});