@prisma/compute-sdk 0.44.0 → 0.45.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 +196 -0
- package/dist/archive.d.ts +2 -1
- package/dist/archive.d.ts.map +1 -1
- package/dist/archive.js +8 -4
- package/dist/archive.js.map +1 -1
- package/dist/build-strategy.d.ts +7 -0
- package/dist/build-strategy.d.ts.map +1 -1
- package/dist/build-strategy.js +3 -0
- package/dist/build-strategy.js.map +1 -1
- package/dist/compute-client.d.ts.map +1 -1
- package/dist/compute-client.js +1 -1
- package/dist/compute-client.js.map +1 -1
- package/dist/config/frameworks.d.ts +1 -1
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +3 -0
- package/dist/errors.js.map +1 -1
- package/dist/package-manager.d.ts +6 -0
- package/dist/package-manager.d.ts.map +1 -0
- package/dist/package-manager.js +21 -0
- package/dist/package-manager.js.map +1 -0
- package/dist/service/artifact/exclude.d.ts +6 -0
- package/dist/service/artifact/exclude.d.ts.map +1 -0
- package/dist/service/artifact/exclude.js +8 -0
- package/dist/service/artifact/exclude.js.map +1 -0
- package/dist/service/artifact/launcher-file.d.ts +3 -0
- package/dist/service/artifact/launcher-file.d.ts.map +1 -0
- package/dist/service/artifact/launcher-file.js +13 -0
- package/dist/service/artifact/launcher-file.js.map +1 -0
- package/dist/service/artifact/write-artifact.d.ts +16 -0
- package/dist/service/artifact/write-artifact.d.ts.map +1 -0
- package/dist/service/artifact/write-artifact.js +24 -0
- package/dist/service/artifact/write-artifact.js.map +1 -0
- package/dist/service/build/build-output.d.ts +15 -0
- package/dist/service/build/build-output.d.ts.map +1 -0
- package/dist/service/build/build-output.js +63 -0
- package/dist/service/build/build-output.js.map +1 -0
- package/dist/service/build/build-service.d.ts +30 -0
- package/dist/service/build/build-service.d.ts.map +1 -0
- package/dist/service/build/build-service.js +95 -0
- package/dist/service/build/build-service.js.map +1 -0
- package/dist/service/build/run-step.d.ts +32 -0
- package/dist/service/build/run-step.d.ts.map +1 -0
- package/dist/service/build/run-step.js +29 -0
- package/dist/service/build/run-step.js.map +1 -0
- package/dist/service/index.d.ts +7 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +7 -0
- package/dist/service/index.js.map +1 -0
- package/dist/service/launcher-contract/events.d.ts +22 -0
- package/dist/service/launcher-contract/events.d.ts.map +1 -0
- package/dist/service/launcher-contract/events.js +39 -0
- package/dist/service/launcher-contract/events.js.map +1 -0
- package/dist/service/launcher-contract/start-plan.d.ts +20 -0
- package/dist/service/launcher-contract/start-plan.d.ts.map +1 -0
- package/dist/service/launcher-contract/start-plan.js +10 -0
- package/dist/service/launcher-contract/start-plan.js.map +1 -0
- package/dist/service/launcher.mjs +482 -0
- package/dist/service/settings/dev-command.d.ts +6 -0
- package/dist/service/settings/dev-command.d.ts.map +1 -0
- package/dist/service/settings/dev-command.js +46 -0
- package/dist/service/settings/dev-command.js.map +1 -0
- package/dist/service/settings/index.d.ts +5 -0
- package/dist/service/settings/index.d.ts.map +1 -0
- package/dist/service/settings/index.js +3 -0
- package/dist/service/settings/index.js.map +1 -0
- package/dist/service/settings/install.d.ts +15 -0
- package/dist/service/settings/install.d.ts.map +1 -0
- package/dist/service/settings/install.js +58 -0
- package/dist/service/settings/install.js.map +1 -0
- package/dist/service/settings/node-version.d.ts +9 -0
- package/dist/service/settings/node-version.d.ts.map +1 -0
- package/dist/service/settings/node-version.js +18 -0
- package/dist/service/settings/node-version.js.map +1 -0
- package/dist/service/settings/package-json.d.ts +14 -0
- package/dist/service/settings/package-json.d.ts.map +1 -0
- package/dist/service/settings/package-json.js +51 -0
- package/dist/service/settings/package-json.js.map +1 -0
- package/dist/service/settings/resolve.d.ts +9 -0
- package/dist/service/settings/resolve.d.ts.map +1 -0
- package/dist/service/settings/resolve.js +49 -0
- package/dist/service/settings/resolve.js.map +1 -0
- package/dist/service/settings/start-order.d.ts +21 -0
- package/dist/service/settings/start-order.d.ts.map +1 -0
- package/dist/service/settings/start-order.js +138 -0
- package/dist/service/settings/start-order.js.map +1 -0
- package/dist/service/settings/types.d.ts +66 -0
- package/dist/service/settings/types.d.ts.map +1 -0
- package/dist/service/settings/types.js +2 -0
- package/dist/service/settings/types.js.map +1 -0
- package/dist/workspace.d.ts +4 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +12 -23
- package/dist/workspace.js.map +1 -1
- package/package.json +16 -2
- package/src/archive.ts +9 -2
- package/src/build-strategy.ts +15 -1
- package/src/compute-client.ts +1 -0
- package/src/errors.ts +13 -0
- package/src/package-manager.ts +27 -0
- package/src/service/artifact/exclude.ts +7 -0
- package/src/service/artifact/launcher-file.ts +18 -0
- package/src/service/artifact/write-artifact.ts +50 -0
- package/src/service/build/build-output.ts +95 -0
- package/src/service/build/build-service.ts +171 -0
- package/src/service/build/run-step.ts +65 -0
- package/src/service/index.ts +24 -0
- package/src/service/launcher/bin-targets.ts +143 -0
- package/src/service/launcher/bin-wrappers.ts +48 -0
- package/src/service/launcher/bun-shell.ts +17 -0
- package/src/service/launcher/listening-ports.ts +112 -0
- package/src/service/launcher/main.ts +54 -0
- package/src/service/launcher/package-manager-shims.ts +147 -0
- package/src/service/launcher/proc.ts +112 -0
- package/src/service/launcher/run-command.ts +82 -0
- package/src/service/launcher/serve-static.ts +102 -0
- package/src/service/launcher-contract/events.ts +53 -0
- package/src/service/launcher-contract/start-plan.ts +18 -0
- package/src/service/settings/dev-command.ts +65 -0
- package/src/service/settings/index.ts +17 -0
- package/src/service/settings/install.ts +105 -0
- package/src/service/settings/node-version.ts +26 -0
- package/src/service/settings/package-json.ts +71 -0
- package/src/service/settings/resolve.ts +80 -0
- package/src/service/settings/start-order.ts +213 -0
- package/src/service/settings/types.ts +73 -0
- package/src/workspace.ts +20 -35
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// The start order: the rules that decide how a Service starts. The first rule that matches wins.
|
|
2
|
+
// The user's own statement comes first, then the user's own script, then what the build made, then source files.
|
|
3
|
+
import { isDevCommand } from "./dev-command.ts";
|
|
4
|
+
import type {
|
|
5
|
+
BuildOutput,
|
|
6
|
+
PackageJson,
|
|
7
|
+
ReadFile,
|
|
8
|
+
Resolved,
|
|
9
|
+
ServiceConfig,
|
|
10
|
+
Source,
|
|
11
|
+
Start,
|
|
12
|
+
} from "./types.ts";
|
|
13
|
+
|
|
14
|
+
/** What a rule may look at before the build runs. */
|
|
15
|
+
interface ServiceBeforeBuild {
|
|
16
|
+
config: ServiceConfig;
|
|
17
|
+
scripts: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** What a rule may look at once the build has run. */
|
|
21
|
+
interface ServiceAfterBuild {
|
|
22
|
+
read: ReadFile;
|
|
23
|
+
packageJson: PackageJson;
|
|
24
|
+
output: BuildOutput;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** A rule returns the start it found, or null when it does not match. */
|
|
28
|
+
type RuleBeforeBuild = (service: ServiceBeforeBuild) => Resolved<Start> | null;
|
|
29
|
+
type RuleAfterBuild = (
|
|
30
|
+
service: ServiceAfterBuild,
|
|
31
|
+
) => Promise<Resolved<Start> | null>;
|
|
32
|
+
|
|
33
|
+
const RULES_BEFORE_BUILD: RuleBeforeBuild[] = [
|
|
34
|
+
statedInServiceConfig,
|
|
35
|
+
startScript,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const RULES_AFTER_BUILD: RuleAfterBuild[] = [
|
|
39
|
+
serverFileFromBuild,
|
|
40
|
+
staticSiteFromBuild,
|
|
41
|
+
entryFileInSource,
|
|
42
|
+
indexHtmlInServiceFolder,
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** Scripts that start the Service in production, most specific first. */
|
|
46
|
+
const START_SCRIPTS = ["start:prod", "start:production", "start"];
|
|
47
|
+
|
|
48
|
+
/** File names a build commonly gives a server, inside a folder the build created. */
|
|
49
|
+
const SERVER_FILES_FROM_BUILD = [
|
|
50
|
+
"server/index.mjs",
|
|
51
|
+
"server/entry.mjs",
|
|
52
|
+
"index.js",
|
|
53
|
+
"main.js",
|
|
54
|
+
"server.js",
|
|
55
|
+
"index.mjs",
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
/** Entry files a server may keep in its source when it has no start script. */
|
|
59
|
+
const ENTRY_FILES_IN_SOURCE = [
|
|
60
|
+
"index.ts",
|
|
61
|
+
"server.ts",
|
|
62
|
+
"src/index.ts",
|
|
63
|
+
"src/server.ts",
|
|
64
|
+
"index.js",
|
|
65
|
+
"server.js",
|
|
66
|
+
"src/index.js",
|
|
67
|
+
"src/server.js",
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
/** The start, when a rule that needs no build output decides it, and the notes for the user. */
|
|
71
|
+
export function startBeforeBuild(service: ServiceBeforeBuild): {
|
|
72
|
+
start: Resolved<Start> | "after build";
|
|
73
|
+
notes: string[];
|
|
74
|
+
} {
|
|
75
|
+
for (const rule of RULES_BEFORE_BUILD) {
|
|
76
|
+
const start = rule(service);
|
|
77
|
+
if (start !== null) {
|
|
78
|
+
return { start, notes: [] };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { start: "after build", notes: devServerNotes(service.scripts) };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The start, decided from the build output and the source. Null means no rule matched. */
|
|
86
|
+
export async function startAfterBuild(
|
|
87
|
+
service: ServiceAfterBuild,
|
|
88
|
+
): Promise<Resolved<Start> | null> {
|
|
89
|
+
for (const rule of RULES_AFTER_BUILD) {
|
|
90
|
+
const start = await rule(service);
|
|
91
|
+
if (start !== null) {
|
|
92
|
+
return start;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** The notes for the user when the start script runs a development server and is passed over. */
|
|
100
|
+
function devServerNotes(scripts: Record<string, string>): string[] {
|
|
101
|
+
const script = findStartScript(scripts);
|
|
102
|
+
if (script === null || !isDevCommand(script.command, scripts)) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return [
|
|
107
|
+
`The ${script.name} script runs a development server (${script.command}). It is not used.`,
|
|
108
|
+
];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Rule 1: the user's statement in the Service config is final. */
|
|
112
|
+
function statedInServiceConfig({
|
|
113
|
+
config,
|
|
114
|
+
}: ServiceBeforeBuild): Resolved<Start> | null {
|
|
115
|
+
if (config.start) {
|
|
116
|
+
return command(config.start, "config");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (config.static) {
|
|
120
|
+
return staticFiles(config.static, "config");
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Rule 2: the repository's own start script, unless it runs a development server. */
|
|
127
|
+
function startScript({ scripts }: ServiceBeforeBuild): Resolved<Start> | null {
|
|
128
|
+
const script = findStartScript(scripts);
|
|
129
|
+
if (script === null || isDevCommand(script.command, scripts)) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return command(script.command, "package.json");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Rule 3: a server file in a folder the build created. */
|
|
137
|
+
async function serverFileFromBuild({
|
|
138
|
+
read,
|
|
139
|
+
output,
|
|
140
|
+
}: ServiceAfterBuild): Promise<Resolved<Start> | null> {
|
|
141
|
+
for (const dir of output.newDirs) {
|
|
142
|
+
for (const file of SERVER_FILES_FROM_BUILD) {
|
|
143
|
+
if (await exists(read, `${dir}/${file}`)) {
|
|
144
|
+
return command(`bun ${dir}/${file}`, "build output");
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** Rule 4: a static site the build created. The shallowest folder is the site's root. */
|
|
153
|
+
async function staticSiteFromBuild({
|
|
154
|
+
output,
|
|
155
|
+
}: ServiceAfterBuild): Promise<Resolved<Start> | null> {
|
|
156
|
+
const dir = output.newStaticDirs[0];
|
|
157
|
+
|
|
158
|
+
return dir === undefined ? null : staticFiles(dir, "build output");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** Rule 5: an entry file in the source. The file `package.json` names comes before the common names. */
|
|
162
|
+
async function entryFileInSource({
|
|
163
|
+
read,
|
|
164
|
+
packageJson,
|
|
165
|
+
}: ServiceAfterBuild): Promise<Resolved<Start> | null> {
|
|
166
|
+
const named = packageJson.main ?? packageJson.module;
|
|
167
|
+
const files = named
|
|
168
|
+
? [named, ...ENTRY_FILES_IN_SOURCE]
|
|
169
|
+
: ENTRY_FILES_IN_SOURCE;
|
|
170
|
+
|
|
171
|
+
for (const file of files) {
|
|
172
|
+
if (await exists(read, file)) {
|
|
173
|
+
return command(`bun ${file}`, "entry file");
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Rule 6: a Service folder with an `index.html` and nothing to run is a static site. */
|
|
181
|
+
async function indexHtmlInServiceFolder({
|
|
182
|
+
read,
|
|
183
|
+
}: ServiceAfterBuild): Promise<Resolved<Start> | null> {
|
|
184
|
+
return (await exists(read, "index.html"))
|
|
185
|
+
? staticFiles(".", "entry file")
|
|
186
|
+
: null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** The first start script the repository has. A more specific name hides `start`, also when it is passed over. */
|
|
190
|
+
function findStartScript(
|
|
191
|
+
scripts: Record<string, string>,
|
|
192
|
+
): { name: string; command: string } | null {
|
|
193
|
+
for (const name of START_SCRIPTS) {
|
|
194
|
+
const script = scripts[name];
|
|
195
|
+
if (script) {
|
|
196
|
+
return { name, command: script };
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function exists(read: ReadFile, path: string): Promise<boolean> {
|
|
204
|
+
return (await read(path)) !== null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function command(text: string, from: Source): Resolved<Start> {
|
|
208
|
+
return { value: { kind: "command", command: text }, from };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function staticFiles(dir: string, from: Source): Resolved<Start> {
|
|
212
|
+
return { value: { kind: "static", dir }, from };
|
|
213
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { PackageManager } from "../../package-manager.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a file's text, or null when the file does not exist. Paths are relative to the Service folder.
|
|
5
|
+
* The same Build rules run on a checkout, on the GitHub contents API, or in a sandbox.
|
|
6
|
+
*/
|
|
7
|
+
export type ReadFile = (path: string) => Promise<string | null> | string | null;
|
|
8
|
+
|
|
9
|
+
/** What a user may state for one Service in `prisma.config.ts`. Every field is optional. */
|
|
10
|
+
export interface ServiceConfig {
|
|
11
|
+
install?: string;
|
|
12
|
+
/** `null` skips the build step. */
|
|
13
|
+
build?: string | null;
|
|
14
|
+
start?: string;
|
|
15
|
+
/** A folder of static files to serve, relative to the Service folder. */
|
|
16
|
+
static?: string;
|
|
17
|
+
port?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Where a Build setting came from. */
|
|
21
|
+
export type Source =
|
|
22
|
+
| "config"
|
|
23
|
+
| "package.json"
|
|
24
|
+
| "lockfile"
|
|
25
|
+
| "build output"
|
|
26
|
+
| "entry file"
|
|
27
|
+
| "default";
|
|
28
|
+
|
|
29
|
+
export interface Resolved<T> {
|
|
30
|
+
value: T;
|
|
31
|
+
from: Source;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** How the Service starts: its own command, or a folder of static files relative to the Service folder. */
|
|
35
|
+
export type Start =
|
|
36
|
+
| { kind: "command"; command: string }
|
|
37
|
+
| { kind: "static"; dir: string };
|
|
38
|
+
|
|
39
|
+
/** The Run contract resolved for one Service. */
|
|
40
|
+
export interface ServiceBuildSettings {
|
|
41
|
+
packageManager: PackageManager;
|
|
42
|
+
/** The major Node.js version the repository pins, or null when it pins none. The Build runner provides it. */
|
|
43
|
+
node: string | null;
|
|
44
|
+
/** A null value means there is nothing to install. */
|
|
45
|
+
install: Resolved<string | null>;
|
|
46
|
+
/** A null value means there is no build step. */
|
|
47
|
+
build: Resolved<string | null>;
|
|
48
|
+
/** `"after build"` means only the build output can decide the start. `resolveStartAfterBuild` decides it. */
|
|
49
|
+
start: Resolved<Start> | "after build";
|
|
50
|
+
/** Null means the user stated no port. The Launcher then uses the `PORT` that Compute sets, or 8080. */
|
|
51
|
+
port: Resolved<number> | null;
|
|
52
|
+
/** Facts the user should see, such as a `start` script that runs a development server. */
|
|
53
|
+
notes: string[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** What the build step wrote, as far as the start order needs it. */
|
|
57
|
+
export interface BuildOutput {
|
|
58
|
+
/** Top-level folders the build created, such as `dist` or `.output`. */
|
|
59
|
+
newDirs: string[];
|
|
60
|
+
/** Folders the build created that hold a self-contained `index.html`, shallowest first. */
|
|
61
|
+
newStaticDirs: string[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The fields of `package.json` that the Build rules read. */
|
|
65
|
+
export interface PackageJson {
|
|
66
|
+
packageManager?: string;
|
|
67
|
+
scripts?: Record<string, string>;
|
|
68
|
+
dependencies?: Record<string, string>;
|
|
69
|
+
devDependencies?: Record<string, string>;
|
|
70
|
+
engines?: { node?: string };
|
|
71
|
+
main?: string;
|
|
72
|
+
module?: string;
|
|
73
|
+
}
|
package/src/workspace.ts
CHANGED
|
@@ -4,6 +4,13 @@ import path from "node:path";
|
|
|
4
4
|
import type { Readable } from "node:stream";
|
|
5
5
|
|
|
6
6
|
import { sourceRootLineage } from "./config/source-root.ts";
|
|
7
|
+
import {
|
|
8
|
+
LOCKFILES,
|
|
9
|
+
type PackageManager,
|
|
10
|
+
packageManagerFromField,
|
|
11
|
+
} from "./package-manager.ts";
|
|
12
|
+
|
|
13
|
+
export type { PackageManager };
|
|
7
14
|
|
|
8
15
|
/**
|
|
9
16
|
* Workspace-aware build primitives shared by the framework strategies. These
|
|
@@ -14,8 +21,6 @@ import { sourceRootLineage } from "./config/source-root.ts";
|
|
|
14
21
|
* or prompts.
|
|
15
22
|
*/
|
|
16
23
|
|
|
17
|
-
export type PackageManager = "bun" | "pnpm" | "yarn" | "npm";
|
|
18
|
-
|
|
19
24
|
/**
|
|
20
25
|
* Build-environment hooks a consumer threads into a strategy: extra `env` for
|
|
21
26
|
* the build child and a per-line output tap. Both are optional, so the CLI
|
|
@@ -45,20 +50,10 @@ export async function resolvePackageManager(
|
|
|
45
50
|
return fromField;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
(await pathExists(path.join(directory,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return "bun";
|
|
53
|
-
}
|
|
54
|
-
if (await pathExists(path.join(directory, "pnpm-lock.yaml"), signal)) {
|
|
55
|
-
return "pnpm";
|
|
56
|
-
}
|
|
57
|
-
if (await pathExists(path.join(directory, "yarn.lock"), signal)) {
|
|
58
|
-
return "yarn";
|
|
59
|
-
}
|
|
60
|
-
if (await pathExists(path.join(directory, "package-lock.json"), signal)) {
|
|
61
|
-
return "npm";
|
|
53
|
+
for (const [lockfile, packageManager] of LOCKFILES) {
|
|
54
|
+
if (await pathExists(path.join(directory, lockfile), signal)) {
|
|
55
|
+
return packageManager;
|
|
56
|
+
}
|
|
62
57
|
}
|
|
63
58
|
}
|
|
64
59
|
|
|
@@ -157,16 +152,21 @@ export function runChildProcess(options: {
|
|
|
157
152
|
env: NodeJS.ProcessEnv;
|
|
158
153
|
shell?: boolean;
|
|
159
154
|
failurePrefix: string;
|
|
155
|
+
/** The step the command is, for the error text. Default `build`. */
|
|
156
|
+
failedStep?: string;
|
|
160
157
|
onOutput?: (line: string, source: "stdout" | "stderr") => void;
|
|
161
158
|
signal?: AbortSignal;
|
|
162
159
|
}): Promise<void> {
|
|
163
160
|
return new Promise((resolve, reject) => {
|
|
161
|
+
const failed = `${options.failurePrefix} ${options.failedStep ?? "build"} failed`;
|
|
164
162
|
const tail = createBoundedTail();
|
|
165
163
|
const child = spawn(options.command, [...options.args], {
|
|
166
164
|
cwd: options.cwd,
|
|
167
165
|
env: options.env,
|
|
168
166
|
signal: options.signal,
|
|
169
167
|
shell: options.shell ?? false,
|
|
168
|
+
// Nothing writes to the command's input, so a command that asks a question gets end-of-input instead of waiting.
|
|
169
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
const streamed = Promise.all([
|
|
@@ -177,10 +177,9 @@ export function runChildProcess(options: {
|
|
|
177
177
|
child.on("error", (error) => {
|
|
178
178
|
// Preserve `code` (e.g. ENOENT) so a launcher ladder can fall through.
|
|
179
179
|
reject(
|
|
180
|
-
Object.assign(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
),
|
|
180
|
+
Object.assign(new Error(`${failed}:\n${error.message}`), {
|
|
181
|
+
code: (error as NodeJS.ErrnoException).code,
|
|
182
|
+
}),
|
|
184
183
|
);
|
|
185
184
|
});
|
|
186
185
|
|
|
@@ -192,11 +191,7 @@ export function runChildProcess(options: {
|
|
|
192
191
|
}
|
|
193
192
|
const detail = tail.text().trim();
|
|
194
193
|
const exit = code != null ? ` (exit code ${code})` : "";
|
|
195
|
-
reject(
|
|
196
|
-
new Error(
|
|
197
|
-
`${options.failurePrefix} build failed${exit}${detail ? `:\n${detail}` : "."}`,
|
|
198
|
-
),
|
|
199
|
-
);
|
|
194
|
+
reject(new Error(`${failed}${exit}${detail ? `:\n${detail}` : "."}`));
|
|
200
195
|
}, reject);
|
|
201
196
|
});
|
|
202
197
|
});
|
|
@@ -301,16 +296,6 @@ export function readBuildScript(
|
|
|
301
296
|
return trimmed.length > 0 ? trimmed : null;
|
|
302
297
|
}
|
|
303
298
|
|
|
304
|
-
function packageManagerFromField(value: unknown): PackageManager | null {
|
|
305
|
-
if (typeof value !== "string") {
|
|
306
|
-
return null;
|
|
307
|
-
}
|
|
308
|
-
const name = value.split("@")[0];
|
|
309
|
-
return name === "bun" || name === "pnpm" || name === "yarn" || name === "npm"
|
|
310
|
-
? name
|
|
311
|
-
: null;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
299
|
async function pathExists(
|
|
315
300
|
targetPath: string,
|
|
316
301
|
signal?: AbortSignal,
|