@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.
Files changed (76) hide show
  1. package/dist/artifact-stage.d.ts +24 -0
  2. package/dist/artifact-stage.d.ts.map +1 -0
  3. package/dist/artifact-stage.js +165 -0
  4. package/dist/artifact-stage.js.map +1 -0
  5. package/dist/astro-build.d.ts +2 -0
  6. package/dist/astro-build.d.ts.map +1 -1
  7. package/dist/astro-build.js +8 -0
  8. package/dist/astro-build.js.map +1 -1
  9. package/dist/auto-build.d.ts +7 -4
  10. package/dist/auto-build.d.ts.map +1 -1
  11. package/dist/auto-build.js +25 -33
  12. package/dist/auto-build.js.map +1 -1
  13. package/dist/build-settings.d.ts +55 -0
  14. package/dist/build-settings.d.ts.map +1 -0
  15. package/dist/build-settings.js +311 -0
  16. package/dist/build-settings.js.map +1 -0
  17. package/dist/build-strategy.d.ts +4 -0
  18. package/dist/build-strategy.d.ts.map +1 -1
  19. package/dist/build-strategy.js +13 -20
  20. package/dist/build-strategy.js.map +1 -1
  21. package/dist/build.d.ts +45 -0
  22. package/dist/build.d.ts.map +1 -0
  23. package/dist/build.js +89 -0
  24. package/dist/build.js.map +1 -0
  25. package/dist/bun-build.d.ts +8 -0
  26. package/dist/bun-build.d.ts.map +1 -1
  27. package/dist/bun-build.js +47 -23
  28. package/dist/bun-build.js.map +1 -1
  29. package/dist/config/frameworks.d.ts +2 -2
  30. package/dist/config/frameworks.d.ts.map +1 -1
  31. package/dist/config/frameworks.js +12 -0
  32. package/dist/config/frameworks.js.map +1 -1
  33. package/dist/config/types.d.ts +1 -1
  34. package/dist/config/types.d.ts.map +1 -1
  35. package/dist/config/types.js +1 -0
  36. package/dist/config/types.js.map +1 -1
  37. package/dist/index.d.ts +5 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +5 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/nestjs-build.d.ts +23 -0
  42. package/dist/nestjs-build.d.ts.map +1 -0
  43. package/dist/nestjs-build.js +317 -0
  44. package/dist/nestjs-build.js.map +1 -0
  45. package/dist/nextjs-build.d.ts +12 -2
  46. package/dist/nextjs-build.d.ts.map +1 -1
  47. package/dist/nextjs-build.js +156 -75
  48. package/dist/nextjs-build.js.map +1 -1
  49. package/dist/nuxt-build.d.ts +2 -0
  50. package/dist/nuxt-build.d.ts.map +1 -1
  51. package/dist/nuxt-build.js +8 -0
  52. package/dist/nuxt-build.js.map +1 -1
  53. package/dist/tanstack-start-build.d.ts +6 -1
  54. package/dist/tanstack-start-build.d.ts.map +1 -1
  55. package/dist/tanstack-start-build.js +35 -15
  56. package/dist/tanstack-start-build.js.map +1 -1
  57. package/dist/workspace.d.ts +90 -0
  58. package/dist/workspace.d.ts.map +1 -0
  59. package/dist/workspace.js +205 -0
  60. package/dist/workspace.js.map +1 -0
  61. package/package.json +5 -3
  62. package/src/artifact-stage.ts +280 -0
  63. package/src/astro-build.ts +11 -1
  64. package/src/auto-build.ts +28 -34
  65. package/src/build-settings.ts +448 -0
  66. package/src/build-strategy.ts +22 -29
  67. package/src/build.ts +127 -0
  68. package/src/bun-build.ts +60 -27
  69. package/src/config/frameworks.ts +13 -0
  70. package/src/config/types.ts +1 -0
  71. package/src/index.ts +29 -0
  72. package/src/nestjs-build.ts +425 -0
  73. package/src/nextjs-build.ts +206 -103
  74. package/src/nuxt-build.ts +11 -1
  75. package/src/tanstack-start-build.ts +44 -18
  76. 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
