@cnc-tools/storm 0.14.0 → 0.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/bin/storm.js +10 -2
  2. package/dist/build-info.js +1 -1
  3. package/dist/chunks/{chunk-27P2QSIM.js → chunk-3HBPNQ4Y.js} +1 -1
  4. package/dist/chunks/{chunk-HOKDKP5A.js → chunk-E3QU74NX.js} +1 -1
  5. package/dist/chunks/{chunk-RKONDLPS.js → chunk-GJOEPJJL.js} +2 -2
  6. package/dist/chunks/{chunk-XPCUINWS.js → chunk-HDL4WKIB.js} +1 -1
  7. package/dist/chunks/{chunk-IVRRGGCD.js → chunk-HP54VHGY.js} +4 -4
  8. package/dist/chunks/{chunk-5ED3IDUJ.js → chunk-I7AN3DIJ.js} +25 -4
  9. package/dist/chunks/{chunk-YBPTMJUM.js → chunk-LUOHJ3LB.js} +9 -9
  10. package/dist/chunks/{chunk-ZH5R7W4A.js → chunk-RUPD4TLT.js} +1 -1
  11. package/dist/chunks/{chunk-BFLYGMG3.js → chunk-TVMEKVOW.js} +4 -4
  12. package/dist/chunks/{chunk-Z5OXOZD3.js → chunk-UUBZTGLV.js} +1 -1
  13. package/dist/chunks/{chunk-5TMHYH7G.js → chunk-VH2POPW5.js} +4 -2
  14. package/dist/chunks/{chunk-QBR5VHJ7.js → chunk-XZCDA5PE.js} +1 -1
  15. package/dist/chunks/{live-app-FBVWUUMT.js → live-app-SZGEILCQ.js} +13 -7
  16. package/dist/commands/exec/command.js +10 -10
  17. package/dist/commands/exec/exec-words.js +1 -1
  18. package/dist/commands/exec/metadata.js +1 -1
  19. package/dist/commands/playwright/command.js +11 -11
  20. package/dist/commands/runs/list/command.js +5 -5
  21. package/dist/commands/runs/logs/command.js +5 -5
  22. package/dist/commands/runs/show/command.js +8 -8
  23. package/dist/commands/snapshots/build/command.js +9 -9
  24. package/dist/commands/snapshots/list/command.js +6 -6
  25. package/dist/commands/vitest/command.js +11 -11
  26. package/dist/context.d.ts +1 -0
  27. package/dist/context.js +4 -1
  28. package/dist/core/payload.d.ts +5 -3
  29. package/dist/core/payload.js +8 -3
  30. package/dist/extensions/testserver/commands/pool/create/command.js +1 -1
  31. package/dist/extensions/testserver/vercel-cli/arguments.d.ts +10 -4
  32. package/dist/extensions/testserver/vercel-cli/arguments.js +17 -6
  33. package/dist/extensions/testserver/vercel-cli/environment.d.ts +12 -1
  34. package/dist/extensions/testserver/vercel-cli/environment.js +35 -5
  35. package/dist/extensions/testserver/vercel-cli/invoker.d.ts +28 -13
  36. package/dist/extensions/testserver/vercel-cli/invoker.js +81 -67
  37. package/dist/extensions/testserver/vercel-cli/live/process-gateway.js +4 -10
  38. package/dist/extensions/testserver/vercel-cli/session-id.js +5 -4
  39. package/dist/extensions/testserver/vitest/diagnostics.d.ts +10 -9
  40. package/dist/extensions/testserver/vitest/diagnostics.js +17 -16
  41. package/dist/extensions/testserver/vitest/fixtures.d.ts +6 -2
  42. package/dist/extensions/testserver/vitest/fixtures.js +13 -10
  43. package/dist/extensions/testserver/vitest/types.d.ts +9 -2
  44. package/dist/live-app.d.ts +3 -1
  45. package/dist/live-app.js +5 -2
  46. package/dist/runner/gateways.d.ts +10 -2
  47. package/dist/runner/index.d.ts +1 -1
  48. package/dist/runner/live/sandbox-gateway.js +16 -2
  49. package/dist/runner/live/terminal.d.ts +15 -3
  50. package/dist/runner/live/terminal.js +25 -3
  51. package/dist/runner/recipe.d.ts +3 -2
  52. package/dist/runner/sandboxed-command.d.ts +5 -5
  53. package/dist/runner/sandboxed-command.js +7 -5
  54. package/package.json +1 -1
@@ -4,29 +4,29 @@ import {
4
4
  } from "../../../chunks/chunk-T6AZIDZD.js";
5
5
  import {
6
6
  redactor
7
- } from "../../../chunks/chunk-27P2QSIM.js";
7
+ } from "../../../chunks/chunk-3HBPNQ4Y.js";
8
8
  import {
9
9
  REJECTIONS_SHOWN,
10
10
  REJECTION_REASONS,
11
11
  builtAtText,
12
12
  rejectionText
13
- } from "../../../chunks/chunk-XPCUINWS.js";
13
+ } from "../../../chunks/chunk-HDL4WKIB.js";
14
14
  import {
15
15
  RESOURCES
16
- } from "../../../chunks/chunk-Z5OXOZD3.js";
16
+ } from "../../../chunks/chunk-UUBZTGLV.js";
17
17
  import "../../../chunks/chunk-UC6DULWY.js";
