@devdogsuga/devtools 0.1.25 → 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.
Files changed (271) hide show
  1. package/README.md +72 -11
  2. package/bin/devtools.mjs +4 -4
  3. package/dist/cli-CZKkNHK5.js +6619 -0
  4. package/dist/failure-log-BBPGejQv.js +256 -0
  5. package/dist/launch.js +267 -281
  6. package/dist/local-env-D8HC2JK_.js +351 -0
  7. package/dist/local-env-DrBCXqD8.js +2 -0
  8. package/dist/menu-CQBsQRgH.js +1684 -0
  9. package/dist/peer-redirect-hooks.js +15 -0
  10. package/dist/peers-RBplwovA.js +229 -0
  11. package/dist/root-C2OmZDwD.js +94 -0
  12. package/dist/stack-Bx-55oi_.js +2 -0
  13. package/dist/stack-BynCgRVS.js +181 -0
  14. package/dist/supabase-project-0knM0mqd.js +426 -0
  15. package/dist/telemetry-C4foD8MD.js +249 -0
  16. package/dist/telemetry.js +2 -148
  17. package/package.json +10 -29
  18. package/bin/devtools-ci-bare.mjs +0 -48
  19. package/bin/devtools-ci.mjs +0 -31
  20. package/dist/args.d.ts +0 -26
  21. package/dist/args.js +0 -78
  22. package/dist/bws/bw.d.ts +0 -18
  23. package/dist/bws/bw.js +0 -70
  24. package/dist/bws/client.d.ts +0 -43
  25. package/dist/bws/client.js +0 -363
  26. package/dist/bws/environments.d.ts +0 -96
  27. package/dist/bws/environments.js +0 -111
  28. package/dist/bws/pace.d.ts +0 -25
  29. package/dist/bws/pace.js +0 -43
  30. package/dist/bws/retry.d.ts +0 -12
  31. package/dist/bws/retry.js +0 -39
  32. package/dist/bws/store.d.ts +0 -1
  33. package/dist/bws/store.js +0 -32
  34. package/dist/bws/token.d.ts +0 -31
  35. package/dist/bws/token.js +0 -88
  36. package/dist/bws/vault.d.ts +0 -29
  37. package/dist/bws/vault.js +0 -200
  38. package/dist/catalog.d.ts +0 -57
  39. package/dist/catalog.js +0 -57
  40. package/dist/cf/build.d.ts +0 -13
  41. package/dist/cf/build.js +0 -65
  42. package/dist/cf/commands.d.ts +0 -1
  43. package/dist/cf/commands.js +0 -172
  44. package/dist/cf/local-env.d.ts +0 -58
  45. package/dist/cf/local-env.js +0 -177
  46. package/dist/ci.d.ts +0 -1
  47. package/dist/ci.js +0 -328
  48. package/dist/cli.d.ts +0 -11
  49. package/dist/cli.js +0 -1094
  50. package/dist/commands.d.ts +0 -261
  51. package/dist/commands.js +0 -1318
  52. package/dist/completions.d.ts +0 -4
  53. package/dist/completions.js +0 -110
  54. package/dist/cron/commands.d.ts +0 -47
  55. package/dist/cron/commands.js +0 -372
  56. package/dist/cron/discovery.d.ts +0 -55
  57. package/dist/cron/discovery.js +0 -85
  58. package/dist/cron/schema.d.ts +0 -45
  59. package/dist/cron/schema.js +0 -35
  60. package/dist/db/config-push.d.ts +0 -8
  61. package/dist/db/config-push.js +0 -11
  62. package/dist/db/connection.d.ts +0 -79
  63. package/dist/db/connection.js +0 -114
  64. package/dist/db/exec.d.ts +0 -1
  65. package/dist/db/exec.js +0 -11
  66. package/dist/db/generate-types.d.ts +0 -1
  67. package/dist/db/generate-types.js +0 -4
  68. package/dist/db/generated-env.d.ts +0 -69
  69. package/dist/db/generated-env.js +0 -113
  70. package/dist/db/introspect.d.ts +0 -1
  71. package/dist/db/introspect.js +0 -122
  72. package/dist/db/local-env.d.ts +0 -65
  73. package/dist/db/local-env.js +0 -23
  74. package/dist/db/new-migration.d.ts +0 -8
  75. package/dist/db/new-migration.js +0 -69
  76. package/dist/db/pooler.d.ts +0 -23
  77. package/dist/db/pooler.js +0 -55
  78. package/dist/db/run.d.ts +0 -68
  79. package/dist/db/run.js +0 -156
  80. package/dist/db/seed-buckets.d.ts +0 -2
  81. package/dist/db/seed-buckets.js +0 -4
  82. package/dist/db/seed-production.d.ts +0 -8
  83. package/dist/db/seed-production.js +0 -79
  84. package/dist/db/seed-roles.d.ts +0 -7
  85. package/dist/db/seed-roles.js +0 -33
  86. package/dist/db/session-refresh.d.ts +0 -43
  87. package/dist/db/session-refresh.js +0 -40
  88. package/dist/deploy/migrations.d.ts +0 -20
  89. package/dist/deploy/migrations.js +0 -68
  90. package/dist/deploy/orphans.d.ts +0 -20
  91. package/dist/deploy/orphans.js +0 -177
  92. package/dist/deploy/preflight.d.ts +0 -53
  93. package/dist/deploy/preflight.js +0 -189
  94. package/dist/deploy/report.d.ts +0 -26
  95. package/dist/deploy/report.js +0 -70
  96. package/dist/deploy/require-planner.d.ts +0 -2
  97. package/dist/deploy/require-planner.js +0 -60
  98. package/dist/deploy/require-token.d.ts +0 -15
  99. package/dist/deploy/require-token.js +0 -78
  100. package/dist/deploy/secrets-file.d.ts +0 -17
  101. package/dist/deploy/secrets-file.js +0 -166
  102. package/dist/deploy/write-env.d.ts +0 -40
  103. package/dist/deploy/write-env.js +0 -395
  104. package/dist/docs/index-pages.d.ts +0 -38
  105. package/dist/docs/index-pages.js +0 -186
  106. package/dist/emails/commands.d.ts +0 -15
  107. package/dist/emails/commands.js +0 -130
  108. package/dist/emails/email-types.d.ts +0 -13
  109. package/dist/emails/email-types.js +0 -1
  110. package/dist/emails/fixtures.d.ts +0 -20
  111. package/dist/emails/fixtures.js +0 -20
  112. package/dist/env/audit.d.ts +0 -206
  113. package/dist/env/audit.js +0 -436
  114. package/dist/env/cloudflare.d.ts +0 -21
  115. package/dist/env/cloudflare.js +0 -61
  116. package/dist/env/commands.d.ts +0 -99
  117. package/dist/env/commands.js +0 -613
  118. package/dist/env/discovery.d.ts +0 -15
  119. package/dist/env/discovery.js +0 -239
  120. package/dist/env/document.d.ts +0 -119
  121. package/dist/env/document.js +0 -323
  122. package/dist/env/example.d.ts +0 -68
  123. package/dist/env/example.js +0 -605
  124. package/dist/env/selection.d.ts +0 -105
  125. package/dist/env/selection.js +0 -228
  126. package/dist/env-entry.d.ts +0 -49
  127. package/dist/env-entry.js +0 -204
  128. package/dist/environment-doctor.d.ts +0 -45
  129. package/dist/environment-doctor.js +0 -429
  130. package/dist/environment.d.ts +0 -92
  131. package/dist/environment.js +0 -185
  132. package/dist/fingerprint.d.ts +0 -10
  133. package/dist/fingerprint.js +0 -18
  134. package/dist/gen/campus-map.d.ts +0 -1
  135. package/dist/gen/campus-map.js +0 -473
  136. package/dist/gen/commands.d.ts +0 -1
  137. package/dist/gen/commands.js +0 -25
  138. package/dist/gen/hypno.d.ts +0 -1
  139. package/dist/gen/hypno.js +0 -134
  140. package/dist/gh/client.d.ts +0 -80
  141. package/dist/gh/client.js +0 -259
  142. package/dist/gh/environments.d.ts +0 -83
  143. package/dist/gh/environments.js +0 -178
  144. package/dist/gh/rulesets/actors.d.ts +0 -14
  145. package/dist/gh/rulesets/actors.js +0 -69
  146. package/dist/gh/rulesets/api.d.ts +0 -15
  147. package/dist/gh/rulesets/api.js +0 -104
  148. package/dist/gh/rulesets/commands.d.ts +0 -3
  149. package/dist/gh/rulesets/commands.js +0 -203
  150. package/dist/gh/rulesets/desired.d.ts +0 -112
  151. package/dist/gh/rulesets/desired.js +0 -271
  152. package/dist/gh/rulesets/diff.d.ts +0 -65
  153. package/dist/gh/rulesets/diff.js +0 -170
  154. package/dist/gh/rulesets/types.d.ts +0 -76
  155. package/dist/gh/rulesets/types.js +0 -13
  156. package/dist/gh/settings/api.d.ts +0 -40
  157. package/dist/gh/settings/api.js +0 -180
  158. package/dist/gh/settings/commands.d.ts +0 -1
  159. package/dist/gh/settings/commands.js +0 -254
  160. package/dist/gh/settings/desired.d.ts +0 -53
  161. package/dist/gh/settings/desired.js +0 -43
  162. package/dist/gh/settings/diff.d.ts +0 -57
  163. package/dist/gh/settings/diff.js +0 -161
  164. package/dist/gh/settings/types.d.ts +0 -92
  165. package/dist/gh/settings/types.js +0 -11
  166. package/dist/gh/settings/workflows.d.ts +0 -41
  167. package/dist/gh/settings/workflows.js +0 -128
  168. package/dist/grantRoot.d.ts +0 -42
  169. package/dist/grantRoot.js +0 -89
  170. package/dist/help.d.ts +0 -18
  171. package/dist/help.js +0 -169
  172. package/dist/images/commands.d.ts +0 -32
  173. package/dist/images/commands.js +0 -231
  174. package/dist/images/events.d.ts +0 -47
  175. package/dist/images/events.js +0 -116
  176. package/dist/images/graphics.d.ts +0 -70
  177. package/dist/images/graphics.js +0 -234
  178. package/dist/images/open-graph-types.d.ts +0 -75
  179. package/dist/images/open-graph-types.js +0 -1
  180. package/dist/images/prompts.d.ts +0 -34
  181. package/dist/images/prompts.js +0 -100
  182. package/dist/images/render.d.ts +0 -21
  183. package/dist/images/render.js +0 -61
  184. package/dist/images/select.d.ts +0 -64
  185. package/dist/images/select.js +0 -96
  186. package/dist/instance.d.ts +0 -69
  187. package/dist/instance.js +0 -102
  188. package/dist/invocation.d.ts +0 -49
  189. package/dist/invocation.js +0 -78
  190. package/dist/launch-ci.d.ts +0 -1
  191. package/dist/launch-ci.js +0 -90
  192. package/dist/launch.d.ts +0 -18
  193. package/dist/menu.d.ts +0 -43
  194. package/dist/menu.js +0 -300
  195. package/dist/moderation.d.ts +0 -70
  196. package/dist/moderation.js +0 -128
  197. package/dist/oauth/browser.d.ts +0 -1
  198. package/dist/oauth/browser.js +0 -13
  199. package/dist/oauth/config.d.ts +0 -24
  200. package/dist/oauth/config.js +0 -24
  201. package/dist/oauth/connect-url.d.ts +0 -17
  202. package/dist/oauth/connect-url.js +0 -23
  203. package/dist/oauth/db.d.ts +0 -37
  204. package/dist/oauth/db.js +0 -108
  205. package/dist/oauth/device.d.ts +0 -93
  206. package/dist/oauth/device.js +0 -198
  207. package/dist/oauth/discovery.d.ts +0 -28
  208. package/dist/oauth/discovery.js +0 -54
  209. package/dist/oauth/env-file.d.ts +0 -6
  210. package/dist/oauth/env-file.js +0 -35
  211. package/dist/oauth/exchange.d.ts +0 -43
  212. package/dist/oauth/exchange.js +0 -93
  213. package/dist/oauth/label.d.ts +0 -1
  214. package/dist/oauth/label.js +0 -25
  215. package/dist/oauth/loopback.d.ts +0 -52
  216. package/dist/oauth/loopback.js +0 -168
  217. package/dist/oauth/pkce.d.ts +0 -6
  218. package/dist/oauth/pkce.js +0 -34
  219. package/dist/oauth/target.d.ts +0 -54
  220. package/dist/oauth/target.js +0 -102
  221. package/dist/oauth/transport.d.ts +0 -41
  222. package/dist/oauth/transport.js +0 -32
  223. package/dist/oauth/wizard.d.ts +0 -40
  224. package/dist/oauth/wizard.js +0 -578
  225. package/dist/persona.d.ts +0 -18
  226. package/dist/persona.js +0 -221
  227. package/dist/pick.d.ts +0 -6
  228. package/dist/pick.js +0 -64
  229. package/dist/pipes.d.ts +0 -1
  230. package/dist/pipes.js +0 -25
  231. package/dist/planner/checks.d.ts +0 -26
  232. package/dist/planner/checks.js +0 -104
  233. package/dist/planner/commands.d.ts +0 -10
  234. package/dist/planner/commands.js +0 -367
  235. package/dist/planner/db.d.ts +0 -15
  236. package/dist/planner/db.js +0 -33
  237. package/dist/planner/role.d.ts +0 -33
  238. package/dist/planner/role.js +0 -68
  239. package/dist/repo/peer-redirect-hooks.d.ts +0 -16
  240. package/dist/repo/peer-redirect-hooks.js +0 -10
  241. package/dist/repo/peer-redirect.d.ts +0 -4
  242. package/dist/repo/peer-redirect.js +0 -26
  243. package/dist/repo/peers.d.ts +0 -39
  244. package/dist/repo/peers.js +0 -139
  245. package/dist/repo/resolve.d.ts +0 -41
  246. package/dist/repo/resolve.js +0 -152
  247. package/dist/repo/root.d.ts +0 -23
  248. package/dist/repo/root.js +0 -91
  249. package/dist/repo/source.d.ts +0 -14
  250. package/dist/repo/source.js +0 -54
  251. package/dist/repo/supabase-project.d.ts +0 -60
  252. package/dist/repo/supabase-project.js +0 -124
  253. package/dist/repo/tsx-loader.d.ts +0 -6
  254. package/dist/repo/tsx-loader.js +0 -41
  255. package/dist/run/pick.d.ts +0 -90
  256. package/dist/run/pick.js +0 -664
  257. package/dist/setup.d.ts +0 -1
  258. package/dist/setup.js +0 -280
  259. package/dist/stack.d.ts +0 -48
  260. package/dist/stack.js +0 -403
  261. package/dist/telemetry.d.ts +0 -59
  262. package/dist/tier.d.ts +0 -40
  263. package/dist/tier.js +0 -96
  264. package/dist/ui.d.ts +0 -40
  265. package/dist/ui.js +0 -71
  266. package/dist/version.d.ts +0 -7
  267. package/dist/version.js +0 -17
  268. package/dist/workers.d.ts +0 -5
  269. package/dist/workers.js +0 -33
  270. package/dist/workflows/commands.d.ts +0 -54
  271. package/dist/workflows/commands.js +0 -763