- constructor(options: { appPath: string; entrypoint?: string }) {
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
- return new Promise((resolve, reject) => {
138
- execFile(
139
- "bun",
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
- { signal },
150
- (error, _stdout, stderr) => {
151
- if (error) {
152
- if ("code" in error && error.code === "ENOENT") {
153
- reject(
154
- new Error(
155
- "Bun is required to build the application but was not found. Install it from https://bun.sh",
156
- ),
157
- );
158
- return;
159
- }
160
- const message = stderr.trim() || error.message;
161
- reject(new Error(`Bun build failed:\n${message}`));
162
- return;
163
- }
164
- resolve();
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(
@@ -11,6 +11,7 @@ export type FrameworkBuildType =
11
11
  | "nextjs"
12
12
  | "nuxt"
13
13
  | "astro"
14
+ | "nestjs"
14
15
  | "tanstack-start"
15
16
  | "bun";
16
17
 
@@ -108,6 +109,18 @@ export const FRAMEWORKS: readonly FrameworkDescriptor[] = [
108
109
  hasLocalDevServer: true,
109
110
  defaultHttpPort: 3000,
110
111
  },
112
+ {
113
+ key: "nestjs",
114
+ displayName: "NestJS",
115
+ buildType: "nestjs",
116
+ aliases: ["nestjs", "nest"],
117
+ detectPackages: ["@nestjs/core"],
118
+ detectConfigFiles: ["nest-cli.json"],
119
+ usesEntrypoint: false,
120
+ defaultEntrypoint: null,
121
+ hasLocalDevServer: false,
122
+ defaultHttpPort: 3000,
123
+ },
111
124
  {
112
125
  key: "tanstack-start",
113
126
  displayName: "TanStack Start",
@@ -11,6 +11,7 @@ export const COMPUTE_FRAMEWORKS = [
11
11
  "nuxt",
12
12
  "astro",
13
13
  "hono",
14
+ "nestjs",
14
15
  "tanstack-start",
15
16
  "bun",
16
17
  ] as const;
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";
@@ -94,6 +112,7 @@ export type {
94
112
  TerminalRecord,
95
113
  } from "./log-stream.ts";
96
114
  export { streamLogs } from "./log-stream.ts";
115
+ export { NestjsBuild } from "./nestjs-build.ts";
97
116
  export { NextjsBuild } from "./nextjs-build.ts";
98
117
  export { NuxtBuild } from "./nuxt-build.ts";
99
118
  export { TanstackStartBuild } from "./tanstack-start-build.ts";
@@ -111,3 +130,13 @@ export type {
111
130
  } from "./types.ts";
112
131
  export { KNOWN_REGION_IDS, REGIONS } from "./types.ts";
113
132
  export { uploadArtifact } from "./upload-artifact.ts";
133
+ export {
134
+ type BuildCommandIo,
135
+ buildCommandEnv,
136
+ type PackageManager,
137
+ type PackageManifest,
138
+ readBuildScript,
139
+ readPackageManifest,
140
+ resolvePackageManager,
141
+ runBuildCommand,
142
+ } from "./workspace.ts";
@@ -0,0 +1,425 @@
1
+ import {
2
+ chmod,
3
+ copyFile,
4
+ lstat,
5
+ mkdir,
6
+ mkdtemp,
7
+ readFile,
8
+ readlink,
9
+ rm,
10
+ stat,
11
+ symlink,
12
+ } from "node:fs/promises";
13
+ import os from "node:os";
14
+ import path from "node:path";
15
+
16
+ import { nodeFileTrace } from "@vercel/nft";
17
+
18
+ import {
19
+ type BuildSettings,
20
+ joinPosix,
21
+ resolveBuildSettings,
22
+ } from "./build-settings.ts";
23
+ import type { BuildArtifact, BuildStrategy } from "./build-strategy.ts";
24
+ import {
25
+ hasPackageDependency,
26
+ hasRootFile,
27
+ runPackageCli,
28
+ } from "./build-strategy.ts";
29
+ import { defaultHttpPortForBuildType } from "./config/frameworks.ts";
30
+ import { resolveSourceRoot } from "./config/source-root.ts";
31
+ import {
32
+ type BuildCommandIo,
33
+ readPackageManifest,
34
+ runBuildCommand,
35
+ } from "./workspace.ts";
36
+
37
+ const NEST_CLI_FILENAME = "nest-cli.json";
38
+
39
+ /** Compiled entrypoints probed, in order, when config does not resolve one. */
40
+ const DEFAULT_COMPILED_ENTRYPOINTS = ["dist/src/main.js", "dist/main.js"];
41
+
42
+ /**
43
+ * Build strategy for NestJS applications. Runs the user's build (so `nest build`
44
+ * and any `prisma generate` in the `build` script run), resolves the compiled
45
+ * entrypoint, then stages a lean artifact by file-tracing that entrypoint with
46
+ * `@vercel/nft`: it ships only the compiled output and the `node_modules` files
47
+ * actually reachable, not the full dependency tree. NestJS has no Next-style
48
+ * standalone output, so the trace is the lean equivalent that keeps the
49
+ * artifact under the compute runtime's disk ceiling.
50
+ */
51
+ export class NestjsBuild implements BuildStrategy {
52
+ readonly #appPath: string;
53
+ readonly #buildSettings?: BuildSettings;
54
+ readonly #io?: BuildCommandIo;
55
+
56
+ constructor(options: {
57
+ appPath: string;
58
+ buildSettings?: BuildSettings;
59
+ io?: BuildCommandIo;
60
+ }) {
61
+ this.#appPath = options.appPath;
62
+ this.#buildSettings = options.buildSettings;
63
+ this.#io = options.io;
64
+ }
65
+
66
+ async canBuild(signal?: AbortSignal): Promise<boolean> {
67
+ return (
68
+ (await hasRootFile(this.#appPath, [NEST_CLI_FILENAME], signal)) ||
69
+ (await hasPackageDependency(this.#appPath, ["@nestjs/core"], signal))
70
+ );
71
+ }
72
+
73
+ async execute(signal?: AbortSignal): Promise<BuildArtifact> {
74
+ signal?.throwIfAborted();
75
+
76
+ const settings =
77
+ this.#buildSettings ??
78
+ (await resolveBuildSettings({
79
+ appPath: this.#appPath,
80
+ buildType: "nestjs",
81
+ signal,
82
+ }));
83
+
84
+ // `resolveBuildSettings` always returns a non-null `nest build` fallback, so
85
+ // route by source: a user `build` script runs as-is, the framework default
86
+ // goes through the launcher ladder (local bin -> npx -> bunx).
87
+ const usingFrameworkDefault =
88
+ settings.buildCommand === null ||
89
+ settings.buildCommandSource === "NestJS default";
90
+ if (!usingFrameworkDefault && settings.buildCommand) {
91
+ await runBuildCommand({
92
+ appPath: this.#appPath,
93
+ command: settings.buildCommand,
94
+ failurePrefix: "NestJS",
95
+ env: this.#io?.env,
96
+ onOutput: this.#io?.onOutput,
97
+ signal,
98
+ });
99
+ } else {
100
+ await runPackageCli({
101
+ appPath: this.#appPath,
102
+ cliName: "nest",
103
+ args: ["build"],
104
+ failurePrefix: "NestJS",
105
+ missingMessage:
106
+ "Could not find the Nest CLI. Add a `build` script to package.json, install @nestjs/cli, or ensure npx/bunx is available.",
107
+ env: this.#io?.env,
108
+ onOutput: this.#io?.onOutput,
109
+ signal,
110
+ });
111
+ }
112
+
113
+ signal?.throwIfAborted();
114
+ const compiledEntry = await this.#resolveCompiledEntrypoint(signal);
115
+
116
+ const outDir = await mkdtemp(path.join(os.tmpdir(), "compute-build-"));
117
+ try {
118
+ const artifactDir = path.join(outDir, "app");
119
+ const entrypoint = await stageTracedArtifact({
120
+ appPath: this.#appPath,
121
+ artifactDir,
122
+ compiledEntry,
123
+ signal,
124
+ });
125
+
126
+ return {
127
+ directory: artifactDir,
128
+ entrypoint,
129
+ defaultPortMapping: { http: defaultHttpPortForBuildType("nestjs") },
130
+ cleanup: () => rm(outDir, { recursive: true, force: true }),
131
+ };
132
+ } catch (error) {
133
+ await rm(outDir, { recursive: true, force: true });
134
+ throw error;
135
+ }
136
+ }
137
+
138
+ /**
139
+ * Resolves the compiled entrypoint relative to the app root, using posix
140
+ * separators. Prefers `package.json` `main`, then the path computed from
141
+ * `nest-cli.json` and the tsconfig `outDir`, then the common defaults.
142
+ */
143
+ async #resolveCompiledEntrypoint(signal?: AbortSignal): Promise<string> {
144
+ const candidates: string[] = [];
145
+
146
+ const fromMain = await this.#mainFieldEntrypoint(signal);
147
+ if (fromMain) {
148
+ candidates.push(fromMain);
149
+ }
150
+
151
+ const fromConfig = await this.#configuredCompiledEntrypoint(signal);
152
+ if (fromConfig) {
153
+ candidates.push(fromConfig);
154
+ }
155
+
156
+ candidates.push(...DEFAULT_COMPILED_ENTRYPOINTS);
157
+
158
+ for (const candidate of candidates) {
159
+ signal?.throwIfAborted();
160
+ const normalized = normalizeRelative(candidate);
161
+ if (!normalized) {
162
+ continue;
163
+ }
164
+ if (await isFile(path.join(this.#appPath, normalized))) {
165
+ return normalized;
166
+ }
167
+ }
168
+
169
+ throw new Error(
170
+ `NestJS build did not produce a compiled entrypoint. Looked for ${candidates.join(", ")} under ${this.#appPath}. ` +
171
+ "Ensure `nest build` ran and check the `main` field, nest-cli.json, or tsconfig outDir.",
172
+ );
173
+ }
174
+
175
+ async #mainFieldEntrypoint(signal?: AbortSignal): Promise<string | null> {
176
+ const manifest = await readPackageManifest(this.#appPath, signal);
177
+ return typeof manifest?.main === "string" && manifest.main.trim().length > 0
178
+ ? manifest.main.trim()
179
+ : null;
180
+ }
181
+
182
+ async #configuredCompiledEntrypoint(
183
+ signal?: AbortSignal,
184
+ ): Promise<string | null> {
185
+ const nestCli = await readNestCliConfig(this.#appPath, signal);
186
+ const sourceRoot = nestCli.sourceRoot ?? "src";
187
+ const entryFile = nestCli.entryFile ?? "main";
188
+ const outDir = await readTsconfigOutDir(this.#appPath, signal);
189
+
190
+ const relativeEntry = path.posix.join(
191
+ path.posix.relative(".", sourceRoot) || ".",
192
+ `${entryFile}.js`,
193
+ );
194
+ return joinPosix(outDir, relativeEntry);
195
+ }
196
+ }
197
+
198
+ interface NestCliConfig {
199
+ sourceRoot?: string;
200
+ entryFile?: string;
201
+ }
202
+
203
+ async function readNestCliConfig(
204
+ appPath: string,
205
+ signal?: AbortSignal,
206
+ ): Promise<NestCliConfig> {
207
+ signal?.throwIfAborted();
208
+ let content: string;
209
+ try {
210
+ content = await readFile(path.join(appPath, NEST_CLI_FILENAME), {
211
+ encoding: "utf-8",
212
+ signal,
213
+ });
214
+ } catch (error) {
215
+ if (signal?.aborted) throw error;
216
+ return {};
217
+ }
218
+
219
+ try {
220
+ const parsed = JSON.parse(content) as {
221
+ sourceRoot?: unknown;
222
+ entryFile?: unknown;
223
+ };
224
+ return {
225
+ sourceRoot:
226
+ typeof parsed.sourceRoot === "string" ? parsed.sourceRoot : undefined,
227
+ entryFile:
228
+ typeof parsed.entryFile === "string" ? parsed.entryFile : undefined,
229
+ };
230
+ } catch {
231
+ return {};
232
+ }
233
+ }
234
+
235
+ const TSCONFIG_FILENAMES = ["tsconfig.build.json", "tsconfig.json"] as const;
236
+
237
+ /** Best-effort read of `compilerOptions.outDir`, defaulting to `dist`. */
238
+ async function readTsconfigOutDir(
239
+ appPath: string,
240
+ signal?: AbortSignal,
241
+ ): Promise<string> {
242
+ for (const fileName of TSCONFIG_FILENAMES) {
243
+ signal?.throwIfAborted();
244
+ let content: string;
245
+ try {
246
+ content = await readFile(path.join(appPath, fileName), {
247
+ encoding: "utf-8",
248
+ signal,
249
+ });
250
+ } catch (error) {
251
+ if (signal?.aborted) throw error;
252
+ continue;
253
+ }
254
+ const outDir = parseTsconfigOutDir(content);
255
+ if (outDir) {
256
+ return outDir;
257
+ }
258
+ }
259
+ return "dist";
260
+ }
261
+
262
+ /** Reads `compilerOptions.outDir` from a tsconfig source, tolerating comments. */
263
+ function parseTsconfigOutDir(content: string): string | null {
264
+ try {
265
+ const parsed = JSON.parse(stripJsonComments(content)) as {
266
+ compilerOptions?: { outDir?: unknown };
267
+ };
268
+ const outDir = parsed.compilerOptions?.outDir;
269
+ if (typeof outDir !== "string") {
270
+ return null;
271
+ }
272
+ return normalizeRelative(outDir);
273
+ } catch {
274
+ return null;
275
+ }
276
+ }
277
+
278
+ /**
279
+ * Stages the compiled entrypoint and its transitive dependencies into
280
+ * `artifactDir` by tracing with `@vercel/nft`, then copying only the traced
281
+ * paths. Returns the artifact-root-relative entrypoint to run with `node`.
282
+ *
283
+ * The trace base is the source root, not the app dir, because nft ignores
284
+ * everything above `base`: in a workspace, deps hoisted to the repo root sit
285
+ * above the app and would be dropped, leaving the artifact with no usable
286
+ * `node_modules`. Tracing from the source root keeps the workspace-relative
287
+ * layout (e.g. `apps/api/dist/main.js` plus root and app-local `node_modules`),
288
+ * so `node <dir>/<entrypoint>` resolves deps by walking up. For a single-app
289
+ * repo the source root equals the app dir, so the entrypoint stays `dist/main.js`.
290
+ *
291
+ * The trace lists both the visible `node_modules/<pkg>` symlinks and the real
292
+ * files they resolve to (e.g. pnpm `.pnpm/<pkg>` / bun `.bun/<pkg>` stores), so
293
+ * symlinks are recreated verbatim and the store files are copied alongside.
294
+ */
295
+ async function stageTracedArtifact(options: {
296
+ appPath: string;
297
+ artifactDir: string;
298
+ compiledEntry: string;
299
+ signal?: AbortSignal;
300
+ }): Promise<string> {
301
+ const appPath = path.resolve(options.appPath);
302
+ const sourceRoot = await resolveSourceRoot(appPath, options.signal);
303
+ const entry = path.join(appPath, options.compiledEntry);
304
+ const entrypoint = path.posix.normalize(
305
+ path.relative(sourceRoot, entry).split(path.sep).join("/"),
306
+ );
307
+
308
+ options.signal?.throwIfAborted();
309
+ const { fileList } = await nodeFileTrace([entry], { base: sourceRoot });
310
+
311
+ await mkdir(options.artifactDir, { recursive: true });
312
+ for (const relativePath of fileList) {
313
+ options.signal?.throwIfAborted();
314
+ await stageTracedPath(
315
+ path.join(sourceRoot, relativePath),
316
+ path.join(options.artifactDir, relativePath),
317
+ );
318
+ }
319
+
320
+ return entrypoint;
321
+ }
322
+
323
+ /** Copies one traced path, preserving symlinks and file mode. */
324
+ async function stageTracedPath(
325
+ sourcePath: string,
326
+ destinationPath: string,
327
+ ): Promise<void> {
328
+ const info = await lstat(sourcePath).catch(() => null);
329
+ if (!info) {
330
+ return;
331
+ }
332
+
333
+ await mkdir(path.dirname(destinationPath), { recursive: true });
334
+
335
+ if (info.isSymbolicLink()) {
336
+ await symlink(await readlink(sourcePath), destinationPath);
337
+ return;
338
+ }
339
+
340
+ if (info.isFile()) {
341
+ await copyFile(sourcePath, destinationPath);
342
+ await chmod(destinationPath, info.mode);
343
+ }
344
+ }
345
+
346
+ function normalizeRelative(value: string): string | null {
347
+ const raw = value.trim().replace(/\\/g, "/");
348
+ if (raw.length === 0) {
349
+ return null;
350
+ }
351
+ const normalized = path.posix.normalize(raw);
352
+ if (
353
+ path.posix.isAbsolute(normalized) ||
354
+ normalized === ".." ||
355
+ normalized.startsWith("../")
356
+ ) {
357
+ return null;
358
+ }
359
+ return normalized === "." ? null : normalized;
360
+ }
361
+
362
+ /**
363
+ * Removes `//` line comments and block comments from JSONC, tracking
364
+ * string state so a `//` inside a string value (e.g. `"https://..."`) is
365
+ * preserved. A naive regex strips such content and mis-reads the surrounding
366
+ * keys; on any malformed input the caller falls back to the default outDir.
367
+ */
368
+ function stripJsonComments(content: string): string {
369
+ let result = "";
370
+ let inString = false;
371
+ let escaped = false;
372
+
373
+ for (let i = 0; i < content.length; i++) {
374
+ const char = content[i];
375
+
376
+ if (inString) {
377
+ result += char;
378
+ if (escaped) {
379
+ escaped = false;
380
+ } else if (char === "\\") {
381
+ escaped = true;
382
+ } else if (char === '"') {
383
+ inString = false;
384
+ }
385
+ continue;
386
+ }
387
+
388
+ if (char === '"') {
389
+ inString = true;
390
+ result += char;
391
+ continue;
392
+ }
393
+
394
+ const next = content[i + 1];
395
+ if (char === "/" && next === "/") {
396
+ while (i < content.length && content[i] !== "\n") {
397
+ i++;
398
+ }
399
+ if (i < content.length) {
400
+ result += content[i];
401
+ }
402
+ continue;
403
+ }
404
+ if (char === "/" && next === "*") {
405
+ i += 2;
406
+ while (
407
+ i < content.length &&
408
+ !(content[i] === "*" && content[i + 1] === "/")
409
+ ) {
410
+ i++;
411
+ }
412
+ i++;
413
+ continue;
414
+ }
415
+
416
+ result += char;
417
+ }
418
+
419
+ return result;
420
+ }
421
+
422
+ async function isFile(targetPath: string): Promise<boolean> {
423
+ const info = await stat(targetPath).catch(() => null);
424
+ return info?.isFile() ?? false;
425
+ }