@prisma/compute-sdk 0.49.0 → 0.50.0

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.
Files changed (32) hide show
  1. package/README.md +27 -2
  2. package/dist/nextjs-build.d.ts +14 -0
  3. package/dist/nextjs-build.d.ts.map +1 -1
  4. package/dist/nextjs-build.js +2 -2
  5. package/dist/nextjs-build.js.map +1 -1
  6. package/dist/service/build/build-service.d.ts +1 -0
  7. package/dist/service/build/build-service.d.ts.map +1 -1
  8. package/dist/service/build/build-service.js +53 -19
  9. package/dist/service/build/build-service.js.map +1 -1
  10. package/dist/service/frameworks/framework.d.ts +26 -0
  11. package/dist/service/frameworks/framework.d.ts.map +1 -0
  12. package/dist/service/frameworks/framework.js +2 -0
  13. package/dist/service/frameworks/framework.js.map +1 -0
  14. package/dist/service/frameworks/index.d.ts +7 -0
  15. package/dist/service/frameworks/index.d.ts.map +1 -0
  16. package/dist/service/frameworks/index.js +8 -0
  17. package/dist/service/frameworks/index.js.map +1 -0
  18. package/dist/service/frameworks/nextjs.d.ts +3 -0
  19. package/dist/service/frameworks/nextjs.d.ts.map +1 -0
  20. package/dist/service/frameworks/nextjs.js +77 -0
  21. package/dist/service/frameworks/nextjs.js.map +1 -0
  22. package/dist/service/output/build-output.d.ts +8 -0
  23. package/dist/service/output/build-output.d.ts.map +1 -1
  24. package/dist/service/output/build-output.js +2 -1
  25. package/dist/service/output/build-output.js.map +1 -1
  26. package/package.json +1 -1
  27. package/src/nextjs-build.ts +4 -2
  28. package/src/service/build/build-service.ts +71 -21
  29. package/src/service/frameworks/framework.ts +28 -0
  30. package/src/service/frameworks/index.ts +12 -0
  31. package/src/service/frameworks/nextjs.ts +98 -0
  32. package/src/service/output/build-output.ts +8 -1
package/README.md CHANGED
@@ -599,13 +599,14 @@ The install command runs with `NODE_ENV=development`, because dev dependencies h
599
599
 
600
600
  ### What the build output holds
601
601
 
602
- Compute unpacks the build output on every start, so it holds only what the Service needs to run. `output.kind` says which of three it is:
602
+ Compute unpacks the build output on every start, so it holds only what the Service needs to run. `output.kind` says which of four it is:
603
603
 
604
604
  | `kind` | The folder | When |
605
605
  | --- | --- | --- |
606
606
  | `"static site"` | The folder of static files the build wrote | The start is a folder of static files |
607
607
  | `"traced server"` | `.prisma/output`: the source files and the trace of the server | The start is a command |
608
608
  | `"whole folder"` | The Service folder, with all of `node_modules` | The server cannot be traced. `output.reason` says why, and the Build settings get a note. |
