@prisma/compute-sdk 0.26.0 → 0.27.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 +301 -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 +86 -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 +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- 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 +4 -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 +430 -0
- package/src/build-strategy.ts +22 -29
- package/src/build.ts +124 -0
- package/src/bun-build.ts +60 -27
- package/src/index.ts +28 -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/bun-build.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
1
|
import {
|
|
3
2
|
access,
|
|
4
3
|
mkdir,
|
|
@@ -9,20 +8,40 @@ import {
|
|
|
9
8
|
} from "node:fs/promises";
|
|
10
9
|
import os from "node:os";
|
|
11
10
|
import path from "node:path";
|
|
11
|
+
import type { BuildSettings } from "./build-settings.ts";
|
|
12
12
|
import type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
|
|
13
13
|
import { defaultHttpPortForBuildType } from "./config/frameworks.ts";
|
|
14
|
+
import {
|
|
15
|
+
type BuildCommandIo,
|
|
16
|
+
buildCommandEnv,
|
|
17
|
+
runBuildCommand,
|
|
18
|
+
runChildProcess,
|
|
19
|
+
} from "./workspace.ts";
|
|
14
20
|
|
|
15
21
|
/**
|
|
16
22
|
* Build strategy that runs `bun build` CLI and manages its own temp output directory.
|
|
17
23
|
* Owns entrypoint resolution from explicit arg or package.json main field.
|
|
24
|
+
*
|
|
25
|
+
* When build settings carry a build command (a `package.json` build script),
|
|
26
|
+
* it runs first — so a Bun app can compile assets or generate code before the
|
|
27
|
+
* entrypoint is bundled.
|
|
18
28
|
*/
|
|
19
29
|
export class BunBuild implements BuildStrategy {
|
|
20
30
|
readonly #appPath: string;
|
|
21
31
|
readonly #entrypoint?: string;
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
readonly #buildSettings?: BuildSettings;
|
|
33
|
+
readonly #io?: BuildCommandIo;
|
|
34
|
+
|
|
35
|
+
constructor(options: {
|
|
36
|
+
appPath: string;
|
|
37
|
+
entrypoint?: string;
|
|
38
|
+
buildSettings?: BuildSettings;
|
|
39
|
+
io?: BuildCommandIo;
|
|
40
|
+
}) {
|
|
24
41
|
this.#appPath = options.appPath;
|
|
25
42
|
this.#entrypoint = options.entrypoint;
|
|
43
|
+
this.#buildSettings = options.buildSettings;
|
|
44
|
+
this.#io = options.io;
|
|
26
45
|
}
|
|
27
46
|
|
|
28
47
|
async canBuild(_signal?: AbortSignal): Promise<boolean> {
|
|
@@ -31,6 +50,16 @@ export class BunBuild implements BuildStrategy {
|
|
|
31
50
|
|
|
32
51
|
async execute(signal?: AbortSignal): Promise<BuildArtifact> {
|
|
33
52
|
signal?.throwIfAborted();
|
|
53
|
+
if (this.#buildSettings?.buildCommand) {
|
|
54
|
+
await runBuildCommand({
|
|
55
|
+
appPath: this.#appPath,
|
|
56
|
+
command: this.#buildSettings.buildCommand,
|
|
57
|
+
failurePrefix: "Bun",
|
|
58
|
+
env: this.#io?.env,
|
|
59
|
+
onOutput: this.#io?.onOutput,
|
|
60
|
+
signal,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
34
63
|
const entrypoint = await this.#resolveEntrypoint(signal);
|
|
35
64
|
|
|
36
65
|
const outDir = await mkdtemp(path.join(os.tmpdir(), "compute-build-"));
|
|
@@ -129,15 +158,20 @@ export class BunBuild implements BuildStrategy {
|
|
|
129
158
|
return typeof parsed.main === "string" ? parsed.main : undefined;
|
|
130
159
|
}
|
|
131
160
|
|
|
132
|
-
#runBuild(
|
|
161
|
+
async #runBuild(
|
|
133
162
|
absoluteEntrypoint: string,
|
|
134
163
|
bundleDir: string,
|
|
135
164
|
signal?: AbortSignal,
|
|
136
165
|
): Promise<void> {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
166
|
+
const env = await buildCommandEnv(
|
|
167
|
+
this.#appPath,
|
|
168
|
+
{ ...process.env, ...this.#io?.env },
|
|
169
|
+
signal,
|
|
170
|
+
);
|
|
171
|
+
try {
|
|
172
|
+
await runChildProcess({
|
|
173
|
+
command: "bun",
|
|
174
|
+
args: [
|
|
141
175
|
"build",
|
|
142
176
|
absoluteEntrypoint,
|
|
143
177
|
"--outdir",
|
|
@@ -146,25 +180,24 @@ export class BunBuild implements BuildStrategy {
|
|
|
146
180
|
"bun",
|
|
147
181
|
"--sourcemap=external",
|
|
148
182
|
],
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
});
|
|
183
|
+
cwd: this.#appPath,
|
|
184
|
+
env,
|
|
185
|
+
failurePrefix: "Bun",
|
|
186
|
+
onOutput: this.#io?.onOutput,
|
|
187
|
+
signal,
|
|
188
|
+
});
|
|
189
|
+
} catch (error) {
|
|
190
|
+
if (
|
|
191
|
+
error instanceof Error &&
|
|
192
|
+
"code" in error &&
|
|
193
|
+
(error as NodeJS.ErrnoException).code === "ENOENT"
|
|
194
|
+
) {
|
|
195
|
+
throw new Error(
|
|
196
|
+
"Bun is required to build the application but was not found. Install it from https://bun.sh",
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
168
201
|
}
|
|
169
202
|
|
|
170
203
|
#selectRuntimeEntrypoint(
|
package/src/index.ts
CHANGED
|
@@ -14,8 +14,26 @@ export type {
|
|
|
14
14
|
export { applyMigrations } from "./apply-migrations.ts";
|
|
15
15
|
export { createArchive } from "./archive.ts";
|
|
16
16
|
export { normalizeArtifactSymlinks } from "./artifact-postprocess.ts";
|
|
17
|
+
export {
|
|
18
|
+
hoistIsolatedStoreDependencies,
|
|
19
|
+
stageStandaloneArtifact,
|
|
20
|
+
} from "./artifact-stage.ts";
|
|
17
21
|
export { AstroBuild } from "./astro-build.ts";
|
|
18
22
|
export { AutoBuild } from "./auto-build.ts";
|
|
23
|
+
export {
|
|
24
|
+
type BuildStrategyHooks,
|
|
25
|
+
type BuildType,
|
|
26
|
+
createBuildStrategy,
|
|
27
|
+
resolveBuildStrategy,
|
|
28
|
+
} from "./build.ts";
|
|
29
|
+
export {
|
|
30
|
+
type BuildSettings,
|
|
31
|
+
joinPosix,
|
|
32
|
+
nextOutputRootFromStandaloneDirectory,
|
|
33
|
+
readStaticNextConfig,
|
|
34
|
+
resolveBuildSettings,
|
|
35
|
+
resolveConfiguredBuildSettings,
|
|
36
|
+
} from "./build-settings.ts";
|
|
19
37
|
export type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
|
|
20
38
|
export { PreBuilt } from "./build-strategy.ts";
|
|
21
39
|
export { BunBuild } from "./bun-build.ts";
|
|
@@ -111,3 +129,13 @@ export type {
|
|
|
111
129
|
} from "./types.ts";
|
|
112
130
|
export { KNOWN_REGION_IDS, REGIONS } from "./types.ts";
|
|
113
131
|
export { uploadArtifact } from "./upload-artifact.ts";
|
|
132
|
+
export {
|
|
133
|
+
type BuildCommandIo,
|
|
134
|
+
buildCommandEnv,
|
|
135
|
+
type PackageManager,
|
|
136
|
+
type PackageManifest,
|
|
137
|
+
readBuildScript,
|
|
138
|
+
readPackageManifest,
|
|
139
|
+
resolvePackageManager,
|
|
140
|
+
runBuildCommand,
|
|
141
|
+
} from "./workspace.ts";
|
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,
|