@prisma/compute-sdk 0.50.0 → 0.51.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/README.md +16 -4
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/service/build/build-service.d.ts +2 -2
- package/dist/service/build/build-service.d.ts.map +1 -1
- package/dist/service/build/build-service.js +24 -15
- package/dist/service/build/build-service.js.map +1 -1
- package/dist/service/output/build-output.d.ts +6 -3
- package/dist/service/output/build-output.d.ts.map +1 -1
- package/dist/service/output/build-output.js +20 -10
- package/dist/service/output/build-output.js.map +1 -1
- package/dist/service/output/entrypoint.d.ts.map +1 -1
- package/dist/service/output/entrypoint.js +4 -22
- package/dist/service/output/entrypoint.js.map +1 -1
- package/dist/service/output/trace/imports.d.ts +3 -0
- package/dist/service/output/trace/imports.d.ts.map +1 -1
- package/dist/service/output/trace/imports.js +6 -0
- package/dist/service/output/trace/imports.js.map +1 -1
- package/dist/service/output/trace/trace.d.ts +8 -3
- package/dist/service/output/trace/trace.d.ts.map +1 -1
- package/dist/service/output/trace/trace.js +13 -8
- package/dist/service/output/trace/trace.js.map +1 -1
- package/dist/service/settings/install.d.ts +8 -3
- package/dist/service/settings/install.d.ts.map +1 -1
- package/dist/service/settings/install.js +28 -11
- package/dist/service/settings/install.js.map +1 -1
- package/dist/service/settings/resolve.d.ts +4 -1
- package/dist/service/settings/resolve.d.ts.map +1 -1
- package/dist/service/settings/resolve.js +5 -2
- package/dist/service/settings/resolve.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +5 -1
- package/src/service/build/build-service.ts +26 -15
- package/src/service/output/build-output.ts +24 -12
- package/src/service/output/entrypoint.ts +4 -24
- package/src/service/output/trace/imports.ts +7 -0
- package/src/service/output/trace/trace.ts +25 -17
- package/src/service/settings/install.ts +32 -12
- package/src/service/settings/resolve.ts +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/service/settings/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../../src/service/settings/install.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EACV,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,qGAAqG;AACrG,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,cAAc,CAAC;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAiBD;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,WAAW,EACxB,YAAY,SAAI,GACf,OAAO,CAAC,oBAAoB,CAAC,CAmB/B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,oBAAoB,EAC5B,MAAM,EAAE,aAAa,EACrB,SAAS,UAAQ,GAChB,OAAO,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAWlC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LOCKFILES, packageManagerFromField, } from "../../package-manager.js";
|
|
2
|
+
import { readPackageJson } from "./package-json.js";
|
|
2
3
|
/** With a lockfile the install is frozen: a deploy must install what the lockfile says. */
|
|
3
4
|
const INSTALL_COMMANDS = {
|
|
4
5
|
npm: { frozen: "npm ci", unfrozen: "npm install" },
|
|
@@ -6,18 +7,32 @@ const INSTALL_COMMANDS = {
|
|
|
6
7
|
yarn: { frozen: "yarn install --frozen-lockfile", unfrozen: "yarn install" },
|
|
7
8
|
bun: { frozen: "bun install --frozen-lockfile", unfrozen: "bun install" },
|
|
8
9
|
};
|
|
9
|
-
/** Yarn 2+ replaced `--frozen-lockfile` with `--immutable`. A repository on Yarn 2+ has a `.yarnrc.yml
|
|
10
|
+
/** Yarn 2+ replaced `--frozen-lockfile` with `--immutable`. A repository on Yarn 2+ has a `.yarnrc.yml` beside its lockfile. */
|
|
10
11
|
const YARN_2_FROZEN_INSTALL = "yarn install --immutable";
|
|
11
12
|
const YARN_2_CONFIG_FILE = ".yarnrc.yml";
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The package manager: the `packageManager` field, then the lockfile, then npm.
|
|
15
|
+
*
|
|
16
|
+
* A workspace keeps both at its root. So when the Service folder has neither, the nearest
|
|
17
|
+
* of the `foldersAbove` folders that has one decides.
|
|
18
|
+
*/
|
|
19
|
+
export async function choosePackageManager(read, packageJson, foldersAbove = 0) {
|
|
20
|
+
for (let level = 0; level <= foldersAbove; level++) {
|
|
21
|
+
const folder = "../".repeat(level);
|
|
22
|
+
const readFolder = (file) => read(folder + file);
|
|
23
|
+
const { packageManager: field } = level === 0
|
|
24
|
+
? packageJson
|
|
25
|
+
: (await readPackageJson(readFolder)).packageJson;
|
|
26
|
+
const fromField = packageManagerFromField(field);
|
|
27
|
+
const lockfile = await findLockfile(readFolder);
|
|
28
|
+
if (fromField !== null || lockfile !== null) {
|
|
29
|
+
return {
|
|
30
|
+
packageManager: fromField ?? lockfile?.packageManager ?? "npm",
|
|
31
|
+
lockfile: lockfile === null ? null : folder + lockfile.file,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { packageManager: "npm", lockfile: null };
|
|
21
36
|
}
|
|
22
37
|
/**
|
|
23
38
|
* The install command: Service config first, then the package manager's own command.
|
|
@@ -50,7 +65,9 @@ async function installCommand(read, { packageManager, lockfile }) {
|
|
|
50
65
|
if (lockfile === null) {
|
|
51
66
|
return INSTALL_COMMANDS[packageManager].unfrozen;
|
|
52
67
|
}
|
|
53
|
-
|
|
68
|
+
const lockfileFolder = lockfile.slice(0, lockfile.lastIndexOf("/") + 1);
|
|
69
|
+
if (packageManager === "yarn" &&
|
|
70
|
+
(await read(lockfileFolder + YARN_2_CONFIG_FILE)) !== null) {
|
|
54
71
|
return YARN_2_FROZEN_INSTALL;
|
|
55
72
|
}
|
|
56
73
|
return INSTALL_COMMANDS[packageManager].frozen;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../../src/service/settings/install.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../../src/service/settings/install.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAET,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAcpD,2FAA2F;AAC3F,MAAM,gBAAgB,GAGlB;IACF,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE;IAClD,IAAI,EAAE,EAAE,MAAM,EAAE,gCAAgC,EAAE,QAAQ,EAAE,cAAc,EAAE;IAC5E,IAAI,EAAE,EAAE,MAAM,EAAE,gCAAgC,EAAE,QAAQ,EAAE,cAAc,EAAE;IAC5E,GAAG,EAAE,EAAE,MAAM,EAAE,+BAA+B,EAAE,QAAQ,EAAE,aAAa,EAAE;CAC1E,CAAC;AAEF,gIAAgI;AAChI,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AACzD,MAAM,kBAAkB,GAAG,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,IAAc,EACd,WAAwB,EACxB,YAAY,GAAG,CAAC;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CAAC,KAAK,IAAI,EAC1D,CAAC;QACD,OAAO,qBAAqB,CAAC;IAC/B,CAAC;IAED,OAAO,gBAAgB,CAAC,cAAc,CAAC,CAAC,MAAM,CAAC;AACjD,CAAC"}
|
|
@@ -2,8 +2,11 @@ import type { OutputDirectories, ReadFile, Resolved, ServiceBuildSettings, Servi
|
|
|
2
2
|
/**
|
|
3
3
|
* Resolves the Build settings that can be known before the build runs.
|
|
4
4
|
* `start` is `"after build"` when only the build output can decide it.
|
|
5
|
+
*
|
|
6
|
+
* `foldersAbove` is how many folders above the Service folder belong to the repository.
|
|
7
|
+
* `read` gets their files with paths that start with `../`.
|
|
5
8
|
*/
|
|
6
|
-
export declare function resolveServiceBuildSettings(read: ReadFile, config?: ServiceConfig, signal?: AbortSignal): Promise<ServiceBuildSettings>;
|
|
9
|
+
export declare function resolveServiceBuildSettings(read: ReadFile, config?: ServiceConfig, signal?: AbortSignal, foldersAbove?: number): Promise<ServiceBuildSettings>;
|
|
7
10
|
/** Decides the start from the build output and the source. Null means no rule matched. */
|
|
8
11
|
export declare function resolveStartAfterBuild(read: ReadFile, output: OutputDirectories, signal?: AbortSignal): Promise<Resolved<Start> | null>;
|
|
9
12
|
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/service/settings/resolve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,aAAa,EACb,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../../src/service/settings/resolve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,oBAAoB,EACpB,aAAa,EACb,KAAK,EACN,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,QAAQ,EACd,MAAM,GAAE,aAAkB,EAC1B,MAAM,CAAC,EAAE,WAAW,EACpB,YAAY,SAAI,GACf,OAAO,CAAC,oBAAoB,CAAC,CAoB/B;AAED,0FAA0F;AAC1F,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,iBAAiB,EACzB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAQjC"}
|
|
@@ -5,12 +5,15 @@ import { startAfterBuild, startBeforeBuild } from "./start-order.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Resolves the Build settings that can be known before the build runs.
|
|
7
7
|
* `start` is `"after build"` when only the build output can decide it.
|
|
8
|
+
*
|
|
9
|
+
* `foldersAbove` is how many folders above the Service folder belong to the repository.
|
|
10
|
+
* `read` gets their files with paths that start with `../`.
|
|
8
11
|
*/
|
|
9
|
-
export async function resolveServiceBuildSettings(read, config = {}, signal) {
|
|
12
|
+
export async function resolveServiceBuildSettings(read, config = {}, signal, foldersAbove = 0) {
|
|
10
13
|
signal?.throwIfAborted();
|
|
11
14
|
const { packageJson, malformed } = await readPackageJson(read);
|
|
12
15
|
const scripts = packageJson.scripts ?? {};
|
|
13
|
-
const choice = await choosePackageManager(read, packageJson);
|
|
16
|
+
const choice = await choosePackageManager(read, packageJson, foldersAbove);
|
|
14
17
|
const { start, notes } = startBeforeBuild({
|
|
15
18
|
config,
|
|
16
19
|
scripts,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../../src/service/settings/resolve.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC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
|
/** A build of one Service that produced no build output. `code` is stable across releases. */
|
|
194
194
|
export class ServiceBuildError extends TaggedError("ServiceBuildError")<{
|
|
195
|
-
code:
|
|
195
|
+
code:
|
|
196
|
+
| "install_failed"
|
|
197
|
+
| "build_failed"
|
|
198
|
+
| "no_start"
|
|
199
|
+
| "files_outside_service";
|
|
196
200
|
/** For the user. */
|
|
197
201
|
message: string;
|
|
198
202
|
settings: ServiceBuildSettings;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Builds one Service folder and writes its build output. Runs on the Build runner: it needs a shell,
|
|
2
2
|
// the repository's package manager, and the checkout. It never starts the Service.
|
|
3
3
|
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
-
import { join } from "node:path";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
5
|
import { Result } from "better-result";
|
|
6
6
|
import { ServiceBuildError } from "../../errors.ts";
|
|
7
7
|
import type { Framework } from "../frameworks/framework.ts";
|
|
@@ -69,8 +69,8 @@ const NO_START: Failure = {
|
|
|
69
69
|
* Runs the Service's install and build commands, decides how the Service starts, and writes the build output.
|
|
70
70
|
* A framework's own build output comes before the one this package writes.
|
|
71
71
|
*
|
|
72
|
-
* A failed install, a failed build
|
|
73
|
-
* they come back as a `ServiceBuildError`, not as a thrown error.
|
|
72
|
+
* A failed install, a failed build, a missing start and a server that imports files from outside
|
|
73
|
+
* the Service folder are expected outcomes: they come back as a `ServiceBuildError`, not as a thrown error.
|
|
74
74
|
*/
|
|
75
75
|
export async function buildService(
|
|
76
76
|
options: BuildServiceOptions,
|
|
@@ -81,6 +81,7 @@ export async function buildService(
|
|
|
81
81
|
read,
|
|
82
82
|
options.config,
|
|
83
83
|
options.signal,
|
|
84
|
+
foldersAboveInRepository(dir),
|
|
84
85
|
);
|
|
85
86
|
const { packageJson } = await readPackageJson(read);
|
|
86
87
|
// A start the user states in the Service config is final, so no framework changes the build.
|
|
@@ -145,22 +146,20 @@ export async function buildService(
|
|
|
145
146
|
outputDirectories: outputDirectories.value,
|
|
146
147
|
signal: options.signal,
|
|
147
148
|
});
|
|
149
|
+
if (output.isErr()) {
|
|
150
|
+
return fail({
|
|
151
|
+
code: "files_outside_service",
|
|
152
|
+
message: `The server imports files from outside the Service folder, and workspaces are not supported yet. The first such file is ${output.error.outside}.`,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
148
155
|
|
|
149
|
-
return done(start, output);
|
|
156
|
+
return done(start, output.value);
|
|
150
157
|
}
|
|
151
158
|
|
|
152
|
-
/**
|
|
159
|
+
/** A note is for a build output the user may want to change. The whole Service folder is one: it is larger than a trace. */
|
|
153
160
|
function buildOutputNotes(output: BuildOutput): string[] {
|
|
154
161
|
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
|
-
];
|
|
162
|
+
return [`The build output is the whole Service folder: ${output.reason}.`];
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
return [];
|
|
@@ -236,7 +235,19 @@ function stepFailed(step: StepToRun, commandOutput: string): Failure {
|
|
|
236
235
|
};
|
|
237
236
|
}
|
|
238
237
|
|
|
239
|
-
/**
|
|
238
|
+
/** How many folders above the Service folder belong to the repository: up to the folder that holds `.git`, or to the file system root. */
|
|
239
|
+
function foldersAboveInRepository(dir: string): number {
|
|
240
|
+
let count = 0;
|
|
241
|
+
let folder = resolve(dir);
|
|
242
|
+
while (!existsSync(join(folder, ".git")) && folder !== dirname(folder)) {
|
|
243
|
+
folder = dirname(folder);
|
|
244
|
+
count++;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return count;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Reads the files of the Service folder for the Build rules. A path that starts with `../` reads a folder above it. */
|
|
240
251
|
function readFrom(dir: string): ReadFile {
|
|
241
252
|
return (path) =>
|
|
242
253
|
existsSync(join(dir, path)) ? readFileSync(join(dir, path), "utf8") : null;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { copyFileSync, mkdirSync, realpathSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { rm } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
|
+
import { Result } from "better-result";
|
|
5
6
|
import {
|
|
6
7
|
LAUNCHER_FILE,
|
|
7
8
|
START_PLAN_FILE,
|
|
@@ -17,6 +18,7 @@ import { excludedFromBuildOutput } from "./exclude.ts";
|
|
|
17
18
|
import { launcherFile } from "./launcher-file.ts";
|
|
18
19
|
import { inOutputDirectory, sourceFiles } from "./source-files.ts";
|
|
19
20
|
import {
|
|
21
|
+
type OutsideServiceFolder,
|
|
20
22
|
type ServerTrace,
|
|
21
23
|
traceServer,
|
|
22
24
|
type Untraceable,
|
|
@@ -42,7 +44,7 @@ export type BuildOutput = {
|
|
|
42
44
|
trace: TraceSummary;
|
|
43
45
|
}
|
|
44
46
|
| {
|
|
45
|
-
/** The whole Service folder
|
|
47
|
+
/** The whole Service folder as it is, because the server could not be traced. */
|
|
46
48
|
kind: "whole folder";
|
|
47
49
|
reason: Untraceable;
|
|
48
50
|
}
|
|
@@ -71,6 +73,8 @@ const SCRIPT_FILE = /\.(c|m)?js$/;
|
|
|
71
73
|
* - Static files: the folder the build wrote.
|
|
72
74
|
* - A start command: the source files and the trace of the server it starts, in `.prisma/output`.
|
|
73
75
|
* - A start command whose server cannot be traced: the whole Service folder.
|
|
76
|
+
*
|
|
77
|
+
* A server that loads files from outside the Service folder gets no build output.
|
|
74
78
|
*/
|
|
75
79
|
export async function writeBuildOutput(options: {
|
|
76
80
|
serviceDir: string;
|
|
@@ -80,15 +84,22 @@ export async function writeBuildOutput(options: {
|
|
|
80
84
|
packageJson: PackageJson;
|
|
81
85
|
outputDirectories: OutputDirectories;
|
|
82
86
|
signal?: AbortSignal;
|
|
83
|
-
}): Promise<BuildOutput
|
|
87
|
+
}): Promise<Result<BuildOutput, OutsideServiceFolder>> {
|
|
84
88
|
const { start } = options;
|
|
85
89
|
// The trace holds real paths, so every path here starts from the real path of the Service folder.
|
|
86
90
|
const serviceDir = realpathSync(options.serviceDir);
|
|
91
|
+
const dir = path.join(serviceDir, BUILD_OUTPUT_FOLDER);
|
|
92
|
+
// An earlier build may have written this folder. It must not stay when the build output is the Service folder itself.
|
|
93
|
+
await rm(dir, { recursive: true, force: true });
|
|
87
94
|
if (start.kind === "static") {
|
|
88
|
-
const
|
|
89
|
-
writeLauncher(
|
|
95
|
+
const staticDir = path.join(serviceDir, start.dir);
|
|
96
|
+
writeLauncher(staticDir, { kind: "static", dir: ".", port: options.port });
|
|
90
97
|
|
|
91
|
-
return {
|
|
98
|
+
return Result.ok({
|
|
99
|
+
dir: staticDir,
|
|
100
|
+
entrypoint: LAUNCHER_FILE,
|
|
101
|
+
kind: "static site",
|
|
102
|
+
});
|
|
92
103
|
}
|
|
93
104
|
|
|
94
105
|
const plan: StartPlan = {
|
|
@@ -112,18 +123,19 @@ export async function writeBuildOutput(options: {
|
|
|
112
123
|
),
|
|
113
124
|
signal: options.signal,
|
|
114
125
|
});
|
|
115
|
-
const dir = path.join(serviceDir, BUILD_OUTPUT_FOLDER);
|
|
116
|
-
// An earlier build may have written this folder. It must not stay in a whole-folder build output.
|
|
117
|
-
await rm(dir, { recursive: true, force: true });
|
|
118
126
|
if (typeof trace === "string") {
|
|
119
127
|
writeLauncher(serviceDir, plan);
|
|
120
128
|
|
|
121
|
-
return {
|
|
129
|
+
return Result.ok({
|
|
122
130
|
dir: serviceDir,
|
|
123
131
|
entrypoint: LAUNCHER_FILE,
|
|
124
132
|
kind: "whole folder",
|
|
125
133
|
reason: trace,
|
|
126
|
-
};
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if ("outside" in trace) {
|
|
138
|
+
return Result.err(trace);
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
const copied = await copyTracedServer(serviceDir, dir, source, trace);
|
|
@@ -131,7 +143,7 @@ export async function writeBuildOutput(options: {
|
|
|
131
143
|
|
|
132
144
|
const relative = (file: string) => path.relative(serviceDir, file);
|
|
133
145
|
|
|
134
|
-
return {
|
|
146
|
+
return Result.ok({
|
|
135
147
|
dir,
|
|
136
148
|
entrypoint: LAUNCHER_FILE,
|
|
137
149
|
kind: "traced server",
|
|
@@ -142,7 +154,7 @@ export async function writeBuildOutput(options: {
|
|
|
142
154
|
bins: trace.bins,
|
|
143
155
|
optionalPeerDependencies: trace.optionalPeerDependencies,
|
|
144
156
|
},
|
|
145
|
-
};
|
|
157
|
+
});
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
/** Copies the source files and the trace into the build output folder, each to the place it has in the Service folder. */
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { existsSync, realpathSync, statSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import type { PackageJson } from "../settings/types.ts";
|
|
6
|
-
import { excludedFromBuildOutput } from "./exclude.ts";
|
|
7
6
|
|
|
8
7
|
/** What a start command runs. */
|
|
9
8
|
export interface StartCommand {
|
|
@@ -19,17 +18,10 @@ export interface StartCommand {
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
const SOURCE_FILE = /\.(c|m)?(j|t)sx?$/;
|
|
22
|
-
const RUNTIMES = new Set(["node", "bun", "
|
|
21
|
+
const RUNTIMES = new Set(["node", "bun", "tsx", "ts-node"]);
|
|
23
22
|
const PACKAGE_MANAGERS = new Set(["npm", "pnpm", "yarn", "bun"]);
|
|
24
23
|
/** Runtime options that preload a module before the entrypoint: `--require ./setup.js` or `--require=./setup.js`. */
|
|
25
|
-
const PRELOAD_OPTIONS = new Set([
|
|
26
|
-
"-r",
|
|
27
|
-
"--require",
|
|
28
|
-
"--import",
|
|
29
|
-
"--loader",
|
|
30
|
-
"--experimental-loader",
|
|
31
|
-
"--preload",
|
|
32
|
-
]);
|
|
24
|
+
const PRELOAD_OPTIONS = new Set(["-r", "--require", "--import", "--preload"]);
|
|
33
25
|
/** Node.js reads the value of a preload option as a file only when it is a path. Any other value names a package. */
|
|
34
26
|
const FILE_PATH = /^\.{0,2}\//;
|
|
35
27
|
/** Words that run the command after them. */
|
|
@@ -146,10 +138,8 @@ function wordsOf(simple: string): string[] {
|
|
|
146
138
|
/**
|
|
147
139
|
* The files a runtime runs and the packages it preloads, from the words after its name.
|
|
148
140
|
*
|
|
149
|
-
* Its entrypoint is the first word that names a script
|
|
150
|
-
* first
|
|
151
|
-
* can come first, as `.env` in `node --env-file .env server.js`, so a script wins over it
|
|
152
|
-
* and a dotenv file is never the entrypoint.
|
|
141
|
+
* Its entrypoint is the first word that names a script. The value of another option can come
|
|
142
|
+
* first, as `.env` in `node --env-file .env server.js`, and is not a script.
|
|
153
143
|
*/
|
|
154
144
|
function readRuntimeWords(
|
|
155
145
|
words: string[],
|
|
@@ -160,7 +150,6 @@ function readRuntimeWords(
|
|
|
160
150
|
} {
|
|
161
151
|
const files: string[] = [];
|
|
162
152
|
const packages: string[] = [];
|
|
163
|
-
let withoutExtension: string | undefined;
|
|
164
153
|
|
|
165
154
|
for (let index = 0; index < words.length; index++) {
|
|
166
155
|
const word = words[index] ?? "";
|
|
@@ -181,18 +170,9 @@ function readRuntimeWords(
|
|
|
181
170
|
if (file !== null && SOURCE_FILE.test(file)) {
|
|
182
171
|
return { files: [...files, word], packages };
|
|
183
172
|
}
|
|
184
|
-
|
|
185
|
-
const isDotenv = excludedFromBuildOutput(path.basename(file ?? ""));
|
|
186
|
-
if (file !== null && !isDotenv) {
|
|
187
|
-
withoutExtension ??= word;
|
|
188
|
-
}
|
|
189
173
|
}
|
|
190
174
|
}
|
|
191
175
|
|
|
192
|
-
if (withoutExtension !== undefined) {
|
|
193
|
-
files.push(withoutExtension);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
176
|
return { files, packages };
|
|
197
177
|
}
|
|
198
178
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Follows imports from files with `@vercel/nft`.
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { nodeFileTrace } from "@vercel/nft";
|
|
4
5
|
|
|
@@ -7,6 +8,9 @@ import { nodeFileTrace } from "@vercel/nft";
|
|
|
7
8
|
*
|
|
8
9
|
* Compute runs a Service with Bun, which reads a package's `bun` export condition.
|
|
9
10
|
* nft's `conditions` replaces the default set, so the imports are followed twice.
|
|
11
|
+
*
|
|
12
|
+
* nft names files that some versions of a package do not have, such as `preload.js` of `semver`,
|
|
13
|
+
* and fails when it reads one. So a file that does not exist is left out.
|
|
10
14
|
*/
|
|
11
15
|
export async function traceImports(
|
|
12
16
|
files: string[],
|
|
@@ -22,6 +26,9 @@ export async function traceImports(
|
|
|
22
26
|
nodeFileTrace(files, {
|
|
23
27
|
base,
|
|
24
28
|
processCwd: serviceDir,
|
|
29
|
+
// nft also passes a folder pattern, such as `views/**/*`, before it lists that folder.
|
|
30
|
+
ignore: (file) =>
|
|
31
|
+
!file.includes("*") && !existsSync(path.join(base, file)),
|
|
25
32
|
...(conditions ? { conditions } : {}),
|
|
26
33
|
}),
|
|
27
34
|
),
|
|
@@ -26,10 +26,16 @@ export interface ServerTrace {
|
|
|
26
26
|
optionalPeerDependencies: string[];
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/** Why a server could not be traced. */
|
|
29
|
+
/** Why a server could not be traced. Its build output is then the whole Service folder. */
|
|
30
30
|
export type Untraceable =
|
|
31
31
|
| "the start command runs no file and no bin that can be followed"
|
|
32
|
-
|
|
|
32
|
+
| `the imports of the server could not be followed: ${string}`;
|
|
33
|
+
|
|
34
|
+
/** The server loads files from outside the Service folder. No build output can hold them. */
|
|
35
|
+
export interface OutsideServiceFolder {
|
|
36
|
+
/** The first such file, relative to the Service folder. */
|
|
37
|
+
outside: string;
|
|
38
|
+
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
35
41
|
* Traces the server that `command` starts:
|
|
@@ -44,7 +50,7 @@ export async function traceServer(options: {
|
|
|
44
50
|
/** Scripts in the output directories. A framework's server loads them by path, and they import packages. */
|
|
45
51
|
builtScripts: string[];
|
|
46
52
|
signal?: AbortSignal;
|
|
47
|
-
}): Promise<ServerTrace | Untraceable> {
|
|
53
|
+
}): Promise<ServerTrace | Untraceable | OutsideServiceFolder> {
|
|
48
54
|
const { packageJson } = options;
|
|
49
55
|
// Traced files are real paths, so the Service folder they are compared with must be its real path too.
|
|
50
56
|
const serviceDir = realpathSync(options.serviceDir);
|
|
@@ -58,10 +64,17 @@ export async function traceServer(options: {
|
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
options.signal?.throwIfAborted();
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
let files: string[];
|
|
68
|
+
try {
|
|
69
|
+
files = await traceImports(
|
|
70
|
+
[...entrypoints, ...options.builtScripts],
|
|
71
|
+
serviceDir,
|
|
72
|
+
);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const cause = error instanceof Error ? error.message : String(error);
|
|
75
|
+
|
|
76
|
+
return `the imports of the server could not be followed: ${cause}`;
|
|
77
|
+
}
|
|
65
78
|
|
|
66
79
|
const packages = binPackages(serviceDir, bins);
|
|
67
80
|
// A preloaded package goes in whole, as a bin's package does: `tsx` loads its own files by path.
|
|
@@ -77,16 +90,11 @@ export async function traceServer(options: {
|
|
|
77
90
|
addWithDependencies(peer, packages);
|
|
78
91
|
}
|
|
79
92
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
!files.every(inside) ||
|
|
87
|
-
![...packages.values()].every((found) => inside(found.dir))
|
|
88
|
-
) {
|
|
89
|
-
return "the server imports files from outside the Service folder";
|
|
93
|
+
const outside = [...files, ...[...packages.values()].map(({ dir }) => dir)]
|
|
94
|
+
.map((file) => path.relative(serviceDir, file))
|
|
95
|
+
.find((file) => file.startsWith("..") || path.isAbsolute(file));
|
|
96
|
+
if (outside !== undefined) {
|
|
97
|
+
return { outside };
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
return {
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
type PackageManager,
|
|
4
4
|
packageManagerFromField,
|
|
5
5
|
} from "../../package-manager.ts";
|
|
6
|
+
import { readPackageJson } from "./package-json.ts";
|
|
6
7
|
import type {
|
|
7
8
|
PackageJson,
|
|
8
9
|
ReadFile,
|
|
@@ -10,7 +11,7 @@ import type {
|
|
|
10
11
|
ServiceConfig,
|
|
11
12
|
} from "./types.ts";
|
|
12
13
|
|
|
13
|
-
/** The Service's package manager, and the lockfile found
|
|
14
|
+
/** The Service's package manager, and the lockfile found, if any, relative to the Service folder. */
|
|
14
15
|
export interface PackageManagerChoice {
|
|
15
16
|
packageManager: PackageManager;
|
|
16
17
|
lockfile: string | null;
|
|
@@ -27,24 +28,39 @@ const INSTALL_COMMANDS: Record<
|
|
|
27
28
|
bun: { frozen: "bun install --frozen-lockfile", unfrozen: "bun install" },
|
|
28
29
|
};
|
|
29
30
|
|
|
30
|
-
/** Yarn 2+ replaced `--frozen-lockfile` with `--immutable`. A repository on Yarn 2+ has a `.yarnrc.yml
|
|
31
|
+
/** Yarn 2+ replaced `--frozen-lockfile` with `--immutable`. A repository on Yarn 2+ has a `.yarnrc.yml` beside its lockfile. */
|
|
31
32
|
const YARN_2_FROZEN_INSTALL = "yarn install --immutable";
|
|
32
33
|
const YARN_2_CONFIG_FILE = ".yarnrc.yml";
|
|
33
34
|
|
|
34
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* The package manager: the `packageManager` field, then the lockfile, then npm.
|
|
37
|
+
*
|
|
38
|
+
* A workspace keeps both at its root. So when the Service folder has neither, the nearest
|
|
39
|
+
* of the `foldersAbove` folders that has one decides.
|
|
40
|
+
*/
|
|
35
41
|
export async function choosePackageManager(
|
|
36
42
|
read: ReadFile,
|
|
37
43
|
packageJson: PackageJson,
|
|
44
|
+
foldersAbove = 0,
|
|
38
45
|
): Promise<PackageManagerChoice> {
|
|
39
|
-
|
|
46
|
+
for (let level = 0; level <= foldersAbove; level++) {
|
|
47
|
+
const folder = "../".repeat(level);
|
|
48
|
+
const readFolder: ReadFile = (file) => read(folder + file);
|
|
49
|
+
const { packageManager: field } =
|
|
50
|
+
level === 0
|
|
51
|
+
? packageJson
|
|
52
|
+
: (await readPackageJson(readFolder)).packageJson;
|
|
53
|
+
const fromField = packageManagerFromField(field);
|
|
54
|
+
const lockfile = await findLockfile(readFolder);
|
|
55
|
+
if (fromField !== null || lockfile !== null) {
|
|
56
|
+
return {
|
|
57
|
+
packageManager: fromField ?? lockfile?.packageManager ?? "npm",
|
|
58
|
+
lockfile: lockfile === null ? null : folder + lockfile.file,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
40
62
|
|
|
41
|
-
return {
|
|
42
|
-
packageManager:
|
|
43
|
-
packageManagerFromField(packageJson.packageManager) ??
|
|
44
|
-
lockfile?.packageManager ??
|
|
45
|
-
"npm",
|
|
46
|
-
lockfile: lockfile?.file ?? null,
|
|
47
|
-
};
|
|
63
|
+
return { packageManager: "npm", lockfile: null };
|
|
48
64
|
}
|
|
49
65
|
|
|
50
66
|
/**
|
|
@@ -97,7 +113,11 @@ async function installCommand(
|
|
|
97
113
|
return INSTALL_COMMANDS[packageManager].unfrozen;
|
|
98
114
|
}
|
|
99
115
|
|
|
100
|
-
|
|
116
|
+
const lockfileFolder = lockfile.slice(0, lockfile.lastIndexOf("/") + 1);
|
|
117
|
+
if (
|
|
118
|
+
packageManager === "yarn" &&
|
|
119
|
+
(await read(lockfileFolder + YARN_2_CONFIG_FILE)) !== null
|
|
120
|
+
) {
|
|
101
121
|
return YARN_2_FROZEN_INSTALL;
|
|
102
122
|
}
|
|
103
123
|
|
|
@@ -16,16 +16,20 @@ import type {
|
|
|
16
16
|
/**
|
|
17
17
|
* Resolves the Build settings that can be known before the build runs.
|
|
18
18
|
* `start` is `"after build"` when only the build output can decide it.
|
|
19
|
+
*
|
|
20
|
+
* `foldersAbove` is how many folders above the Service folder belong to the repository.
|
|
21
|
+
* `read` gets their files with paths that start with `../`.
|
|
19
22
|
*/
|
|
20
23
|
export async function resolveServiceBuildSettings(
|
|
21
24
|
read: ReadFile,
|
|
22
25
|
config: ServiceConfig = {},
|
|
23
26
|
signal?: AbortSignal,
|
|
27
|
+
foldersAbove = 0,
|
|
24
28
|
): Promise<ServiceBuildSettings> {
|
|
25
29
|
signal?.throwIfAborted();
|
|
26
30
|
const { packageJson, malformed } = await readPackageJson(read);
|
|
27
31
|
const scripts = packageJson.scripts ?? {};
|
|
28
|
-
const choice = await choosePackageManager(read, packageJson);
|
|
32
|
+
const choice = await choosePackageManager(read, packageJson, foldersAbove);
|
|
29
33
|
const { start, notes } = startBeforeBuild({
|
|
30
34
|
config,
|
|
31
35
|
scripts,
|