609
+ | `"standalone output"` | `.prisma/output`: the standalone output of a framework's build | The framework's build wrote standalone output. `output.framework` names the framework, and the Build settings get a note. See [Next.js](#nextjs). |
609
610
 
610
611
  The **source files** are the repository's files and the output directories of the build. The installed `node_modules` is not among them. A `node_modules` folder inside an output directory is kept, because Nuxt and Next.js put their server's packages there.
611
612
 
@@ -615,10 +616,34 @@ The **trace** is every file of `node_modules` that the server loads. It starts f
615
616
  2. Whole, the package of a bin the start command runs, such as `tsx`, with its dependencies. A bin loads its own files by path, which imports do not show. A package that a runtime option preloads goes in the same way, such as `dotenv` in `node -r dotenv/config server.js`.
616
617
  3. An optional peer dependency of a traced package, when the Service lists it in `dependencies`. sequelize loads `pg` by a name held in a variable.
617
618
 
618
- The start command is not changed. The Launcher runs it as written.
619
+ The start command is not changed. The Launcher runs it as written. Standalone output is the one exception: it starts with its own server file.
619
620
 
620
621
  A server cannot be traced when the start command runs no file and no bin (`./run.sh`), or when it imports files from outside the Service folder, as in a workspace.
621
622
 
623
+ ### Next.js
624
+
625
+ A Service with `next` in `dependencies` or `devDependencies` is a Next.js Service. Its start command is `next start`, and `next` is a bin, so the trace would hold all of the `next` package. Next.js has a smaller build output of its own: standalone output, a server with only the files of `node_modules` that it loads.
626
+
627
+ The build command of a Next.js Service runs with `NEXT_PRIVATE_STANDALONE=true`. `next build` then writes standalone output to `.next/standalone`, as it does for `output: "standalone"` in `next.config`. The user changes nothing in `next.config`. A variable of the same name in `env` wins.
628
+
629
+ When `.next/standalone` exists after the build, it becomes the build output, with `public` and `.next/static` copied beside the server. The start is `node server.js`. The Launcher runs it, so the port works as for every other Service.
630
+
631
+ ```ts
632
+ const built = await buildService({ dir: "." }); // package.json: { "scripts": { "start": "next start" } }
633
+
634
+ built.value.output; // { dir: "/repo/.prisma/output", entrypoint: ".prisma/launcher.mjs", kind: "standalone output", framework: "Next.js" }
635
+ built.value.start; // { value: { kind: "command", command: "node server.js" }, from: "build output" }
636
+ ```
637
+
638
+ For a fresh Next.js 16.5 app, the standalone output is 37 MB and the traced server is 357 MB.
639
+
640
+ The Service is built as any other Service, with a traced server, in these cases:
641
+
642
+ - The Service config states `start` or `static`. The user's statement is final, and the build then runs without the variable.
643
+ - The build wrote no `.next/standalone`. A Next.js version that does not read the variable writes none, and neither does a build with `output: "export"` in `next.config`.
644
+
645
+ - The start script does more than start Next.js: a command in front of `next start`, such as `prisma migrate deploy && next start`, a `prestart` or `poststart` script, or a custom server. The standalone server would replace the script, and those steps would not run. Options after `next start` do not count.
646
+
622
647
  ### What the caller does next
623
648
 
624
649
  The build output is a folder (`output.dir`, a real path) and an entry file (`output.entrypoint`, relative to the folder). The caller copies or uploads the folder and tells Compute to start the entry file with Bun.
@@ -21,4 +21,18 @@ export declare class NextjsBuild implements BuildStrategy {
21
21
  canBuild(signal?: AbortSignal): Promise<boolean>;
22
22
  execute(signal?: AbortSignal): Promise<BuildArtifact>;
23
23
  }
24
+ export declare function copyStaticAssets(options: {
25
+ appPath: string;
26
+ artifactDir: string;
27
+ outputRoot: string;
28
+ entrypoint: string;
29
+ signal?: AbortSignal;
30
+ }): Promise<void>;
31
+ /**
32
+ * Locates `server.js` in the staged standalone output. In monorepos Next
33
+ * preserves the workspace-relative path (e.g. `apps/web/server.js`), so the
34
+ * entrypoint is the shallowest match. `node_modules` is skipped because
35
+ * third-party packages may ship their own `server.js`.
36
+ */
37
+ export declare function findStandaloneEntrypoint(artifactDir: string): Promise<string>;
24
38
  //# sourceMappingURL=nextjs-build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nextjs-build.d.ts","sourceRoot":"","sources":["../src/nextjs-build.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AASrD;;;;;;;GAOG;AACH,qBAAa,WAAY,YAAW,aAAa;;gBAMnC,OAAO,EAAE;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,EAAE,CAAC,EAAE,cAAc,CAAC;QACpB,2EAA2E;QAC3E,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B;IAOK,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAOhD,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;CA6E5D"}
1
+ {"version":3,"file":"nextjs-build.d.ts","sourceRoot":"","sources":["../src/nextjs-build.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AASrD;;;;;;;GAOG;AACH,qBAAa,WAAY,YAAW,aAAa;;gBAMnC,OAAO,EAAE;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,CAAC,EAAE,aAAa,CAAC;QAC9B,EAAE,CAAC,EAAE,cAAc,CAAC;QACpB,2EAA2E;QAC3E,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B;IAOK,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAOhD,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;CA6E5D;AA4DD,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBhB;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAwCjB"}
@@ -151,7 +151,7 @@ async function stageFullTreeFallbackArtifact(appPath, signal) {
151
151
  function isExcludedFromFullTree(basename) {
152
152
  return (basename === ".git" || basename === ".env" || basename.startsWith(".env."));
153
153
  }
154
- async function copyStaticAssets(options) {
154
+ export async function copyStaticAssets(options) {
155
155
  const serverSubpath = serverSubpathOf(options.entrypoint);
156
156
  const serverDir = serverSubpath
157
157
  ? path.join(options.artifactDir, serverSubpath)
@@ -179,7 +179,7 @@ async function copyStaticAssets(options) {
179
179
  * entrypoint is the shallowest match. `node_modules` is skipped because
180
180
  * third-party packages may ship their own `server.js`.
181
181
  */
182
- async function findStandaloneEntrypoint(artifactDir) {
182
+ export async function findStandaloneEntrypoint(artifactDir) {
183
183
  const rootStat = await stat(path.join(artifactDir, "server.js")).catch(() => null);
184
184
  if (rootStat?.isFile()) {
185
185
  return "server.js";
@@ -1 +1 @@
1
- {"version":3,"file":"nextjs-build.js","sourceRoot":"","sources":["../src/nextjs-build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,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CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3C,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AAChC,CAAC;AAED,KAAK,UAAU,eAAe,CAAC,OAAe;IAC5C,MAAM,CAAC,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,CAAC,EAAE,WAAW,EAAE,IAAI,KAAK,CAAC;AACnC,CAAC"}
@@ -22,6 +22,7 @@ export interface BuiltService {
22
22
  }
23
23
  /**
24
24
  * Runs the Service's install and build commands, decides how the Service starts, and writes the build output.
25
+ * A framework's own build output comes before the one this package writes.
25
26
  *
26
27
  * A failed install, a failed build and a missing start are expected outcomes:
27
28
  * they come back as a `ServiceBuildError`, not as a thrown error.
@@ -1 +1 @@
1
- {"version":3,"file":"build-service.d.ts","sourceRoot":"","sources":["../../../src/service/build/build-service.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAoB,MAAM,2BAA2B,CAAC;AAM/E,OAAO,KAAK,EAGV,QAAQ,EACR,oBAAoB,EACpB,aAAa,EACb,KAAK,EACN,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,eAAe,CAAC;AAEvB,MAAM,WAAW,mBAAmB;IAClC,0BAA0B;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,0DAA0D;IAC1D,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,0DAA0D;IAC1D,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,MAAM,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AAM,EAAE,WAAW,CAAC;CACrB;AAiBD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAyElD"}
@@ -4,6 +4,7 @@ import { existsSync, readFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { Result } from "better-result";
6
6
  import { ServiceBuildError } from "../../errors.js";
7
+ import { findFramework } from "../frameworks/index.js";
7
8
  import { writeBuildOutput } from "../output/build-output.js";
8
9
  import { readPackageJson } from "../settings/package-json.js";
9
10
  import { resolveServiceBuildSettings, resolveStartAfterBuild, } from "../settings/resolve.js";
@@ -20,6 +21,7 @@ const NO_START = {
20
21
  };
21
22
  /**
22
23
  * Runs the Service's install and build commands, decides how the Service starts, and writes the build output.
24
+ * A framework's own build output comes before the one this package writes.
23
25
  *
24
26
  * A failed install, a failed build and a missing start are expected outcomes:
25
27
  * they come back as a `ServiceBuildError`, not as a thrown error.
@@ -28,12 +30,35 @@ export async function buildService(options) {
28
30
  const { dir } = options;
29
31
  const read = readFrom(dir);
30
32
  const settings = await resolveServiceBuildSettings(read, options.config, options.signal);
33
+ const { packageJson } = await readPackageJson(read);
34
+ // A start the user states in the Service config is final, so no framework changes the build.
35
+ const startIsFromConfig = settings.start !== "after build" && settings.start.from === "config";
36
+ const framework = startIsFromConfig ? null : findFramework(packageJson);
31
37
  const steps = [];
32
38
  const fail = (failure) => Result.err(new ServiceBuildError({ ...failure, settings, steps }));
33
- const outputDirectories = await installAndBuild(settings, options, steps);
39
+ const done = (start, output) => Result.ok({
40
+ settings: {
41
+ ...settings,
42
+ start,
43
+ notes: [...settings.notes, ...buildOutputNotes(output)],
44
+ },
45
+ start,
46
+ steps,
47
+ output,
48
+ });
49
+ const outputDirectories = await installAndBuild(settings, framework, options, steps);
34
50
  if (outputDirectories.isErr()) {
35
51
  return fail(outputDirectories.error);
36
52
  }
53
+ const port = settings.port?.value ?? null;
54
+ const fromFramework = await framework?.buildOutput?.({
55
+ serviceDir: dir,
56
+ port,
57
+ signal: options.signal,
58
+ });
59
+ if (fromFramework) {
60
+ return done({ value: fromFramework.start, from: "build output" }, fromFramework.output);
61
+ }
37
62
  const start = settings.start === "after build"
38
63
  ? await resolveStartAfterBuild(read, outputDirectories.value, options.signal)
39
64
  : settings.start;
@@ -43,26 +68,29 @@ export async function buildService(options) {
43
68
  const output = await writeBuildOutput({
44
69
  serviceDir: dir,
45
70
  start: start.value,
46
- port: settings.port?.value ?? null,
47
- packageJson: (await readPackageJson(read)).packageJson,
71
+ port,
72
+ packageJson,
48
73
  outputDirectories: outputDirectories.value,
49
74
  signal: options.signal,
50
75
  });
51
- const notes = output.kind === "whole folder"
52
- ? [
53
- ...settings.notes,
76
+ return done(start, output);
77
+ }
78
+ /** What the user should know about a build output that is not the trace of their start command. */
79
+ function buildOutputNotes(output) {
80
+ if (output.kind === "whole folder") {
81
+ return [
54
82
  `The build output is the whole folder, with all of node_modules: ${output.reason}.`,
55
- ]
56
- : settings.notes;
57
- return Result.ok({
58
- settings: { ...settings, start, notes },
59
- start,
60
- steps,
61
- output,
62
- });
83
+ ];
84
+ }
85
+ if (output.kind === "standalone output") {
86
+ return [
87
+ `The build output is the standalone output of ${output.framework}. It starts with its own server file, not with a start script.`,
88
+ ];
89
+ }
90
+ return [];
63
91
  }
64
92
  /** Runs the install, then the build. Returns what the build created, or the step that failed. */
65
- async function installAndBuild(settings, options, steps) {
93
+ async function installAndBuild(settings, framework, options, steps) {
66
94
  const { dir, env, signal } = options;
67
95
  const run = { dir, steps, log: options.log ?? (() => { }), signal };
68
96
  const install = installStep(settings, env);
@@ -71,19 +99,25 @@ async function installAndBuild(settings, options, steps) {
71
99
  return Result.err(stepFailed(install, installed.output));
72
100
  }
73
101
  const beforeBuild = snapshotFolders(dir);
74
- const build = buildStep(settings, env);
102
+ const build = buildStep(settings, framework, env);
75
103
  const built = await runStep(build, run);
76
104
  if (!built.ok) {
77
105
  return Result.err(stepFailed(build, built.output));
78
106
  }
79
107
  return Result.ok(outputDirectoriesSince(dir, beforeBuild));
80
108
  }
81
- /** The build runs in production mode. The caller's variables win over these. */
82
- function buildStep(settings, extraEnv = {}) {
109
+ /** The build runs in production mode, with the framework's variables. The caller's variables win over these. */
110
+ function buildStep(settings, framework, extraEnv = {}) {
83
111
  return {
84
112
  name: "build",
85
113
  command: settings.build.value,
86
- env: { ...process.env, CI: "true", NODE_ENV: "production", ...extraEnv },
114
+ env: {
115
+ ...process.env,
116
+ CI: "true",
117
+ NODE_ENV: "production",
118
+ ...framework?.buildEnv,
119
+ ...extraEnv,
120
+ },
87
121
  };
88
122
  }
89
123
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"build-service.js","sourceRoot":"","sources":["../../../src/service/build/build-service.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,mFAAmF;AACnF,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAoB,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,GACvB,MAAM,wBAAwB,CAAC;AAShC,OAAO,EACL,sBAAsB,EACtB,eAAe,GAChB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,OAAO,GAGR,MAAM,eAAe,CAAC;AAwBvB,2FAA2F;AAC3F,MAAM,aAAa,GAAG;IACpB,OAAO,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,SAAS,EAAE;IACrD,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,OAAO,EAAE;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C3B,WAAmC,EAAE;IAErC,OAAO;QACL,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK;QAC7B,GAAG,EAAE;YACH,GAAG,OAAO,CAAC,GAAG;YACd,EAAE,EAAE,MAAM;YACV,QAAQ,EAAE,YAAY;YACtB,GAAG,SAAS,EAAE,QAAQ;YACtB,GAAG,QAAQ;SACZ;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAS,WAAW,CAClB,QAA8B,EAC9B,WAAmC,EAAE;IAErC,OAAO;QACL,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,KAAK;QAC/B,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE;KAC1E,CAAC;AACJ,CAAC;AAED,SAAS,UAAU,CAAC,IAAe,EAAE,aAAqB;IACxD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjD,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,GAAG,KAAK,YAAY,IAAI,CAAC,OAAO,EAAE;QAC3C,aAAa;KACd,CAAC;AACJ,CAAC;AAED,iEAAiE;AACjE,SAAS,QAAQ,CAAC,GAAW;IAC3B,OAAO,CAAC,IAAI,EAAE,EAAE,CACd,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { BuildOutput } from "../output/build-output.ts";
2
+ import type { PackageJson, Start } from "../settings/types.ts";
3
+ export interface Framework {
4
+ /** The name the framework goes by, such as `Next.js`. The build output it produces carries the name. */
5
+ name: string;
6
+ /** True when the Service uses the framework. */
7
+ detect(packageJson: PackageJson): boolean;
8
+ /** Variables for the build command. */
9
+ buildEnv?: Record<string, string>;
10
+ /**
11
+ * Runs after the build. Returns the build output that the framework's build wrote,
12
+ * or null when it wrote none. The build then writes its own build output.
13
+ */
14
+ buildOutput?(service: {
15
+ serviceDir: string;
16
+ /** The port the user stated, or null. */
17
+ port: number | null;
18
+ signal?: AbortSignal;
19
+ }): Promise<FrameworkBuildOutput | null>;
20
+ }
21
+ /** The build output that a framework's build wrote, and how the Service starts from it. */
22
+ export interface FrameworkBuildOutput {
23
+ output: BuildOutput;
24
+ start: Start;
25
+ }
26
+ //# sourceMappingURL=framework.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework.d.ts","sourceRoot":"","sources":["../../../src/service/frameworks/framework.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAE/D,MAAM,WAAW,SAAS;IACxB,wGAAwG;IACxG,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,MAAM,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC;IAC1C,uCAAuC;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC;;;OAGG;IACH,WAAW,CAAC,CAAC,OAAO,EAAE;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,yCAAyC;QACzC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;CAC1C;AAED,2FAA2F;AAC3F,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;CACd"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=framework.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework.js","sourceRoot":"","sources":["../../../src/service/frameworks/framework.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ import type { PackageJson } from "../settings/types.ts";
2
+ import type { Framework } from "./framework.ts";
3
+ /** The first definition that detects the Service is its framework. */
4
+ export declare const FRAMEWORKS: Framework[];
5
+ /** The framework the Service uses, or null when no definition detects it. */
6
+ export declare function findFramework(packageJson: PackageJson): Framework | null;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/service/frameworks/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,sEAAsE;AACtE,eAAO,MAAM,UAAU,EAAE,SAAS,EAAa,CAAC;AAEhD,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,WAAW,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAExE"}
@@ -0,0 +1,8 @@
1
+ import { nextjs } from "./nextjs.js";
2
+ /** The first definition that detects the Service is its framework. */
3
+ export const FRAMEWORKS = [nextjs];
4
+ /** The framework the Service uses, or null when no definition detects it. */
5
+ export function findFramework(packageJson) {
6
+ return FRAMEWORKS.find((framework) => framework.detect(packageJson)) ?? null;
7
+ }
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/service/frameworks/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,sEAAsE;AACtE,MAAM,CAAC,MAAM,UAAU,GAAgB,CAAC,MAAM,CAAC,CAAC;AAEhD,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAAC,WAAwB;IACpD,OAAO,UAAU,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC;AAC/E,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { Framework } from "./framework.ts";
2
+ export declare const nextjs: Framework;
3
+ //# sourceMappingURL=nextjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../../src/service/frameworks/nextjs.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AA+BhD,eAAO,MAAM,MAAM,EAAE,SAuDpB,CAAC"}
@@ -0,0 +1,77 @@
1
+ // The Next.js framework definition: `next build` writes standalone output, and that becomes the build output.
2
+ import { statSync } from "node:fs";
3
+ import { rm } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { stageStandaloneArtifact } from "../../artifact-stage.js";
6
+ import { copyStaticAssets, findStandaloneEntrypoint, } from "../../nextjs-build.js";
7
+ import { LAUNCHER_FILE } from "../launcher-contract/start-plan.js";
8
+ import { BUILD_OUTPUT_FOLDER, writeLauncher } from "../output/build-output.js";
9
+ const NAME = "Next.js";
10
+ /** `next start` alone, with options at most. A command joined to it with `&&`, `;` or `|` is something else. */
11
+ const NEXT_START = /^\s*next\s+start(\s+[^&|;]*)?$/;
12
+ /**
13
+ * The standalone server replaces the start script. That is only right when the script does nothing
14
+ * but start Next.js: a migration in front of it, a `prestart` script or a custom server would not run.
15
+ */
16
+ function startsOnlyNext(scripts) {
17
+ const { start, prestart, poststart } = scripts;
18
+ return ((start === undefined || NEXT_START.test(start)) &&
19
+ prestart === undefined &&
20
+ poststart === undefined);
21
+ }
22
+ /** The output directory of `next build`, relative to the Service folder. */
23
+ const OUTPUT_DIRECTORY = ".next";
24
+ /** The Launcher runs the start command in a shell, and the path of the server file comes from the file system. */
25
+ function shellWord(filePath) {
26
+ return /^[\w./-]+$/.test(filePath)
27
+ ? filePath
28
+ : `'${filePath.replaceAll("'", "'\\''")}'`;
29
+ }
30
+ export const nextjs = {
31
+ name: NAME,
32
+ detect: ({ dependencies, devDependencies, scripts }) => "next" in { ...dependencies, ...devDependencies } &&
33
+ startsOnlyNext(scripts ?? {}),
34
+ // `next build` then writes standalone output, as it does for `output: "standalone"` in next.config.
35
+ buildEnv: { NEXT_PRIVATE_STANDALONE: "true" },
36
+ async buildOutput({ serviceDir, port, signal }) {
37
+ const standaloneDir = path.join(serviceDir, OUTPUT_DIRECTORY, "standalone");
38
+ // A Next.js version that does not read the variable writes no standalone output.
39
+ if (!statSync(standaloneDir, { throwIfNoEntry: false })?.isDirectory()) {
40
+ return null;
41
+ }
42
+ const dir = path.join(serviceDir, BUILD_OUTPUT_FOLDER);
43
+ await rm(dir, { recursive: true, force: true });
44
+ await stageStandaloneArtifact({
45
+ standaloneDir,
46
+ artifactDir: dir,
47
+ appPath: serviceDir,
48
+ signal,
49
+ });
50
+ // Standalone output with no server file cannot start. The build then writes its own build output.
51
+ const server = await findStandaloneEntrypoint(dir).catch(() => null);
52
+ if (server === null) {
53
+ await rm(dir, { recursive: true, force: true });
54
+ return null;
55
+ }
56
+ // Standalone output leaves out `public` and `.next/static`. The server serves them from its own folder.
57
+ await copyStaticAssets({
58
+ appPath: serviceDir,
59
+ artifactDir: dir,
60
+ outputRoot: OUTPUT_DIRECTORY,
61
+ entrypoint: server,
62
+ signal,
63
+ });
64
+ const command = `node ${shellWord(server)}`;
65
+ writeLauncher(dir, { kind: "command", command, port });
66
+ return {
67
+ start: { kind: "command", command },
68
+ output: {
69
+ dir,
70
+ entrypoint: LAUNCHER_FILE,
71
+ kind: "standalone output",
72
+ framework: NAME,
73
+ },
74
+ };
75
+ },
76
+ };
77
+ //# sourceMappingURL=nextjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextjs.js","sourceRoot":"","sources":["../../../src/service/frameworks/nextjs.ts"],"names":[],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O,GAAG,QAAQ,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5C,aAAa,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAEvD,OAAO;YACL,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE;YACnC,MAAM,EAAE;gBACN,GAAG;gBACH,UAAU,EAAE,aAAa;gBACzB,IAAI,EAAE,mBAAmB;gBACzB,SAAS,EAAE,IAAI;aAChB;SACF,CAAC;IACJ,CAAC;CACF,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { type StartPlan } from "../launcher-contract/start-plan.ts";
1
2
  import type { OutputDirectories, PackageJson, Start } from "../settings/types.ts";
2
3
  import { type Untraceable } from "./trace/trace.ts";
3
4
  /** Where the build output of a traced server is written, relative to the Service folder. */
@@ -19,6 +20,11 @@ export type BuildOutput = {
19
20
  /** The whole Service folder, with all of `node_modules`, because the server could not be traced. */
20
21
  kind: "whole folder";
21
22
  reason: Untraceable;
23
+ } | {
24
+ /** The standalone output of a framework's build: a server with only the files of `node_modules` that it loads. */
25
+ kind: "standalone output";
26
+ /** The framework whose build wrote it, such as `Next.js`. */
27
+ framework: string;
22
28
  });
23
29
  /** What the build output of a traced server holds, for the caller to show. Paths are relative to the Service folder. */
24
30
  export interface TraceSummary {
@@ -44,4 +50,6 @@ export declare function writeBuildOutput(options: {
44
50
  outputDirectories: OutputDirectories;
45
51
  signal?: AbortSignal;
46
52
  }): Promise<BuildOutput>;
53
+ /** Writes the Launcher and the Start plan into a build output folder. */
54
+ export declare function writeLauncher(dir: string, plan: StartPlan): void;
47
55
  //# sourceMappingURL=build-output.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-output.d.ts","sourceRoot":"","sources":["../../../src/service/output/build-output.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EACX,KAAK,EACN,MAAM,sBAAsB,CAAC;AAK9B,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,kBAAkB,CAAC;AAE1B,4FAA4F;AAC5F,eAAO,MAAM,mBAAmB,QAAiC,CAAC;AAElE,oFAAoF;AACpF,MAAM,MAAM,WAAW,GAAG;IACxB,iIAAiI;IACjI,GAAG,EAAE,MAAM,CAAC;IACZ,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,CACA;IACE,yFAAyF;IACzF,IAAI,EAAE,aAAa,CAAC;CACrB,GACD;IACE,+FAA+F;IAC/F,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;CACrB,GACD;IACE,oGAAoG;IACpG,IAAI,EAAE,cAAc,CAAC;IACrB,MAAM,EAAE,WAAW,CAAC;CACrB,CACJ,CAAC;AAEF,wHAAwH;AACxH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,wBAAwB,EAAE,MAAM,EAAE,CAAC;CACpC;AAID;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,yCAAyC;IACzC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,WAAW,EAAE,WAAW,CAAC;IACzB,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,OAAO,CAAC,WAAW,CAAC,CA+DvB"}
1
+ {"version":3,"file":"build-output.d.ts","sourceRoot":"","sources":["../../../src/service/output/build-output.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,SAAS,EACf,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACV,iBAAiB,EACjB,WAAW,EACX,KAAK,EACN,MAAM,sB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,IAAI,CAIhE"}
@@ -89,7 +89,8 @@ async function copyTracedServer(serviceDir, dir, source, trace) {
89
89
  }
90
90
  return copy;
91
91
  }
92
- function writeLauncher(dir, plan) {
92
+ /** Writes the Launcher and the Start plan into a build output folder. */
93
+ export function writeLauncher(dir, plan) {
93
94
  mkdirSync(path.join(dir, path.dirname(LAUNCHER_FILE)), { recursive: true });
94
95
  copyFileSync(launcherFile(), path.join(dir, LAUNCHER_FILE));
95
96
  writeFileSync(path.join(dir, START_PLAN_FILE), JSON.stringify(plan));
@@ -1 +1 @@
1
- {"version":3,"file":"build-output.js","sourceRoot":"","sources":["../../../src/service/output/build-output.ts"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/E,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,aAAa,EACb,eAAe,GAEhB,MAAM,oCAAoC,CAAC;AAM5C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAEL,WAAW,GAEZ,MAAM,kBAAkB,CAAC;AAE1B,4FAA4F;AAC5F,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AAkClE,MAAM,WAAW,GAAG,aAAa,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAQtC;IACC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,kGAAkG;IAClG,MAAM,UAAU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CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5E,YAAY,CAAC,YAAY,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC;IAC5D,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;AACvE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/compute-sdk",
3
- "version": "0.49.0",
3
+ "version": "0.50.0",
4
4
  "description": "TypeScript SDK for deploying and managing applications on Prisma Compute",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "prisma/project-compute",
@@ -196,7 +196,7 @@ function isExcludedFromFullTree(basename: string): boolean {
196
196
  );
197
197
  }
198
198
 
199
- async function copyStaticAssets(options: {
199
+ export async function copyStaticAssets(options: {
200
200
  appPath: string;
201
201
  artifactDir: string;
202
202
  outputRoot: string;
@@ -233,7 +233,9 @@ async function copyStaticAssets(options: {
233
233
  * entrypoint is the shallowest match. `node_modules` is skipped because
234
234
  * third-party packages may ship their own `server.js`.
235
235
  */
236
- async function findStandaloneEntrypoint(artifactDir: string): Promise<string> {
236
+ export async function findStandaloneEntrypoint(
237
+ artifactDir: string,
238
+ ): Promise<string> {
237
239
  const rootStat = await stat(path.join(artifactDir, "server.js")).catch(
238
240
  () => null,
239
241
  );
@@ -4,6 +4,8 @@ import { existsSync, readFileSync } from "node:fs";
4
4
  import { join } from "node:path";
5
5
  import { Result } from "better-result";
6
6
  import { ServiceBuildError } from "../../errors.ts";
7
+ import type { Framework } from "../frameworks/framework.ts";
8
+ import { findFramework } from "../frameworks/index.ts";
7
9
  import { type BuildOutput, writeBuildOutput } from "../output/build-output.ts";
8
10
  import { readPackageJson } from "../settings/package-json.ts";
9
11
  import {
@@ -65,6 +67,7 @@ const NO_START: Failure = {
65
67
 
66
68
  /**
67
69
  * Runs the Service's install and build commands, decides how the Service starts, and writes the build output.
70
+ * A framework's own build output comes before the one this package writes.
68
71
  *
69
72
  * A failed install, a failed build and a missing start are expected outcomes:
70
73
  * they come back as a `ServiceBuildError`, not as a thrown error.
@@ -79,15 +82,49 @@ export async function buildService(
79
82
  options.config,
80
83
  options.signal,
81
84
  );
85
+ const { packageJson } = await readPackageJson(read);
86
+ // A start the user states in the Service config is final, so no framework changes the build.
87
+ const startIsFromConfig =
88
+ settings.start !== "after build" && settings.start.from === "config";
89
+ const framework = startIsFromConfig ? null : findFramework(packageJson);
82
90
  const steps: BuildStep[] = [];
83
91
  const fail = (failure: Failure) =>
84
92
  Result.err(new ServiceBuildError({ ...failure, settings, steps }));
85
-
86
- const outputDirectories = await installAndBuild(settings, options, steps);
93
+ const done = (start: Resolved<Start>, output: BuildOutput) =>
94
+ Result.ok({
95
+ settings: {
96
+ ...settings,
97
+ start,
98
+ notes: [...settings.notes, ...buildOutputNotes(output)],
99
+ },
100
+ start,
101
+ steps,
102
+ output,
103
+ });
104
+
105
+ const outputDirectories = await installAndBuild(
106
+ settings,
107
+ framework,
108
+ options,
109
+ steps,
110
+ );
87
111
  if (outputDirectories.isErr()) {
88
112
  return fail(outputDirectories.error);
89
113
  }
90
114
 
115
+ const port = settings.port?.value ?? null;
116
+ const fromFramework = await framework?.buildOutput?.({
117
+ serviceDir: dir,
118
+ port,
119
+ signal: options.signal,
120
+ });
121
+ if (fromFramework) {
122
+ return done(
123
+ { value: fromFramework.start, from: "build output" },
124
+ fromFramework.output,
125
+ );
126
+ }
127
+
91
128
  const start =
92
129
  settings.start === "after build"
93
130
  ? await resolveStartAfterBuild(
@@ -103,30 +140,36 @@ export async function buildService(
103
140
  const output = await writeBuildOutput({
104
141
  serviceDir: dir,
105
142
  start: start.value,
106
- port: settings.port?.value ?? null,
107
- packageJson: (await readPackageJson(read)).packageJson,
143
+ port,
144
+ packageJson,
108
145
  outputDirectories: outputDirectories.value,
109
146
  signal: options.signal,
110
147
  });
111
- const notes =
112
- output.kind === "whole folder"
113
- ? [
114
- ...settings.notes,
115
- `The build output is the whole folder, with all of node_modules: ${output.reason}.`,
116
- ]
117
- : settings.notes;
118
-
119
- return Result.ok({
120
- settings: { ...settings, start, notes },
121
- start,
122
- steps,
123
- output,
124
- });
148
+
149
+ return done(start, output);
150
+ }
151
+
152
+ /** What the user should know about a build output that is not the trace of their start command. */
153
+ function buildOutputNotes(output: BuildOutput): string[] {
154
+ if (output.kind === "whole folder") {
155
+ return [
156
+ `The build output is the whole folder, with all of node_modules: ${output.reason}.`,
157
+ ];
158
+ }
159
+
160
+ if (output.kind === "standalone output") {
161
+ return [
162
+ `The build output is the standalone output of ${output.framework}. It starts with its own server file, not with a start script.`,
163
+ ];
164
+ }
165
+
166
+ return [];
125
167
  }
126
168
 
127
169
  /** Runs the install, then the build. Returns what the build created, or the step that failed. */
128
170
  async function installAndBuild(
129
171
  settings: ServiceBuildSettings,
172
+ framework: Framework | null,
130
173
  options: BuildServiceOptions,
131
174
  steps: BuildStep[],
132
175
  ): Promise<Result<OutputDirectories, Failure>> {
@@ -140,7 +183,7 @@ async function installAndBuild(
140
183
  }
141
184
 
142
185
  const beforeBuild = snapshotFolders(dir);
143
- const build = buildStep(settings, env);
186
+ const build = buildStep(settings, framework, env);
144
187
  const built = await runStep(build, run);
145
188
  if (!built.ok) {
146
189
  return Result.err(stepFailed(build, built.output));
@@ -149,15 +192,22 @@ async function installAndBuild(
149
192
  return Result.ok(outputDirectoriesSince(dir, beforeBuild));
150
193
  }
151
194
 
152
- /** The build runs in production mode. The caller's variables win over these. */
195
+ /** The build runs in production mode, with the framework's variables. The caller's variables win over these. */
153
196
  function buildStep(
154
197
  settings: ServiceBuildSettings,
198
+ framework: Framework | null,
155
199
  extraEnv: Record<string, string> = {},
156
200
  ): StepToRun {
157
201
  return {
158
202
  name: "build",
159
203
  command: settings.build.value,
160
- env: { ...process.env, CI: "true", NODE_ENV: "production", ...extraEnv },
204
+ env: {
205
+ ...process.env,
206
+ CI: "true",
207
+ NODE_ENV: "production",
208
+ ...framework?.buildEnv,
209
+ ...extraEnv,
210
+ },
161
211
  };
162
212
  }
163
213
 
@@ -0,0 +1,28 @@
1
+ // A framework definition: how the build of one Service detects a framework, and what the build does differently for it.
2
+ import type { BuildOutput } from "../output/build-output.ts";
3
+ import type { PackageJson, Start } from "../settings/types.ts";
4
+
5
+ export interface Framework {
6
+ /** The name the framework goes by, such as `Next.js`. The build output it produces carries the name. */
7
+ name: string;
8
+ /** True when the Service uses the framework. */
9
+ detect(packageJson: PackageJson): boolean;
10
+ /** Variables for the build command. */
11
+ buildEnv?: Record<string, string>;
12
+ /**
13
+ * Runs after the build. Returns the build output that the framework's build wrote,
14
+ * or null when it wrote none. The build then writes its own build output.
15
+ */
16
+ buildOutput?(service: {
17
+ serviceDir: string;
18
+ /** The port the user stated, or null. */
19
+ port: number | null;
20
+ signal?: AbortSignal;
21
+ }): Promise<FrameworkBuildOutput | null>;
22
+ }
23
+
24
+ /** The build output that a framework's build wrote, and how the Service starts from it. */
25
+ export interface FrameworkBuildOutput {
26
+ output: BuildOutput;
27
+ start: Start;
28
+ }
@@ -0,0 +1,12 @@
1
+ // The framework definitions that the build of one Service knows, in detection order.
2
+ import type { PackageJson } from "../settings/types.ts";
3
+ import type { Framework } from "./framework.ts";
4
+ import { nextjs } from "./nextjs.ts";
5
+
6
+ /** The first definition that detects the Service is its framework. */
7
+ export const FRAMEWORKS: Framework[] = [nextjs];
8
+
9
+ /** The framework the Service uses, or null when no definition detects it. */
10
+ export function findFramework(packageJson: PackageJson): Framework | null {
11
+ return FRAMEWORKS.find((framework) => framework.detect(packageJson)) ?? null;
12
+ }
@@ -0,0 +1,98 @@
1
+ // The Next.js framework definition: `next build` writes standalone output, and that becomes the build output.
2
+ import { statSync } from "node:fs";
3
+ import { rm } from "node:fs/promises";
4
+ import path from "node:path";
5
+ import { stageStandaloneArtifact } from "../../artifact-stage.ts";
6
+ import {
7
+ copyStaticAssets,
8
+ findStandaloneEntrypoint,
9
+ } from "../../nextjs-build.ts";
10
+ import { LAUNCHER_FILE } from "../launcher-contract/start-plan.ts";
11
+ import { BUILD_OUTPUT_FOLDER, writeLauncher } from "../output/build-output.ts";
12
+ import type { Framework } from "./framework.ts";
13
+
14
+ const NAME = "Next.js";
15
+
16
+ /** `next start` alone, with options at most. A command joined to it with `&&`, `;` or `|` is something else. */
17
+ const NEXT_START = /^\s*next\s+start(\s+[^&|;]*)?$/;
18
+
19
+ /**
20
+ * The standalone server replaces the start script. That is only right when the script does nothing
21
+ * but start Next.js: a migration in front of it, a `prestart` script or a custom server would not run.
22
+ */
23
+ function startsOnlyNext(scripts: Record<string, string>): boolean {
24
+ const { start, prestart, poststart } = scripts;
25
+
26
+ return (
27
+ (start === undefined || NEXT_START.test(start)) &&
28
+ prestart === undefined &&
29
+ poststart === undefined
30
+ );
31
+ }
32
+
33
+ /** The output directory of `next build`, relative to the Service folder. */
34
+ const OUTPUT_DIRECTORY = ".next";
35
+
36
+ /** The Launcher runs the start command in a shell, and the path of the server file comes from the file system. */
37
+ function shellWord(filePath: string): string {
38
+ return /^[\w./-]+$/.test(filePath)
39
+ ? filePath
40
+ : `'${filePath.replaceAll("'", "'\\''")}'`;
41
+ }
42
+
43
+ export const nextjs: Framework = {
44
+ name: NAME,
45
+
46
+ detect: ({ dependencies, devDependencies, scripts }) =>
47
+ "next" in { ...dependencies, ...devDependencies } &&
48
+ startsOnlyNext(scripts ?? {}),
49
+
50
+ // `next build` then writes standalone output, as it does for `output: "standalone"` in next.config.
51
+ buildEnv: { NEXT_PRIVATE_STANDALONE: "true" },
52
+
53
+ async buildOutput({ serviceDir, port, signal }) {
54
+ const standaloneDir = path.join(serviceDir, OUTPUT_DIRECTORY, "standalone");
55
+ // A Next.js version that does not read the variable writes no standalone output.
56
+ if (!statSync(standaloneDir, { throwIfNoEntry: false })?.isDirectory()) {
57
+ return null;
58
+ }
59
+
60
+ const dir = path.join(serviceDir, BUILD_OUTPUT_FOLDER);
61
+ await rm(dir, { recursive: true, force: true });
62
+ await stageStandaloneArtifact({
63
+ standaloneDir,
64
+ artifactDir: dir,
65
+ appPath: serviceDir,
66
+ signal,
67
+ });
68
+ // Standalone output with no server file cannot start. The build then writes its own build output.
69
+ const server = await findStandaloneEntrypoint(dir).catch(() => null);
70
+ if (server === null) {
71
+ await rm(dir, { recursive: true, force: true });
72
+
73
+ return null;
74
+ }
75
+
76
+ // Standalone output leaves out `public` and `.next/static`. The server serves them from its own folder.
77
+ await copyStaticAssets({
78
+ appPath: serviceDir,
79
+ artifactDir: dir,
80
+ outputRoot: OUTPUT_DIRECTORY,
81
+ entrypoint: server,
82
+ signal,
83
+ });
84
+
85
+ const command = `node ${shellWord(server)}`;
86
+ writeLauncher(dir, { kind: "command", command, port });
87
+
88
+ return {
89
+ start: { kind: "command", command },
90
+ output: {
91
+ dir,
92
+ entrypoint: LAUNCHER_FILE,
93
+ kind: "standalone output",
94
+ framework: NAME,
95
+ },
96
+ };
97
+ },
98
+ };
@@ -46,6 +46,12 @@ export type BuildOutput = {
46
46
  kind: "whole folder";
47
47
  reason: Untraceable;
48
48
  }
49
+ | {
50
+ /** The standalone output of a framework's build: a server with only the files of `node_modules` that it loads. */
51
+ kind: "standalone output";
52
+ /** The framework whose build wrote it, such as `Next.js`. */
53
+ framework: string;
54
+ }
49
55
  );
50
56
 
51
57
  /** What the build output of a traced server holds, for the caller to show. Paths are relative to the Service folder. */
@@ -167,7 +173,8 @@ async function copyTracedServer(
167
173
  return copy;
168
174
  }
169
175
 
170
- function writeLauncher(dir: string, plan: StartPlan): void {
176
+ /** Writes the Launcher and the Start plan into a build output folder. */
177
+ export function writeLauncher(dir: string, plan: StartPlan): void {
171
178
  mkdirSync(path.join(dir, path.dirname(LAUNCHER_FILE)), { recursive: true });
172
179
  copyFileSync(launcherFile(), path.join(dir, LAUNCHER_FILE));
173
180
  writeFileSync(path.join(dir, START_PLAN_FILE), JSON.stringify(plan));