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
42 changes: 41 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 Bun is missing or older.

## Quick start

Use your package manager:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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/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",
Expand Down
45 changes: 45 additions & 0 deletions src/tasks/composer/dev-bun.ts
Original file line number Diff line number Diff line change
@@ -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}.`;
});
24 changes: 15 additions & 9 deletions src/tasks/prisma-setup/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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") {
Expand Down
15 changes: 14 additions & 1 deletion src/tasks/setup-prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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";
Expand All @@ -22,7 +23,12 @@ import {
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,
Expand Down Expand Up @@ -202,6 +208,13 @@ export const executePrismaSetupContextEffect = Effect.fn("PrismaSetup.execute")(
gitInitialization?.status === "skipped"
? [`Could not initialize Git repository: ${gitInitialization.reason}`]
: [];
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 }));
}
}
const projectSummary = formatProjectSummary({
createdProjectPath: options.createdProjectPath,
...(deployment ? { deployment } : {}),
Expand Down
4 changes: 2 additions & 2 deletions src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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]!;
}
Expand Down
85 changes: 85 additions & 0 deletions tests/composer-dev-bun.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
Loading
Loading