@prisma/compute-sdk 0.26.0 → 0.28.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.
- package/dist/artifact-stage.d.ts +24 -0
- package/dist/artifact-stage.d.ts.map +1 -0
- package/dist/artifact-stage.js +165 -0
- package/dist/artifact-stage.js.map +1 -0
- package/dist/astro-build.d.ts +2 -0
- package/dist/astro-build.d.ts.map +1 -1
- package/dist/astro-build.js +8 -0
- package/dist/astro-build.js.map +1 -1
- package/dist/auto-build.d.ts +7 -4
- package/dist/auto-build.d.ts.map +1 -1
- package/dist/auto-build.js +25 -33
- package/dist/auto-build.js.map +1 -1
- package/dist/build-settings.d.ts +55 -0
- package/dist/build-settings.d.ts.map +1 -0
- package/dist/build-settings.js +311 -0
- package/dist/build-settings.js.map +1 -0
- package/dist/build-strategy.d.ts +4 -0
- package/dist/build-strategy.d.ts.map +1 -1
- package/dist/build-strategy.js +13 -20
- package/dist/build-strategy.js.map +1 -1
- package/dist/build.d.ts +45 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +89 -0
- package/dist/build.js.map +1 -0
- package/dist/bun-build.d.ts +8 -0
- package/dist/bun-build.d.ts.map +1 -1
- package/dist/bun-build.js +47 -23
- package/dist/bun-build.js.map +1 -1
- package/dist/config/frameworks.d.ts +2 -2
- package/dist/config/frameworks.d.ts.map +1 -1
- package/dist/config/frameworks.js +12 -0
- package/dist/config/frameworks.js.map +1 -1
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +1 -0
- package/dist/config/types.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/nestjs-build.d.ts +23 -0
- package/dist/nestjs-build.d.ts.map +1 -0
- package/dist/nestjs-build.js +317 -0
- package/dist/nestjs-build.js.map +1 -0
- package/dist/nextjs-build.d.ts +12 -2
- package/dist/nextjs-build.d.ts.map +1 -1
- package/dist/nextjs-build.js +156 -75
- package/dist/nextjs-build.js.map +1 -1
- package/dist/nuxt-build.d.ts +2 -0
- package/dist/nuxt-build.d.ts.map +1 -1
- package/dist/nuxt-build.js +8 -0
- package/dist/nuxt-build.js.map +1 -1
- package/dist/tanstack-start-build.d.ts +6 -1
- package/dist/tanstack-start-build.d.ts.map +1 -1
- package/dist/tanstack-start-build.js +35 -15
- package/dist/tanstack-start-build.js.map +1 -1
- package/dist/workspace.d.ts +90 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +205 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +5 -3
- package/src/artifact-stage.ts +280 -0
- package/src/astro-build.ts +11 -1
- package/src/auto-build.ts +28 -34
- package/src/build-settings.ts +448 -0
- package/src/build-strategy.ts +22 -29
- package/src/build.ts +127 -0
- package/src/bun-build.ts +60 -27
- package/src/config/frameworks.ts +13 -0
- package/src/config/types.ts +1 -0
- package/src/index.ts +29 -0
- package/src/nestjs-build.ts +425 -0
- package/src/nextjs-build.ts +206 -103
- package/src/nuxt-build.ts +11 -1
- package/src/tanstack-start-build.ts +44 -18
- package/src/workspace.ts +319 -0
package/src/nextjs-build.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { cp, mkdtemp, readdir, rm, stat } from "node:fs/promises";
|
|
1
|
+
import { cp, mkdtemp, readdir, rm, stat, writeFile } from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
import
|
|
4
|
+
|
|
5
|
+
import { stageStandaloneArtifact } from "./artifact-stage.ts";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from "./build-
|
|
7
|
+
type BuildSettings,
|
|
8
|
+
nextOutputRootFromStandaloneDirectory,
|
|
9
|
+
resolveBuildSettings,
|
|
10
|
+
} from "./build-settings.ts";
|
|
11
|
+
import type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
|
|
12
|
+
import { hasPackageDependency, hasRootFile } from "./build-strategy.ts";
|
|
11
13
|
import { defaultHttpPortForBuildType } from "./config/frameworks.ts";
|
|
14
|
+
import { type BuildCommandIo, runBuildCommand } from "./workspace.ts";
|
|
12
15
|
|
|
13
16
|
const NEXT_CONFIG_FILENAMES = [
|
|
14
17
|
"next.config.js",
|
|
@@ -18,14 +21,30 @@ const NEXT_CONFIG_FILENAMES = [
|
|
|
18
21
|
];
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
|
-
* Build strategy for Next.js applications
|
|
22
|
-
*
|
|
24
|
+
* Build strategy for Next.js applications. Runs the resolved build command
|
|
25
|
+
* (the user's `package.json` build script, or `next build`), then stages the
|
|
26
|
+
* `output: "standalone"` tree — materializing workspace symlinks and hoisting
|
|
27
|
+
* isolated-store dependencies. Apps built without standalone output fall back
|
|
28
|
+
* to packaging the full tree and serving with `next start`, unless
|
|
29
|
+
* `requireStandalone` is set (a disk-limited deploy target opts out of that).
|
|
23
30
|
*/
|
|
24
31
|
export class NextjsBuild implements BuildStrategy {
|
|
25
32
|
readonly #appPath: string;
|
|
33
|
+
readonly #buildSettings?: BuildSettings;
|
|
34
|
+
readonly #io?: BuildCommandIo;
|
|
35
|
+
readonly #requireStandalone: boolean;
|
|
26
36
|
|
|
27
|
-
constructor(options: {
|
|
37
|
+
constructor(options: {
|
|
38
|
+
appPath: string;
|
|
39
|
+
buildSettings?: BuildSettings;
|
|
40
|
+
io?: BuildCommandIo;
|
|
41
|
+
/** Fail instead of falling back to the full-tree `next start` artifact. */
|
|
42
|
+
requireStandalone?: boolean;
|
|
43
|
+
}) {
|
|
28
44
|
this.#appPath = options.appPath;
|
|
45
|
+
this.#buildSettings = options.buildSettings;
|
|
46
|
+
this.#io = options.io;
|
|
47
|
+
this.#requireStandalone = options.requireStandalone ?? false;
|
|
29
48
|
}
|
|
30
49
|
|
|
31
50
|
async canBuild(signal?: AbortSignal): Promise<boolean> {
|
|
@@ -37,67 +56,57 @@ export class NextjsBuild implements BuildStrategy {
|
|
|
37
56
|
|
|
38
57
|
async execute(signal?: AbortSignal): Promise<BuildArtifact> {
|
|
39
58
|
signal?.throwIfAborted();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
59
|
+
const settings =
|
|
60
|
+
this.#buildSettings ??
|
|
61
|
+
(await resolveBuildSettings({
|
|
62
|
+
appPath: this.#appPath,
|
|
63
|
+
buildType: "nextjs",
|
|
64
|
+
signal,
|
|
65
|
+
}));
|
|
66
|
+
if (settings.buildCommand) {
|
|
67
|
+
await runBuildCommand({
|
|
68
|
+
appPath: this.#appPath,
|
|
69
|
+
command: settings.buildCommand,
|
|
70
|
+
failurePrefix: "Next.js",
|
|
71
|
+
env: this.#io?.env,
|
|
72
|
+
onOutput: this.#io?.onOutput,
|
|
73
|
+
signal,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
49
76
|
|
|
50
|
-
const standaloneDir = path.join(this.#appPath,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
const standaloneDir = path.join(this.#appPath, settings.outputDirectory);
|
|
78
|
+
if (!(await directoryExists(standaloneDir))) {
|
|
79
|
+
if (this.#requireStandalone) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Next.js build did not produce standalone output at ${settings.outputDirectory}. ` +
|
|
82
|
+
'Set output: "standalone" in your next.config; this deploy target requires it.',
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
// No `output: "standalone"` in next.config: the build succeeded, so
|
|
86
|
+
// package the full tree and serve with `next start`. Bigger artifact,
|
|
87
|
+
// same running app.
|
|
88
|
+
return stageFullTreeFallbackArtifact(this.#appPath, signal);
|
|
56
89
|
}
|
|
57
90
|
|
|
58
91
|
const outDir = await mkdtemp(path.join(os.tmpdir(), "compute-build-"));
|
|
59
|
-
|
|
60
92
|
try {
|
|
61
93
|
const artifactDir = path.join(outDir, "app");
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
94
|
+
await stageStandaloneArtifact({
|
|
95
|
+
standaloneDir,
|
|
96
|
+
artifactDir,
|
|
97
|
+
appPath: this.#appPath,
|
|
98
|
+
signal,
|
|
99
|
+
});
|
|
100
|
+
const entrypoint = await findStandaloneEntrypoint(artifactDir);
|
|
101
|
+
await copyStaticAssets({
|
|
102
|
+
appPath: this.#appPath,
|
|
103
|
+
artifactDir,
|
|
104
|
+
outputRoot: nextOutputRootFromStandaloneDirectory(
|
|
105
|
+
settings.outputDirectory,
|
|
106
|
+
),
|
|
107
|
+
entrypoint,
|
|
108
|
+
signal,
|
|
66
109
|
});
|
|
67
|
-
|
|
68
|
-
// In monorepos, Next preserves the workspace-relative path from the
|
|
69
|
-
// workspace root down to the app, so server.js lands at e.g.
|
|
70
|
-
// .next/standalone/apps/web/server.js, not at the standalone root.
|
|
71
|
-
// The runtime needs the correct entrypoint, and Next expects public/
|
|
72
|
-
// and .next/static/ to be siblings of server.js.
|
|
73
|
-
const serverSubpath = await findServerSubpath(artifactDir);
|
|
74
|
-
const serverDir =
|
|
75
|
-
serverSubpath === undefined
|
|
76
|
-
? artifactDir
|
|
77
|
-
: path.join(artifactDir, serverSubpath);
|
|
78
|
-
|
|
79
|
-
const publicDir = path.join(this.#appPath, "public");
|
|
80
|
-
if (await directoryExists(publicDir)) {
|
|
81
|
-
await cp(publicDir, path.join(serverDir, "public"), {
|
|
82
|
-
recursive: true,
|
|
83
|
-
verbatimSymlinks: true,
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const staticDir = path.join(this.#appPath, ".next", "static");
|
|
88
|
-
if (await directoryExists(staticDir)) {
|
|
89
|
-
await cp(staticDir, path.join(serverDir, ".next", "static"), {
|
|
90
|
-
recursive: true,
|
|
91
|
-
verbatimSymlinks: true,
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const entrypoint =
|
|
96
|
-
serverSubpath === undefined
|
|
97
|
-
? "server.js"
|
|
98
|
-
: path.posix.join(serverSubpath, "server.js");
|
|
99
|
-
|
|
100
|
-
await normalizeArtifactSymlinks(artifactDir, this.#appPath, signal);
|
|
101
110
|
|
|
102
111
|
return {
|
|
103
112
|
directory: artifactDir,
|
|
@@ -112,55 +121,149 @@ export class NextjsBuild implements BuildStrategy {
|
|
|
112
121
|
}
|
|
113
122
|
}
|
|
114
123
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
const FULL_TREE_ENTRYPOINT = "prisma-next-start.cjs";
|
|
125
|
+
|
|
126
|
+
// Bootstrap for apps built without `output: "standalone"`. Entering through
|
|
127
|
+
// the CLI bin (not `next/dist/server/lib/start-server`) keeps Next in charge
|
|
128
|
+
// of config loading, which is the part that drifts across Next majors.
|
|
129
|
+
const FULL_TREE_START_SOURCE = [
|
|
130
|
+
// The runtime unpacks us at the artifact root, but `next start` resolves
|
|
131
|
+
// `.next` from cwd.
|
|
132
|
+
"process.chdir(__dirname);",
|
|
133
|
+
'process.env.NODE_ENV = "production";',
|
|
134
|
+
'process.argv.push("start", "-p", process.env.PORT ?? "3000");',
|
|
135
|
+
'require("next/dist/bin/next");',
|
|
136
|
+
"",
|
|
137
|
+
].join("\n");
|
|
138
|
+
|
|
139
|
+
async function stageFullTreeFallbackArtifact(
|
|
140
|
+
appPath: string,
|
|
141
|
+
signal?: AbortSignal,
|
|
142
|
+
): Promise<BuildArtifact> {
|
|
143
|
+
const outDir = await mkdtemp(path.join(os.tmpdir(), "compute-build-"));
|
|
144
|
+
try {
|
|
145
|
+
const artifactDir = path.join(outDir, "app");
|
|
146
|
+
// node_modules ships on purpose: without standalone output the artifact
|
|
147
|
+
// must carry the full runtime dependency tree for `next start`.
|
|
148
|
+
signal?.throwIfAborted();
|
|
149
|
+
await cp(appPath, artifactDir, {
|
|
150
|
+
recursive: true,
|
|
151
|
+
// Keep relative symlinks relative (node_modules/.bin/*): the default
|
|
152
|
+
// rewrites them to absolute paths into the source tree, which the
|
|
153
|
+
// archiver rejects as escaping the artifact root.
|
|
154
|
+
verbatimSymlinks: true,
|
|
155
|
+
filter: (source) => !isExcludedFromFullTree(path.basename(source)),
|
|
156
|
+
});
|
|
157
|
+
signal?.throwIfAborted();
|
|
158
|
+
await writeFile(
|
|
159
|
+
path.join(artifactDir, FULL_TREE_ENTRYPOINT),
|
|
160
|
+
FULL_TREE_START_SOURCE,
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
directory: artifactDir,
|
|
165
|
+
entrypoint: FULL_TREE_ENTRYPOINT,
|
|
166
|
+
defaultPortMapping: { http: defaultHttpPortForBuildType("nextjs") },
|
|
167
|
+
cleanup: () => rm(outDir, { recursive: true, force: true }),
|
|
168
|
+
};
|
|
169
|
+
} catch (error) {
|
|
170
|
+
await rm(outDir, { recursive: true, force: true });
|
|
171
|
+
throw error;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Excludes VCS internals and dotenv files (local secrets, superseded by the deploy env). */
|
|
176
|
+
function isExcludedFromFullTree(basename: string): boolean {
|
|
177
|
+
return (
|
|
178
|
+
basename === ".git" || basename === ".env" || basename.startsWith(".env.")
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
async function copyStaticAssets(options: {
|
|
183
|
+
appPath: string;
|
|
184
|
+
artifactDir: string;
|
|
185
|
+
outputRoot: string;
|
|
186
|
+
entrypoint: string;
|
|
187
|
+
signal?: AbortSignal;
|
|
188
|
+
}): Promise<void> {
|
|
189
|
+
const serverSubpath = serverSubpathOf(options.entrypoint);
|
|
190
|
+
const serverDir = serverSubpath
|
|
191
|
+
? path.join(options.artifactDir, serverSubpath)
|
|
192
|
+
: options.artifactDir;
|
|
193
|
+
|
|
194
|
+
const publicDir = path.join(options.appPath, "public");
|
|
195
|
+
if (await directoryExists(publicDir)) {
|
|
196
|
+
options.signal?.throwIfAborted();
|
|
197
|
+
await cp(publicDir, path.join(serverDir, "public"), {
|
|
198
|
+
recursive: true,
|
|
199
|
+
verbatimSymlinks: true,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const staticDir = path.join(options.appPath, options.outputRoot, "static");
|
|
204
|
+
if (await directoryExists(staticDir)) {
|
|
205
|
+
options.signal?.throwIfAborted();
|
|
206
|
+
await cp(staticDir, path.join(serverDir, options.outputRoot, "static"), {
|
|
207
|
+
recursive: true,
|
|
208
|
+
verbatimSymlinks: true,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
118
211
|
}
|
|
119
212
|
|
|
120
213
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
* third-party packages may ship a file named server.js.
|
|
214
|
+
* Locates `server.js` in the staged standalone output. In monorepos Next
|
|
215
|
+
* preserves the workspace-relative path (e.g. `apps/web/server.js`), so the
|
|
216
|
+
* entrypoint is the shallowest match. `node_modules` is skipped because
|
|
217
|
+
* third-party packages may ship their own `server.js`.
|
|
126
218
|
*/
|
|
127
|
-
async function
|
|
128
|
-
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
219
|
+
async function findStandaloneEntrypoint(artifactDir: string): Promise<string> {
|
|
220
|
+
const rootStat = await stat(path.join(artifactDir, "server.js")).catch(
|
|
221
|
+
() => null,
|
|
222
|
+
);
|
|
223
|
+
if (rootStat?.isFile()) {
|
|
224
|
+
return "server.js";
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const candidates: string[] = [];
|
|
228
|
+
await walk(artifactDir);
|
|
229
|
+
candidates.sort(
|
|
230
|
+
(left, right) =>
|
|
231
|
+
left.split("/").length - right.split("/").length ||
|
|
232
|
+
left.localeCompare(right),
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const selected = candidates[0];
|
|
236
|
+
if (!selected) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
`Next.js standalone output did not contain server.js in ${artifactDir}`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return selected;
|
|
242
|
+
|
|
243
|
+
async function walk(directory: string): Promise<void> {
|
|
244
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
137
245
|
for (const entry of entries) {
|
|
138
|
-
if (entry.name === "node_modules")
|
|
139
|
-
|
|
246
|
+
if (entry.name === "node_modules") {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const fullPath = path.join(directory, entry.name);
|
|
140
250
|
if (entry.isDirectory()) {
|
|
141
|
-
|
|
142
|
-
relative === undefined
|
|
143
|
-
? entry.name
|
|
144
|
-
: path.posix.join(relative, entry.name);
|
|
145
|
-
await walk(fullPath, nextRelative);
|
|
251
|
+
await walk(fullPath);
|
|
146
252
|
} else if (entry.isFile() && entry.name === "server.js") {
|
|
147
|
-
|
|
253
|
+
candidates.push(
|
|
254
|
+
path.relative(artifactDir, fullPath).split(path.sep).join("/"),
|
|
255
|
+
);
|
|
148
256
|
}
|
|
149
257
|
}
|
|
150
258
|
}
|
|
259
|
+
}
|
|
151
260
|
|
|
152
|
-
|
|
261
|
+
function serverSubpathOf(entrypoint: string): string {
|
|
262
|
+
const dir = path.posix.dirname(entrypoint);
|
|
263
|
+
return dir === "." ? "" : dir;
|
|
264
|
+
}
|
|
153
265
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
`Next.js standalone output has multiple server.js files (${locations}). Cannot determine the application entrypoint.`,
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
if (matches.length === 0) {
|
|
161
|
-
throw new Error(
|
|
162
|
-
"Next.js standalone output is missing server.js. The build may not have completed successfully.",
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
return matches[0];
|
|
266
|
+
async function directoryExists(dirPath: string): Promise<boolean> {
|
|
267
|
+
const s = await stat(dirPath).catch(() => null);
|
|
268
|
+
return s?.isDirectory() ?? false;
|
|
166
269
|
}
|
package/src/nuxt-build.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { cp, mkdtemp, rm, stat } from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { normalizeArtifactSymlinks } from "./artifact-postprocess.ts";
|
|
4
6
|
import type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
|
|
5
7
|
import {
|
|
6
8
|
hasPackageDependency,
|
|
@@ -8,6 +10,7 @@ import {
|
|
|
8
10
|
runPackageCli,
|
|
9
11
|
} from "./build-strategy.ts";
|
|
10
12
|
import { defaultHttpPortForBuildType } from "./config/frameworks.ts";
|
|
13
|
+
import type { BuildCommandIo } from "./workspace.ts";
|
|
11
14
|
|
|
12
15
|
const NUXT_CONFIG_FILENAMES = [
|
|
13
16
|
"nuxt.config.js",
|
|
@@ -23,9 +26,11 @@ const NUXT_CONFIG_FILENAMES = [
|
|
|
23
26
|
*/
|
|
24
27
|
export class NuxtBuild implements BuildStrategy {
|
|
25
28
|
readonly #appPath: string;
|
|
29
|
+
readonly #io?: BuildCommandIo;
|
|
26
30
|
|
|
27
|
-
constructor(options: { appPath: string }) {
|
|
31
|
+
constructor(options: { appPath: string; io?: BuildCommandIo }) {
|
|
28
32
|
this.#appPath = options.appPath;
|
|
33
|
+
this.#io = options.io;
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
async canBuild(signal?: AbortSignal): Promise<boolean> {
|
|
@@ -44,6 +49,8 @@ export class NuxtBuild implements BuildStrategy {
|
|
|
44
49
|
failurePrefix: "Nuxt",
|
|
45
50
|
missingMessage:
|
|
46
51
|
"Could not find the Nuxt CLI. Install it with `npm install nuxt` or ensure npx/bunx is available.",
|
|
52
|
+
env: this.#io?.env,
|
|
53
|
+
onOutput: this.#io?.onOutput,
|
|
47
54
|
signal,
|
|
48
55
|
});
|
|
49
56
|
|
|
@@ -64,6 +71,9 @@ export class NuxtBuild implements BuildStrategy {
|
|
|
64
71
|
recursive: true,
|
|
65
72
|
verbatimSymlinks: true,
|
|
66
73
|
});
|
|
74
|
+
// Materialize any symlinks into the app/workspace node_modules so the
|
|
75
|
+
// artifact is self-contained once unpacked elsewhere.
|
|
76
|
+
await normalizeArtifactSymlinks(artifactDir, this.#appPath, signal);
|
|
67
77
|
|
|
68
78
|
return {
|
|
69
79
|
directory: artifactDir,
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { cp, mkdtemp, rm, stat } from "node:fs/promises";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
+
|
|
5
|
+
import { normalizeArtifactSymlinks } from "./artifact-postprocess.ts";
|
|
6
|
+
import { type BuildSettings, resolveBuildSettings } from "./build-settings.ts";
|
|
4
7
|
import type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
|
|
5
|
-
import { hasPackageDependency
|
|
8
|
+
import { hasPackageDependency } from "./build-strategy.ts";
|
|
6
9
|
import { defaultHttpPortForBuildType } from "./config/frameworks.ts";
|
|
10
|
+
import { type BuildCommandIo, runBuildCommand } from "./workspace.ts";
|
|
7
11
|
|
|
8
12
|
const TANSTACK_START_PACKAGES = [
|
|
9
13
|
"@tanstack/react-start",
|
|
@@ -12,13 +16,22 @@ const TANSTACK_START_PACKAGES = [
|
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Build strategy for TanStack Start applications targeting the Nitro node
|
|
15
|
-
* preset. Runs
|
|
19
|
+
* preset. Runs the resolved build command (the user's `package.json` build
|
|
20
|
+
* script, or `vite build`) and produces an artifact from its output directory.
|
|
16
21
|
*/
|
|
17
22
|
export class TanstackStartBuild implements BuildStrategy {
|
|
18
23
|
readonly #appPath: string;
|
|
24
|
+
readonly #buildSettings?: BuildSettings;
|
|
25
|
+
readonly #io?: BuildCommandIo;
|
|
19
26
|
|
|
20
|
-
constructor(options: {
|
|
27
|
+
constructor(options: {
|
|
28
|
+
appPath: string;
|
|
29
|
+
buildSettings?: BuildSettings;
|
|
30
|
+
io?: BuildCommandIo;
|
|
31
|
+
}) {
|
|
21
32
|
this.#appPath = options.appPath;
|
|
33
|
+
this.#buildSettings = options.buildSettings;
|
|
34
|
+
this.#io = options.io;
|
|
22
35
|
}
|
|
23
36
|
|
|
24
37
|
async canBuild(signal?: AbortSignal): Promise<boolean> {
|
|
@@ -27,37 +40,50 @@ export class TanstackStartBuild implements BuildStrategy {
|
|
|
27
40
|
|
|
28
41
|
async execute(signal?: AbortSignal): Promise<BuildArtifact> {
|
|
29
42
|
signal?.throwIfAborted();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
const settings =
|
|
44
|
+
this.#buildSettings ??
|
|
45
|
+
(await resolveBuildSettings({
|
|
46
|
+
appPath: this.#appPath,
|
|
47
|
+
buildType: "tanstack-start",
|
|
48
|
+
signal,
|
|
49
|
+
}));
|
|
50
|
+
if (settings.buildCommand) {
|
|
51
|
+
await runBuildCommand({
|
|
52
|
+
appPath: this.#appPath,
|
|
53
|
+
command: settings.buildCommand,
|
|
54
|
+
failurePrefix: "TanStack Start",
|
|
55
|
+
env: this.#io?.env,
|
|
56
|
+
onOutput: this.#io?.onOutput,
|
|
57
|
+
signal,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
39
60
|
|
|
40
|
-
const outputDir = path.join(this.#appPath,
|
|
41
|
-
const
|
|
42
|
-
const entryStat = await stat(
|
|
61
|
+
const outputDir = path.join(this.#appPath, settings.outputDirectory);
|
|
62
|
+
const entrypoint = "server/index.mjs";
|
|
63
|
+
const entryStat = await stat(path.join(outputDir, entrypoint)).catch(
|
|
64
|
+
() => null,
|
|
65
|
+
);
|
|
43
66
|
if (!entryStat?.isFile()) {
|
|
44
67
|
throw new Error(
|
|
45
|
-
|
|
68
|
+
`TanStack Start build did not produce a Nitro node server entrypoint at ${settings.outputDirectory}/${entrypoint}. ` +
|
|
69
|
+
"Ensure your vite.config includes the tanstackStart() and nitro() plugins with the default node preset.",
|
|
46
70
|
);
|
|
47
71
|
}
|
|
48
72
|
|
|
49
73
|
const outDir = await mkdtemp(path.join(os.tmpdir(), "compute-build-"));
|
|
50
|
-
|
|
51
74
|
try {
|
|
52
75
|
const artifactDir = path.join(outDir, "app");
|
|
53
76
|
await cp(outputDir, artifactDir, {
|
|
54
77
|
recursive: true,
|
|
55
78
|
verbatimSymlinks: true,
|
|
56
79
|
});
|
|
80
|
+
// Materialize any symlinks into the app/workspace node_modules so the
|
|
81
|
+
// artifact is self-contained once unpacked elsewhere.
|
|
82
|
+
await normalizeArtifactSymlinks(artifactDir, this.#appPath, signal);
|
|
57
83
|
|
|
58
84
|
return {
|
|
59
85
|
directory: artifactDir,
|
|
60
|
-
entrypoint
|
|
86
|
+
entrypoint,
|
|
61
87
|
defaultPortMapping: {
|
|
62
88
|
http: defaultHttpPortForBuildType("tanstack-start"),
|
|
63
89
|
},
|