18
18
  import "../../../chunks/chunk-BRUIATTR.js";
19
19
  import {
20
20
  short
21
- } from "../../../chunks/chunk-QBR5VHJ7.js";
22
- import "../../../chunks/chunk-5TMHYH7G.js";
21
+ } from "../../../chunks/chunk-XZCDA5PE.js";
22
+ import "../../../chunks/chunk-VH2POPW5.js";
23
23
  import {
24
24
  configErrors,
25
25
  declaredSecretValues,
26
26
  inspectSnapshotCache,
27
27
  invalidConfig,
28
28
  loadSettingsFile
29
- } from "../../../chunks/chunk-5ED3IDUJ.js";
29
+ } from "../../../chunks/chunk-I7AN3DIJ.js";
30
30
  import "../../../chunks/chunk-RA4L2ACU.js";
31
31
  import "../../../chunks/chunk-GQIL3AHY.js";
32
32
  import "../../../chunks/chunk-GSC6SRTW.js";
@@ -1,22 +1,22 @@
1
1
  import {
2
2
  defineRunCommand
3
- } from "../../chunks/chunk-IVRRGGCD.js";
4
- import "../../chunks/chunk-HOKDKP5A.js";
5
- import "../../chunks/chunk-YBPTMJUM.js";
3
+ } from "../../chunks/chunk-HP54VHGY.js";
4
+ import "../../chunks/chunk-E3QU74NX.js";
5
+ import "../../chunks/chunk-LUOHJ3LB.js";
6
6
  import "../../chunks/chunk-I5GZLOLQ.js";
7
- import "../../chunks/chunk-27P2QSIM.js";
8
- import "../../chunks/chunk-BFLYGMG3.js";
9
- import "../../chunks/chunk-XPCUINWS.js";
7
+ import "../../chunks/chunk-3HBPNQ4Y.js";
8
+ import "../../chunks/chunk-TVMEKVOW.js";
9
+ import "../../chunks/chunk-HDL4WKIB.js";
10
10
  import {
11
11
  driverNamed
12
- } from "../../chunks/chunk-Z5OXOZD3.js";
12
+ } from "../../chunks/chunk-UUBZTGLV.js";
13
13
  import "../../chunks/chunk-UC6DULWY.js";
14
14
  import "../../chunks/chunk-BRUIATTR.js";
15
15
  import "../../chunks/chunk-NMVODY3P.js";
16
- import "../../chunks/chunk-RKONDLPS.js";
17
- import "../../chunks/chunk-QBR5VHJ7.js";
18
- import "../../chunks/chunk-5TMHYH7G.js";
19
- import "../../chunks/chunk-5ED3IDUJ.js";
16
+ import "../../chunks/chunk-GJOEPJJL.js";
17
+ import "../../chunks/chunk-XZCDA5PE.js";
18
+ import "../../chunks/chunk-VH2POPW5.js";
19
+ import "../../chunks/chunk-I7AN3DIJ.js";
20
20
  import "../../chunks/chunk-RA4L2ACU.js";
21
21
  import "../../chunks/chunk-BW2ADH7U.js";
22
22
  import "../../chunks/chunk-GQIL3AHY.js";
