@devdogsuga/devtools 0.1.26 → 0.1.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -11
- package/bin/devtools.mjs +4 -4
- package/dist/cli-CZKkNHK5.js +6619 -0
- package/dist/failure-log-BBPGejQv.js +256 -0
- package/dist/launch.js +267 -281
- package/dist/local-env-D8HC2JK_.js +351 -0
- package/dist/local-env-DrBCXqD8.js +2 -0
- package/dist/menu-CQBsQRgH.js +1684 -0
- package/dist/peer-redirect-hooks.js +15 -0
- package/dist/peers-RBplwovA.js +229 -0
- package/dist/root-C2OmZDwD.js +94 -0
- package/dist/stack-Bx-55oi_.js +2 -0
- package/dist/stack-BynCgRVS.js +181 -0
- package/dist/supabase-project-0knM0mqd.js +426 -0
- package/dist/telemetry-C4foD8MD.js +249 -0
- package/dist/telemetry.js +2 -148
- package/package.json +10 -29
- package/bin/devtools-ci-bare.mjs +0 -48
- package/bin/devtools-ci.mjs +0 -31
- package/dist/args.d.ts +0 -26
- package/dist/args.js +0 -78
- package/dist/bws/bw.d.ts +0 -18
- package/dist/bws/bw.js +0 -70
- package/dist/bws/client.d.ts +0 -43
- package/dist/bws/client.js +0 -363
- package/dist/bws/environments.d.ts +0 -96
- package/dist/bws/environments.js +0 -111
- package/dist/bws/pace.d.ts +0 -25
- package/dist/bws/pace.js +0 -43
- package/dist/bws/retry.d.ts +0 -12
- package/dist/bws/retry.js +0 -39
- package/dist/bws/store.d.ts +0 -1
- package/dist/bws/store.js +0 -32
- package/dist/bws/token.d.ts +0 -31
- package/dist/bws/token.js +0 -88
- package/dist/bws/vault.d.ts +0 -29
- package/dist/bws/vault.js +0 -200
- package/dist/catalog.d.ts +0 -57
- package/dist/catalog.js +0 -57
- package/dist/cf/build.d.ts +0 -13
- package/dist/cf/build.js +0 -65
- package/dist/cf/commands.d.ts +0 -1
- package/dist/cf/commands.js +0 -172
- package/dist/cf/local-env.d.ts +0 -58
- package/dist/cf/local-env.js +0 -177
- package/dist/ci.d.ts +0 -1
- package/dist/ci.js +0 -328
- package/dist/cli.d.ts +0 -11
- package/dist/cli.js +0 -1094
- package/dist/commands.d.ts +0 -261
- package/dist/commands.js +0 -1318
- package/dist/completions.d.ts +0 -4
- package/dist/completions.js +0 -110
- package/dist/cron/commands.d.ts +0 -47
- package/dist/cron/commands.js +0 -372
- package/dist/cron/discovery.d.ts +0 -55
- package/dist/cron/discovery.js +0 -85
- package/dist/cron/schema.d.ts +0 -45
- package/dist/cron/schema.js +0 -35
- package/dist/db/config-push.d.ts +0 -8
- package/dist/db/config-push.js +0 -11
- package/dist/db/connection.d.ts +0 -79
- package/dist/db/connection.js +0 -114
- package/dist/db/exec.d.ts +0 -1
- package/dist/db/exec.js +0 -11
- package/dist/db/generate-types.d.ts +0 -1
- package/dist/db/generate-types.js +0 -4
- package/dist/db/generated-env.d.ts +0 -69
- package/dist/db/generated-env.js +0 -113
- package/dist/db/introspect.d.ts +0 -1
- package/dist/db/introspect.js +0 -122
- package/dist/db/local-env.d.ts +0 -65
- package/dist/db/local-env.js +0 -23
- package/dist/db/new-migration.d.ts +0 -8
- package/dist/db/new-migration.js +0 -69
- package/dist/db/pooler.d.ts +0 -23
- package/dist/db/pooler.js +0 -55
- package/dist/db/run.d.ts +0 -68
- package/dist/db/run.js +0 -156
- package/dist/db/seed-buckets.d.ts +0 -2
- package/dist/db/seed-buckets.js +0 -4
- package/dist/db/seed-production.d.ts +0 -8
- package/dist/db/seed-production.js +0 -79
- package/dist/db/seed-roles.d.ts +0 -7
- package/dist/db/seed-roles.js +0 -33
- package/dist/db/session-refresh.d.ts +0 -43
- package/dist/db/session-refresh.js +0 -40
- package/dist/deploy/migrations.d.ts +0 -20
- package/dist/deploy/migrations.js +0 -68
- package/dist/deploy/orphans.d.ts +0 -20
- package/dist/deploy/orphans.js +0 -177
- package/dist/deploy/preflight.d.ts +0 -53
- package/dist/deploy/preflight.js +0 -189
- package/dist/deploy/report.d.ts +0 -26
- package/dist/deploy/report.js +0 -70
- package/dist/deploy/require-planner.d.ts +0 -2
- package/dist/deploy/require-planner.js +0 -60
- package/dist/deploy/require-token.d.ts +0 -15
- package/dist/deploy/require-token.js +0 -78
- package/dist/deploy/secrets-file.d.ts +0 -17
- package/dist/deploy/secrets-file.js +0 -166
- package/dist/deploy/write-env.d.ts +0 -40
- package/dist/deploy/write-env.js +0 -395
- package/dist/docs/index-pages.d.ts +0 -38
- package/dist/docs/index-pages.js +0 -186
- package/dist/emails/commands.d.ts +0 -15
- package/dist/emails/commands.js +0 -130
- package/dist/emails/email-types.d.ts +0 -13
- package/dist/emails/email-types.js +0 -1
- package/dist/emails/fixtures.d.ts +0 -20
- package/dist/emails/fixtures.js +0 -20
- package/dist/env/audit.d.ts +0 -206
- package/dist/env/audit.js +0 -436
- package/dist/env/cloudflare.d.ts +0 -21
- package/dist/env/cloudflare.js +0 -61
- package/dist/env/commands.d.ts +0 -99
- package/dist/env/commands.js +0 -613
- package/dist/env/discovery.d.ts +0 -15
- package/dist/env/discovery.js +0 -239
- package/dist/env/document.d.ts +0 -119
- package/dist/env/document.js +0 -323
- package/dist/env/example.d.ts +0 -68
- package/dist/env/example.js +0 -605
- package/dist/env/selection.d.ts +0 -105
- package/dist/env/selection.js +0 -228
- package/dist/env-entry.d.ts +0 -49
- package/dist/env-entry.js +0 -204
- package/dist/environment-doctor.d.ts +0 -45
- package/dist/environment-doctor.js +0 -429
- package/dist/environment.d.ts +0 -92
- package/dist/environment.js +0 -185
- package/dist/fingerprint.d.ts +0 -10
- package/dist/fingerprint.js +0 -18
- package/dist/gen/campus-map.d.ts +0 -1
- package/dist/gen/campus-map.js +0 -473
- package/dist/gen/commands.d.ts +0 -1
- package/dist/gen/commands.js +0 -25
- package/dist/gen/hypno.d.ts +0 -1
- package/dist/gen/hypno.js +0 -134
- package/dist/gh/client.d.ts +0 -80
- package/dist/gh/client.js +0 -259
- package/dist/gh/environments.d.ts +0 -83
- package/dist/gh/environments.js +0 -178
- package/dist/gh/rulesets/actors.d.ts +0 -14
- package/dist/gh/rulesets/actors.js +0 -69
- package/dist/gh/rulesets/api.d.ts +0 -15
- package/dist/gh/rulesets/api.js +0 -104
- package/dist/gh/rulesets/commands.d.ts +0 -3
- package/dist/gh/rulesets/commands.js +0 -203
- package/dist/gh/rulesets/desired.d.ts +0 -112
- package/dist/gh/rulesets/desired.js +0 -271
- package/dist/gh/rulesets/diff.d.ts +0 -65
- package/dist/gh/rulesets/diff.js +0 -170
- package/dist/gh/rulesets/types.d.ts +0 -76
- package/dist/gh/rulesets/types.js +0 -13
- package/dist/gh/settings/api.d.ts +0 -40
- package/dist/gh/settings/api.js +0 -180
- package/dist/gh/settings/commands.d.ts +0 -1
- package/dist/gh/settings/commands.js +0 -254
- package/dist/gh/settings/desired.d.ts +0 -53
- package/dist/gh/settings/desired.js +0 -43
- package/dist/gh/settings/diff.d.ts +0 -57
- package/dist/gh/settings/diff.js +0 -161
- package/dist/gh/settings/types.d.ts +0 -92
- package/dist/gh/settings/types.js +0 -11
- package/dist/gh/settings/workflows.d.ts +0 -41
- package/dist/gh/settings/workflows.js +0 -128
- package/dist/grantRoot.d.ts +0 -42
- package/dist/grantRoot.js +0 -89
- package/dist/help.d.ts +0 -18
- package/dist/help.js +0 -169
- package/dist/images/commands.d.ts +0 -32
- package/dist/images/commands.js +0 -231
- package/dist/images/events.d.ts +0 -47
- package/dist/images/events.js +0 -116
- package/dist/images/graphics.d.ts +0 -70
- package/dist/images/graphics.js +0 -234
- package/dist/images/open-graph-types.d.ts +0 -75
- package/dist/images/open-graph-types.js +0 -1
- package/dist/images/prompts.d.ts +0 -34
- package/dist/images/prompts.js +0 -100
- package/dist/images/render.d.ts +0 -21
- package/dist/images/render.js +0 -61
- package/dist/images/select.d.ts +0 -64
- package/dist/images/select.js +0 -96
- package/dist/instance.d.ts +0 -69
- package/dist/instance.js +0 -102
- package/dist/invocation.d.ts +0 -49
- package/dist/invocation.js +0 -78
- package/dist/launch-ci.d.ts +0 -1
- package/dist/launch-ci.js +0 -90
- package/dist/launch.d.ts +0 -18
- package/dist/menu.d.ts +0 -43
- package/dist/menu.js +0 -300
- package/dist/moderation.d.ts +0 -70
- package/dist/moderation.js +0 -128
- package/dist/oauth/browser.d.ts +0 -1
- package/dist/oauth/browser.js +0 -13
- package/dist/oauth/config.d.ts +0 -24
- package/dist/oauth/config.js +0 -24
- package/dist/oauth/connect-url.d.ts +0 -17
- package/dist/oauth/connect-url.js +0 -23
- package/dist/oauth/db.d.ts +0 -37
- package/dist/oauth/db.js +0 -108
- package/dist/oauth/device.d.ts +0 -93
- package/dist/oauth/device.js +0 -198
- package/dist/oauth/discovery.d.ts +0 -28
- package/dist/oauth/discovery.js +0 -54
- package/dist/oauth/env-file.d.ts +0 -6
- package/dist/oauth/env-file.js +0 -35
- package/dist/oauth/exchange.d.ts +0 -43
- package/dist/oauth/exchange.js +0 -93
- package/dist/oauth/label.d.ts +0 -1
- package/dist/oauth/label.js +0 -25
- package/dist/oauth/loopback.d.ts +0 -52
- package/dist/oauth/loopback.js +0 -168
- package/dist/oauth/pkce.d.ts +0 -6
- package/dist/oauth/pkce.js +0 -34
- package/dist/oauth/target.d.ts +0 -54
- package/dist/oauth/target.js +0 -102
- package/dist/oauth/transport.d.ts +0 -41
- package/dist/oauth/transport.js +0 -32
- package/dist/oauth/wizard.d.ts +0 -40
- package/dist/oauth/wizard.js +0 -578
- package/dist/persona.d.ts +0 -18
- package/dist/persona.js +0 -221
- package/dist/pick.d.ts +0 -6
- package/dist/pick.js +0 -64
- package/dist/pipes.d.ts +0 -1
- package/dist/pipes.js +0 -25
- package/dist/planner/checks.d.ts +0 -26
- package/dist/planner/checks.js +0 -104
- package/dist/planner/commands.d.ts +0 -10
- package/dist/planner/commands.js +0 -367
- package/dist/planner/db.d.ts +0 -15
- package/dist/planner/db.js +0 -33
- package/dist/planner/role.d.ts +0 -33
- package/dist/planner/role.js +0 -68
- package/dist/repo/peer-redirect-hooks.d.ts +0 -16
- package/dist/repo/peer-redirect-hooks.js +0 -10
- package/dist/repo/peer-redirect.d.ts +0 -4
- package/dist/repo/peer-redirect.js +0 -26
- package/dist/repo/peers.d.ts +0 -39
- package/dist/repo/peers.js +0 -139
- package/dist/repo/resolve.d.ts +0 -41
- package/dist/repo/resolve.js +0 -152
- package/dist/repo/root.d.ts +0 -23
- package/dist/repo/root.js +0 -91
- package/dist/repo/source.d.ts +0 -14
- package/dist/repo/source.js +0 -54
- package/dist/repo/supabase-project.d.ts +0 -60
- package/dist/repo/supabase-project.js +0 -124
- package/dist/repo/tsx-loader.d.ts +0 -6
- package/dist/repo/tsx-loader.js +0 -41
- package/dist/run/pick.d.ts +0 -90
- package/dist/run/pick.js +0 -664
- package/dist/setup.d.ts +0 -1
- package/dist/setup.js +0 -280
- package/dist/stack.d.ts +0 -48
- package/dist/stack.js +0 -403
- package/dist/telemetry.d.ts +0 -59
- package/dist/tier.d.ts +0 -40
- package/dist/tier.js +0 -96
- package/dist/ui.d.ts +0 -40
- package/dist/ui.js +0 -71
- package/dist/version.d.ts +0 -7
- package/dist/version.js +0 -17
- package/dist/workers.d.ts +0 -5
- package/dist/workers.js +0 -33
- package/dist/workflows/commands.d.ts +0 -54
- package/dist/workflows/commands.js +0 -763
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { a as ownVersion } from "./root-C2OmZDwD.js";
|
|
2
|
+
import { mkdirSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { homedir, platform, release } from "node:os";
|
|
5
|
+
//#region ../cli-core/src/catalog.ts
|
|
6
|
+
/**
|
|
7
|
+
* How each scope reads, in the two places that draw it.
|
|
8
|
+
*
|
|
9
|
+
* `menu` sits inline in a hint, so it is one word. `help` heads a block of
|
|
10
|
+
* commands, so it can be a phrase. Both live here rather than in the renderers
|
|
11
|
+
* because they are labels, the same kind of data as a group title.
|
|
12
|
+
*/
|
|
13
|
+
const SCOPES = {
|
|
14
|
+
machine: {
|
|
15
|
+
menu: "This machine",
|
|
16
|
+
help: "Supabase on this machine"
|
|
17
|
+
},
|
|
18
|
+
repo: {
|
|
19
|
+
menu: "Repo",
|
|
20
|
+
help: "files in the repo"
|
|
21
|
+
},
|
|
22
|
+
endpoint: {
|
|
23
|
+
menu: "Database",
|
|
24
|
+
help: "the session's database (--tier)"
|
|
25
|
+
},
|
|
26
|
+
infra: {
|
|
27
|
+
menu: "Hosted",
|
|
28
|
+
help: "hosted infrastructure, each naming its own connection"
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Machine-readable output to stdout.
|
|
33
|
+
*
|
|
34
|
+
* Promptless by design: the wizard is already interactive; a flag that switches
|
|
35
|
+
* its output format has no meaning there. `commands.test.ts` pins the promptless
|
|
36
|
+
* set with a "scripting-only" category for exactly this kind of flag.
|
|
37
|
+
*/
|
|
38
|
+
const JSON_FLAG = {
|
|
39
|
+
flag: "--json",
|
|
40
|
+
summary: "Print machine-readable JSON to stdout."
|
|
41
|
+
};
|
|
42
|
+
/** Skip every interactive confirmation prompt. On every destructive command. */
|
|
43
|
+
const YES = {
|
|
44
|
+
flag: "--yes",
|
|
45
|
+
summary: "Skip the confirmations."
|
|
46
|
+
};
|
|
47
|
+
function walk(roots, path) {
|
|
48
|
+
let nodes = roots;
|
|
49
|
+
let found = null;
|
|
50
|
+
for (const name of path) {
|
|
51
|
+
const next = nodes.find((node) => node.name === name);
|
|
52
|
+
if (!next) return null;
|
|
53
|
+
found = next;
|
|
54
|
+
nodes = next.subcommands ?? [];
|
|
55
|
+
}
|
|
56
|
+
return found;
|
|
57
|
+
}
|
|
58
|
+
function createCatalog(trees) {
|
|
59
|
+
const groups = trees.groups;
|
|
60
|
+
const ciGroups = trees.ciGroups ?? [];
|
|
61
|
+
const topLevel = groups.flatMap((group) => group.commands);
|
|
62
|
+
const ciTopLevel = ciGroups.flatMap((group) => group.commands);
|
|
63
|
+
const subcommandNames = (path) => (walk(topLevel, path)?.subcommands ?? []).map((node) => node.name);
|
|
64
|
+
return {
|
|
65
|
+
usage: trees.usage,
|
|
66
|
+
commonTasks: trees.commonTasks ?? [],
|
|
67
|
+
groups,
|
|
68
|
+
ciGroups,
|
|
69
|
+
topLevel,
|
|
70
|
+
ciTopLevel,
|
|
71
|
+
findCommand: (path) => walk(topLevel, path),
|
|
72
|
+
findCiCommand: (path) => walk(ciTopLevel, path),
|
|
73
|
+
groupOf: (name) => groups.find((group) => group.commands.some((command) => command.name === name)),
|
|
74
|
+
subcommandNames,
|
|
75
|
+
subcommandCiNames: (path) => (walk(ciTopLevel, path)?.subcommands ?? []).map((node) => node.name),
|
|
76
|
+
subcommandList: (path) => {
|
|
77
|
+
const names = subcommandNames(path);
|
|
78
|
+
if (names.length <= 1) return names.join("");
|
|
79
|
+
return `${names.slice(0, -1).join(", ")} or ${names[names.length - 1]}`;
|
|
80
|
+
},
|
|
81
|
+
allPaths: () => {
|
|
82
|
+
const paths = [];
|
|
83
|
+
const visit = (nodes, prefix) => {
|
|
84
|
+
for (const node of nodes) {
|
|
85
|
+
const path = [...prefix, node.name];
|
|
86
|
+
paths.push(path);
|
|
87
|
+
visit(node.subcommands ?? [], path);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
visit(topLevel, []);
|
|
91
|
+
return paths;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region ../cli-core/src/cli-name.ts
|
|
97
|
+
let current = "devtools";
|
|
98
|
+
function cliName() {
|
|
99
|
+
return current;
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region ../cli-core/src/failure-log.ts
|
|
103
|
+
/**
|
|
104
|
+
* A local log for a failed run, so a contributor has something to attach to
|
|
105
|
+
* #tech-support.
|
|
106
|
+
*
|
|
107
|
+
* When the process is about to exit non-zero, one file is written holding what
|
|
108
|
+
* helps someone else diagnose it: the command line, the version and platform,
|
|
109
|
+
* the tool commands that ran with their exit codes, devtools' own output, the
|
|
110
|
+
* error, and the Sentry event id when telemetry sent one. The path is printed
|
|
111
|
+
* last, on stderr. Output a tool wrote straight to the terminal is not
|
|
112
|
+
* captured (tools keep the terminal so colours and prompts work), and the log
|
|
113
|
+
* says so.
|
|
114
|
+
*
|
|
115
|
+
* Secrets are redacted before anything is stored: credentials inside URLs,
|
|
116
|
+
* and the value of any environment variable named like a secret.
|
|
117
|
+
*
|
|
118
|
+
* Not a failure, so no log: a clean exit, Ctrl-C (130) or SIGTERM (143), the
|
|
119
|
+
* drift code (2) that `--check` uses on purpose, and a cancelled prompt.
|
|
120
|
+
*/
|
|
121
|
+
function nonEmpty(value) {
|
|
122
|
+
if (value === void 0 || value === "") return void 0;
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
function describe(error) {
|
|
126
|
+
return error instanceof Error ? error.message : String(error);
|
|
127
|
+
}
|
|
128
|
+
function versionOrUnknown() {
|
|
129
|
+
try {
|
|
130
|
+
return ownVersion();
|
|
131
|
+
} catch {
|
|
132
|
+
return "unknown";
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const SECRET_NAME = /(SECRET|TOKEN|PASSWORD|PASSWD|KEY|DSN|DB_URL|CREDENTIAL)/i;
|
|
136
|
+
const URL_CREDENTIALS = /\/\/[^/@\s:]+(:[^/@\s]*)?@/g;
|
|
137
|
+
let state = null;
|
|
138
|
+
/** Replaces credentials in `text` with a placeholder. */
|
|
139
|
+
function redact(text, env = process.env) {
|
|
140
|
+
let out = text.replace(URL_CREDENTIALS, "//***@");
|
|
141
|
+
for (const [name, value] of Object.entries(env)) if (value && value.length >= 8 && SECRET_NAME.test(name)) out = out.split(value).join("<redacted>");
|
|
142
|
+
return out;
|
|
143
|
+
}
|
|
144
|
+
function failureLogDir(env = process.env) {
|
|
145
|
+
return nonEmpty(env.DEVTOOLS_LOG_DIR) ?? join(nonEmpty(env.XDG_STATE_HOME) ?? join(homedir(), ".local", "state"), "devdogs", "logs");
|
|
146
|
+
}
|
|
147
|
+
/** Whether an exit code means the run failed. */
|
|
148
|
+
function isFailureCode(code) {
|
|
149
|
+
return code !== 0 && code !== 2 && code !== 130 && code !== 143;
|
|
150
|
+
}
|
|
151
|
+
/** The file's text. Pure, so it is testable without a process to fail. */
|
|
152
|
+
function renderFailureLog(input) {
|
|
153
|
+
const env = input.env ?? process.env;
|
|
154
|
+
const lines = [
|
|
155
|
+
"devtools failure log",
|
|
156
|
+
"Attach this file to your #tech-support message.",
|
|
157
|
+
"",
|
|
158
|
+
`time: ${input.now.toISOString()}`,
|
|
159
|
+
`version: ${versionOrUnknown()}`,
|
|
160
|
+
`command: devtools ${input.argv.join(" ")}`,
|
|
161
|
+
`exit code: ${input.code}`,
|
|
162
|
+
`tier: ${nonEmpty(env.DEPLOY_ENV) ?? "development"}`,
|
|
163
|
+
`node: ${process.version}`,
|
|
164
|
+
`platform: ${platform()} ${release()}`,
|
|
165
|
+
`cwd: ${process.cwd()}`,
|
|
166
|
+
`sentry: ${input.eventId ?? "none (telemetry sent nothing)"}`,
|
|
167
|
+
"",
|
|
168
|
+
"== Tool commands that ran ==",
|
|
169
|
+
...input.ran.length > 0 ? input.ran : ["(none)"],
|
|
170
|
+
"",
|
|
171
|
+
"== Error =="
|
|
172
|
+
];
|
|
173
|
+
if (input.error === void 0) lines.push("(none thrown)");
|
|
174
|
+
else lines.push(input.error instanceof Error ? input.error.stack ?? input.error.message : describe(input.error));
|
|
175
|
+
lines.push("", "== devtools output (tool output that went straight to the terminal is not here) ==", input.output.length > 0 ? input.output : "(none)");
|
|
176
|
+
return redact(`${lines.join("\n")}\n`, env);
|
|
177
|
+
}
|
|
178
|
+
/** Records a command a tool ran, for the log. */
|
|
179
|
+
function noteRan(line) {
|
|
180
|
+
state?.ran.push(line);
|
|
181
|
+
}
|
|
182
|
+
/** Records the error a failure came from, for the log. */
|
|
183
|
+
function noteError(error) {
|
|
184
|
+
if (state) state.error ??= error;
|
|
185
|
+
}
|
|
186
|
+
/** A cancelled prompt is the user's choice, not a failure. */
|
|
187
|
+
function suppressFailureLog() {
|
|
188
|
+
if (state) state.quiet = true;
|
|
189
|
+
}
|
|
190
|
+
function keepNewest(dir) {
|
|
191
|
+
try {
|
|
192
|
+
const old = readdirSync(dir).filter((name) => name.startsWith("devtools-") && name.endsWith(".log")).sort().slice(0, -10);
|
|
193
|
+
for (const name of old) rmSync(join(dir, name), { force: true });
|
|
194
|
+
} catch {}
|
|
195
|
+
}
|
|
196
|
+
/** Writes the log and returns its path, or `null` if it could not be written. */
|
|
197
|
+
function writeLog(input) {
|
|
198
|
+
try {
|
|
199
|
+
const dir = failureLogDir(input.env);
|
|
200
|
+
mkdirSync(dir, { recursive: true });
|
|
201
|
+
const stamp = input.now.toISOString().replace(/[:.]/g, "-");
|
|
202
|
+
const path = join(dir, `devtools-${stamp}.log`);
|
|
203
|
+
writeFileSync(path, renderFailureLog(input), { mode: 384 });
|
|
204
|
+
keepNewest(dir);
|
|
205
|
+
return path;
|
|
206
|
+
} catch {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Starts recording and writes the log if the process exits with a failure.
|
|
212
|
+
* Call once, early. A second call is ignored.
|
|
213
|
+
*/
|
|
214
|
+
function installFailureLog(options) {
|
|
215
|
+
if (state) return;
|
|
216
|
+
state = {
|
|
217
|
+
argv: [...options.argv],
|
|
218
|
+
eventId: options.eventId,
|
|
219
|
+
ran: [],
|
|
220
|
+
output: "",
|
|
221
|
+
error: void 0,
|
|
222
|
+
quiet: false
|
|
223
|
+
};
|
|
224
|
+
const capture = (stream) => {
|
|
225
|
+
const original = stream.write.bind(stream);
|
|
226
|
+
stream.write = (chunk, ...rest) => {
|
|
227
|
+
if (state && typeof chunk === "string") state.output = (state.output + chunk).slice(-65536);
|
|
228
|
+
return original(chunk, ...rest);
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
capture(process.stdout);
|
|
232
|
+
capture(process.stderr);
|
|
233
|
+
process.once("exit", (exitCode) => {
|
|
234
|
+
const current = state;
|
|
235
|
+
if (!current || current.quiet) return;
|
|
236
|
+
const code = process.exitCode === void 0 ? exitCode : Number(process.exitCode);
|
|
237
|
+
if (!isFailureCode(code)) return;
|
|
238
|
+
const path = writeLog({
|
|
239
|
+
argv: current.argv,
|
|
240
|
+
code,
|
|
241
|
+
ran: current.ran,
|
|
242
|
+
output: current.output,
|
|
243
|
+
error: current.error,
|
|
244
|
+
eventId: current.eventId(),
|
|
245
|
+
now: /* @__PURE__ */ new Date()
|
|
246
|
+
});
|
|
247
|
+
const eventId = current.eventId();
|
|
248
|
+
process.stderr.write([
|
|
249
|
+
path ? `Log for #tech-support: ${path}` : "Could not write a failure log.",
|
|
250
|
+
...eventId ? [`Sentry event: ${eventId}`] : [],
|
|
251
|
+
""
|
|
252
|
+
].join("\n"));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
//#endregion
|
|
256
|
+
export { cliName as a, YES as c, suppressFailureLog as i, createCatalog as l, noteError as n, JSON_FLAG as o, noteRan as r, SCOPES as s, installFailureLog as t };
|