create-prisma 0.4.2-pr.53.197.1 → 0.4.2-pr.53.198.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import "./create-BPGG92im.mjs";
2
+ import "./create-BHcAcUH1.mjs";
3
3
  import { createCreatePrismaCli } from "./index.mjs";
4
4
 
5
5
  //#region src/cli.ts
@@ -40,7 +40,7 @@ async function getAnonymousId() {
40
40
  }
41
41
  function getCommonProperties() {
42
42
  return {
43
- "cli-version": "0.4.2-pr.53.197.1",
43
+ "cli-version": "0.4.2-pr.53.198.1",
44
44
  "node-version": process.version,
45
45
  platform: process.platform,
46
46
  arch: process.arch
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as PackageManagerSchema, r as CreateCommandInputSchema, t as runCreateCommand } from "./create-BPGG92im.mjs";
2
+ import { a as DatabaseProviderSchema, i as CreateTemplateSchema, n as AuthoringStyleSchema, o as PackageManagerSchema, r as CreateCommandInputSchema, t as runCreateCommand } from "./create-BHcAcUH1.mjs";
3
3
  import { os } from "@orpc/server";
4
4
  import { createCli } from "trpc-cli";
5
5
  import { z } from "zod";
6
6
 
7
7
  //#region src/index.ts
8
- const CLI_VERSION = "0.4.2-pr.53.197.1";
8
+ const CLI_VERSION = "0.4.2-pr.53.198.1";
9
9
  const CreateCliInputSchema = z.tuple([z.string().trim().min(1, "Please enter a valid project name").optional().describe("Project name / directory"), CreateCommandInputSchema]);
10
10
  function normalizeCreateCliInput(input) {
11
11
  const [projectName, options] = input;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-prisma",
3
- "version": "0.4.2-pr.53.197.1",
3
+ "version": "0.4.2-pr.53.198.1",
4
4
  "private": false,
5
5
  "description": "Create Prisma 8 projects with first-party templates and great DX.",
6
6
  "homepage": "https://github.com/prisma/create-prisma",
@@ -18,7 +18,7 @@ This builds the app and starts it with Composer. PostgreSQL projects get a local
18
18
 
19
19
  The deploy script builds the framework output, provisions Prisma Postgres when selected, applies migrations, and deploys the app to Prisma Compute.
20
20
 
21
- The starter users are inserted idempotently on the first database query through the Composer service binding. `{{runScriptCommand packageManager "db:seed"}}` is only for seeding an explicit `DATABASE_URL` outside Composer.
21
+ The starter users are inserted idempotently on the first database query through the Composer service binding. `{{runScriptCommand packageManager "db:seed"}}` starts the app with Composer, seeds through its database route, and stops it again. If `DATABASE_URL` is set explicitly, the command seeds that database directly instead.
22
22
 
23
23
  {{#if (eq provider "mongo")}}
24
24
  MongoDB is not provisioned by Composer. Set `MONGODB_URL` before running Composer locally or deploying.
@@ -1,19 +1,97 @@
1
1
  import "dotenv/config";
2
+ import { spawn, type ChildProcess } from "node:child_process";
2
3
 
3
- if (!process.env.DATABASE_URL) {
4
- throw new Error(
5
- "DATABASE_URL is not set. Set it explicitly for this standalone command. Composer apps seed through their service binding on the first database query.",
6
- );
4
+ const seedPath = {{#if (eq template "astro")}}"/api/users"{{else if (eq template "nuxt")}}"/api/users"{{else if (eq template "hono")}}"/users"{{else if (eq template "elysia")}}"/users"{{else if (eq template "nest")}}"/users"{{else}}"/"{{/if}};
5
+
6
+ async function seedExplicitDatabase(): Promise<void> {
7
+ const [{ db }, { seedStarterData }] = await Promise.all([
8
+ import("./db.ts"),
9
+ import("./starter-data.ts"),
10
+ ]);
11
+
12
+ try {
13
+ await seedStarterData();
14
+ } finally {
15
+ await db.close();
16
+ }
7
17
  }
8
18
 
9
- const [{ db }, { seedStarterData }] = await Promise.all([
10
- import("./db.ts"),
11
- import("./starter-data.ts"),
12
- ]);
19
+ function stopComposer(child: ChildProcess): void {
20
+ if (child.exitCode !== null || child.pid === undefined) return;
21
+ try {
22
+ if (process.platform === "win32") child.kill("SIGINT");
23
+ else process.kill(-child.pid, "SIGINT");
24
+ } catch (error) {
25
+ if (!(error instanceof Error && "code" in error && error.code === "ESRCH")) throw error;
26
+ }
27
+ }
13
28
 
14
- try {
15
- await seedStarterData();
16
- console.log("Starter users are ready.");
17
- } finally {
18
- await db.close();
29
+ async function requestStarterUsers(origin: string): Promise<void> {
30
+ let lastStatus = 0;
31
+ for (let attempt = 0; attempt < 30; attempt += 1) {
32
+ try {
33
+ const response = await fetch(new URL(seedPath, origin));
34
+ const body = await response.text();
35
+ lastStatus = response.status;
36
+ if (response.ok && ["Alice", "Bob", "Carol"].every((name) => body.includes(name))) return;
37
+ } catch {
38
+ // The service may still be accepting its first connection after Composer reports ready.
39
+ }
40
+ await new Promise((resolve) => setTimeout(resolve, 1_000));
41
+ }
42
+ throw new Error(`The app's database route did not return the starter users (HTTP ${lastStatus}).`);
19
43
  }
44
+
45
+ async function seedThroughComposer(): Promise<void> {
46
+ const child = spawn("{{packageManager}}", ["run", "dev:composer"], {
47
+ cwd: new URL("../..", import.meta.url),
48
+ detached: process.platform !== "win32",
49
+ env: process.env,
50
+ stdio: ["ignore", "pipe", "pipe"],
51
+ });
52
+
53
+ let output = "";
54
+ let settled = false;
55
+ const ready = new Promise<string>((resolve, reject) => {
56
+ const timeout = setTimeout(() => reject(new Error("Timed out waiting for composer dev.")), 120_000);
57
+ const consume = (chunk: Buffer) => {
58
+ const text = chunk.toString();
59
+ output = `${output}${text}`.slice(-20_000);
60
+ if (!settled) process.stderr.write(text);
61
+ const url = output.match(/\bapp(?::|\s+)\s+(http:\/\/(?:127\.0\.0\.1|localhost):\d+)/)?.[1];
62
+ if (url && !settled) {
63
+ settled = true;
64
+ clearTimeout(timeout);
65
+ resolve(url);
66
+ }
67
+ };
68
+ child.stdout?.on("data", consume);
69
+ child.stderr?.on("data", consume);
70
+ child.once("error", (error) => {
71
+ clearTimeout(timeout);
72
+ reject(error);
73
+ });
74
+ child.once("exit", (code) => {
75
+ if (settled) return;
76
+ clearTimeout(timeout);
77
+ reject(new Error(`composer dev exited before the app was ready (code ${String(code)}).`));
78
+ });
79
+ });
80
+
81
+ const stopOnSignal = () => stopComposer(child);
82
+ process.once("SIGINT", stopOnSignal);
83
+ process.once("SIGTERM", stopOnSignal);
84
+ try {
85
+ const origin = await ready;
86
+ await requestStarterUsers(origin);
87
+ } finally {
88
+ process.removeListener("SIGINT", stopOnSignal);
89
+ process.removeListener("SIGTERM", stopOnSignal);
90
+ stopComposer(child);
91
+ }
92
+ }
93
+
94
+ if (process.env.DATABASE_URL) await seedExplicitDatabase();
95
+ else await seedThroughComposer();
96
+
97
+ console.log("Starter users are ready.");