@prisma/cli-engine 0.0.8 → 8.0.0-rc.1
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/index.d.ts +54 -3
- package/dist/index.js +165 -3
- package/dist/{protocol-C1JQcGl9.js → protocol-D1CRNkhv.js} +25 -4
- package/dist/{protocol-CpZLdxML.d.ts → protocol-YjqPCCOG.d.ts} +23 -3
- package/dist/protocol.d.ts +2 -2
- package/dist/protocol.js +2 -2
- package/dist/{run-summary-CVHIRjTS.d.ts → report-B7M-sp7P.d.ts} +204 -65
- package/dist/testing.d.ts +29 -2
- package/dist/testing.js +46 -23
- package/dist/{token-claims-_AF7BYbq.js → token-claims-Cwrz7N2O.js} +966 -138
- package/package.json +10 -9
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as okVoid, r as notOk, t as CliStructuredError } from "./protocol-D1CRNkhv.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { FlagNotFoundError, buildApplication, buildCommand, buildRouteMap, run, text_en } from "@stricli/core";
|
|
4
|
-
import
|
|
4
|
+
import vendors from "ci-info/vendors.json" with { type: "json" };
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync, renameSync, writeFileSync } from "node:fs";
|
|
5
7
|
import { dirname, join, resolve } from "node:path";
|
|
8
|
+
import { detect } from "package-manager-detector/detect";
|
|
6
9
|
import { createColors } from "colorette";
|
|
7
10
|
import stringWidth from "string-width";
|
|
8
11
|
import { Readable, Writable } from "node:stream";
|
|
@@ -155,6 +158,516 @@ function isChildStatusSettlement(value) {
|
|
|
155
158
|
return typeof value === "object" && value !== null && value[CHILD_STATUS] === true;
|
|
156
159
|
}
|
|
157
160
|
//#endregion
|
|
161
|
+
//#region src/ci.ts
|
|
162
|
+
/**
|
|
163
|
+
* ci-info's own list of CI providers, read from the installed package
|
|
164
|
+
* rather than copied here, so upgrading ci-info is what teaches the
|
|
165
|
+
* engine a new provider. Its `isCI` export cannot be used instead: that
|
|
166
|
+
* module evaluates against the real `process.env` the moment it is
|
|
167
|
+
* imported, and the engine may only read the environment its host
|
|
168
|
+
* injected.
|
|
169
|
+
*/
|
|
170
|
+
const VENDORS = vendors;
|
|
171
|
+
/**
|
|
172
|
+
* The variables ci-info checks outside the vendor table, catching CI
|
|
173
|
+
* systems that set a conventional variable but have no table entry.
|
|
174
|
+
* These are cross-vendor conventions rather than per-vendor facts,
|
|
175
|
+
* which is why this list holds still while the table grows.
|
|
176
|
+
*/
|
|
177
|
+
const CONVENTIONAL_CI_VARS = [
|
|
178
|
+
"BUILD_ID",
|
|
179
|
+
"BUILD_NUMBER",
|
|
180
|
+
"CI",
|
|
181
|
+
"CI_APP_ID",
|
|
182
|
+
"CI_BUILD_ID",
|
|
183
|
+
"CI_BUILD_NUMBER",
|
|
184
|
+
"CI_NAME",
|
|
185
|
+
"CONTINUOUS_INTEGRATION",
|
|
186
|
+
"RUN_ID"
|
|
187
|
+
];
|
|
188
|
+
function isSet(value) {
|
|
189
|
+
return value !== void 0 && value !== "";
|
|
190
|
+
}
|
|
191
|
+
function checkMatches(check, env) {
|
|
192
|
+
if (typeof check === "string") return isSet(env[check]);
|
|
193
|
+
const { env: variable, includes, any } = check;
|
|
194
|
+
if (typeof variable === "string" && typeof includes === "string") return env[variable]?.includes(includes) === true;
|
|
195
|
+
if (Array.isArray(any)) return any.some((name) => isSet(env[String(name)]));
|
|
196
|
+
return Object.entries(check).every(([name, value]) => env[name] === value);
|
|
197
|
+
}
|
|
198
|
+
function vendorMatches(vendor, env) {
|
|
199
|
+
return (Array.isArray(vendor.env) ? vendor.env : [vendor.env]).every((check) => checkMatches(check, env));
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Whether this environment is a CI environment, by ci-info's rules
|
|
203
|
+
* applied to the environment the host injected rather than to
|
|
204
|
+
* `process.env`. `CI=false` is an explicit denial that stops every
|
|
205
|
+
* other check, exactly as ci-info treats it.
|
|
206
|
+
*/
|
|
207
|
+
function detectCI(env) {
|
|
208
|
+
if (env.CI === "false") return false;
|
|
209
|
+
if (CONVENTIONAL_CI_VARS.some((name) => isSet(env[name]))) return true;
|
|
210
|
+
return VENDORS.some((vendor) => vendorMatches(vendor, env));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The engine's one answer to "is this run in CI", read by telemetry
|
|
214
|
+
* gating, `ctx.isCI` and the default interactivity decision. A host
|
|
215
|
+
* that says nothing gets detection, so forgetting to answer cannot turn
|
|
216
|
+
* a CI run into a reporting one.
|
|
217
|
+
*/
|
|
218
|
+
function resolveIsCI(host) {
|
|
219
|
+
return host.isCIOverride ?? detectCI(host.env);
|
|
220
|
+
}
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/telemetry/endpoint.ts
|
|
223
|
+
/**
|
|
224
|
+
* Production endpoint pinned to the deployed Prisma Compute backend.
|
|
225
|
+
* Compiled as a build-time constant; not user-configurable.
|
|
226
|
+
*/
|
|
227
|
+
const TELEMETRY_BACKEND_URL = "https://cmpbfbsdp09hr3jf7pojjs5qs.ewr.prisma.build";
|
|
228
|
+
/**
|
|
229
|
+
* Path within the backend that accepts telemetry POSTs.
|
|
230
|
+
*/
|
|
231
|
+
const TELEMETRY_ENDPOINT_PATH = "/events";
|
|
232
|
+
/**
|
|
233
|
+
* Resolve the full POST URL the sender targets. The
|
|
234
|
+
* `PRISMA_TELEMETRY_ENDPOINT` env var is an integration-testing
|
|
235
|
+
* affordance only — it lets a test suite spin up a mock HTTP server on an
|
|
236
|
+
* ephemeral port and point the spawned sender at it. The override is
|
|
237
|
+
* intentionally undocumented in user-facing material.
|
|
238
|
+
*
|
|
239
|
+
* Fail-open: a malformed override (typo in a dev shell, bad CI config)
|
|
240
|
+
* silently falls back to the production backend rather than throwing,
|
|
241
|
+
* matching the telemetry layer's broader silent-on-failure contract.
|
|
242
|
+
*/
|
|
243
|
+
function resolveTelemetryEndpoint(env) {
|
|
244
|
+
const override = env.PRISMA_TELEMETRY_ENDPOINT;
|
|
245
|
+
const base = override !== void 0 && override.length > 0 ? override : TELEMETRY_BACKEND_URL;
|
|
246
|
+
try {
|
|
247
|
+
return new URL(TELEMETRY_ENDPOINT_PATH, base).toString();
|
|
248
|
+
} catch {
|
|
249
|
+
return new URL(TELEMETRY_ENDPOINT_PATH, TELEMETRY_BACKEND_URL).toString();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/telemetry/gating.ts
|
|
254
|
+
/**
|
|
255
|
+
* A `PRISMA_DISABLE_TELEMETRY` value counts as an opt-out only if it
|
|
256
|
+
* parses as a truthy string. The set-but-falsy spellings (`''`, `'0'`,
|
|
257
|
+
* `'false'`) are intentionally treated as not-set so a parent shell that
|
|
258
|
+
* exports the variable to a benign value doesn't accidentally disable
|
|
259
|
+
* telemetry for child processes.
|
|
260
|
+
*/
|
|
261
|
+
function isTruthyOptOut(raw) {
|
|
262
|
+
if (raw === void 0) return false;
|
|
263
|
+
const normalised = raw.trim().toLowerCase();
|
|
264
|
+
if (normalised === "") return false;
|
|
265
|
+
if (normalised === "0") return false;
|
|
266
|
+
if (normalised === "false") return false;
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Pure-function resolution of the gating decision. Same input → same
|
|
271
|
+
* output; no I/O. The caller reads the env, the user config and the CI
|
|
272
|
+
* signal.
|
|
273
|
+
*
|
|
274
|
+
* Decision order:
|
|
275
|
+
* 1. CI (`inCI`) → disabled (`ci`). CI environments never emit,
|
|
276
|
+
* regardless of any stored consent.
|
|
277
|
+
* 2. Env-var override (`PRISMA_DISABLE_TELEMETRY` truthy, or
|
|
278
|
+
* `DO_NOT_TRACK=1`) → disabled (`env-opt-out`), winning over any
|
|
279
|
+
* stored or unset preference.
|
|
280
|
+
* 3. Stored `enableTelemetry === false` → disabled (`stored-opt-out`).
|
|
281
|
+
* 4. Stored `enableTelemetry === true` → enabled (`stored-opt-in`).
|
|
282
|
+
* 5. Stored `enableTelemetry === undefined` (file missing, or field
|
|
283
|
+
* not set) → ENABLED (`default-on`). This is the opt-out default:
|
|
284
|
+
* absence of an explicit choice means telemetry is on. This branch
|
|
285
|
+
* carries the whole opt-out model — do not "fix" it to default-off.
|
|
286
|
+
*/
|
|
287
|
+
function resolveGating(inputs) {
|
|
288
|
+
if (inputs.inCI) return {
|
|
289
|
+
enabled: false,
|
|
290
|
+
reason: "ci"
|
|
291
|
+
};
|
|
292
|
+
if (isTruthyOptOut(inputs.env.PRISMA_DISABLE_TELEMETRY) || inputs.env.DO_NOT_TRACK === "1") return {
|
|
293
|
+
enabled: false,
|
|
294
|
+
reason: "env-opt-out"
|
|
295
|
+
};
|
|
296
|
+
if (inputs.config.enableTelemetry === false) return {
|
|
297
|
+
enabled: false,
|
|
298
|
+
reason: "stored-opt-out"
|
|
299
|
+
};
|
|
300
|
+
if (inputs.config.enableTelemetry === true) return {
|
|
301
|
+
enabled: true,
|
|
302
|
+
reason: "stored-opt-in"
|
|
303
|
+
};
|
|
304
|
+
return {
|
|
305
|
+
enabled: true,
|
|
306
|
+
reason: "default-on"
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/telemetry/payload.ts
|
|
311
|
+
/**
|
|
312
|
+
* Project the parse-time snapshot into the wire-shape command and flag
|
|
313
|
+
* names. Pure; the snapshot's fields are the only inputs.
|
|
314
|
+
*
|
|
315
|
+
* No flag values, no positionals, no raw argv:
|
|
316
|
+
* - The wire ships `telemetry status`, never the binary name (the
|
|
317
|
+
* snapshot's commandPath already excludes it).
|
|
318
|
+
* - Only flags whose source is `cli` survive — defaulted and
|
|
319
|
+
* env-sourced flags say nothing about what the user typed.
|
|
320
|
+
* - Flag names ship in the user-facing kebab-case spelling the engine
|
|
321
|
+
* recorded; nothing is renamed or filtered per command.
|
|
322
|
+
* - `positionalCount` is accepted and never read.
|
|
323
|
+
*/
|
|
324
|
+
function sanitizeCommandSnapshot(snapshot) {
|
|
325
|
+
return {
|
|
326
|
+
command: snapshot.commandPath.join(" "),
|
|
327
|
+
flags: snapshot.flags.flatMap((flag) => flag.source === "cli" ? [flag.name] : [])
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* The whole payload, from the run's identity plus its snapshot. The
|
|
332
|
+
* snapshot reaches the payload only through
|
|
333
|
+
* {@link sanitizeCommandSnapshot}, so no field of it can arrive by
|
|
334
|
+
* another route. `databaseTarget` is left unset — see its doc-block.
|
|
335
|
+
*/
|
|
336
|
+
function composeTelemetryPayload(inputs) {
|
|
337
|
+
return {
|
|
338
|
+
installationId: inputs.installationId,
|
|
339
|
+
version: inputs.version,
|
|
340
|
+
projectRoot: inputs.projectRoot,
|
|
341
|
+
endpoint: inputs.endpoint,
|
|
342
|
+
...sanitizeCommandSnapshot(inputs.snapshot)
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/telemetry/user-config.ts
|
|
347
|
+
const APP_DIR = "prisma";
|
|
348
|
+
const FILE_NAME = "config.json";
|
|
349
|
+
function set(raw) {
|
|
350
|
+
return raw !== void 0 && raw.length > 0 ? raw : void 0;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Resolves the user-level config directory:
|
|
354
|
+
* - Windows: `%APPDATA%\prisma\` (fallback: `%USERPROFILE%\AppData\Roaming\prisma\`).
|
|
355
|
+
* - Unix (incl. macOS): `$XDG_CONFIG_HOME/prisma/` if set, else
|
|
356
|
+
* `$HOME/.config/prisma/` per the XDG Base Directory Specification.
|
|
357
|
+
*
|
|
358
|
+
* XDG is chosen over the macOS-native `~/Library/Preferences/`
|
|
359
|
+
* convention so the path resolution follows an environment variable and
|
|
360
|
+
* matches the documented behaviour on all *nix platforms. The directory
|
|
361
|
+
* is `prisma`, after the binary: the `prisma-next` name it carried is
|
|
362
|
+
* retired with that binary, and nothing reads the old location — no
|
|
363
|
+
* fallback, no migration.
|
|
364
|
+
*
|
|
365
|
+
* EVERY variable comes from the invocation's env — the engine reads no
|
|
366
|
+
* process globals, and `os.homedir()` is one: it answers from the
|
|
367
|
+
* process's own `$HOME`, not the invocation's. An env that names none of
|
|
368
|
+
* them resolves to `undefined`: the preference store is unavailable, and
|
|
369
|
+
* the engine then reads nothing, writes nothing and reports nothing.
|
|
370
|
+
* Failing closed is the only safe direction for a privacy feature —
|
|
371
|
+
* `runtime.env` is `process.env` in production, where `HOME` (or
|
|
372
|
+
* `USERPROFILE`) is always set, so this is a test-shaped state.
|
|
373
|
+
*
|
|
374
|
+
* `process.platform` stays: it does not vary with an invocation and is
|
|
375
|
+
* not modelled on the Runtime.
|
|
376
|
+
*/
|
|
377
|
+
function configDir(env) {
|
|
378
|
+
if (process.platform === "win32") {
|
|
379
|
+
const appData = set(env.APPDATA);
|
|
380
|
+
if (appData !== void 0) return join(appData, APP_DIR);
|
|
381
|
+
const userProfile = set(env.USERPROFILE);
|
|
382
|
+
return userProfile === void 0 ? void 0 : join(userProfile, "AppData", "Roaming", APP_DIR);
|
|
383
|
+
}
|
|
384
|
+
const xdg = set(env.XDG_CONFIG_HOME);
|
|
385
|
+
if (xdg !== void 0) return join(xdg, APP_DIR);
|
|
386
|
+
const home = set(env.HOME);
|
|
387
|
+
return home === void 0 ? void 0 : join(home, ".config", APP_DIR);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Path to the user-level config file for this invocation, or `undefined`
|
|
391
|
+
* when the environment says nothing about where the user's config
|
|
392
|
+
* directory is. Callers treat `undefined` as "the preference store is
|
|
393
|
+
* unavailable".
|
|
394
|
+
*/
|
|
395
|
+
function userConfigPath(env) {
|
|
396
|
+
const dir = configDir(env);
|
|
397
|
+
return dir === void 0 ? void 0 : join(dir, FILE_NAME);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Reads the user-level config. File-missing, unreadable, or malformed →
|
|
401
|
+
* `{}` (the absence of consent is the same answer in every error mode).
|
|
402
|
+
* Unknown fields from a future client are passed through verbatim.
|
|
403
|
+
*/
|
|
404
|
+
function readUserConfig(env) {
|
|
405
|
+
const path = userConfigPath(env);
|
|
406
|
+
if (path === void 0 || !existsSync(path)) return {};
|
|
407
|
+
try {
|
|
408
|
+
const raw = readFileSync(path, "utf-8");
|
|
409
|
+
const parsed = JSON.parse(raw);
|
|
410
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
411
|
+
return {};
|
|
412
|
+
} catch {
|
|
413
|
+
return {};
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Merges `partial` into the current config and writes the result
|
|
418
|
+
* atomically (temp file + rename) so a crash mid-write never leaves a
|
|
419
|
+
* half-baked file readable on disk. Unknown fields already on disk are
|
|
420
|
+
* preserved.
|
|
421
|
+
*
|
|
422
|
+
* When `partial.enableTelemetry === true` and no `installationId` is
|
|
423
|
+
* stored yet, generates a v4 random UUID and persists both fields in the
|
|
424
|
+
* same write. An existing `installationId` is never rotated. This is the
|
|
425
|
+
* *explicit-consent* mint path: a `false` answer
|
|
426
|
+
* (`writeUserConfig({ enableTelemetry: false })`) writes no id, and a
|
|
427
|
+
* bare `writeUserConfig({ installationId })` mints nothing extra. The
|
|
428
|
+
* default-on first-send path mints its id separately via
|
|
429
|
+
* {@link ensureInstallationId}, which records no consent answer.
|
|
430
|
+
*/
|
|
431
|
+
function writeUserConfig(env, partial) {
|
|
432
|
+
const merged = {
|
|
433
|
+
...readUserConfig(env),
|
|
434
|
+
...partial
|
|
435
|
+
};
|
|
436
|
+
if (partial.enableTelemetry === true && merged.installationId === void 0) merged.installationId = randomUUID();
|
|
437
|
+
const path = userConfigPath(env);
|
|
438
|
+
if (path === void 0) throw new Error("@prisma/cli-engine: cannot resolve the user config directory — the environment sets none of XDG_CONFIG_HOME, HOME, APPDATA or USERPROFILE");
|
|
439
|
+
const dir = dirname(path);
|
|
440
|
+
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
|
441
|
+
const tmpPath = `${path}.${process.pid}.tmp`;
|
|
442
|
+
writeFileSync(tmpPath, `${JSON.stringify(merged, null, 2)}\n`, "utf-8");
|
|
443
|
+
renameSync(tmpPath, path);
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Returns the stored `installationId`, minting and persisting a fresh v4
|
|
447
|
+
* UUID when none exists yet. Crucially, this persists *only* the id —
|
|
448
|
+
* `enableTelemetry` is left untouched (stays `undefined` on a default-on
|
|
449
|
+
* first run), so no explicit consent the user never gave is recorded.
|
|
450
|
+
*
|
|
451
|
+
* Used by the default-on first-run fire path: the gating resolution has
|
|
452
|
+
* already come back enabled, so this only ever runs when telemetry is on.
|
|
453
|
+
*/
|
|
454
|
+
function ensureInstallationId(env) {
|
|
455
|
+
const existing = readUserConfig(env).installationId;
|
|
456
|
+
if (typeof existing === "string" && existing.length > 0) return existing;
|
|
457
|
+
const installationId = randomUUID();
|
|
458
|
+
writeUserConfig(env, { installationId });
|
|
459
|
+
return installationId;
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region src/telemetry/report.ts
|
|
463
|
+
/**
|
|
464
|
+
* The command path the whole telemetry surface is exempt from. Running
|
|
465
|
+
* `telemetry disable` must not report a usage event on its way to
|
|
466
|
+
* disabling, and `telemetry status` must not mint an id while merely
|
|
467
|
+
* reporting state.
|
|
468
|
+
*/
|
|
469
|
+
const EXEMPT_COMMAND = "telemetry";
|
|
470
|
+
/**
|
|
471
|
+
* The one-time first-run disclosure. `<name> telemetry disable` is named
|
|
472
|
+
* as the primary, friendliest opt-out, alongside the environment
|
|
473
|
+
* variables. The config file is not named and hand-editing it is not
|
|
474
|
+
* suggested: the preference is machine-edited, which is what the
|
|
475
|
+
* telemetry commands are for, and `telemetry status` reports the path
|
|
476
|
+
* for anyone who wants it.
|
|
477
|
+
*/
|
|
478
|
+
function firstRunNotice(cliName, docsUrl) {
|
|
479
|
+
return [
|
|
480
|
+
"Prisma collects anonymous CLI usage data, enabled by default.",
|
|
481
|
+
`What's collected and why: ${docsUrl}.`,
|
|
482
|
+
`Opt out: run "${cliName} telemetry disable", set DO_NOT_TRACK=1 or`,
|
|
483
|
+
"PRISMA_DISABLE_TELEMETRY=1."
|
|
484
|
+
].join(" ");
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* The first enabled run on this machine: disclose, then mint. Both are
|
|
488
|
+
* best-effort. A failed write returns no id, which skips the event
|
|
489
|
+
* rather than sending a junk one, and leaves the notice to print again
|
|
490
|
+
* next run — the stored id is what makes it print exactly once.
|
|
491
|
+
*/
|
|
492
|
+
function discloseAndMint(inputs) {
|
|
493
|
+
const { host } = inputs;
|
|
494
|
+
try {
|
|
495
|
+
host.stderr.write(`${firstRunNotice(inputs.name, inputs.telemetry.docsUrl)}\n`);
|
|
496
|
+
} catch {}
|
|
497
|
+
try {
|
|
498
|
+
return ensureInstallationId(host.env);
|
|
499
|
+
} catch {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Report one run, at command start — before the handler, from the
|
|
505
|
+
* parse-time snapshot. Exempt the telemetry command, resolve gating,
|
|
506
|
+
* disclose and mint on a first enabled run, compose, hand the payload to
|
|
507
|
+
* the host's seam. The engine composes; the host spawns.
|
|
508
|
+
*
|
|
509
|
+
* A host with no seam is turned away first, before the config is even
|
|
510
|
+
* read: a CLI that cannot deliver an event must not tell the user it
|
|
511
|
+
* collects data, and must not mint an installation id it has no use
|
|
512
|
+
* for. Declaring telemetry and wiring the seam are two halves of one
|
|
513
|
+
* decision; either one missing means the run reports nothing. An
|
|
514
|
+
* environment that says nothing about where the user's config lives is
|
|
515
|
+
* turned away at the same point and for the same reason.
|
|
516
|
+
*
|
|
517
|
+
* Every failure is swallowed: a malformed stored config, an unwritable
|
|
518
|
+
* config directory and a throwing seam all leave the run's exit code,
|
|
519
|
+
* stdout and stderr exactly as they would have been.
|
|
520
|
+
*/
|
|
521
|
+
function reportCommandStart(inputs) {
|
|
522
|
+
try {
|
|
523
|
+
const { host, snapshot } = inputs;
|
|
524
|
+
const deliver = host.spawnTelemetry;
|
|
525
|
+
const configPath = userConfigPath(host.env);
|
|
526
|
+
if (deliver === void 0 || configPath === void 0 || snapshot.commandPath[0] === EXEMPT_COMMAND) return;
|
|
527
|
+
const config = readUserConfig(host.env);
|
|
528
|
+
if (!resolveGating({
|
|
529
|
+
env: host.env,
|
|
530
|
+
config,
|
|
531
|
+
inCI: resolveIsCI(host)
|
|
532
|
+
}).enabled) return;
|
|
533
|
+
const stored = config.installationId;
|
|
534
|
+
const installationId = typeof stored === "string" && stored.length > 0 ? stored : discloseAndMint(inputs);
|
|
535
|
+
if (installationId === void 0) return;
|
|
536
|
+
deliver(composeTelemetryPayload({
|
|
537
|
+
installationId,
|
|
538
|
+
version: inputs.version,
|
|
539
|
+
projectRoot: host.cwd,
|
|
540
|
+
endpoint: resolveTelemetryEndpoint(host.env),
|
|
541
|
+
snapshot
|
|
542
|
+
}));
|
|
543
|
+
} catch {}
|
|
544
|
+
}
|
|
545
|
+
//#endregion
|
|
546
|
+
//#region src/package-manager.ts
|
|
547
|
+
const MANAGERS = new Set([
|
|
548
|
+
"npm",
|
|
549
|
+
"pnpm",
|
|
550
|
+
"yarn",
|
|
551
|
+
"bun",
|
|
552
|
+
"deno"
|
|
553
|
+
]);
|
|
554
|
+
function isManager(name) {
|
|
555
|
+
return MANAGERS.has(name);
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* The manager that invoked this process, read from the environment the
|
|
559
|
+
* host handed the engine. package-manager-detector's own getUserAgent
|
|
560
|
+
* reads process.env directly, which the engine may not do; this is the
|
|
561
|
+
* same parse over Runtime.env.
|
|
562
|
+
*/
|
|
563
|
+
function invokingManager(env) {
|
|
564
|
+
const name = env.npm_config_user_agent?.split("/")[0];
|
|
565
|
+
return name !== void 0 && isManager(name) ? name : void 0;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Resolves the manager to drive at `cwd`. In order: the caller's
|
|
569
|
+
* choice, the host's, the project the library detects by walking up
|
|
570
|
+
* from `cwd`, the manager that invoked this process, then npm. Always
|
|
571
|
+
* resolves — "we could not tell" is not an outcome.
|
|
572
|
+
*
|
|
573
|
+
* Two inherited behaviors of package-manager-detector, deliberate and
|
|
574
|
+
* documented so they are not rediscovered as bugs: the walk goes to the
|
|
575
|
+
* filesystem root with no project boundary, so a lockfile above the
|
|
576
|
+
* project counts; and within one directory a package.json
|
|
577
|
+
* `packageManager` field beats a lockfile.
|
|
578
|
+
*/
|
|
579
|
+
async function resolvePackageManager(request) {
|
|
580
|
+
const chosen = request.override ?? request.host;
|
|
581
|
+
if (chosen !== void 0) return chosen;
|
|
582
|
+
const detected = await detect({ cwd: request.cwd });
|
|
583
|
+
if (detected !== null && isManager(detected.name)) return detected.name;
|
|
584
|
+
return invokingManager(request.env) ?? "npm";
|
|
585
|
+
}
|
|
586
|
+
/**
|
|
587
|
+
* The characters a POSIX shell hands to a command unchanged. Everything
|
|
588
|
+
* else — whitespace, `|`, `>`, `$`, `*`, quotes — either moves an
|
|
589
|
+
* argument boundary or is syntax the shell acts on, and the line is
|
|
590
|
+
* offered to the user as the command to run by hand: it has to reach
|
|
591
|
+
* their package manager as the argv the engine composed.
|
|
592
|
+
*/
|
|
593
|
+
const SHELL_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
594
|
+
/**
|
|
595
|
+
* Single quotes, because a POSIX shell expands nothing inside them; a
|
|
596
|
+
* single quote in the entry itself has to leave and re-enter them.
|
|
597
|
+
* Known limitation: this is not a Windows rule — cmd.exe treats `'` as
|
|
598
|
+
* an ordinary character and reads `%` and `^` — so a line pasted into
|
|
599
|
+
* cmd.exe or PowerShell is not quoted for those shells.
|
|
600
|
+
*/
|
|
601
|
+
function shellQuote(entry) {
|
|
602
|
+
if (SHELL_SAFE.test(entry)) return entry;
|
|
603
|
+
return `'${entry.replaceAll("'", String.raw`'\''`)}'`;
|
|
604
|
+
}
|
|
605
|
+
function spell$1(file, args) {
|
|
606
|
+
return {
|
|
607
|
+
file,
|
|
608
|
+
args,
|
|
609
|
+
line: [file, ...args].map(shellQuote).join(" ")
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function addSpelling(file) {
|
|
613
|
+
return (packages, dev) => spell$1(file, [
|
|
614
|
+
"add",
|
|
615
|
+
...dev ? ["-D"] : [],
|
|
616
|
+
...packages
|
|
617
|
+
]);
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Every command line the engine will run, for every manager and both
|
|
621
|
+
* forms. Nothing else in the engine spells a manager command.
|
|
622
|
+
*/
|
|
623
|
+
const SPELLINGS = {
|
|
624
|
+
npm: {
|
|
625
|
+
install: addSpelling("npm"),
|
|
626
|
+
run: (packageName, args) => spell$1("npx", [packageName, ...args])
|
|
627
|
+
},
|
|
628
|
+
pnpm: {
|
|
629
|
+
install: addSpelling("pnpm"),
|
|
630
|
+
run: (packageName, args) => spell$1("pnpm", [
|
|
631
|
+
"dlx",
|
|
632
|
+
packageName,
|
|
633
|
+
...args
|
|
634
|
+
])
|
|
635
|
+
},
|
|
636
|
+
yarn: {
|
|
637
|
+
install: addSpelling("yarn"),
|
|
638
|
+
run: (packageName, args) => spell$1("yarn", [
|
|
639
|
+
"dlx",
|
|
640
|
+
packageName,
|
|
641
|
+
...args
|
|
642
|
+
])
|
|
643
|
+
},
|
|
644
|
+
bun: {
|
|
645
|
+
install: addSpelling("bun"),
|
|
646
|
+
run: (packageName, args) => spell$1("bunx", [packageName, ...args])
|
|
647
|
+
},
|
|
648
|
+
deno: {
|
|
649
|
+
install: (packages, dev) => spell$1("deno", [
|
|
650
|
+
"add",
|
|
651
|
+
...dev ? ["--dev"] : [],
|
|
652
|
+
...packages.map((specifier) => `npm:${specifier}`)
|
|
653
|
+
]),
|
|
654
|
+
run: (packageName, args) => spell$1("deno", [
|
|
655
|
+
"run",
|
|
656
|
+
"-A",
|
|
657
|
+
`npm:${packageName}`,
|
|
658
|
+
...args
|
|
659
|
+
])
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
/** Adds dependencies to the project. */
|
|
663
|
+
function installCommand(manager, request) {
|
|
664
|
+
return SPELLINGS[manager].install(request.packages, request.dev ?? false);
|
|
665
|
+
}
|
|
666
|
+
/** Runs a package's bin once, without adding a dependency. */
|
|
667
|
+
function runCommand(manager, request) {
|
|
668
|
+
return SPELLINGS[manager].run(request.package, request.args ?? []);
|
|
669
|
+
}
|
|
670
|
+
//#endregion
|
|
158
671
|
//#region src/presentation.ts
|
|
159
672
|
const PRESENTED = Symbol.for("prisma.cli-engine.presented");
|
|
160
673
|
//#endregion
|
|
@@ -283,9 +796,9 @@ const SERVICE_TOKEN_ENV_VAR = "PRISMA_SERVICE_TOKEN";
|
|
|
283
796
|
const WORKSPACE_ID_ENV_VAR = "PRISMA_WORKSPACE_ID";
|
|
284
797
|
//#endregion
|
|
285
798
|
//#region src/execution/debug.ts
|
|
286
|
-
const DEBUG_ENV_VAR = "
|
|
799
|
+
const DEBUG_ENV_VAR = "PRISMA_DEBUG";
|
|
287
800
|
/**
|
|
288
|
-
* The engine's debug valve: silent unless
|
|
801
|
+
* The engine's debug valve: silent unless PRISMA_DEBUG=1 in the
|
|
289
802
|
* injected env (never process.env), writing to the injected stderr.
|
|
290
803
|
* Token material never reaches it.
|
|
291
804
|
*/
|
|
@@ -912,9 +1425,13 @@ function resolveColorEnabled(shared, runtime) {
|
|
|
912
1425
|
* --no-interactive override in either direction. Format never decides
|
|
913
1426
|
* interactivity (operator ruling, 2026-08-09): an interactive json run
|
|
914
1427
|
* may prompt — the prompt UI writes to stderr, so stdout stays a clean
|
|
915
|
-
* frame stream.
|
|
1428
|
+
* frame stream.
|
|
1429
|
+
*
|
|
1430
|
+
* This asks the engine's CI detection rather than testing `CI` for
|
|
1431
|
+
* being set at all: a Jenkins, TeamCity or Azure Pipelines job sets no
|
|
1432
|
+
* `CI` variable, and used to be offered a prompt no one could answer. */
|
|
916
1433
|
function defaultInteractive(runtime) {
|
|
917
|
-
return runtime.isTty.stdin && runtime
|
|
1434
|
+
return runtime.isTty.stdin && !resolveIsCI(runtime);
|
|
918
1435
|
}
|
|
919
1436
|
function resolveAutoFormat(shared, runtime) {
|
|
920
1437
|
if (shared.json === true) return "json";
|
|
@@ -1468,7 +1985,7 @@ function structuredErrorFromDiagnostic(diagnostic) {
|
|
|
1468
1985
|
* success it carries the validated section value for ctx.config. */
|
|
1469
1986
|
async function checkNeeds(def, invocation) {
|
|
1470
1987
|
const needs = def.needs;
|
|
1471
|
-
const failure = checkInteraction(needs, invocation) ?? checkDependencies(needs, invocation);
|
|
1988
|
+
const failure = checkInteraction(needs, invocation) ?? await checkDependencies(needs, invocation);
|
|
1472
1989
|
if (failure !== void 0) return failure;
|
|
1473
1990
|
const credentials = await checkCredentials(needs, invocation);
|
|
1474
1991
|
if (credentials.failure !== void 0) return credentials.failure;
|
|
@@ -1495,8 +2012,15 @@ function checkInteraction(needs, invocation) {
|
|
|
1495
2012
|
}]
|
|
1496
2013
|
}));
|
|
1497
2014
|
}
|
|
1498
|
-
function checkDependencies(needs, invocation) {
|
|
1499
|
-
|
|
2015
|
+
async function checkDependencies(needs, invocation) {
|
|
2016
|
+
const runtime = invocation.runtime;
|
|
2017
|
+
const missing = needs.dependencies.find((specifier) => !dependencyResolvable(specifier, runtime.cwd));
|
|
2018
|
+
if (missing === void 0) return;
|
|
2019
|
+
return needsErrored(missingDependencyError(missing, await resolvePackageManager({
|
|
2020
|
+
cwd: runtime.cwd,
|
|
2021
|
+
env: runtime.env,
|
|
2022
|
+
host: runtime.packageManager
|
|
2023
|
+
})));
|
|
1500
2024
|
}
|
|
1501
2025
|
/**
|
|
1502
2026
|
* The credentials need, single-sourced from the credential manager:
|
|
@@ -1618,30 +2142,18 @@ function dependencyResolvable(specifier, cwd) {
|
|
|
1618
2142
|
return false;
|
|
1619
2143
|
}
|
|
1620
2144
|
}
|
|
1621
|
-
function installCommand(packageManager, specifier) {
|
|
1622
|
-
switch (packageManager) {
|
|
1623
|
-
case "npm": return `npm install ${specifier}`;
|
|
1624
|
-
case "pnpm": return `pnpm add ${specifier}`;
|
|
1625
|
-
case "yarn": return `yarn add ${specifier}`;
|
|
1626
|
-
case "bun": return `bun add ${specifier}`;
|
|
1627
|
-
case "unknown": return;
|
|
1628
|
-
}
|
|
1629
|
-
}
|
|
1630
2145
|
/** Optional peer dependencies: the engine probes and phrases. */
|
|
1631
|
-
function missingDependencyError(specifier,
|
|
1632
|
-
const install = installCommand(
|
|
2146
|
+
function missingDependencyError(specifier, manager) {
|
|
2147
|
+
const install = installCommand(manager, { packages: [specifier] }).line;
|
|
1633
2148
|
return new CliStructuredError("CLI.MISSING_DEPENDENCY", `This command requires the optional dependency '${specifier}', which is not installed in this project.`, {
|
|
1634
|
-
nextActions: [
|
|
1635
|
-
kind: "user-choice",
|
|
1636
|
-
label: `Install '${specifier}' with your package manager, then run the command again.`
|
|
1637
|
-
} : {
|
|
2149
|
+
nextActions: [{
|
|
1638
2150
|
kind: "run-command",
|
|
1639
2151
|
label: `Install '${specifier}'`,
|
|
1640
2152
|
command: install
|
|
1641
2153
|
}],
|
|
1642
2154
|
meta: {
|
|
1643
2155
|
specifier,
|
|
1644
|
-
|
|
2156
|
+
installCommand: install
|
|
1645
2157
|
}
|
|
1646
2158
|
});
|
|
1647
2159
|
}
|
|
@@ -1663,6 +2175,252 @@ async function announceUrl(invocation, request) {
|
|
|
1663
2175
|
}
|
|
1664
2176
|
}
|
|
1665
2177
|
//#endregion
|
|
2178
|
+
//#region src/package-manager-errors.ts
|
|
2179
|
+
function why(failure) {
|
|
2180
|
+
if (failure.reason === "runner-unavailable") return "This host wires no package-manager runner, so nothing was run.";
|
|
2181
|
+
return `${failure.manager} exited with code ${failure.exitCode}.`;
|
|
2182
|
+
}
|
|
2183
|
+
/**
|
|
2184
|
+
* The single constructor of CLI.PACKAGE_MANAGER_FAILED — both forms of
|
|
2185
|
+
* ctx.packages, and the host that can run neither.
|
|
2186
|
+
*/
|
|
2187
|
+
function packageManagerFailedError(failure) {
|
|
2188
|
+
const installing = failure.form === "install";
|
|
2189
|
+
return new CliStructuredError("CLI.PACKAGE_MANAGER_FAILED", installing ? `Installing packages with ${failure.manager} failed.` : `Running ${failure.package} with ${failure.manager} failed.`, {
|
|
2190
|
+
why: why(failure),
|
|
2191
|
+
nextActions: [{
|
|
2192
|
+
kind: "run-command",
|
|
2193
|
+
label: installing ? "Run the install yourself" : "Run the command yourself",
|
|
2194
|
+
command: failure.command
|
|
2195
|
+
}],
|
|
2196
|
+
meta: {
|
|
2197
|
+
form: failure.form,
|
|
2198
|
+
manager: failure.manager,
|
|
2199
|
+
command: failure.command,
|
|
2200
|
+
exitCode: failure.exitCode,
|
|
2201
|
+
stderrTail: failure.stderrTail,
|
|
2202
|
+
...failure.reason === void 0 ? {} : { reason: failure.reason }
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
//#endregion
|
|
2207
|
+
//#region src/execution/redaction.ts
|
|
2208
|
+
const REDACTED = "…";
|
|
2209
|
+
/** A candidate runs from a scheme to the end of the authority, which is
|
|
2210
|
+
* the only part of a URL userinfo can be in. Delimiting it is all this
|
|
2211
|
+
* does; `URL` below decides whether the candidate is a URL at all. What
|
|
2212
|
+
* follows the authority is never matched, so a path holding an `@`, and
|
|
2213
|
+
* the punctuation a URL ending a sentence carries, are untouched. */
|
|
2214
|
+
const URL_AUTHORITY = /[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s/?#<>]+/g;
|
|
2215
|
+
const AUTHORITY_MARK = "://";
|
|
2216
|
+
/** `new URL` throws for everything that is not a URL, which is how a
|
|
2217
|
+
* candidate is rejected. */
|
|
2218
|
+
function asUrl(candidate) {
|
|
2219
|
+
try {
|
|
2220
|
+
return new URL(candidate);
|
|
2221
|
+
} catch {
|
|
2222
|
+
return;
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
/** `URL` reports whether there is userinfo at all, and the `@` that ends
|
|
2226
|
+
* it is the last one in the authority. Only that span of the original
|
|
2227
|
+
* text is replaced: serialising the parsed URL back out would return a
|
|
2228
|
+
* normalised one — default port dropped, path resolved, password
|
|
2229
|
+
* percent-encoded — and the surrounding output has to survive verbatim. */
|
|
2230
|
+
function redactUserinfo(candidate) {
|
|
2231
|
+
const url = asUrl(candidate);
|
|
2232
|
+
if (url === void 0 || url.username === "" && url.password === "") return candidate;
|
|
2233
|
+
const start = candidate.indexOf(AUTHORITY_MARK) + 3;
|
|
2234
|
+
const end = candidate.lastIndexOf("@");
|
|
2235
|
+
return `${candidate.slice(0, start)}${REDACTED}${candidate.slice(end)}`;
|
|
2236
|
+
}
|
|
2237
|
+
const VALUE = String.raw`"[^"]*"|'[^']*'|\S+`;
|
|
2238
|
+
const ASSIGNMENT = new RegExp(String.raw`\b([A-Za-z_][A-Za-z0-9_]*)=(${VALUE})`, "g");
|
|
2239
|
+
/** A header's value runs to the end of its line, because an auth scheme
|
|
2240
|
+
* and its credential are one value: `Authorization: Bearer eyJ…`. */
|
|
2241
|
+
const HEADER = /\b([A-Za-z][A-Za-z0-9_-]*):[ \t]+[^\n]+/g;
|
|
2242
|
+
/** A flag's value is the word after it. A word starting with a dash is
|
|
2243
|
+
* the next flag rather than this one's value. */
|
|
2244
|
+
const FLAG = new RegExp(String.raw`(--?[A-Za-z][A-Za-z0-9_-]*)[ \t]+(?!-)(?:${VALUE})`, "g");
|
|
2245
|
+
const SECRET_WORDS = new Set([
|
|
2246
|
+
"TOKEN",
|
|
2247
|
+
"KEY",
|
|
2248
|
+
"SECRET",
|
|
2249
|
+
"PASSWORD",
|
|
2250
|
+
"AUTHORIZATION"
|
|
2251
|
+
]);
|
|
2252
|
+
/** Underscores, hyphens and camelCase humps: `MY_API_TOKEN`,
|
|
2253
|
+
* `--auth-token` and `_authToken` name a secret; `monkey`,
|
|
2254
|
+
* `--keyring` and `tokenizer` do not. */
|
|
2255
|
+
const NAME_WORDS = /[_-]+|(?<=[a-z0-9])(?=[A-Z])/;
|
|
2256
|
+
function namesSecret(name) {
|
|
2257
|
+
return name.split(NAME_WORDS).some((word) => SECRET_WORDS.has(word.toUpperCase()));
|
|
2258
|
+
}
|
|
2259
|
+
/**
|
|
2260
|
+
* Removes the shapes a package manager's output leaks credentials in:
|
|
2261
|
+
* the userinfo of a URL, and the value carried by a name that says it
|
|
2262
|
+
* holds a secret — after an `=`, after a header's colon, or after a
|
|
2263
|
+
* flag. Everything else survives verbatim, so a caller matching an
|
|
2264
|
+
* error code out of stderr still finds it.
|
|
2265
|
+
*/
|
|
2266
|
+
function redactSecrets(text) {
|
|
2267
|
+
return text.replace(URL_AUTHORITY, redactUserinfo).replace(ASSIGNMENT, (assignment, name) => namesSecret(name) ? `${name}=${REDACTED}` : assignment).replace(HEADER, (header, name) => namesSecret(name) ? `${name}: ${REDACTED}` : header).replace(FLAG, (flag, name) => namesSecret(name) ? `${name} ${REDACTED}` : flag);
|
|
2268
|
+
}
|
|
2269
|
+
//#endregion
|
|
2270
|
+
//#region src/execution/package-operations.ts
|
|
2271
|
+
/** What the seam reports for a child that never ran, and what a host
|
|
2272
|
+
* with no runner at all reports for the same reason. */
|
|
2273
|
+
const NO_CHILD_EXIT_CODE = 1;
|
|
2274
|
+
function spell(operation, manager) {
|
|
2275
|
+
return operation.form === "install" ? installCommand(manager, {
|
|
2276
|
+
packages: operation.packages,
|
|
2277
|
+
dev: operation.dev
|
|
2278
|
+
}) : runCommand(manager, {
|
|
2279
|
+
package: operation.package,
|
|
2280
|
+
args: operation.args
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
function failed(operation, command, outcome) {
|
|
2284
|
+
const spelling = redactSecrets(command.line);
|
|
2285
|
+
return packageManagerFailedError(operation.form === "install" ? {
|
|
2286
|
+
...outcome,
|
|
2287
|
+
command: spelling,
|
|
2288
|
+
form: "install"
|
|
2289
|
+
} : {
|
|
2290
|
+
...outcome,
|
|
2291
|
+
command: spelling,
|
|
2292
|
+
form: "run",
|
|
2293
|
+
package: operation.package
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
/** Cancellation throws rather than resolving a failure, so an aborted
|
|
2297
|
+
* operation settles the way Ctrl-C settles everywhere else. Asked again
|
|
2298
|
+
* after detection: that await is long enough for the signal to fire,
|
|
2299
|
+
* and an operation nothing spawned must announce nothing. */
|
|
2300
|
+
function stopIfCancelled(signal) {
|
|
2301
|
+
if (signal.aborted) throw signal.reason;
|
|
2302
|
+
}
|
|
2303
|
+
/** The seam hands over chunks as the child writes them; an `output`
|
|
2304
|
+
* event carries one line, so a line split across two chunks waits for
|
|
2305
|
+
* its second half. */
|
|
2306
|
+
function lineAssembler(emit) {
|
|
2307
|
+
let pending = "";
|
|
2308
|
+
const emitLine = (line) => {
|
|
2309
|
+
emit(redactSecrets(line.endsWith("\r") ? line.slice(0, -1) : line));
|
|
2310
|
+
};
|
|
2311
|
+
return {
|
|
2312
|
+
push: (chunk) => {
|
|
2313
|
+
const lines = (pending + chunk).split("\n");
|
|
2314
|
+
pending = lines.pop() ?? "";
|
|
2315
|
+
for (const line of lines) emitLine(line);
|
|
2316
|
+
},
|
|
2317
|
+
flush: () => {
|
|
2318
|
+
if (pending !== "") {
|
|
2319
|
+
emitLine(pending);
|
|
2320
|
+
pending = "";
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
function outputChannels(invocation, manager) {
|
|
2326
|
+
const assemble = (channel) => lineAssembler((line) => {
|
|
2327
|
+
reportEvent(invocation, {
|
|
2328
|
+
kind: "output",
|
|
2329
|
+
source: manager,
|
|
2330
|
+
channel,
|
|
2331
|
+
line
|
|
2332
|
+
});
|
|
2333
|
+
});
|
|
2334
|
+
const channels = {
|
|
2335
|
+
data: assemble("data"),
|
|
2336
|
+
diagnostic: assemble("diagnostic")
|
|
2337
|
+
};
|
|
2338
|
+
return {
|
|
2339
|
+
push: (channel, chunk) => {
|
|
2340
|
+
channels[channel].push(chunk);
|
|
2341
|
+
},
|
|
2342
|
+
flush: () => {
|
|
2343
|
+
channels.data.flush();
|
|
2344
|
+
channels.diagnostic.flush();
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
async function execute(invocation, operation, placement) {
|
|
2349
|
+
const { runtime, signal } = invocation;
|
|
2350
|
+
stopIfCancelled(signal);
|
|
2351
|
+
const cwd = placement.cwd ?? runtime.cwd;
|
|
2352
|
+
const manager = await resolvePackageManager({
|
|
2353
|
+
cwd,
|
|
2354
|
+
env: runtime.env,
|
|
2355
|
+
override: placement.manager,
|
|
2356
|
+
host: runtime.packageManager
|
|
2357
|
+
});
|
|
2358
|
+
stopIfCancelled(signal);
|
|
2359
|
+
const command = spell(operation, manager);
|
|
2360
|
+
const runner = runtime.runPackageManager;
|
|
2361
|
+
if (runner === void 0) return notOk(failed(operation, command, {
|
|
2362
|
+
manager,
|
|
2363
|
+
exitCode: NO_CHILD_EXIT_CODE,
|
|
2364
|
+
stderrTail: "",
|
|
2365
|
+
reason: "runner-unavailable"
|
|
2366
|
+
}));
|
|
2367
|
+
const output = outputChannels(invocation, manager);
|
|
2368
|
+
const step = redactSecrets(command.line);
|
|
2369
|
+
reportEvent(invocation, {
|
|
2370
|
+
kind: "step-started",
|
|
2371
|
+
step
|
|
2372
|
+
});
|
|
2373
|
+
let result;
|
|
2374
|
+
try {
|
|
2375
|
+
result = await runner({
|
|
2376
|
+
file: command.file,
|
|
2377
|
+
args: command.args,
|
|
2378
|
+
cwd,
|
|
2379
|
+
signal,
|
|
2380
|
+
onOutput: output.push
|
|
2381
|
+
});
|
|
2382
|
+
} finally {
|
|
2383
|
+
output.flush();
|
|
2384
|
+
}
|
|
2385
|
+
reportEvent(invocation, {
|
|
2386
|
+
kind: "step-finished",
|
|
2387
|
+
step,
|
|
2388
|
+
outcome: signal.aborted || result.exitCode !== 0 ? "failed" : "ok"
|
|
2389
|
+
});
|
|
2390
|
+
stopIfCancelled(signal);
|
|
2391
|
+
if (result.exitCode === 0) return okVoid();
|
|
2392
|
+
return notOk(failed(operation, command, {
|
|
2393
|
+
manager,
|
|
2394
|
+
exitCode: result.exitCode,
|
|
2395
|
+
stderrTail: redactSecrets(result.stderr)
|
|
2396
|
+
}));
|
|
2397
|
+
}
|
|
2398
|
+
function makePackageOperations(invocation) {
|
|
2399
|
+
const state = invocation.state;
|
|
2400
|
+
const perform = async (operation, placement) => {
|
|
2401
|
+
if (state.delegatedTerminal !== void 0) throw constructionError(`command '${state.commandId}' called ctx.packages while a child owned the terminal`);
|
|
2402
|
+
if (state.packageOperationRunning) throw constructionError("ctx.packages runs one operation at a time, so two package managers can never write one project at once");
|
|
2403
|
+
state.packageOperationRunning = true;
|
|
2404
|
+
try {
|
|
2405
|
+
return await execute(invocation, operation, placement);
|
|
2406
|
+
} finally {
|
|
2407
|
+
state.packageOperationRunning = false;
|
|
2408
|
+
}
|
|
2409
|
+
};
|
|
2410
|
+
return {
|
|
2411
|
+
install: (request) => perform({
|
|
2412
|
+
form: "install",
|
|
2413
|
+
packages: request.packages,
|
|
2414
|
+
dev: request.dev ?? false
|
|
2415
|
+
}, request),
|
|
2416
|
+
run: (request) => perform({
|
|
2417
|
+
form: "run",
|
|
2418
|
+
package: request.package,
|
|
2419
|
+
args: request.args
|
|
2420
|
+
}, request)
|
|
2421
|
+
};
|
|
2422
|
+
}
|
|
2423
|
+
//#endregion
|
|
1666
2424
|
//#region src/execution/clack-renderer.ts
|
|
1667
2425
|
/**
|
|
1668
2426
|
* Interactive prompt rendering backed by @clack/prompts, driven
|
|
@@ -1760,22 +2518,24 @@ function makeLineReader(stdin, invocation) {
|
|
|
1760
2518
|
const decoder = new TextDecoder();
|
|
1761
2519
|
let buffer = "";
|
|
1762
2520
|
let done = false;
|
|
2521
|
+
const takeBufferedLine = () => {
|
|
2522
|
+
const newline = buffer.indexOf("\n");
|
|
2523
|
+
if (newline === -1) return;
|
|
2524
|
+
const line = buffer.slice(0, newline);
|
|
2525
|
+
buffer = buffer.slice(newline + 1);
|
|
2526
|
+
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
2527
|
+
};
|
|
2528
|
+
const takeFinalLine = () => {
|
|
2529
|
+
if (buffer.length === 0) return;
|
|
2530
|
+
const line = buffer;
|
|
2531
|
+
buffer = "";
|
|
2532
|
+
return line;
|
|
2533
|
+
};
|
|
1763
2534
|
return async () => {
|
|
1764
2535
|
for (;;) {
|
|
1765
|
-
const
|
|
1766
|
-
if (
|
|
1767
|
-
|
|
1768
|
-
buffer = buffer.slice(newline + 1);
|
|
1769
|
-
return line.endsWith("\r") ? line.slice(0, -1) : line;
|
|
1770
|
-
}
|
|
1771
|
-
if (done) {
|
|
1772
|
-
if (buffer.length > 0) {
|
|
1773
|
-
const line = buffer;
|
|
1774
|
-
buffer = "";
|
|
1775
|
-
return line;
|
|
1776
|
-
}
|
|
1777
|
-
return;
|
|
1778
|
-
}
|
|
2536
|
+
const buffered = takeBufferedLine();
|
|
2537
|
+
if (buffered !== void 0) return buffered;
|
|
2538
|
+
if (done) return takeFinalLine();
|
|
1779
2539
|
const next = await iterator.next();
|
|
1780
2540
|
if (next.done === true) {
|
|
1781
2541
|
done = true;
|
|
@@ -1794,6 +2554,12 @@ function promptUnanswerable(question, state) {
|
|
|
1794
2554
|
label: "Run the command from an interactive terminal, or pass a flag that answers the prompt."
|
|
1795
2555
|
}] });
|
|
1796
2556
|
}
|
|
2557
|
+
/** What a prompt resolves to when it cannot be shown: its declared
|
|
2558
|
+
* default, or a halt when it has none. */
|
|
2559
|
+
function answerWithoutAsking(question, fallback, state) {
|
|
2560
|
+
if (fallback === void 0) throw promptUnanswerable(question, state);
|
|
2561
|
+
return fallback;
|
|
2562
|
+
}
|
|
1797
2563
|
function consentUnavailable(question, state, token) {
|
|
1798
2564
|
const situation = state.yes ? `"${question}" requires explicit consent, which --yes cannot grant.` : `"${question}" requires explicit consent, and the session is not interactive.`;
|
|
1799
2565
|
if (token === void 0) return new CliStructuredError("CLI.CONSENT_REQUIRED", situation, { nextActions: [{
|
|
@@ -1911,6 +2677,28 @@ function makePromptSurface(invocation) {
|
|
|
1911
2677
|
if (typeof typed !== "string" || typed.trim() !== token) throw consentTokenMismatch(question, token, String(typed));
|
|
1912
2678
|
return true;
|
|
1913
2679
|
};
|
|
2680
|
+
const askSelect = async (question, options, fallback) => {
|
|
2681
|
+
const raw = await ask(question, [
|
|
2682
|
+
`? ${question}`,
|
|
2683
|
+
...options.map((option) => ` ${option.value === fallback ? "▸" : " "} ${option.value}: ${option.label}`),
|
|
2684
|
+
"> "
|
|
2685
|
+
].join("\n"));
|
|
2686
|
+
if (typeof raw !== "string") throw promptInvalid(question, String(raw));
|
|
2687
|
+
const answer = raw.trim();
|
|
2688
|
+
if (answer === "") {
|
|
2689
|
+
if (fallback === void 0) throw promptInvalid(question, raw);
|
|
2690
|
+
return fallback;
|
|
2691
|
+
}
|
|
2692
|
+
const match = options.find((option) => option.value === answer);
|
|
2693
|
+
if (match === void 0) throw promptInvalid(question, raw);
|
|
2694
|
+
return match.value;
|
|
2695
|
+
};
|
|
2696
|
+
const askText = async (question, fallback) => {
|
|
2697
|
+
const raw = await ask(question, `? ${question}${fallback === void 0 ? "" : ` (${fallback})`} `);
|
|
2698
|
+
if (typeof raw !== "string") throw promptInvalid(question, String(raw));
|
|
2699
|
+
if (raw === "") return fallback ?? "";
|
|
2700
|
+
return raw;
|
|
2701
|
+
};
|
|
1914
2702
|
/** A prompt writes to stderr and reads the engine's stdin — the same
|
|
1915
2703
|
* terminal a live child inherited. Like ctx.present, prompting while
|
|
1916
2704
|
* a child owns the terminal is a construction error. */
|
|
@@ -1920,10 +2708,7 @@ function makePromptSurface(invocation) {
|
|
|
1920
2708
|
const surface = {
|
|
1921
2709
|
confirm: async (question, opts) => {
|
|
1922
2710
|
const fallback = opts?.default;
|
|
1923
|
-
if (state.yes || !state.interactive)
|
|
1924
|
-
if (fallback === void 0) throw promptUnanswerable(question, state);
|
|
1925
|
-
return fallback;
|
|
1926
|
-
}
|
|
2711
|
+
if (state.yes || !state.interactive) return answerWithoutAsking(question, fallback, state);
|
|
1927
2712
|
if (useClack()) return renderWithClack(question, (r) => r.confirm(question, fallback));
|
|
1928
2713
|
let hint = "(y/n)";
|
|
1929
2714
|
if (fallback === true) hint = "(Y/n)";
|
|
@@ -1942,40 +2727,16 @@ function makePromptSurface(invocation) {
|
|
|
1942
2727
|
},
|
|
1943
2728
|
select: async (question, options, opts) => {
|
|
1944
2729
|
const fallback = opts?.default;
|
|
1945
|
-
if (state.yes || !state.interactive)
|
|
1946
|
-
if (fallback === void 0) throw promptUnanswerable(question, state);
|
|
1947
|
-
return fallback;
|
|
1948
|
-
}
|
|
2730
|
+
if (state.yes || !state.interactive) return answerWithoutAsking(question, fallback, state);
|
|
1949
2731
|
if (useClack()) return renderWithClack(question, (r) => r.select(question, options, fallback));
|
|
1950
|
-
|
|
1951
|
-
`? ${question}`,
|
|
1952
|
-
...options.map((option) => ` ${option.value === fallback ? "▸" : " "} ${option.value}: ${option.label}`),
|
|
1953
|
-
"> "
|
|
1954
|
-
].join("\n"));
|
|
1955
|
-
if (typeof raw !== "string") throw promptInvalid(question, String(raw));
|
|
1956
|
-
const answer = raw.trim();
|
|
1957
|
-
if (answer === "") {
|
|
1958
|
-
if (fallback === void 0) throw promptInvalid(question, raw);
|
|
1959
|
-
return fallback;
|
|
1960
|
-
}
|
|
1961
|
-
const match = options.find((option) => option.value === answer);
|
|
1962
|
-
if (match === void 0) throw promptInvalid(question, raw);
|
|
1963
|
-
return match.value;
|
|
2732
|
+
return askSelect(question, options, fallback);
|
|
1964
2733
|
},
|
|
1965
2734
|
text: async (question, opts) => {
|
|
1966
2735
|
const fallback = opts?.default;
|
|
1967
|
-
if (state.yes || !state.interactive)
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
if (useClack()) {
|
|
1972
|
-
const value = await renderWithClack(question, (r) => r.text(question, opts?.placeholder, fallback));
|
|
1973
|
-
return value === "" ? fallback ?? "" : value;
|
|
1974
|
-
}
|
|
1975
|
-
const raw = await ask(question, `? ${question}${fallback === void 0 ? "" : ` (${fallback})`} `);
|
|
1976
|
-
if (typeof raw !== "string") throw promptInvalid(question, String(raw));
|
|
1977
|
-
if (raw === "") return fallback ?? "";
|
|
1978
|
-
return raw;
|
|
2736
|
+
if (state.yes || !state.interactive) return answerWithoutAsking(question, fallback, state);
|
|
2737
|
+
if (!useClack()) return askText(question, fallback);
|
|
2738
|
+
const value = await renderWithClack(question, (r) => r.text(question, opts?.placeholder, fallback));
|
|
2739
|
+
return value === "" ? fallback ?? "" : value;
|
|
1979
2740
|
},
|
|
1980
2741
|
browserWait: async ({ url, message, poll, timeout, interval }) => {
|
|
1981
2742
|
if (!state.interactive) throw browserWaitUnavailable(message, url);
|
|
@@ -2038,6 +2799,7 @@ function makeSpawn(invocation, def) {
|
|
|
2038
2799
|
if (!def.maySpawn) throw constructionError(`command '${state.commandId}' called ctx.spawn without declaring maySpawn`);
|
|
2039
2800
|
if (state.delegatedTerminal !== void 0) throw constructionError(`command '${state.commandId}' called ctx.spawn while a child was still live (one live child per run)`);
|
|
2040
2801
|
if (state.activePrompts > 0) throw constructionError(`command '${state.commandId}' called ctx.spawn while a prompt owned the terminal`);
|
|
2802
|
+
if (state.packageOperationRunning) throw constructionError(`command '${state.commandId}' called ctx.spawn while a package operation was still running`);
|
|
2041
2803
|
const spawnChild = invocation.runtime.spawn;
|
|
2042
2804
|
if (spawnChild === void 0) throw new Error("@prisma/cli-engine: the command declares maySpawn but the Runtime supplies no spawn adapter");
|
|
2043
2805
|
const terminal = {
|
|
@@ -2233,7 +2995,7 @@ function materializePresentation(state, ui, presentations) {
|
|
|
2233
2995
|
next: presentations.next?.() ?? []
|
|
2234
2996
|
};
|
|
2235
2997
|
}
|
|
2236
|
-
function makeContext(invocation, def, config,
|
|
2998
|
+
function makeContext(invocation, def, config, capabilities) {
|
|
2237
2999
|
const state = invocation.state;
|
|
2238
3000
|
const ui = makeUi(state.colorEnabled, invocation.runtime.stderr);
|
|
2239
3001
|
const present = (outcome, presentations) => {
|
|
@@ -2266,9 +3028,17 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
2266
3028
|
signal: invocation.signal,
|
|
2267
3029
|
cwd: invocation.runtime.cwd,
|
|
2268
3030
|
env: invocation.runtime.env,
|
|
2269
|
-
|
|
3031
|
+
isCI: resolveIsCI(invocation.runtime),
|
|
3032
|
+
requireDependency: async (specifier) => {
|
|
3033
|
+
if (dependencyResolvable(specifier, invocation.runtime.cwd)) return okVoid();
|
|
3034
|
+
return notOk(missingDependencyError(specifier, await resolvePackageManager({
|
|
3035
|
+
cwd: invocation.runtime.cwd,
|
|
3036
|
+
env: invocation.runtime.env,
|
|
3037
|
+
host: invocation.runtime.packageManager
|
|
3038
|
+
})));
|
|
3039
|
+
}
|
|
2270
3040
|
};
|
|
2271
|
-
if (managesCredentials) Object.defineProperty(context, "credentialManager", {
|
|
3041
|
+
if (capabilities.managesCredentials) Object.defineProperty(context, "credentialManager", {
|
|
2272
3042
|
enumerable: true,
|
|
2273
3043
|
get() {
|
|
2274
3044
|
const manager = invocation.runtime.credentialManager;
|
|
@@ -2276,6 +3046,10 @@ function makeContext(invocation, def, config, managesCredentials) {
|
|
|
2276
3046
|
return manager;
|
|
2277
3047
|
}
|
|
2278
3048
|
});
|
|
3049
|
+
if (capabilities.installsPackages) Object.defineProperty(context, "packages", {
|
|
3050
|
+
enumerable: true,
|
|
3051
|
+
value: makePackageOperations(invocation)
|
|
3052
|
+
});
|
|
2279
3053
|
return context;
|
|
2280
3054
|
}
|
|
2281
3055
|
//#endregion
|
|
@@ -2303,13 +3077,40 @@ function aliasMap(def) {
|
|
|
2303
3077
|
return aliases;
|
|
2304
3078
|
}
|
|
2305
3079
|
/**
|
|
3080
|
+
* The key a long token marks. Long tokens match in both the kebab and
|
|
3081
|
+
* camel spellings (the scanner allows kebab-for-camel), and a
|
|
3082
|
+
* `--no-<flag>` token marks its base flag. Values are irrelevant here:
|
|
3083
|
+
* `--name=value` is cut at the `=` before matching.
|
|
3084
|
+
*/
|
|
3085
|
+
function longFlagKey(token, declared) {
|
|
3086
|
+
const equals = token.indexOf("=");
|
|
3087
|
+
const raw = token.slice(2, equals === -1 ? void 0 : equals);
|
|
3088
|
+
const exact = camelCase(raw);
|
|
3089
|
+
if (declared.has(exact)) return exact;
|
|
3090
|
+
if (!raw.startsWith("no-")) return;
|
|
3091
|
+
const negated = camelCase(raw.slice(3));
|
|
3092
|
+
return declared.has(negated) ? negated : void 0;
|
|
3093
|
+
}
|
|
3094
|
+
function shortFlagKeys(token, declared, aliases) {
|
|
3095
|
+
const keys = [];
|
|
3096
|
+
for (const char of token.slice(1)) {
|
|
3097
|
+
const key = aliases.get(char);
|
|
3098
|
+
if (key !== void 0 && declared.has(key)) keys.push(key);
|
|
3099
|
+
}
|
|
3100
|
+
return keys;
|
|
3101
|
+
}
|
|
3102
|
+
function tokenFlagKeys(token, declared, aliases) {
|
|
3103
|
+
if (token.startsWith("--")) {
|
|
3104
|
+
const key = longFlagKey(token, declared);
|
|
3105
|
+
return key === void 0 ? [] : [key];
|
|
3106
|
+
}
|
|
3107
|
+
if (token.startsWith("-") && token.length > 1) return shortFlagKeys(token, declared, aliases);
|
|
3108
|
+
return [];
|
|
3109
|
+
}
|
|
3110
|
+
/**
|
|
2306
3111
|
* The flag keys explicitly present on argv, resolved against the
|
|
2307
|
-
* command's declared keys and aliases.
|
|
2308
|
-
*
|
|
2309
|
-
* `--no-<flag>` token marks its base flag, and single-dash tokens are
|
|
2310
|
-
* resolved character-by-character through the alias map. Everything
|
|
2311
|
-
* after a bare `--` is positional and never consulted. Values are
|
|
2312
|
-
* irrelevant here: `--name=value` is cut at the `=` before matching.
|
|
3112
|
+
* command's declared keys and aliases. Everything after a bare `--` is
|
|
3113
|
+
* positional and never consulted.
|
|
2313
3114
|
*/
|
|
2314
3115
|
function explicitFlagKeys(def, declared, argv) {
|
|
2315
3116
|
const declaredSet = new Set(declared);
|
|
@@ -2317,24 +3118,7 @@ function explicitFlagKeys(def, declared, argv) {
|
|
|
2317
3118
|
const explicit = /* @__PURE__ */ new Set();
|
|
2318
3119
|
for (const token of argv) {
|
|
2319
3120
|
if (token === "--") break;
|
|
2320
|
-
|
|
2321
|
-
const equals = token.indexOf("=");
|
|
2322
|
-
const raw = token.slice(2, equals === -1 ? void 0 : equals);
|
|
2323
|
-
const exact = camelCase(raw);
|
|
2324
|
-
if (declaredSet.has(exact)) {
|
|
2325
|
-
explicit.add(exact);
|
|
2326
|
-
continue;
|
|
2327
|
-
}
|
|
2328
|
-
if (raw.startsWith("no-")) {
|
|
2329
|
-
const negated = camelCase(raw.slice(3));
|
|
2330
|
-
if (declaredSet.has(negated)) explicit.add(negated);
|
|
2331
|
-
}
|
|
2332
|
-
continue;
|
|
2333
|
-
}
|
|
2334
|
-
if (token.startsWith("-") && token.length > 1) for (const char of token.slice(1)) {
|
|
2335
|
-
const key = aliases.get(char);
|
|
2336
|
-
if (key !== void 0 && declaredSet.has(key)) explicit.add(key);
|
|
2337
|
-
}
|
|
3121
|
+
for (const key of tokenFlagKeys(token, declaredSet, aliases)) explicit.add(key);
|
|
2338
3122
|
}
|
|
2339
3123
|
return explicit;
|
|
2340
3124
|
}
|
|
@@ -2580,6 +3364,15 @@ function diagnosticOf(error) {
|
|
|
2580
3364
|
const { ok: _ok, ...diagnostic } = error.toEnvelope();
|
|
2581
3365
|
return diagnostic;
|
|
2582
3366
|
}
|
|
3367
|
+
/** The list is typed, but nothing at runtime has checked it: an error
|
|
3368
|
+
* built by another copy of the engine passes `CliStructuredError.is`
|
|
3369
|
+
* on its name, its code and its `toEnvelope` alone, and a handler's
|
|
3370
|
+
* `notOk` failure is checked by nothing at all. A value that is not a
|
|
3371
|
+
* list settles as no accompanying findings rather than reaching the
|
|
3372
|
+
* human renderer and the json envelope as garbage. */
|
|
3373
|
+
function accompanyingFindings(diagnostics) {
|
|
3374
|
+
return Array.isArray(diagnostics) ? diagnostics : [];
|
|
3375
|
+
}
|
|
2583
3376
|
function settleErrored(invocation, error, diagnostics = []) {
|
|
2584
3377
|
const state = invocation.state;
|
|
2585
3378
|
state.settledExitCode = error.code === "CLI.PROMPT_CANCELLED" ? 3 : 2;
|
|
@@ -2587,7 +3380,7 @@ function settleErrored(invocation, error, diagnostics = []) {
|
|
|
2587
3380
|
ok: false,
|
|
2588
3381
|
commandId: state.commandId,
|
|
2589
3382
|
error: diagnosticOf(error),
|
|
2590
|
-
diagnostics,
|
|
3383
|
+
diagnostics: accompanyingFindings(diagnostics),
|
|
2591
3384
|
nextActions: error.nextActions
|
|
2592
3385
|
});
|
|
2593
3386
|
}
|
|
@@ -2619,7 +3412,7 @@ function isAbortCause(cause, signal) {
|
|
|
2619
3412
|
}
|
|
2620
3413
|
function settleThrown(invocation, cause) {
|
|
2621
3414
|
if (isAbortCause(cause, invocation.signal)) settleAborted(invocation);
|
|
2622
|
-
else if (CliStructuredError.is(cause)) settleErrored(invocation, cause);
|
|
3415
|
+
else if (CliStructuredError.is(cause)) settleErrored(invocation, cause, cause.diagnostics);
|
|
2623
3416
|
else settleBug(invocation, cause);
|
|
2624
3417
|
}
|
|
2625
3418
|
function settleAborted(invocation) {
|
|
@@ -2881,6 +3674,7 @@ var EngineImpl = class {
|
|
|
2881
3674
|
delegatedTerminal: void 0,
|
|
2882
3675
|
lastChild: void 0,
|
|
2883
3676
|
activePrompts: 0,
|
|
3677
|
+
packageOperationRunning: false,
|
|
2884
3678
|
deliveredSignal: void 0,
|
|
2885
3679
|
pendingForceExit: void 0,
|
|
2886
3680
|
spawnCredential: void 0
|
|
@@ -3005,25 +3799,71 @@ var EngineImpl = class {
|
|
|
3005
3799
|
hooks.onSettled(summary);
|
|
3006
3800
|
} catch {}
|
|
3007
3801
|
}
|
|
3802
|
+
/** The refusals a maySpawn command can hit before anything runs: a
|
|
3803
|
+
* child's terminal output cannot be framed as a json stream, and a
|
|
3804
|
+
* host that mounts the command without a spawn adapter is
|
|
3805
|
+
* misconfigured. Returns whether the run was settled here. */
|
|
3806
|
+
refuseUnspawnable(invocation, entry) {
|
|
3807
|
+
const state = invocation.state;
|
|
3808
|
+
if (!entry.def.maySpawn) return false;
|
|
3809
|
+
if (formatFlagGiven(state.argv) === "json") {
|
|
3810
|
+
state.format = "human";
|
|
3811
|
+
settleErrored(invocation, jsonUnsupportedError(entry.id));
|
|
3812
|
+
return true;
|
|
3813
|
+
}
|
|
3814
|
+
if (invocation.runtime.spawn === void 0) {
|
|
3815
|
+
state.format = "human";
|
|
3816
|
+
settleBug(invocation, /* @__PURE__ */ new Error(`@prisma/cli-engine: command '${entry.id}' declares maySpawn but the Runtime supplies no spawn adapter`));
|
|
3817
|
+
return true;
|
|
3818
|
+
}
|
|
3819
|
+
return false;
|
|
3820
|
+
}
|
|
3821
|
+
/** Every mounted handler settles the same way: an abandoned child
|
|
3822
|
+
* wins over the handler's own outcome, a failure settles errored, a
|
|
3823
|
+
* child-status value settles as that child's exit, and any other
|
|
3824
|
+
* value is the command's own completion. */
|
|
3825
|
+
async settleHandlerOutcome(invocation, entry, runHandler, settleCompletion) {
|
|
3826
|
+
const state = invocation.state;
|
|
3827
|
+
try {
|
|
3828
|
+
const result = await runHandler();
|
|
3829
|
+
if (await this.settleAbandonedChild(invocation, false)) return;
|
|
3830
|
+
state.resolved = true;
|
|
3831
|
+
if (!result.ok) settleErrored(invocation, result.failure, result.failure.diagnostics);
|
|
3832
|
+
else if (isChildStatusSettlement(result.value)) settleChildStatus(invocation, entry.def, result.value);
|
|
3833
|
+
else settleCompletion(result.value);
|
|
3834
|
+
} catch (cause) {
|
|
3835
|
+
if (await this.settleAbandonedChild(invocation, true, cause)) return;
|
|
3836
|
+
state.resolved = true;
|
|
3837
|
+
settleThrown(invocation, cause);
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
/** The telemetry fire, at command start: once per run, from the
|
|
3841
|
+
* parse-time snapshot, before the handler and before any command
|
|
3842
|
+
* output. A CLI that declared no telemetry block reports nothing —
|
|
3843
|
+
* no config read, no disclosure, no mint, no seam call. Runs that
|
|
3844
|
+
* never mount a command never reach here and so never report. */
|
|
3845
|
+
fireTelemetry(invocation) {
|
|
3846
|
+
const { snapshot } = invocation.state;
|
|
3847
|
+
if (this.spec.telemetry === void 0 || snapshot === void 0) return;
|
|
3848
|
+
reportCommandStart({
|
|
3849
|
+
host: invocation.runtime,
|
|
3850
|
+
telemetry: this.spec.telemetry,
|
|
3851
|
+
name: this.spec.name,
|
|
3852
|
+
version: this.spec.version,
|
|
3853
|
+
snapshot
|
|
3854
|
+
});
|
|
3855
|
+
}
|
|
3008
3856
|
async executeMounted(invocation, entry, rawFlags, values) {
|
|
3009
3857
|
const state = invocation.state;
|
|
3010
3858
|
state.commandId = entry.id;
|
|
3011
3859
|
state.docsBaseUrl = entry.docsBaseUrl;
|
|
3012
3860
|
state.snapshot = buildCommandSnapshot(entry.id, entry.def, state.argv, values);
|
|
3861
|
+
this.fireTelemetry(invocation);
|
|
3013
3862
|
if (entry.def.kind === "server-command") {
|
|
3014
3863
|
await this.executeServer(invocation, entry, rawFlags);
|
|
3015
3864
|
return;
|
|
3016
3865
|
}
|
|
3017
|
-
if (
|
|
3018
|
-
state.format = "human";
|
|
3019
|
-
settleErrored(invocation, jsonUnsupportedError(entry.id));
|
|
3020
|
-
return;
|
|
3021
|
-
}
|
|
3022
|
-
if (entry.def.maySpawn && invocation.runtime.spawn === void 0) {
|
|
3023
|
-
state.format = "human";
|
|
3024
|
-
settleBug(invocation, /* @__PURE__ */ new Error(`@prisma/cli-engine: command '${entry.id}' declares maySpawn but the Runtime supplies no spawn adapter`));
|
|
3025
|
-
return;
|
|
3026
|
-
}
|
|
3866
|
+
if (this.refuseUnspawnable(invocation, entry)) return;
|
|
3027
3867
|
let needsOutcome;
|
|
3028
3868
|
try {
|
|
3029
3869
|
applySharedFlags(state, rawFlags, invocation.runtime);
|
|
@@ -3047,34 +3887,12 @@ var EngineImpl = class {
|
|
|
3047
3887
|
flags: declaredFlags(entry.def, rawFlags),
|
|
3048
3888
|
positionals: distributePositionals(entry.def, values)
|
|
3049
3889
|
};
|
|
3050
|
-
const ctx = makeContext(invocation, entry.def, needsOutcome.config, entry.def
|
|
3890
|
+
const ctx = makeContext(invocation, entry.def, needsOutcome.config, declaredCapabilities(entry.def));
|
|
3051
3891
|
if (entry.def.kind === "session-command") {
|
|
3052
|
-
|
|
3053
|
-
const result = await handler(args, ctx);
|
|
3054
|
-
if (await this.settleAbandonedChild(invocation, false)) return;
|
|
3055
|
-
state.resolved = true;
|
|
3056
|
-
if (!result.ok) settleErrored(invocation, result.failure);
|
|
3057
|
-
else if (isChildStatusSettlement(result.value)) settleChildStatus(invocation, entry.def, result.value);
|
|
3058
|
-
else settleSessionCompleted(invocation);
|
|
3059
|
-
} catch (cause) {
|
|
3060
|
-
if (await this.settleAbandonedChild(invocation, true, cause)) return;
|
|
3061
|
-
state.resolved = true;
|
|
3062
|
-
settleThrown(invocation, cause);
|
|
3063
|
-
}
|
|
3892
|
+
await this.settleHandlerOutcome(invocation, entry, () => handler(args, ctx), () => settleSessionCompleted(invocation));
|
|
3064
3893
|
return;
|
|
3065
3894
|
}
|
|
3066
|
-
|
|
3067
|
-
const result = await handler(args, ctx);
|
|
3068
|
-
if (await this.settleAbandonedChild(invocation, false)) return;
|
|
3069
|
-
state.resolved = true;
|
|
3070
|
-
if (!result.ok) settleErrored(invocation, result.failure);
|
|
3071
|
-
else if (isChildStatusSettlement(result.value)) settleChildStatus(invocation, entry.def, result.value);
|
|
3072
|
-
else settleCompleted(invocation, entry.def, result.value);
|
|
3073
|
-
} catch (cause) {
|
|
3074
|
-
if (await this.settleAbandonedChild(invocation, true, cause)) return;
|
|
3075
|
-
state.resolved = true;
|
|
3076
|
-
settleThrown(invocation, cause);
|
|
3077
|
-
}
|
|
3895
|
+
await this.settleHandlerOutcome(invocation, entry, () => handler(args, ctx), (presented) => settleCompleted(invocation, entry.def, presented));
|
|
3078
3896
|
}
|
|
3079
3897
|
/** The handler resolved or threw with its child still live. The
|
|
3080
3898
|
* engine ends that child — SIGTERM, the ruled grace period, then
|
|
@@ -3168,6 +3986,16 @@ function jsonUnsupportedError(commandId) {
|
|
|
3168
3986
|
}]
|
|
3169
3987
|
});
|
|
3170
3988
|
}
|
|
3989
|
+
function declaredCapabilities(def) {
|
|
3990
|
+
if (def.kind !== "result-command") return {
|
|
3991
|
+
managesCredentials: false,
|
|
3992
|
+
installsPackages: false
|
|
3993
|
+
};
|
|
3994
|
+
return {
|
|
3995
|
+
managesCredentials: def.managesCredentials,
|
|
3996
|
+
installsPackages: def.installsPackages
|
|
3997
|
+
};
|
|
3998
|
+
}
|
|
3171
3999
|
function declaredFlags(def, rawFlags) {
|
|
3172
4000
|
const flags = {};
|
|
3173
4001
|
for (const key of Object.keys(def.args.flags)) flags[key] = rawFlags[key];
|
|
@@ -3252,4 +4080,4 @@ function claimedIdentity(token) {
|
|
|
3252
4080
|
};
|
|
3253
4081
|
}
|
|
3254
4082
|
//#endregion
|
|
3255
|
-
export { PRESENTED as _, CONFIG_FILE_NAME as a,
|
|
4083
|
+
export { flag as C, exitWithChildStatus as S, PRESENTED as _, CONFIG_FILE_NAME as a, writeUserConfig as b, PRISMA_CONFIG_VERSION as c, authServiceError as d, credentialRejectedError as f, noSessionForWorkspaceError as g, emptyServiceTokenError as h, buildEngine as i, SERVICE_TOKEN_ENV_VAR as l, credentialsRequiredError as m, claimedIdentity as n, defineConfig as o, credentialWorkspaceMismatchError as p, credentialWorkspaceId as r, loadConfig as s, claimedExpiresAt as t, WORKSPACE_ID_ENV_VAR as u, readUserConfig as v, positional as w, resolveGating as x, userConfigPath as y };
|