@@ -1,172 +0,0 @@
1
- /**
2
- * Dispatch for `devtools cf *`.
3
- *
4
- * Delegates to each app's package scripts for preview/typegen/build, and
5
- * passes through to wrangler for `cf exec`.
6
- */
7
- import { confirm } from "@clack/prompts";
8
- import { loadEnvLoad } from "../repo/peers.js";
9
- import { run } from "../db/run.js";
10
- import { buildWorkerApp } from "./build.js";
11
- import { resolveTier } from "../tier.js";
12
- import { unwrap } from "../ui.js";
13
- import { isWorkerApp, workerApps } from "../workers.js";
14
- import { withWranglerEnv } from "./local-env.js";
15
- // A function, not a top-level constant — `workerApps()` reads `workers.json`
16
- // via `findRepoRoot()`, which must not run at import time (see
17
- // `workers.ts`'s header on why that broke `--help`/`setup` outside a repo).
18
- function unknownAppHint() {
19
- return `Expected: ${workerApps().join(", ")}.`;
20
- }
21
- function parseAppAndRest(argv) {
22
- const idx = argv.indexOf("--app");
23
- if (idx === -1 || idx + 1 >= argv.length)
24
- return { rest: argv };
25
- const app = argv[idx + 1];
26
- const rest = [...argv.slice(0, idx), ...argv.slice(idx + 2)];
27
- return { app, rest };
28
- }
29
- function parseTier(argv) {
30
- const idx = argv.indexOf("--tier");
31
- return idx !== -1 ? argv[idx + 1] : undefined;
32
- }
33
- export async function runCf(argv) {
34
- const sub = argv[0];
35
- const rest = argv.slice(1);
36
- if (sub === "preview") {
37
- const { app } = parseAppAndRest(rest);
38
- if (!app) {
39
- process.stderr.write("devtools cf preview: --app <slug> is required.\n");
40
- return 1;
41
- }
42
- if (!isWorkerApp(app)) {
43
- process.stderr.write(`devtools cf preview: unknown app "${app}". ${unknownAppHint()}\n`);
44
- return 1;
45
- }
46
- // The command tree's own `--tier` option carries no `prompt` (see
47
- // `commands.ts`): asking there AND here would ask twice, once on its own
48
- // wizard screen and once from this resolver, whenever more than one tier
49
- // file is present. `resolveTier` owns both the validation an explicit
50
- // `--tier` needs and the conditional prompt an absent one gets.
51
- const tier = await resolveTier(parseTier(rest), "Which tier's env should the preview use?", { label: "devtools cf preview" });
52
- if (tier === null)
53
- return 1;
54
- // Previewing production means the local Worker talks to live production
55
- // data (DB_URL, third-party API keys, the lot) from a developer's own
56
- // machine — the same exposure `cron run`/`workflows run` gate behind a
57
- // confirm for a deployed TIER. Staging carries no such weight; it is a
58
- // normal development target and asks for nothing extra.
59
- if (tier === "production" && !rest.includes("--yes")) {
60
- if (!process.stdin.isTTY) {
61
- process.stderr.write("devtools cf preview: --yes is required to preview production.\n");
62
- return 1;
63
- }
64
- const approved = unwrap(await confirm({
65
- message: `Preview ${app} against live production data?`,
66
- initialValue: false,
67
- }));
68
- if (!approved)
69
- return 1;
70
- }
71
- const envLoad = await loadEnvLoad();
72
- let loaded;
73
- if (tier !== "development") {
74
- try {
75
- // This process runs under `with-env` (development), so process.env
76
- // already holds development's values; override: true makes the
77
- // tier's own .env.<tier> win instead of quietly previewing against
78
- // whatever development happened to have loaded.
79
- loaded = await envLoad.loadEnvironment(tier, { override: true });
80
- }
81
- catch (err) {
82
- // `err.message` already names the fetch command (see
83
- // `MissingEnvFileError`'s constructor); repeating it here would just
84
- // duplicate the line.
85
- if (err instanceof envLoad.MissingEnvFileError) {
86
- process.stderr.write(`devtools cf preview: ${err.message}\n`);
87
- return 1;
88
- }
89
- throw err;
90
- }
91
- }
92
- // The build bakes tier-scoped values (NEXT_PUBLIC_* and anything else
93
- // read at build time) into the bundle, exactly like `cf:build:<tier>`'s
94
- // `DEPLOY_ENV=<tier> with-env` does — so it gets both the tier's loaded
95
- // env AND DEPLOY_ENV itself, since build-time code may branch on that
96
- // variable directly. The `wrangler dev` child below does NOT: the tier
97
- // reaches the Worker at RUNTIME through the scoped `--env-file`
98
- // `withWranglerEnv` materializes, not through this process's own
99
- // environment, so passing DEPLOY_ENV there would be a no-op at best and a
100
- // stale value baked nowhere at worst.
101
- //
102
- // Both Next.js apps are on vinext: `vinext build` additionally needs
103
- // `CLOUDFLARE_ENV=<tier>` (see each app's `cf:build:<tier>` script) —
104
- // vinext bakes the target environment in at BUILD time, and `wrangler
105
- // dev` cross-checks it against `-e`/the env it resolves, erroring loudly
106
- // on a mismatch rather than silently running the wrong tier. The sandbox
107
- // app has no framework build; `buildWorkerApp` only builds its workspace
108
- // dependencies.
109
- const build = await buildWorkerApp(app, tier && loaded
110
- ? { ...loaded.env, DEPLOY_ENV: tier, CLOUDFLARE_ENV: tier }
111
- : undefined);
112
- if (build !== 0)
113
- return build;
114
- // Create this after the framework build. Apart from shortening the time a
115
- // credential-bearing file exists, this prevents build-tool temp cleanup
116
- // from invalidating the path before Wrangler opens it.
117
- return withWranglerEnv(app, (envFile) =>
118
- // For a vinext app, `wrangler dev` auto-redirects to the just-built
119
- // `dist/server/wrangler.json` (a "config redirect" vinext writes to
120
- // `.wrangler/deploy/config.json`), so no `--config` flag is needed.
121
- // The bundle is already built above; invoke the project's Wrangler
122
- // directly so the scoped file becomes Worker vars.
123
- run([
124
- "--filter",
125
- app,
126
- "exec",
127
- "wrangler",
128
- "dev",
129
- "--env-file",
130
- envFile,
131
- ]), { env: loaded?.env });
132
- }
133
- if (sub === "typegen") {
134
- const { app, rest: remaining } = parseAppAndRest(rest);
135
- if (!app) {
136
- process.stderr.write("devtools cf typegen: --app <slug> is required.\n");
137
- return 1;
138
- }
139
- if (!isWorkerApp(app)) {
140
- process.stderr.write(`devtools cf typegen: unknown app "${app}". ${unknownAppHint()}\n`);
141
- return 1;
142
- }
143
- const check = remaining.includes("--check");
144
- const script = check ? "cf:typegen:check" : "cf:typegen";
145
- return run(["--filter", app, "run", script]);
146
- }
147
- if (sub === "build") {
148
- const { app } = parseAppAndRest(rest);
149
- const tier = parseTier(rest);
150
- if (!app) {
151
- process.stderr.write("devtools cf build: --app <slug> is required.\n");
152
- return 1;
153
- }
154
- if (!isWorkerApp(app)) {
155
- process.stderr.write(`devtools cf build: unknown app "${app}". ${unknownAppHint()}\n`);
156
- return 1;
157
- }
158
- if (!tier || (tier !== "staging" && tier !== "production")) {
159
- process.stderr.write("devtools cf build: --tier <staging|production> is required.\n");
160
- return 1;
161
- }
162
- return run(["--filter", app, "run", `cf:build:${tier}`]);
163
- }
164
- if (sub === "exec") {
165
- // Everything after "exec" (or after "--") passes to wrangler
166
- const wranglerArgs = rest[0] === "--" ? rest.slice(1) : rest;
167
- return run(["exec", "wrangler", ...wranglerArgs]);
168
- }
169
- process.stderr.write(`devtools cf: unknown subcommand "${sub ?? "(none)"}". ` +
170
- "Expected: preview, typegen, build, exec.\n");
171
- return 1;
172
- }
@@ -1,58 +0,0 @@
1
- import type { EnvEntry } from "@devdogsuga/env";
2
- export declare function renderWranglerEnvFile(keys: readonly string[], environment: NodeJS.ProcessEnv): string;
3
- /**
4
- * The process env for a `vinext dev` child, scoped the way the temp
5
- * `.dev.vars` is for `wrangler dev`.
6
- *
7
- * `@cloudflare/vite-plugin` has no `--env-file`: it reads the app dir's own
8
- * `.dev.vars`/`.env`, or — with `CLOUDFLARE_INCLUDE_PROCESS_ENV` — its whole
9
- * `process.env`, as Worker vars that override wrangler.jsonc's `vars`. So the
10
- * scoping happens on the child's env instead: every key some OTHER app
11
- * declares (and this app doesn't) is dropped, `NODE_ENV` is left to Vite, and
12
- * `DEPLOY_ENV` is pinned to the tier rather than dropped, because the Vite
13
- * process's own `next.config.ts` reads it too. Undeclared keys (PATH, HOME,
14
- * pnpm's own) stay; the child needs them and they carry no app secrets.
15
- */
16
- export declare function scopedProcessEnv(app: string, environment: NodeJS.ProcessEnv, tier: string, entries?: readonly EnvEntry[]): Promise<NodeJS.ProcessEnv>;
17
- /**
18
- * Runs `fn` with the path to an app-scoped, mode-0600 `.dev.vars` file, and
19
- * guarantees the file (and its containing directory) is gone before this
20
- * resolves or rejects — including when `fn` throws, AND when a SIGINT/SIGTERM
21
- * (e.g. the developer's Ctrl+C on a `wrangler dev` child `fn` is awaiting)
22
- * arrives while `fn` is still running: without this, the signal kills the
23
- * process before the `finally` below gets to run, leaving the credential-
24
- * bearing temp directory behind in a world-findable location. Prefer this
25
- * over `createTemporaryWranglerEnv` below for anything whose credential-
26
- * bearing file's lifetime matches a single call's lifetime: a credential-
27
- * bearing temp file can never outlive the call that needed it.
28
- */
29
- export declare function withWranglerEnv<T>(app: string, fn: (envFilePath: string) => Promise<T>, options?: {
30
- env?: NodeJS.ProcessEnv;
31
- entries?: readonly EnvEntry[];
32
- }): Promise<T>;
33
- export interface TemporaryWranglerEnv {
34
- path: string;
35
- remove: () => void;
36
- }
37
- /**
38
- * Create an app-scoped, mode-0600 env file for a local Worker runtime whose
39
- * lifetime a single bracket callback cannot express.
40
- *
41
- * ⚠️ KEPT DELIBERATELY, not an oversight: `workflows/commands.ts` holds this
42
- * file open across a long-lived `wrangler dev` child process, and in the
43
- * `workflows run` temporary-session path that span crosses a `finally` that
44
- * is unrelated to starting Wrangler at all — it also triggers a Workflow and
45
- * polls for its completion before the session stops. Squeezing that into a
46
- * single `withWranglerEnv` callback would mean merging two previously
47
- * independent concerns (spinning up a dev session; triggering-and-waiting)
48
- * into one control path, which is a real redesign of a 700-line orchestrator,
49
- * not a mechanical bracket swap — and duplicating this function's
50
- * retry/readiness loop across a bracket-shaped variant just to convert the
51
- * `workflows serve` half would fragment one shared, tested implementation
52
- * into two for no behavioural gain.
53
- *
54
- * `env` mirrors `withWranglerEnv`'s `options.env`: pass a tier's loaded map to
55
- * materialize a scoped file from THAT tier rather than the inherited process
56
- * environment; omit it to keep today's behavior.
57
- */
58
- export declare function createTemporaryWranglerEnv(app: string, env?: NodeJS.ProcessEnv): Promise<TemporaryWranglerEnv>;
@@ -1,177 +0,0 @@
1
- import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
2
- import { tmpdir } from "node:os";
3
- import { join } from "node:path";
4
- import { loadEnv } from "../repo/peers.js";
5
- import { loadRegistry } from "../env/discovery.js";
6
- export function renderWranglerEnvFile(keys, environment) {
7
- return (keys
8
- .flatMap((key) => {
9
- const value = environment[key];
10
- // dotenv preserves single-quoted values byte-for-byte, including
11
- // multiline private keys and literal backslash sequences.
12
- return value === undefined ? [] : [`${key}='${value}'`];
13
- })
14
- .join("\n") + "\n");
15
- }
16
- /** The app's declared keys, deduped and sorted, from the given entries or the
17
- * loaded registry.
18
- *
19
- * `DEPLOY_ENV` and `NODE_ENV` are excluded BY NAME, not by any registry-meta
20
- * heuristic. Their committed source is wrangler.jsonc's per-env `vars` blocks
21
- * (and the framework), never an env file — see each key's `define()` doc.
22
- * Materializing them into the temp `.dev.vars` this file feeds to `wrangler
23
- * dev` lets a stray or empty `.env` value OVERRIDE the tier's wrangler var,
24
- * which surfaced as a Workflow isolate reading a blank `DEPLOY_ENV` and
25
- * throwing "has no HYPERDRIVE binding".
26
- *
27
- * A `scope: "default"` + `commented: true` filter was tried first and is
28
- * WRONG: that shape also matches `GITHUB_COMPETITION_REPO`, an opt-in
29
- * override a contributor sets deliberately in their `.env` (its wrangler
30
- * config defines no such var), and the heuristic silently stripped it from
31
- * `wrangler dev`'s environment. Wrangler-ownership is a fact about
32
- * wrangler.jsonc, not about registry metadata, so the two keys it is true
33
- * for are named outright. */
34
- const WRANGLER_OWNED_KEYS = new Set(["DEPLOY_ENV", "NODE_ENV"]);
35
- async function scopedKeys(app, entries) {
36
- if (!entries) {
37
- await loadRegistry();
38
- entries = (await loadEnv()).declarations();
39
- }
40
- return [
41
- ...new Set(entries
42
- .filter((entry) => entry.source === app)
43
- .filter((entry) => !WRANGLER_OWNED_KEYS.has(entry.key))
44
- .map((entry) => entry.key)),
45
- ].sort();
46
- }
47
- /**
48
- * The process env for a `vinext dev` child, scoped the way the temp
49
- * `.dev.vars` is for `wrangler dev`.
50
- *
51
- * `@cloudflare/vite-plugin` has no `--env-file`: it reads the app dir's own
52
- * `.dev.vars`/`.env`, or — with `CLOUDFLARE_INCLUDE_PROCESS_ENV` — its whole
53
- * `process.env`, as Worker vars that override wrangler.jsonc's `vars`. So the
54
- * scoping happens on the child's env instead: every key some OTHER app
55
- * declares (and this app doesn't) is dropped, `NODE_ENV` is left to Vite, and
56
- * `DEPLOY_ENV` is pinned to the tier rather than dropped, because the Vite
57
- * process's own `next.config.ts` reads it too. Undeclared keys (PATH, HOME,
58
- * pnpm's own) stay; the child needs them and they carry no app secrets.
59
- */
60
- export async function scopedProcessEnv(app, environment, tier, entries) {
61
- if (!entries) {
62
- await loadRegistry();
63
- entries = (await loadEnv()).declarations();
64
- }
65
- const own = new Set(await scopedKeys(app, entries));
66
- const scoped = { ...environment };
67
- for (const entry of entries) {
68
- if (entry.source !== app && !own.has(entry.key))
69
- delete scoped[entry.key];
70
- }
71
- delete scoped.NODE_ENV;
72
- scoped.DEPLOY_ENV = tier;
73
- scoped.CLOUDFLARE_INCLUDE_PROCESS_ENV = "true";
74
- return scoped;
75
- }
76
- /** Writes the mode-0600 `.dev.vars` into a fresh private temp directory. */
77
- function materializeEnvFile(keys, environment) {
78
- const directory = mkdtempSync(join(tmpdir(), "devtools-wrangler-env-"));
79
- const path = join(directory, ".dev.vars");
80
- writeFileSync(path, renderWranglerEnvFile(keys, environment), {
81
- encoding: "utf8",
82
- mode: 0o600,
83
- });
84
- return { directory, path };
85
- }
86
- /** Signals a `wrangler dev` child normally dies to: Ctrl+C sends SIGINT, and
87
- * SIGTERM is how a parent (or `kill`) asks any child to stop. Both bypass a
88
- * `finally` block only if the process exits before it runs — which it
89
- * doesn't here, since Node keeps running while a signal handler is
90
- * registered — so installing one turns "the shell killed us" into an
91
- * ordinary early return through the same `finally`. */
92
- const CLEANUP_SIGNALS = ["SIGINT", "SIGTERM"];
93
- /** Registers `cleanup` on SIGINT/SIGTERM for the duration of a bracket and
94
- * returns a function that un-registers it. On signal, `cleanup` runs, the
95
- * handler removes itself, and the signal is re-sent to this process so the
96
- * default handler (absent any other listener) terminates it with the
97
- * conventional 128+signal exit status — the caller's `fn` never resumes. */
98
- function installSignalCleanup(cleanup) {
99
- const handlers = new Map();
100
- for (const signal of CLEANUP_SIGNALS) {
101
- const handler = () => {
102
- cleanup();
103
- process.off(signal, handler);
104
- process.kill(process.pid, signal);
105
- };
106
- handlers.set(signal, handler);
107
- process.on(signal, handler);
108
- }
109
- return () => {
110
- for (const [signal, handler] of handlers)
111
- process.off(signal, handler);
112
- };
113
- }
114
- /**
115
- * Runs `fn` with the path to an app-scoped, mode-0600 `.dev.vars` file, and
116
- * guarantees the file (and its containing directory) is gone before this
117
- * resolves or rejects — including when `fn` throws, AND when a SIGINT/SIGTERM
118
- * (e.g. the developer's Ctrl+C on a `wrangler dev` child `fn` is awaiting)
119
- * arrives while `fn` is still running: without this, the signal kills the
120
- * process before the `finally` below gets to run, leaving the credential-
121
- * bearing temp directory behind in a world-findable location. Prefer this
122
- * over `createTemporaryWranglerEnv` below for anything whose credential-
123
- * bearing file's lifetime matches a single call's lifetime: a credential-
124
- * bearing temp file can never outlive the call that needed it.
125
- */
126
- export async function withWranglerEnv(app, fn, options) {
127
- const keys = await scopedKeys(app, options?.entries);
128
- const { directory, path } = materializeEnvFile(keys, options?.env ?? process.env);
129
- // Idempotent: the signal handler and the `finally` below can both fire
130
- // (the handler runs cleanup, then re-raises the signal — which unwinds
131
- // `fn` and reaches `finally` on its way out) and rmSync's `force: true`
132
- // alone only suppresses ENOENT, not a guarantee against re-entrant calls.
133
- let removed = false;
134
- const cleanup = () => {
135
- if (removed)
136
- return;
137
- removed = true;
138
- rmSync(directory, { recursive: true, force: true });
139
- };
140
- const uninstall = installSignalCleanup(cleanup);
141
- try {
142
- return await fn(path);
143
- }
144
- finally {
145
- uninstall();
146
- cleanup();
147
- }
148
- }
149
- /**
150
- * Create an app-scoped, mode-0600 env file for a local Worker runtime whose
151
- * lifetime a single bracket callback cannot express.
152
- *
153
- * ⚠️ KEPT DELIBERATELY, not an oversight: `workflows/commands.ts` holds this
154
- * file open across a long-lived `wrangler dev` child process, and in the
155
- * `workflows run` temporary-session path that span crosses a `finally` that
156
- * is unrelated to starting Wrangler at all — it also triggers a Workflow and
157
- * polls for its completion before the session stops. Squeezing that into a
158
- * single `withWranglerEnv` callback would mean merging two previously
159
- * independent concerns (spinning up a dev session; triggering-and-waiting)
160
- * into one control path, which is a real redesign of a 700-line orchestrator,
161
- * not a mechanical bracket swap — and duplicating this function's
162
- * retry/readiness loop across a bracket-shaped variant just to convert the
163
- * `workflows serve` half would fragment one shared, tested implementation
164
- * into two for no behavioural gain.
165
- *
166
- * `env` mirrors `withWranglerEnv`'s `options.env`: pass a tier's loaded map to
167
- * materialize a scoped file from THAT tier rather than the inherited process
168
- * environment; omit it to keep today's behavior.
169
- */
170
- export async function createTemporaryWranglerEnv(app, env) {
171
- const keys = await scopedKeys(app);
172
- const { directory, path } = materializeEnvFile(keys, env ?? process.env);
173
- return {
174
- path,
175
- remove: () => rmSync(directory, { recursive: true, force: true }),
176
- };
177
- }
package/dist/ci.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function main(argv: string[]): Promise<void>;