@prisma/cli 3.0.0-dev.87.1 → 3.0.0-dev.90.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.
@@ -1,522 +0,0 @@
1
- import { readBunPackageJson, resolveBunEntrypoint } from "./bun-project.js";
2
- import { PRISMA_APP_CONFIG_FILENAME, hasAnyPackageDependency, hasPackageDependency, hasRootFile, joinPosix, nextOutputRootFromStandaloneDirectory, resolvePreviewBuildSettings, runResolvedBuildCommand } from "./preview-build-settings.js";
3
- import { chmod, copyFile, cp, lstat, mkdir, mkdtemp, readFile, readdir, readlink, rm, stat, writeFile } from "node:fs/promises";
4
- import path from "node:path";
5
- import os from "node:os";
6
- import { AstroBuild, BunBuild, NuxtBuild } from "@prisma/compute-sdk";
7
- //#region src/lib/app/preview-build.ts
8
- const PREVIEW_BUILD_TYPES = [
9
- "auto",
10
- "bun",
11
- "nextjs",
12
- "nuxt",
13
- "astro",
14
- "tanstack-start"
15
- ];
16
- const RESOLVED_PREVIEW_BUILD_TYPES = PREVIEW_BUILD_TYPES.filter((buildType) => buildType !== "auto");
17
- var PreviewBuildStrategy = class {
18
- #appPath;
19
- #entrypoint;
20
- #buildType;
21
- #signal;
22
- #buildSettings;
23
- constructor(options) {
24
- this.#appPath = options.appPath;
25
- this.#entrypoint = options.entrypoint;
26
- this.#buildType = options.buildType ?? "auto";
27
- this.#signal = options.signal;
28
- this.#buildSettings = options.buildSettings;
29
- }
30
- async canBuild(signal = this.#signal) {
31
- const { strategy } = await resolvePreviewBuildStrategy({
32
- appPath: this.#appPath,
33
- entrypoint: this.#entrypoint,
34
- buildType: this.#buildType,
35
- signal,
36
- buildSettings: this.#buildSettings
37
- });
38
- return strategy.canBuild(signal);
39
- }
40
- async execute(signal = this.#signal) {
41
- const { artifact } = await executePreviewBuild({
42
- appPath: this.#appPath,
43
- entrypoint: this.#entrypoint,
44
- buildType: this.#buildType,
45
- signal,
46
- buildSettings: this.#buildSettings
47
- });
48
- return artifact;
49
- }
50
- };
51
- async function executePreviewBuild(options) {
52
- const { strategy, buildType } = await resolvePreviewBuildStrategy({
53
- appPath: options.appPath,
54
- entrypoint: options.entrypoint,
55
- buildType: options.buildType ?? "auto",
56
- signal: options.signal,
57
- buildSettings: options.buildSettings
58
- });
59
- const artifact = await strategy.execute(options.signal);
60
- try {
61
- await normalizeArtifactSymlinks(artifact.directory, options.appPath, options.signal);
62
- return {
63
- artifact,
64
- buildType
65
- };
66
- } catch (error) {
67
- await artifact.cleanup?.().catch(() => void 0);
68
- throw error;
69
- }
70
- }
71
- async function resolvePreviewBuildStrategy(options) {
72
- if (options.buildType !== "auto") {
73
- const strategy = await createPreviewBuildStrategy({
74
- appPath: options.appPath,
75
- entrypoint: options.entrypoint,
76
- buildType: options.buildType,
77
- signal: options.signal,
78
- buildSettings: options.buildSettings
79
- });
80
- return {
81
- buildType: options.buildType,
82
- strategy
83
- };
84
- }
85
- for (const buildType of RESOLVED_PREVIEW_BUILD_TYPES) {
86
- if (buildType === "bun") continue;
87
- const strategy = await createPreviewBuildStrategy({
88
- appPath: options.appPath,
89
- entrypoint: options.entrypoint,
90
- buildType,
91
- signal: options.signal,
92
- buildSettings: options.buildSettings
93
- });
94
- if (await strategy.canBuild(options.signal)) return {
95
- buildType,
96
- strategy
97
- };
98
- }
99
- return {
100
- buildType: "bun",
101
- strategy: await createPreviewBuildStrategy({
102
- appPath: options.appPath,
103
- entrypoint: options.entrypoint,
104
- buildType: "bun",
105
- signal: options.signal,
106
- buildSettings: options.buildSettings
107
- })
108
- };
109
- }
110
- async function createPreviewBuildStrategy(options) {
111
- switch (options.buildType) {
112
- case "nextjs": return new PreviewNextjsBuild({
113
- appPath: options.appPath,
114
- buildSettings: options.buildSettings
115
- });
116
- case "nuxt": return new NuxtBuild({ appPath: options.appPath });
117
- case "astro": return new AstroBuild({ appPath: options.appPath });
118
- case "tanstack-start": return new PreviewTanstackStartBuild({
119
- appPath: options.appPath,
120
- buildSettings: options.buildSettings
121
- });
122
- case "bun": {
123
- const entrypoint = await resolveBunEntrypoint(options.appPath, options.entrypoint, options.signal);
124
- return new PreviewBunBuild({
125
- appPath: options.appPath,
126
- strategy: new BunBuild({
127
- appPath: options.appPath,
128
- entrypoint
129
- }),
130
- buildSettings: options.buildSettings
131
- });
132
- }
133
- }
134
- }
135
- var PreviewNextjsBuild = class {
136
- #appPath;
137
- #buildSettings;
138
- constructor(options) {
139
- this.#appPath = options.appPath;
140
- this.#buildSettings = options.buildSettings;
141
- }
142
- async canBuild(signal) {
143
- const packageJson = await readBunPackageJson(this.#appPath, signal);
144
- return await hasRootFile(this.#appPath, NEXT_CONFIG_FILENAMES, signal) || hasPackageDependency(packageJson, "next");
145
- }
146
- async execute(signal) {
147
- const settings = this.#buildSettings ?? await resolvePreviewBuildSettings({
148
- appPath: this.#appPath,
149
- buildType: "nextjs",
150
- signal
151
- });
152
- await runResolvedBuildCommand(this.#appPath, settings, "Next.js", signal);
153
- const standaloneDir = path.join(this.#appPath, settings.outputDirectory);
154
- if (!await directoryExists(standaloneDir, signal)) return stageNextjsFullTreeFallbackArtifact(this.#appPath, signal);
155
- const outDir = await unsupportedFilesystemBoundary(signal, () => mkdtemp(path.join(os.tmpdir(), "compute-build-")));
156
- try {
157
- const artifactDir = path.join(outDir, "app");
158
- await stageNextjsStandaloneArtifact({
159
- standaloneDir,
160
- artifactDir,
161
- appPath: this.#appPath,
162
- signal
163
- });
164
- const entrypoint = await findNextStandaloneEntrypoint(artifactDir, signal);
165
- await copyNextjsStaticAssets({
166
- appPath: this.#appPath,
167
- artifactDir,
168
- outputRoot: nextOutputRootFromStandaloneDirectory(settings.outputDirectory),
169
- entrypoint,
170
- signal
171
- });
172
- return {
173
- directory: artifactDir,
174
- entrypoint,
175
- defaultPortMapping: { http: 3e3 },
176
- cleanup: () => rm(outDir, {
177
- recursive: true,
178
- force: true
179
- })
180
- };
181
- } catch (error) {
182
- await rm(outDir, {
183
- recursive: true,
184
- force: true
185
- });
186
- throw error;
187
- }
188
- }
189
- };
190
- const FULL_TREE_NEXT_START_ENTRYPOINT = "prisma-next-start.cjs";
191
- const FULL_TREE_NEXT_START_SOURCE = [
192
- "process.chdir(__dirname);",
193
- "process.env.NODE_ENV = \"production\";",
194
- "process.argv.push(\"start\", \"-p\", process.env.PORT ?? \"3000\");",
195
- "require(\"next/dist/bin/next\");",
196
- ""
197
- ].join("\n");
198
- async function stageNextjsFullTreeFallbackArtifact(appPath, signal) {
199
- const outDir = await unsupportedFilesystemBoundary(signal, () => mkdtemp(path.join(os.tmpdir(), "compute-build-")));
200
- try {
201
- const artifactDir = path.join(outDir, "app");
202
- await unsupportedFilesystemBoundary(signal, () => cp(appPath, artifactDir, {
203
- recursive: true,
204
- verbatimSymlinks: true,
205
- filter: (source) => !isExcludedFromFullTreeArtifact(path.basename(source))
206
- }));
207
- await unsupportedFilesystemBoundary(signal, () => writeFile(path.join(artifactDir, FULL_TREE_NEXT_START_ENTRYPOINT), FULL_TREE_NEXT_START_SOURCE));
208
- return {
209
- directory: artifactDir,
210
- entrypoint: FULL_TREE_NEXT_START_ENTRYPOINT,
211
- defaultPortMapping: { http: 3e3 },
212
- cleanup: () => rm(outDir, {
213
- recursive: true,
214
- force: true
215
- })
216
- };
217
- } catch (error) {
218
- await rm(outDir, {
219
- recursive: true,
220
- force: true
221
- });
222
- throw error;
223
- }
224
- }
225
- /** Excludes VCS internals and dotenv files (local secrets, superseded by the deploy env). */
226
- function isExcludedFromFullTreeArtifact(basename) {
227
- return basename === ".git" || basename === ".env" || basename.startsWith(".env.");
228
- }
229
- var PreviewTanstackStartBuild = class {
230
- #appPath;
231
- #buildSettings;
232
- constructor(options) {
233
- this.#appPath = options.appPath;
234
- this.#buildSettings = options.buildSettings;
235
- }
236
- async canBuild(signal) {
237
- return hasAnyPackageDependency(await readBunPackageJson(this.#appPath, signal), TANSTACK_START_PACKAGES);
238
- }
239
- async execute(signal) {
240
- const settings = this.#buildSettings ?? await resolvePreviewBuildSettings({
241
- appPath: this.#appPath,
242
- buildType: "tanstack-start",
243
- signal
244
- });
245
- await runResolvedBuildCommand(this.#appPath, settings, "TanStack Start", signal);
246
- const outputDir = path.join(this.#appPath, settings.outputDirectory);
247
- const entrypoint = "server/index.mjs";
248
- const entryPath = path.join(outputDir, entrypoint);
249
- if (!(await unsupportedFilesystemBoundary(signal, () => stat(entryPath).catch(() => null)))?.isFile()) throw new Error(`TanStack Start build did not produce a Nitro node server entrypoint at ${joinPosix(settings.outputDirectory, entrypoint)}. Ensure your vite.config includes the tanstackStart() and nitro() plugins with the default node preset, or update ${PRISMA_APP_CONFIG_FILENAME}.`);
250
- const outDir = await unsupportedFilesystemBoundary(signal, () => mkdtemp(path.join(os.tmpdir(), "compute-build-")));
251
- try {
252
- const artifactDir = path.join(outDir, "app");
253
- await unsupportedFilesystemBoundary(signal, () => cp(outputDir, artifactDir, {
254
- recursive: true,
255
- verbatimSymlinks: true
256
- }));
257
- return {
258
- directory: artifactDir,
259
- entrypoint,
260
- defaultPortMapping: { http: 3e3 },
261
- cleanup: () => rm(outDir, {
262
- recursive: true,
263
- force: true
264
- })
265
- };
266
- } catch (error) {
267
- await rm(outDir, {
268
- recursive: true,
269
- force: true
270
- });
271
- throw error;
272
- }
273
- }
274
- };
275
- var PreviewBunBuild = class {
276
- #appPath;
277
- #strategy;
278
- #buildSettings;
279
- constructor(options) {
280
- this.#appPath = options.appPath;
281
- this.#strategy = options.strategy;
282
- this.#buildSettings = options.buildSettings;
283
- }
284
- async canBuild(signal) {
285
- return this.#strategy.canBuild(signal);
286
- }
287
- async execute(signal) {
288
- const settings = this.#buildSettings ?? await resolvePreviewBuildSettings({
289
- appPath: this.#appPath,
290
- buildType: "bun",
291
- signal
292
- });
293
- await runResolvedBuildCommand(this.#appPath, settings, "Bun", signal);
294
- return this.#strategy.execute(signal);
295
- }
296
- };
297
- const NEXT_CONFIG_FILENAMES = [
298
- "next.config.js",
299
- "next.config.mjs",
300
- "next.config.ts",
301
- "next.config.mts"
302
- ];
303
- const TANSTACK_START_PACKAGES = [
304
- "@tanstack/react-start",
305
- "@tanstack/solid-start",
306
- "@tanstack/start"
307
- ];
308
- async function stageNextjsStandaloneArtifact(options) {
309
- const standaloneRoot = path.resolve(options.standaloneDir);
310
- const artifactRoot = path.resolve(options.artifactDir);
311
- const appRoot = path.resolve(options.appPath);
312
- await copyPathMaterializingSymlinks(standaloneRoot, artifactRoot, {
313
- standaloneRoot,
314
- appRoot,
315
- sourceRoot: await resolveSourceRoot(appRoot, options.signal),
316
- signal: options.signal
317
- });
318
- await hoistPnpmDependencies(path.join(artifactRoot, "node_modules"), options.signal);
319
- }
320
- async function copyNextjsStaticAssets(options) {
321
- const serverSubpath = nextjsServerSubpath(options.entrypoint);
322
- const serverDir = serverSubpath ? path.join(options.artifactDir, serverSubpath) : options.artifactDir;
323
- const publicDir = path.join(options.appPath, "public");
324
- if (await directoryExists(publicDir, options.signal)) await unsupportedFilesystemBoundary(options.signal, () => cp(publicDir, path.join(serverDir, "public"), {
325
- recursive: true,
326
- verbatimSymlinks: true
327
- }));
328
- const staticDir = path.join(options.appPath, options.outputRoot, "static");
329
- if (await directoryExists(staticDir, options.signal)) await unsupportedFilesystemBoundary(options.signal, () => cp(staticDir, path.join(serverDir, options.outputRoot, "static"), {
330
- recursive: true,
331
- verbatimSymlinks: true
332
- }));
333
- }
334
- async function findNextStandaloneEntrypoint(artifactDir, signal) {
335
- const rootEntrypoint = path.join(artifactDir, "server.js");
336
- if ((await unsupportedFilesystemBoundary(signal, () => stat(rootEntrypoint).catch(() => null)))?.isFile()) return "server.js";
337
- const candidates = [];
338
- await walk(artifactDir);
339
- candidates.sort((left, right) => left.split("/").length - right.split("/").length || left.localeCompare(right));
340
- const selected = candidates[0];
341
- if (!selected) throw new Error(`Next.js standalone output did not contain server.js in ${artifactDir}`);
342
- return selected;
343
- async function walk(directory) {
344
- const entries = await unsupportedFilesystemBoundary(signal, () => readdir(directory, { withFileTypes: true }));
345
- for (const entry of entries) {
346
- if (entry.name === "node_modules") continue;
347
- const fullPath = path.join(directory, entry.name);
348
- if (entry.isDirectory()) {
349
- await walk(fullPath);
350
- continue;
351
- }
352
- if (entry.isFile() && entry.name === "server.js") candidates.push(path.relative(artifactDir, fullPath).split(path.sep).join("/"));
353
- }
354
- }
355
- }
356
- function nextjsServerSubpath(entrypoint) {
357
- const dir = path.posix.dirname(entrypoint);
358
- return dir === "." ? "" : dir;
359
- }
360
- async function hoistPnpmDependencies(nodeModulesDir, signal) {
361
- const pnpmNodeModulesDir = path.join(nodeModulesDir, ".pnpm", "node_modules");
362
- if (!await directoryExists(pnpmNodeModulesDir, signal)) return;
363
- const entries = await unsupportedFilesystemBoundary(signal, () => readdir(pnpmNodeModulesDir, { withFileTypes: true }));
364
- for (const entry of entries) {
365
- const sourcePath = path.join(pnpmNodeModulesDir, entry.name);
366
- if (entry.name.startsWith("@") && entry.isDirectory()) {
367
- const scopedEntries = await unsupportedFilesystemBoundary(signal, () => readdir(sourcePath, { withFileTypes: true }));
368
- for (const scopedEntry of scopedEntries) {
369
- const scopedDestination = path.join(nodeModulesDir, entry.name, scopedEntry.name);
370
- if (await pathExists(scopedDestination, signal)) continue;
371
- await unsupportedFilesystemBoundary(signal, () => mkdir(path.dirname(scopedDestination), { recursive: true }));
372
- await copyPathMaterializingSymlinks(path.join(sourcePath, scopedEntry.name), scopedDestination, {
373
- standaloneRoot: pnpmNodeModulesDir,
374
- appRoot: nodeModulesDir,
375
- sourceRoot: nodeModulesDir,
376
- signal
377
- });
378
- }
379
- continue;
380
- }
381
- const destinationPath = path.join(nodeModulesDir, entry.name);
382
- if (await pathExists(destinationPath, signal)) continue;
383
- await copyPathMaterializingSymlinks(sourcePath, destinationPath, {
384
- standaloneRoot: pnpmNodeModulesDir,
385
- appRoot: nodeModulesDir,
386
- sourceRoot: nodeModulesDir,
387
- signal
388
- });
389
- }
390
- }
391
- async function normalizeArtifactSymlinks(artifactDir, appPath, signal) {
392
- const normalizedArtifactDir = path.resolve(artifactDir);
393
- const normalizedAppPath = path.resolve(appPath);
394
- await walkDirectory(normalizedArtifactDir);
395
- async function walkDirectory(directory) {
396
- const entries = await unsupportedFilesystemBoundary(signal, () => readdir(directory, { withFileTypes: true }));
397
- for (const entry of entries) {
398
- const fullPath = path.join(directory, entry.name);
399
- if (entry.isDirectory()) {
400
- await walkDirectory(fullPath);
401
- continue;
402
- }
403
- if (!entry.isSymbolicLink()) continue;
404
- if (await materializeArtifactSymlink({
405
- fullPath,
406
- normalizedArtifactDir,
407
- normalizedAppPath,
408
- signal
409
- }) === "directory") await walkDirectory(fullPath);
410
- }
411
- }
412
- }
413
- async function materializeArtifactSymlink(options) {
414
- const target = await unsupportedFilesystemBoundary(options.signal, () => readlink(options.fullPath));
415
- const resolvedTarget = path.resolve(path.dirname(options.fullPath), target);
416
- if (isPathWithin(options.normalizedArtifactDir, resolvedTarget)) return "internal";
417
- if (!isPathWithin(options.normalizedAppPath, resolvedTarget)) throw new Error(`Build artifact symlink escapes the app directory: ${resolvedTarget}`);
418
- const targetStat = await unsupportedFilesystemBoundary(options.signal, () => stat(resolvedTarget));
419
- await unsupportedFilesystemBoundary(options.signal, () => rm(options.fullPath, {
420
- force: true,
421
- recursive: true
422
- }));
423
- await unsupportedFilesystemBoundary(options.signal, () => cp(resolvedTarget, options.fullPath, {
424
- recursive: targetStat.isDirectory(),
425
- dereference: true
426
- }));
427
- return targetStat.isDirectory() ? "directory" : "file";
428
- }
429
- function isPathWithin(rootPath, candidatePath) {
430
- const relativePath = path.relative(rootPath, candidatePath);
431
- return relativePath === "" || !relativePath.startsWith(`..${path.sep}`) && relativePath !== ".." && !path.isAbsolute(relativePath);
432
- }
433
- function isPathWithinWorkspaceDependency(sourceRoot, candidatePath) {
434
- return isPathWithin(path.join(sourceRoot, "node_modules"), candidatePath);
435
- }
436
- async function copyPathMaterializingSymlinks(sourcePath, destinationPath, options) {
437
- const sourceStat = await unsupportedFilesystemBoundary(options.signal, () => lstat(sourcePath));
438
- if (sourceStat.isSymbolicLink()) {
439
- const resolvedTarget = await resolveSymlinkTarget(sourcePath, options);
440
- if (resolvedTarget === null) return;
441
- await copyPathMaterializingSymlinks(resolvedTarget, destinationPath, options);
442
- return;
443
- }
444
- if (sourceStat.isDirectory()) {
445
- await unsupportedFilesystemBoundary(options.signal, () => mkdir(destinationPath, { recursive: true }));
446
- const entries = await unsupportedFilesystemBoundary(options.signal, () => readdir(sourcePath, { withFileTypes: true }));
447
- for (const entry of entries) await copyPathMaterializingSymlinks(path.join(sourcePath, entry.name), path.join(destinationPath, entry.name), options);
448
- return;
449
- }
450
- if (sourceStat.isFile()) {
451
- await unsupportedFilesystemBoundary(options.signal, () => mkdir(path.dirname(destinationPath), { recursive: true }));
452
- await unsupportedFilesystemBoundary(options.signal, () => copyFile(sourcePath, destinationPath));
453
- await unsupportedFilesystemBoundary(options.signal, () => chmod(destinationPath, sourceStat.mode));
454
- }
455
- }
456
- async function resolveSymlinkTarget(symlinkPath, options) {
457
- const linkTarget = await unsupportedFilesystemBoundary(options.signal, () => readlink(symlinkPath));
458
- const resolvedTarget = path.resolve(path.dirname(symlinkPath), linkTarget);
459
- if (await pathExists(resolvedTarget, options.signal)) {
460
- if (!isPathWithin(options.appRoot, resolvedTarget) && !isPathWithinWorkspaceDependency(options.sourceRoot, resolvedTarget)) throw new Error(`Build artifact symlink escapes the app directory: ${resolvedTarget}`);
461
- return resolvedTarget;
462
- }
463
- if (isPathWithin(options.standaloneRoot, resolvedTarget)) {
464
- const fallbackTarget = path.join(options.appRoot, path.relative(options.standaloneRoot, resolvedTarget));
465
- if (await pathExists(fallbackTarget, options.signal)) return fallbackTarget;
466
- }
467
- if (isPnpmHoistLink(symlinkPath)) return null;
468
- throw new Error(`Next.js standalone symlink target is missing: ${symlinkPath} -> ${linkTarget} (resolved to ${resolvedTarget})`);
469
- }
470
- function isPnpmHoistLink(symlinkPath) {
471
- const parts = path.dirname(symlinkPath).split(path.sep);
472
- for (let i = 0; i < parts.length - 1; i++) if (parts[i] === ".pnpm" && parts[i + 1] === "node_modules") return true;
473
- return false;
474
- }
475
- async function pathExists(targetPath, signal) {
476
- try {
477
- await unsupportedFilesystemBoundary(signal, () => stat(targetPath));
478
- return true;
479
- } catch (error) {
480
- if (signal?.aborted) throw error;
481
- return false;
482
- }
483
- }
484
- async function directoryExists(targetPath, signal) {
485
- try {
486
- return (await unsupportedFilesystemBoundary(signal, () => stat(targetPath))).isDirectory();
487
- } catch (error) {
488
- if (signal?.aborted) throw error;
489
- return false;
490
- }
491
- }
492
- async function resolveSourceRoot(appRoot, signal) {
493
- let current = path.resolve(appRoot);
494
- while (true) {
495
- if (await pathExists(path.join(current, ".git"), signal) || await pathExists(path.join(current, "pnpm-workspace.yaml"), signal) || await pathExists(path.join(current, "bun.lock"), signal) || await pathExists(path.join(current, "bun.lockb"), signal) || await packageJsonDeclaresWorkspaces(current, signal)) return current;
496
- const parent = path.dirname(current);
497
- if (parent === current) return path.resolve(appRoot);
498
- current = parent;
499
- }
500
- }
501
- async function packageJsonDeclaresWorkspaces(directory, signal) {
502
- signal?.throwIfAborted();
503
- try {
504
- const content = await readFile(path.join(directory, "package.json"), {
505
- encoding: "utf8",
506
- signal
507
- });
508
- const parsed = JSON.parse(content);
509
- return Boolean(parsed.workspaces);
510
- } catch (error) {
511
- if (signal?.aborted) throw error;
512
- return false;
513
- }
514
- }
515
- async function unsupportedFilesystemBoundary(signal, operation) {
516
- signal?.throwIfAborted();
517
- const result = await operation();
518
- signal?.throwIfAborted();
519
- return result;
520
- }
521
- //#endregion
522
- export { PREVIEW_BUILD_TYPES, PreviewBuildStrategy, RESOLVED_PREVIEW_BUILD_TYPES, executePreviewBuild };
@@ -1,5 +0,0 @@
1
- import "../../shell/prompt.js";
2
- //#region src/lib/app/preview-interaction.ts
3
- const PREVIEW_DEFAULT_REGION = "eu-central-1";
4
- //#endregion
5
- export { PREVIEW_DEFAULT_REGION };