package/dist/context.d.ts CHANGED
@@ -119,4 +119,5 @@ export declare function localServices(launcher: {
119
119
  */
120
120
  export declare function liveContext(options: {
121
121
  readonly env: Readonly<Record<string, string | undefined>>;
122
+ readonly noColor?: boolean;
122
123
  }): StormContext;
package/dist/context.js CHANGED
@@ -47,7 +47,10 @@ export function liveContext(options) {
47
47
  ? liveRunnerSnapshotCacheGateway({ directory: snapshots.directory })
48
48
  : unavailableRunnerSnapshotCacheGateway(stateDirectoryPattern(RUNNER_SNAPSHOTS_SUBPATH), snapshots.reason),
49
49
  runnerSandboxes: liveRunnerSandboxGateway(),
50
- runnerTerminal: liveRunnerTerminal({ env: options.env }),
50
+ runnerTerminal: liveRunnerTerminal({
51
+ env: options.env,
52
+ ...(options.noColor === undefined ? {} : { noColor: options.noColor }),
53
+ }),
51
54
  runDirectories: runs.ok
52
55
  ? liveRunDirectoryGateway({ directory: runs.directory })
53
56
  : unavailableRunDirectoryGateway(stateDirectoryPattern(RUNS_SUBPATH), runs.reason),
@@ -1,3 +1,4 @@
1
+ import type { RunnerTerminalColor } from "../runner/index.ts";
1
2
  import { type RunPayloadInstance, type RunPayloadJson } from "../sdk/run/launcher.ts";
2
3
  /**
3
4
  * The run payload for a run with `resources`, what each acquired resource instance hands the command, under its
@@ -19,7 +20,8 @@ export declare function runPayload<R extends {
19
20
  export declare function commandEnvironment(env: Readonly<Record<string, string | undefined>>, payload: RunPayloadJson): Readonly<Record<string, string>>;
20
21
  /**
21
22
  * `env` with color set for a spawned command whose stdout and stderr are pipes, so it can't tell whether a
22
- * terminal shows color: `FORCE_COLOR=1` when the terminal storm writes its output to shows color, else `NO_COLOR=1`. An
23
- * `env` that sets either already is left as it is.
23
+ * terminal shows color: `FORCE_COLOR=1` when the launcher terminal asks for color (`"on"`), `NO_COLOR=1` when the
24
+ * launcher explicitly opted out (`"off"`), and neither on a plain non-TTY launcher (`"auto"`). An `env` that sets
25
+ * either already is left as it is.
24
26
  */
25
- export declare function colorEnvironment(env: Readonly<Record<string, string | undefined>>, color: boolean): Readonly<Record<string, string | undefined>>;
27
+ export declare function colorEnvironment(env: Readonly<Record<string, string | undefined>>, color: RunnerTerminalColor): Readonly<Record<string, string | undefined>>;
@@ -24,11 +24,16 @@ export function commandEnvironment(env, payload) {
24
24
  }
25
25
  /**
26
26
  * `env` with color set for a spawned command whose stdout and stderr are pipes, so it can't tell whether a
27
- * terminal shows color: `FORCE_COLOR=1` when the terminal storm writes its output to shows color, else `NO_COLOR=1`. An
28
- * `env` that sets either already is left as it is.
27
+ * terminal shows color: `FORCE_COLOR=1` when the launcher terminal asks for color (`"on"`), `NO_COLOR=1` when the
28
+ * launcher explicitly opted out (`"off"`), and neither on a plain non-TTY launcher (`"auto"`). An `env` that sets
29
+ * either already is left as it is.
29
30
  */
30
31
  export function colorEnvironment(env, color) {
31
32
  if (env["FORCE_COLOR"] !== undefined || env["NO_COLOR"] !== undefined)
32
33
  return env;
33
- return { ...env, ...(color ? { FORCE_COLOR: "1" } : { NO_COLOR: "1" }) };
34
+ if (color === "on")
35
+ return { ...env, FORCE_COLOR: "1" };
36
+ if (color === "off")
37
+ return { ...env, NO_COLOR: "1" };
38
+ return env;
34
39
  }
@@ -24,7 +24,7 @@ import {
24
24
  configErrors,
25
25
  credentialErrors,
26
26
  credentialSourceErrors
27
- } from "../../../../../chunks/chunk-5ED3IDUJ.js";
27
+ } from "../../../../../chunks/chunk-I7AN3DIJ.js";
28
28
  import "../../../../../chunks/chunk-RA4L2ACU.js";
29
29
  import {
30
30
  testserverCommands
@@ -1,9 +1,15 @@
1
1
  import type { Redactor } from "./redaction.ts";
2
2
  /**
3
- * An invocation's `vercel` arguments: `args`, then the hidden `--api` flag pointing the CLI at the proxy, `--token`
4
- * when a token is given, `--global-config`, and `--scope` when one is given. Throws a `TypeError` when `args` already
5
- * passes a flag the invoker adds, `--token` included when no token is given, or a scope flag along with `scope`: the
6
- * invoker never sends a flag twice, and owns how an invocation authenticates.
3
+ * `args` with `extra` inserted immediately before the first `"--"`, or appended at the end when `args` has no `"--"`,
4
+ * so flags the invoker adds are never turned into positional arguments after `"--"`.
5
+ */
6
+ export declare function insertBeforeDoubleDash(args: readonly string[], extra: readonly string[]): readonly string[];
7
+ /**
8
+ * An invocation's `vercel` arguments: `args`, with the hidden `--api` flag pointing the CLI at the proxy, `--token`
9
+ * when a token is given, `--global-config`, and `--scope` when one is given inserted immediately before the first
10
+ * `"--"` (or appended at the end when `args` has no `"--"`). Throws a `TypeError` when `args` already passes a flag
11
+ * the invoker adds, `--token` included when no token is given, or a scope flag along with `scope`: the invoker never
12
+ * sends a flag twice, and owns how an invocation authenticates.
7
13
  */
8
14
  export declare function vercelArguments(options: {
9
15
  readonly args: readonly string[];
@@ -6,10 +6,21 @@ const SCOPE_FLAGS = ["--scope", "-S", "--team"];
6
6
  /** Flags whose next argument is a token. */
7
7
  const TOKEN_FLAGS = new Set(["--token", "-t"]);
8
8
  /**
9
- * An invocation's `vercel` arguments: `args`, then the hidden `--api` flag pointing the CLI at the proxy, `--token`
10
- * when a token is given, `--global-config`, and `--scope` when one is given. Throws a `TypeError` when `args` already
11
- * passes a flag the invoker adds, `--token` included when no token is given, or a scope flag along with `scope`: the
12
- * invoker never sends a flag twice, and owns how an invocation authenticates.
9
+ * `args` with `extra` inserted immediately before the first `"--"`, or appended at the end when `args` has no `"--"`,
10
+ * so flags the invoker adds are never turned into positional arguments after `"--"`.
11
+ */
12
+ export function insertBeforeDoubleDash(args, extra) {
13
+ const separator = args.indexOf("--");
14
+ if (separator === -1)
15
+ return [...args, ...extra];
16
+ return [...args.slice(0, separator), ...extra, ...args.slice(separator)];
17
+ }
18
+ /**
19
+ * An invocation's `vercel` arguments: `args`, with the hidden `--api` flag pointing the CLI at the proxy, `--token`
20
+ * when a token is given, `--global-config`, and `--scope` when one is given inserted immediately before the first
21
+ * `"--"` (or appended at the end when `args` has no `"--"`). Throws a `TypeError` when `args` already passes a flag
22
+ * the invoker adds, `--token` included when no token is given, or a scope flag along with `scope`: the invoker never
23
+ * sends a flag twice, and owns how an invocation authenticates.
13
24
  */
14
25
  export function vercelArguments(options) {
15
26
  const given = flagsIn(options.args);
@@ -23,8 +34,7 @@ export function vercelArguments(options) {
23
34
  throw new TypeError(`vercel-cli: pass the scope either as the scope option or as ${scoped.join(", ")}, not both`);
24
35
  }
25
36
  }
26
- return [
27
- ...options.args,
37
+ const invokerFlags = [
28
38
  "--api",
29
39
  options.proxyUrl,
30
40
  ...(options.token === undefined ? [] : ["--token", options.token]),
@@ -32,6 +42,7 @@ export function vercelArguments(options) {
32
42
  options.globalConfigDir,
33
43
  ...(options.scope === undefined ? [] : ["--scope", options.scope]),
34
44
  ];
45
+ return insertBeforeDoubleDash(options.args, invokerFlags);
35
46
  }
36
47
  /** Whether `args` names the scope with `--scope`, `-S` or `--team`, alone or with `=`, before any `--`. */
37
48
  export function passesScopeFlag(args) {
@@ -13,7 +13,18 @@ export declare const TERMINAL_COLUMNS = 400;
13
13
  */
14
14
  export declare const RESERVED_VARIABLES: ReadonlySet<string>;
15
15
  /**
16
- * An invocation's whole environment: `PATH`, `SystemRoot` and `TEMP` from `host` when set, `HOME`, the fixed
16
+ * Throws a `TypeError` when `env` names any variable in `RESERVED_VARIABLES`, even when its value is `null`.
17
+ */
18
+ export declare function checkExtraEnvironment(env: Readonly<Record<string, string | null>>): void;
19
+ /**
20
+ * Merges a handle's default environment variables (`VercelCliOptions.env` and `withEnv`) with an overlay (`withEnv`
21
+ * or a call's `env`): a string value sets or replaces the key, and `null` deletes it from the merged map so the
22
+ * variable is not inherited (and `{ PATH: null }` falls back to `host.PATH`). Validates every key against
23
+ * `RESERVED_VARIABLES`, including keys whose value is `null`.
24
+ */
25
+ export declare function resolveExtraEnvironment(defaults: Readonly<Record<string, string>> | undefined, call: Readonly<Record<string, string | null>> | undefined): Readonly<Record<string, string>>;
26
+ /**
27
+ * An invocation's whole environment: `PATH`, `SystemRoot`, and `TEMP` from `host` when set, `HOME`, the fixed
17
28
  * variables (`NO_COLOR`, `NO_UPDATE_NOTIFIER`, `VERCEL_TELEMETRY_DISABLED`, `VERCEL_TEST_KEYRING_UNAVAILABLE`),
18
29
  * `FORCE_TTY=1`, no `CI`, and `CLI_WIDTH` and `COLUMNS` set to `columns` (default `TERMINAL_COLUMNS`) for an
19
30
  * invocation at a terminal, or else `CI=1` and no width, as a script or CI has, and the call's `extra`, whose `PATH`
@@ -38,7 +38,40 @@ export const RESERVED_VARIABLES = new Set([
38
38
  "VERCEL_TOKEN",
39
39
  ]);
40
40
  /**
41
- * An invocation's whole environment: `PATH`, `SystemRoot` and `TEMP` from `host` when set, `HOME`, the fixed
41
+ * Throws a `TypeError` when `env` names any variable in `RESERVED_VARIABLES`, even when its value is `null`.
42
+ */
43
+ export function checkExtraEnvironment(env) {
44
+ const reserved = Object.keys(env).filter((name) => RESERVED_VARIABLES.has(name));
45
+ if (reserved.length > 0) {
46
+ throw new TypeError(`vercel-cli: env may not set ${reserved.join(", ")}, which the invoker owns`);
47
+ }
48
+ }
49
+ /**
50
+ * Merges a handle's default environment variables (`VercelCliOptions.env` and `withEnv`) with an overlay (`withEnv`
51
+ * or a call's `env`): a string value sets or replaces the key, and `null` deletes it from the merged map so the
52
+ * variable is not inherited (and `{ PATH: null }` falls back to `host.PATH`). Validates every key against
53
+ * `RESERVED_VARIABLES`, including keys whose value is `null`.
54
+ */
55
+ export function resolveExtraEnvironment(defaults, call) {
56
+ if (defaults !== undefined)
57
+ checkExtraEnvironment(defaults);
58
+ if (call !== undefined)
59
+ checkExtraEnvironment(call);
60
+ const merged = defaults === undefined ? {} : { ...defaults };
61
+ if (call !== undefined) {
62
+ for (const [name, value] of Object.entries(call)) {
63
+ if (value === null) {
64
+ delete merged[name];
65
+ }
66
+ else {
67
+ merged[name] = value;
68
+ }
69
+ }
70
+ }
71
+ return merged;
72
+ }
73
+ /**
74
+ * An invocation's whole environment: `PATH`, `SystemRoot`, and `TEMP` from `host` when set, `HOME`, the fixed
42
75
  * variables (`NO_COLOR`, `NO_UPDATE_NOTIFIER`, `VERCEL_TELEMETRY_DISABLED`, `VERCEL_TEST_KEYRING_UNAVAILABLE`),
43
76
  * `FORCE_TTY=1`, no `CI`, and `CLI_WIDTH` and `COLUMNS` set to `columns` (default `TERMINAL_COLUMNS`) for an
44
77
  * invocation at a terminal, or else `CI=1` and no width, as a script or CI has, and the call's `extra`, whose `PATH`
@@ -50,10 +83,7 @@ export const RESERVED_VARIABLES = new Set([
50
83
  */
51
84
  export function invocationEnvironment(options) {
52
85
  const extra = options.extra ?? {};
53
- const reserved = Object.keys(extra).filter((name) => RESERVED_VARIABLES.has(name));
54
- if (reserved.length > 0) {
55
- throw new TypeError(`vercel-cli: env may not set ${reserved.join(", ")}, which the invoker owns`);
56
- }
86
+ checkExtraEnvironment(extra);
57
87
  const env = {};
58
88
  for (const name of PASSED_ON) {
59
89
  const value = options.host[name];
@@ -32,10 +32,16 @@ export interface VercelCliOptions {
32
32
  /** How long an invocation may run before it's killed, unless the call says otherwise; default 45s. */
33
33
  readonly timeoutMs?: number;
34
34
  /**
35
- * Where `PATH`, `SystemRoot` and `TEMP` come from; default `process.env`. Nothing else in it reaches `vercel`. A
36
- * call's `env.PATH` replaces its `PATH` for that invocation.
35
+ * Where `PATH`, `SystemRoot`, and `TEMP` come from; default `process.env`. Nothing else in it reaches `vercel`. A
36
+ * handle's or call's `env.PATH` replaces its `PATH` for that invocation.
37
37
  */
38
38
  readonly hostEnv?: Readonly<Record<string, string | undefined>>;
39
+ /**
40
+ * Default environment variables added to every invocation on the returned handle (and handles derived from it via
41
+ * `withEnv`). Validated eagerly against the invoker's reserved variables and shallow-copied. A derived handle's
42
+ * `withEnv` or a call's `env` overrides a key or unsets an inherited key with `null`.
43
+ */
44
+ readonly env?: Readonly<Record<string, string>>;
39
45
  /**
40
46
  * Hears each invocation once it has ended, or failed to start, tokens redacted, such as to print it with
41
47
  * `describeInvocation` as the test goes. What it throws is dropped. Without one, `vercelCli` prints each invocation
@@ -73,8 +79,8 @@ export interface VercelCallOptions {
73
79
  * - `"flag"`: `--token <secret>`, with the token `as` or the default identity names.
74
80
  * - `"saved"`: no `--token`. The invoker first saves that token as `token` in `<globalConfigDir>/auth.json`,
75
81
  * keeping the file's other keys, so `vercel` reads it as it reads a `vercel login`.
76
- * - `"none"`: no `--token`, and the invoker removes `token`, `refreshToken` and `expiresAt` from `auth.json`, keeping
77
- * its other keys: a logged-out `vercel`. It needs no default identity.
82
+ * - `"none"`: no `--token`, and the invoker removes `token`, `refreshToken`, and `expiresAt` from `auth.json`,
83
+ * keeping its other keys: a logged-out `vercel`. It needs no default identity.
78
84
  *
79
85
  * The invoker writes `auth.json` only when it differs from what the call needs in those keys. Under `"saved"` and
80
86
  * `"none"`, only the call's own `scope` sends `--scope`: `vercel` picks the team as after a login, the saved
@@ -92,14 +98,15 @@ export interface VercelCallOptions {
92
98
  /** Where it runs; default `<home>/work`. */
93
99
  readonly cwd?: string;
94
100
  /**
95
- * Variables added to its environment. `PATH` replaces the one from `hostEnv`; setting any other variable the
96
- * invoker sets (`HOME`, `SystemRoot`, `TEMP`, `FORCE_TTY`, `CI`, `CLI_WIDTH`, `COLUMNS`, `NO_COLOR`,
97
- * `NO_UPDATE_NOTIFIER`, `VERCEL_TELEMETRY_DISABLED`, `VERCEL_TEST_KEYRING_UNAVAILABLE`), or `VERCEL_TOKEN`, which
98
- * would undo `auth`, is a usage error. A bare `command.file`,
99
- * such as the default `vercel`, is looked up on this `PATH`, so a `PATH` without `vercel` needs an absolute
100
- * `command`.
101
+ * Variables added to its environment on top of any defaults this handle carries (`VercelCliOptions.env` and
102
+ * `withEnv`). A string value sets or replaces a variable, and `null` unsets an inherited default (`{ PATH: null }`
103
+ * falls back to `hostEnv.PATH`). `PATH` replaces the one from `hostEnv`; naming any other variable the invoker sets
104
+ * (`HOME`, `SystemRoot`, `TEMP`, `FORCE_TTY`, `CI`, `CLI_WIDTH`, `COLUMNS`, `NO_COLOR`, `NO_UPDATE_NOTIFIER`,
105
+ * `VERCEL_TELEMETRY_DISABLED`, `VERCEL_TEST_KEYRING_UNAVAILABLE`), or `VERCEL_TOKEN`, which would undo `auth`, is a
106
+ * usage error, even with `null`. A bare `command.file`, such as the default `vercel`, is looked up on this `PATH`,
107
+ * so a `PATH` without `vercel` needs an absolute `command`.
101
108
  */
102
- readonly env?: Readonly<Record<string, string>>;
109
+ readonly env?: Readonly<Record<string, string | null>>;
103
110
  /** How long it may run before it's killed; default the invoker's `timeoutMs`. */
104
111
  readonly timeoutMs?: number;
105
112
  }
@@ -177,12 +184,20 @@ export interface VercelCli {
177
184
  * Sets who `vercel` acts as by default: `token.secretString` for `--token` and `team.slug` for `--scope` (none for
178
185
  * `team: null`), and `auth`, how a call authenticates unless it says otherwise (default `"flag"`). Calling it again
179
186
  * replaces the default, `auth` included. The token reads `<token>` in everything the invoker returns or prints from
180
- * now on. A call's `as`, `scope` or `auth` overrides it; the default scope steps aside when a call's arguments name
181
- * `--scope`, `-S` or `--team`, and under `"saved"` and `"none"`.
187
+ * now on. A call's `as`, `scope`, or `auth` overrides it; the default scope steps aside when a call's arguments name
188
+ * `--scope`, `-S`, or `--team`, and under `"saved"` and `"none"`.
182
189
  */
183
190
  actAs(identity: VercelIdentity, options?: {
184
191
  readonly auth?: VercelAuth;
185
192
  }): void;
193
+ /**
194
+ * Returns a new `VercelCli` handle over the same underlying session (`home`, `globalConfigDir`, `workDir`,
195
+ * `invocations`, `close()`, `failureReport()`, and shared `actAs` identity) with `env` merged over this handle's
196
+ * default environment. String values set or replace a variable, and `null` unsets an inherited default (`{ PATH:
197
+ * null }` falls back to `hostEnv.PATH`). Validates every key eagerly against the invoker's reserved variables,
198
+ * including `null` entries, and leaves this handle unchanged.
199
+ */
200
+ withEnv(env: Readonly<Record<string, string | null>>): VercelCli;
186
201
  /**
187
202
  * Runs `vercel` with `args`, and resolves however it ends: its `stdout` and `stderr` with ANSI codes removed, as
188
203
  * `waitFor` removes them, and `rawStdout` and `rawStderr` as they arrived. At a terminal, stdin closes at once:
@@ -3,10 +3,10 @@
3
3
  // invocations share. `createVercelCli` takes its Context; `vercelCli` (`entry.ts`), the published entry, passes the
4
4
  // live one.
5
5
  import { join } from "node:path";
6
- import { displayCommand, passesFlag, passesScopeFlag, vercelArguments } from "./arguments.js";
6
+ import { displayCommand, insertBeforeDoubleDash, passesFlag, passesScopeFlag, vercelArguments } from "./arguments.js";
7
7
  import { authFileConflict, authFileSettled, settledAuthConfig, VERCEL_AUTH_MODES, } from "./auth-config.js";
8
8
  import { AUTH_CONFIG_FILE, readConfigText, serializeConfig } from "./config-files.js";
9
- import { invocationEnvironment } from "./environment.js";
9
+ import { checkExtraEnvironment, invocationEnvironment, resolveExtraEnvironment } from "./environment.js";
10
10
  import { VercelCliError } from "./errors.js";
11
11
  import { Invocation, STOP_SIGNALS, WAIT_FOR_TIMEOUT_MS, } from "./invocation.js";
12
12
  import { KEY_SEQUENCES } from "./keys.js";
@@ -19,6 +19,9 @@ const DEFAULT_COMMAND = { file: "vercel", args: [] };
19
19
  /** A `VercelCli` over `context`. It prepares `<home>/global-config` and `<home>/work` first. */
20
20
  export async function createVercelCli(options, context) {
21
21
  const defaultTimeoutMs = checkedTimeout(options.timeoutMs ?? VERCEL_TIMEOUT_MS, "timeoutMs");
22
+ if (options.env !== undefined)
23
+ checkExtraEnvironment(options.env);
24
+ const initialEnv = options.env === undefined ? {} : { ...options.env };
22
25
  const home = options.home;
23
26
  const globalConfigDir = join(home, "global-config");
24
27
  const workDir = join(home, "work");
@@ -52,7 +55,7 @@ export async function createVercelCli(options, context) {
52
55
  * and `close()` kills it even while it is starting. Then it settles `auth.json` for a saved login or a logged-out
53
56
  * invocation, after any settlement already under way, and starts the process.
54
57
  */
55
- const launch = async (args, call, how) => {
58
+ const launch = async (args, call, handleEnv, how) => {
56
59
  const { interactive, stdin } = how;
57
60
  const terminal = stdin.kind === "terminal";
58
61
  const authentication = resolveAuthentication(checkedAuth(call.auth ?? defaultAuth), call.as, identity?.token);
@@ -67,7 +70,13 @@ export async function createVercelCli(options, context) {
67
70
  globalConfigDir,
68
71
  scope,
69
72
  });
70
- const env = invocationEnvironment({ host: hostEnv, home, terminal, columns: how.columns, extra: call.env });
73
+ const env = invocationEnvironment({
74
+ host: hostEnv,
75
+ home,
76
+ terminal,
77
+ columns: how.columns,
78
+ extra: resolveExtraEnvironment(handleEnv, call.env),
79
+ });
71
80
  const cwd = call.cwd ?? workDir;
72
81
  const conflict = invocations.find((other) => other.running && authFileConflict(authentication, other.authentication));
73
82
  if (conflict !== undefined)
@@ -168,11 +177,11 @@ export async function createVercelCli(options, context) {
168
177
  * result once it has ended. Kills it when `block` throws. Every call but `json` runs through here; `run`'s block
169
178
  * does nothing.
170
179
  */
171
- const execute = async (args, call, interactive, block) => {
180
+ const execute = async (args, call, handleEnv, interactive, block) => {
172
181
  const stdin = invocationStdin(call);
173
182
  const columns = invocationColumns(call);
174
183
  const terminal = stdin.kind === "terminal";
175
- const invocation = await launch(args, call, { interactive, stdin, columns });
184
+ const invocation = await launch(args, call, handleEnv, { interactive, stdin, columns });
176
185
  try {
177
186
  await block(handle(invocation, terminal));
178
187
  }
@@ -185,69 +194,74 @@ export async function createVercelCli(options, context) {
185
194
  invocation.closeStdin();
186
195
  return invocation.result();
187
196
  };
188
- async function interact(args, callOrBlock, maybeBlock) {
189
- const [call, block] = typeof callOrBlock === "function" ? [{}, callOrBlock] : [callOrBlock, maybeBlock];
190
- if (typeof block !== "function") {
191
- throw new TypeError("vercel-cli: interact takes a block: interact(args, options?, async (invocation) => ...)");
192
- }
193
- return execute(args, call, true, block);
194
- }
195
- return {
196
- home,
197
- globalConfigDir,
198
- workDir,
199
- actAs({ token, team }, actAsOptions = {}) {
200
- if (token.secretString === "")
201
- throw new TypeError("vercel-cli: actAs names an empty token");
202
- if (team !== null && team.slug === "")
203
- throw new TypeError("vercel-cli: actAs names a team with an empty slug");
204
- const auth = checkedAuth(actAsOptions.auth ?? "flag");
205
- redactor.add(token.secretString);
206
- identity = { token: token.secretString, scope: team?.slug };
207
- defaultAuth = auth;
208
- },
209
- run: async (args, call = {}) => execute(args, call, false, () => undefined),
210
- interact,
211
- async json(args, schema, call = {}) {
212
- if (passesFlag(args, "--format")) {
213
- throw new TypeError("vercel-cli: json adds --format json itself; leave --format out of the arguments");
214
- }
215
- const invocation = await launch([...args, "--format", "json"], call, {
216
- interactive: false,
217
- stdin: { kind: "ignored" },
218
- });
219
- const result = await invocation.result();
220
- const failed = (why) => new VercelCliError(`vercel-cli: invocation ${invocation.number} ${why}\n${describeInvocation(invocation.snapshot())}`);
221
- if (result.exitCode !== 0 || result.timedOut || result.aborted)
222
- throw failed("didn't exit 0");
223
- let document;
224
- try {
225
- document = JSON.parse(result.stdout);
226
- }
227
- catch {
228
- throw failed("printed something other than JSON");
229
- }
230
- const parsed = schema.safeParse(document);
231
- if (!parsed.success) {
232
- const issue = parsed.error.issues[0];
233
- const where = issue === undefined || issue.path.length === 0 ? "" : ` at ${issue.path.map(String).join(".")}`;
234
- throw failed(`printed JSON its schema rejects${where}: ${redactor.redact(issue?.message ?? "invalid")}`);
197
+ const actAs = ({ token, team }, actAsOptions = {}) => {
198
+ if (token.secretString === "")
199
+ throw new TypeError("vercel-cli: actAs names an empty token");
200
+ if (team !== null && team.slug === "")
201
+ throw new TypeError("vercel-cli: actAs names a team with an empty slug");
202
+ const auth = checkedAuth(actAsOptions.auth ?? "flag");
203
+ redactor.add(token.secretString);
204
+ identity = { token: token.secretString, scope: team?.slug };
205
+ defaultAuth = auth;
206
+ };
207
+ const close = async () => {
208
+ const running = invocations.filter((invocation) => invocation.running);
209
+ for (const invocation of running)
210
+ invocation.kill("close");
211
+ await Promise.all(running.map((invocation) => invocation.ended()));
212
+ };
213
+ const failureReport = () => describeInvocations(invocations.map((invocation) => invocation.snapshot()));
214
+ const cliWithEnv = (handleEnv) => {
215
+ async function interact(args, callOrBlock, maybeBlock) {
216
+ const [call, block] = typeof callOrBlock === "function" ? [{}, callOrBlock] : [callOrBlock, maybeBlock];
217
+ if (typeof block !== "function") {
218
+ throw new TypeError("vercel-cli: interact takes a block: interact(args, options?, async (invocation) => ...)");
235
219
  }
236
- return parsed.data;
237
- },
238
- get invocations() {
239
- return invocations.map((invocation) => invocation.snapshot());
240
- },
241
- async close() {
242
- const running = invocations.filter((invocation) => invocation.running);
243
- for (const invocation of running)
244
- invocation.kill("close");
245
- await Promise.all(running.map((invocation) => invocation.ended()));
246
- },
247
- failureReport() {
248
- return describeInvocations(invocations.map((invocation) => invocation.snapshot()));
249
- },
220
+ return execute(args, call, handleEnv, true, block);
221
+ }
222
+ return {
223
+ home,
224
+ globalConfigDir,
225
+ workDir,
226
+ actAs,
227
+ withEnv: (extra) => cliWithEnv(resolveExtraEnvironment(handleEnv, extra)),
228
+ run: async (args, call = {}) => execute(args, call, handleEnv, false, () => undefined),
229
+ interact,
230
+ async json(args, schema, call = {}) {
231
+ if (passesFlag(args, "--format")) {
232
+ throw new TypeError("vercel-cli: json adds --format json itself; leave --format out of the arguments");
233
+ }
234
+ const invocation = await launch(insertBeforeDoubleDash(args, ["--format", "json"]), call, handleEnv, {
235
+ interactive: false,
236
+ stdin: { kind: "ignored" },
237
+ });
238
+ const result = await invocation.result();
239
+ const failed = (why) => new VercelCliError(`vercel-cli: invocation ${invocation.number} ${why}\n${describeInvocation(invocation.snapshot())}`);
240
+ if (result.exitCode !== 0 || result.timedOut || result.aborted)
241
+ throw failed("didn't exit 0");
242
+ let document;
243
+ try {
244
+ document = JSON.parse(result.stdout);
245
+ }
246
+ catch {
247
+ throw failed("printed something other than JSON");
248
+ }
249
+ const parsed = schema.safeParse(document);
250
+ if (!parsed.success) {
251
+ const issue = parsed.error.issues[0];
252
+ const where = issue === undefined || issue.path.length === 0 ? "" : ` at ${issue.path.map(String).join(".")}`;
253
+ throw failed(`printed JSON its schema rejects${where}: ${redactor.redact(issue?.message ?? "invalid")}`);
254
+ }
255
+ return parsed.data;
256
+ },
257
+ get invocations() {
258
+ return invocations.map((invocation) => invocation.snapshot());
259
+ },
260
+ close,
261
+ failureReport,
262
+ };
250
263
  };
264
+ return cliWithEnv(initialEnv);
251
265
  }
252
266
  /** A `TypeError` for starting `wanted` while `other`, still running, needs `auth.json` to hold something else. */
253
267
  function authFileConflictError(wanted, other) {
@@ -61,7 +61,6 @@ function startProcess(request) {
61
61
  let started = false;
62
62
  let completed = false;
63
63
  let terminated = false;
64
- let drainExpired = false;
65
64
  let drainTimer;
66
65
  let processExit;
67
66
  let stdinOpen = request.stdin === "pipe";
@@ -78,19 +77,14 @@ function startProcess(request) {
78
77
  clearTimeout(drainTimer);
79
78
  resolveExit(exit);
80
79
  };
81
- const stopDraining = () => {
82
- if (!drainExpired || processExit === undefined)
83
- return;
84
- complete({ ...processExit, outputComplete: false });
85
- child.stdout?.destroy();
86
- child.stderr?.destroy();
87
- };
88
80
  const startDrainTimer = () => {
89
81
  if (!terminated || processExit === undefined || drainTimer !== undefined || completed)
90
82
  return;
83
+ const exit = processExit;
91
84
  drainTimer = setTimeout(() => {
92
- drainExpired = true;
93
- stopDraining();
85
+ complete({ ...exit, outputComplete: false });
86
+ child.stdout?.destroy();
87
+ child.stderr?.destroy();
94
88
  }, TERMINATE_DRAIN_MS);
95
89
  };
96
90
  // A write racing the process's exit fails with EPIPE; the invoker learns of the exit from `exited`.
@@ -1,8 +1,9 @@
1
1
  // The `vercel` CLI's session id, read from a request record's headers. The Vercel CLI invoker's failure report counts
2
- // proxy records by it, and the Testserver Vitest fixtures' request lines name it. A record shows a header's value only
3
- // when its proxy's `recordHeaders` names it, so the Testserver Vitest fixtures' `proxy` adds this one; a proxy that
4
- // doesn't leaves every record without a session id. It belongs with the `vercel` CLI's own tests, and moves to
5
- // vercel-internal with the invoker. It loads no other file at run time.
2
+ // proxy records by it, and a suite using the Testserver Vitest fixtures can pass `VERCEL_CLI_SESSION_ID_HEADER` to
3
+ // `proxySessionHeader` so the proxy records it and prints `, session <id>` on request lines. A record shows a header's
4
+ // value only when its proxy's `recordHeaders` names it; a proxy that doesn't leaves every record without a session id.
5
+ // It belongs with the `vercel` CLI's own tests, and moves to vercel-internal with the invoker. It loads no other file
6
+ // at run time.
6
7
  import { REDACTED_HEADER } from "../../../vendor/testserver-sdk/index.js";
7
8
  /** The header the `vercel` CLI sends with the same id on every request of one invocation. */
8
9
  export const VERCEL_CLI_SESSION_ID_HEADER = "x-vercel-cli-session-id";