@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,351 @@
|
|
|
1
|
+
import { i as ownPackageDir, r as findRepoRoot } from "./root-C2OmZDwD.js";
|
|
2
|
+
import { a as repoPeerUrl, n as loadEnv, t as getEnvSync } from "./peers-RBplwovA.js";
|
|
3
|
+
import { register } from "node:module";
|
|
4
|
+
import { existsSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
//#region ../cli-core/src/repo/peer-redirect.ts
|
|
9
|
+
/**
|
|
10
|
+
* Points one module's bare import of a peer at the copy the target repo
|
|
11
|
+
* resolved (`repo/peers.ts`).
|
|
12
|
+
*
|
|
13
|
+
* devtools' own `env.ts` manifest imports `@devdogsuga/env` by bare
|
|
14
|
+
* specifier, and from an installed copy that specifier resolves relative to
|
|
15
|
+
* the manifest's own location: inside the pnpm store, next to devtools,
|
|
16
|
+
* where an optional peer is never installed under `pnpm dlx`. The import
|
|
17
|
+
* failed with ERR_MODULE_NOT_FOUND, and every `env` command with it. Even
|
|
18
|
+
* where the specifier does resolve (devtools installed as a devDependency),
|
|
19
|
+
* the only copy that keeps the registry's module identity is the one the
|
|
20
|
+
* repo's manifests use, so the redirect is applied whenever that copy is
|
|
21
|
+
* known rather than only as a fallback.
|
|
22
|
+
*
|
|
23
|
+
* Node resolve hooks (`module.register`) rather than rewriting the file: the
|
|
24
|
+
* manifest also imports `zod`, which has to keep resolving from devtools'
|
|
25
|
+
* own location, and a copy written anywhere else would lose that.
|
|
26
|
+
*/
|
|
27
|
+
/** Registers `redirect`. Hooks cannot be unregistered, so each call adds a
|
|
28
|
+
* loader for the rest of the process; call it once per redirect. */
|
|
29
|
+
function redirectPeer(redirect) {
|
|
30
|
+
register("./peer-redirect-hooks.js", import.meta.url, { data: [redirect] });
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region ../cli-core/src/repo/tsx-loader.ts
|
|
34
|
+
/**
|
|
35
|
+
* Loads the repo's own TypeScript at runtime: env manifests
|
|
36
|
+
* (each app's `src/env.ts` and friends), cron contracts
|
|
37
|
+
* (each app's `cloudflare/scheduled.ts`), and — via `source.ts` — the
|
|
38
|
+
* `devdogs-source` condition packages (`open-graph`, `email`, `docs`).
|
|
39
|
+
*
|
|
40
|
+
* Uses `tsx`'s programmatic API (`register()` from `tsx/esm/api`), NOT the
|
|
41
|
+
* `--conditions=devdogs-source` CLI flag the old in-repo devtools used —
|
|
42
|
+
* this package ships built JS and runs from `dist/`, so there is no `tsx`
|
|
43
|
+
* process wrapping it anymore (see the package README / CUTOVER note on
|
|
44
|
+
* "built JS, tsx only for repo TS").
|
|
45
|
+
*
|
|
46
|
+
* Gotcha (FINDINGS.md experiments 3 and 4, gotcha C): do NOT pass a
|
|
47
|
+
* `namespace` to `register()`. It silently breaks tsx's own relative
|
|
48
|
+
* `./foo.js` → `./foo.ts` extension-fallback resolution for files loaded
|
|
49
|
+
* under that registration — exactly the convention `open-graph`, `email`,
|
|
50
|
+
* and any future `devdogs-source` package use for their internal relative
|
|
51
|
+
* imports. `register({})` (no options) is the only form validated.
|
|
52
|
+
*/
|
|
53
|
+
let registered = false;
|
|
54
|
+
/** Idempotent: registers tsx's ESM loader hooks once per process. */
|
|
55
|
+
async function ensureRegistered() {
|
|
56
|
+
if (registered) return;
|
|
57
|
+
const { register } = await import("tsx/esm/api");
|
|
58
|
+
register();
|
|
59
|
+
registered = true;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Imports a repo TypeScript file at an absolute path, loaded through tsx.
|
|
63
|
+
* Returns the module namespace, typed as `T` by the caller (there is no way
|
|
64
|
+
* to know the shape of an arbitrary repo file's exports statically here).
|
|
65
|
+
*/
|
|
66
|
+
async function importRepoTs(absolutePath) {
|
|
67
|
+
await ensureRegistered();
|
|
68
|
+
return import(pathToFileURL(absolutePath).href);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region ../cli-core/src/env/discovery.ts
|
|
72
|
+
/**
|
|
73
|
+
* Fills the `@devdogsuga/env` registry by importing every manifest.
|
|
74
|
+
*
|
|
75
|
+
* The registry populates as a SIDE EFFECT of importing each manifest module.
|
|
76
|
+
* `declare()` runs at import time, so a process that never imports them sees an
|
|
77
|
+
* empty registry and every derived selector returns nothing. That is the
|
|
78
|
+
* fail-open shape this module closes: anything that routes secrets calls
|
|
79
|
+
* `loadRegistry()` first, and `assertRegistryLoaded()` is the guard the
|
|
80
|
+
* selectors' consumers use to refuse an empty answer.
|
|
81
|
+
*
|
|
82
|
+
* Discovery is by filename, per the model doc: `src/env.ts`, then `env.ts`, per
|
|
83
|
+
* workspace package. Both present is a hard error, because two manifests in one
|
|
84
|
+
* package means two places for the next declaration to land and no rule saying
|
|
85
|
+
* which. No `package.json` pointer: every other tool in this repo is found by
|
|
86
|
+
* filename (`tsconfig.json`, `wrangler.jsonc`, `supadart.yaml`), and a pointer
|
|
87
|
+
* would be the only one of its kind.
|
|
88
|
+
*
|
|
89
|
+
* One special case: `supabase/env.ts` sits at the repo root, OUTSIDE the
|
|
90
|
+
* workspace globs. Its variables belong to `config.toml` and the Supabase
|
|
91
|
+
* CLI, not to any package, so it lives next to the config that reads them.
|
|
92
|
+
*
|
|
93
|
+
* `@devdogsuga/env` itself (the package that exports `define()`/`declare()`)
|
|
94
|
+
* no longer needs a special-case exclusion here: since the Backstage
|
|
95
|
+
* cutover it is an installed npm dependency, not a workspace package under
|
|
96
|
+
* `packages/`, so this scan never sees it at all.
|
|
97
|
+
*
|
|
98
|
+
* devtools' OWN operator manifest (this package's root `env.ts` — the keys
|
|
99
|
+
* no app reads at all: `BWS_ACCESS_TOKEN`, `CLOUDFLARE_API_TOKEN`, and
|
|
100
|
+
* friends) has the same problem in reverse: since the Backstage cutover
|
|
101
|
+
* devtools is no longer one of the TARGET repo's workspace packages either,
|
|
102
|
+
* so the scan below would never see it. It is loaded unconditionally,
|
|
103
|
+
* always, regardless of which repo devtools is running against — see
|
|
104
|
+
* `ownManifestPath()`'s own comment for how it stays resolvable both from a
|
|
105
|
+
* workspace checkout and from an installed `pnpm dlx`/`node_modules` copy,
|
|
106
|
+
* and for why loading it through the same `importRepoTs()` tsx path as
|
|
107
|
+
* every other manifest (rather than a plain static `import`) is what keeps
|
|
108
|
+
* its `declare()`/`define()` calls landing in the SAME `@devdogsuga/env`
|
|
109
|
+
* registry instance the target repo's manifests populate (module identity —
|
|
110
|
+
* see `repo/peers.ts`'s header and the devtools-dlx prototype's
|
|
111
|
+
* FINDINGS.md experiment 3). Its bare `@devdogsuga/env` import is
|
|
112
|
+
* redirected to the copy `loadEnv()` resolved through the repo, because
|
|
113
|
+
* from a `pnpm dlx` copy the specifier does not resolve at all: devtools
|
|
114
|
+
* ships no copy of its own (`@devdogsuga/env` is only ever an optional
|
|
115
|
+
* peer), and nothing installs one next to it. See `repo/peer-redirect.ts`.
|
|
116
|
+
*
|
|
117
|
+
* Most workspace packages declare nothing, so "no env.ts found" means
|
|
118
|
+
* not-a-manifest rather than an error.
|
|
119
|
+
*
|
|
120
|
+
* ⚠️ `apps/sandbox` was once listed here as having no manifest ON PURPOSE, on
|
|
121
|
+
* the grounds that a Worker reads bindings that arrive as a function argument
|
|
122
|
+
* rather than `process.env`. That premise is still true and the conclusion
|
|
123
|
+
* drawn from it was still wrong: a manifest is also the only thing that routes
|
|
124
|
+
* a credential to a deployed environment and the only thing that tells
|
|
125
|
+
* `env audit` a Worker secret is supposed to be there. Without one,
|
|
126
|
+
* `SANDBOX_PROXY_TOKEN`, minted at deploy time and therefore in no Bitwarden
|
|
127
|
+
* project by design, was reported as an orphan, i.e. as safe for the §3.6 prune
|
|
128
|
+
* path to delete. `apps/sandbox/env.ts` exists now, and states that reasoning
|
|
129
|
+
* at length.
|
|
130
|
+
*/
|
|
131
|
+
/**
|
|
132
|
+
* The single in-flight (or settled) load.
|
|
133
|
+
*
|
|
134
|
+
* Node's module cache already makes a second `import()` of the same manifest a
|
|
135
|
+
* no-op, but memoizing the whole pass is asserted here rather than inherited: a
|
|
136
|
+
* future bundler or test runner that re-evaluates modules would duplicate every
|
|
137
|
+
* declaration, and duplicated declarations are what the completeness test
|
|
138
|
+
* treats as a bug. A failed load stays failed. Every later call gets the same
|
|
139
|
+
* rejection, because retrying into a half-populated registry would hide the
|
|
140
|
+
* manifest that broke.
|
|
141
|
+
*/
|
|
142
|
+
let loaded;
|
|
143
|
+
/**
|
|
144
|
+
* Imports every manifest so the registry populates. Idempotent; concurrent
|
|
145
|
+
* callers share one pass. Await this before touching any derived selector.
|
|
146
|
+
*/
|
|
147
|
+
function loadRegistry() {
|
|
148
|
+
loaded ??= importManifests();
|
|
149
|
+
return loaded;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Refuses to proceed on an empty registry.
|
|
153
|
+
*
|
|
154
|
+
* For SYNC consumers of the derived selectors (`selectForPush`, `routeTo`),
|
|
155
|
+
* which cannot await the load themselves. An empty registry makes every
|
|
156
|
+
* selector return `[]`, and `[]` fails open in the worst direction: nothing is
|
|
157
|
+
* never-store, so `BWS_ACCESS_TOKEN` would upload. Better a crash naming the
|
|
158
|
+
* missing call than a push that quietly stores the unstorable.
|
|
159
|
+
*/
|
|
160
|
+
function assertRegistryLoaded() {
|
|
161
|
+
if (getEnvSync().variables().size === 0) throw new Error("The env registry is empty — no manifest has been imported, so the derived key sets would all be []. Await loadRegistry() (from devtools' env/discovery.ts) before routing or selecting secrets.");
|
|
162
|
+
}
|
|
163
|
+
async function importManifests() {
|
|
164
|
+
await loadEnv();
|
|
165
|
+
const envUrl = repoPeerUrl("@devdogsuga/env");
|
|
166
|
+
if (envUrl) redirectPeer({
|
|
167
|
+
parentURL: pathToFileURL(ownManifestPath()).href,
|
|
168
|
+
specifier: "@devdogsuga/env",
|
|
169
|
+
url: envUrl
|
|
170
|
+
});
|
|
171
|
+
const previous = process.env.SKIP_ENV_VALIDATION;
|
|
172
|
+
process.env.SKIP_ENV_VALIDATION = "1";
|
|
173
|
+
try {
|
|
174
|
+
for (const path of manifestPaths()) try {
|
|
175
|
+
await importRepoTs(path);
|
|
176
|
+
} catch (cause) {
|
|
177
|
+
throw new Error(`The env manifest at ${path} failed to import.`, { cause });
|
|
178
|
+
}
|
|
179
|
+
} finally {
|
|
180
|
+
if (previous === void 0) delete process.env.SKIP_ENV_VALIDATION;
|
|
181
|
+
else process.env.SKIP_ENV_VALIDATION = previous;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Every manifest file, in a stable order.
|
|
186
|
+
*
|
|
187
|
+
* The workspace members are enumerated by scanning `apps/*` and `packages/*`
|
|
188
|
+
* plus the literal `docs`, a deliberately boring mirror of the three globs in
|
|
189
|
+
* `pnpm-workspace.yaml` rather than a YAML parse: the globs have not changed
|
|
190
|
+
* since the workspace existed, devtools carries no YAML dependency, and a new
|
|
191
|
+
* top-level glob would already mean editing more interesting files than this
|
|
192
|
+
* one.
|
|
193
|
+
*/
|
|
194
|
+
function manifestPaths() {
|
|
195
|
+
const paths = [];
|
|
196
|
+
for (const dir of workspaceDirs()) {
|
|
197
|
+
const manifest = manifestIn(dir);
|
|
198
|
+
if (manifest) paths.push(manifest);
|
|
199
|
+
}
|
|
200
|
+
const supabase = manifestIn(join(findRepoRoot(), "supabase"));
|
|
201
|
+
if (supabase) paths.push(supabase);
|
|
202
|
+
paths.push(ownManifestPath());
|
|
203
|
+
return paths;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The absolute path to devtools' own `env.ts`, resolved relative to THIS
|
|
207
|
+
* module's own file rather than the target repo — it ships alongside
|
|
208
|
+
* `dist/` (see `package.json`'s `files`), not inside the target repo's
|
|
209
|
+
* workspace, so `findRepoRoot()`/`workspaceDirs()` can never find it.
|
|
210
|
+
*
|
|
211
|
+
* The package root is `ownPackageDir()`: `env.ts` sits there, deliberately
|
|
212
|
+
* outside `src/` (see that file's own header, and `tsconfig.typecheck.json`,
|
|
213
|
+
* which includes it as a sibling of `src` for exactly that reason). Same file,
|
|
214
|
+
* same relative shape, in both a workspace checkout
|
|
215
|
+
* (`packages/devtools/env.ts`) and an installed copy
|
|
216
|
+
* (`node_modules/@devdogsuga/devtools/env.ts`).
|
|
217
|
+
*/
|
|
218
|
+
function ownManifestPath() {
|
|
219
|
+
return join(ownPackageDir(), "env.ts");
|
|
220
|
+
}
|
|
221
|
+
function workspaceDirs() {
|
|
222
|
+
const dirs = [];
|
|
223
|
+
const repoRoot = findRepoRoot();
|
|
224
|
+
for (const parent of ["apps", "packages"]) {
|
|
225
|
+
const names = [];
|
|
226
|
+
for (const entry of readdirSync(join(repoRoot, parent), { withFileTypes: true })) {
|
|
227
|
+
if (!entry.isDirectory()) continue;
|
|
228
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
229
|
+
names.push(entry.name);
|
|
230
|
+
}
|
|
231
|
+
names.sort();
|
|
232
|
+
for (const name of names) dirs.push(join(repoRoot, parent, name));
|
|
233
|
+
}
|
|
234
|
+
dirs.push(join(repoRoot, "docs"));
|
|
235
|
+
return dirs;
|
|
236
|
+
}
|
|
237
|
+
/** `src/env.ts`, then `env.ts`; both present in one package is a hard error. */
|
|
238
|
+
function manifestIn(dir) {
|
|
239
|
+
const inSrc = join(dir, "src", "env.ts");
|
|
240
|
+
const atRoot = join(dir, "env.ts");
|
|
241
|
+
const hasSrc = existsSync(inSrc);
|
|
242
|
+
const hasRoot = existsSync(atRoot);
|
|
243
|
+
if (hasSrc && hasRoot) throw new Error(`${dir} has BOTH src/env.ts and env.ts. One package gets one manifest — two of them means two places for the next declaration to land, and no rule saying which. Merge them.`);
|
|
244
|
+
return hasSrc ? inSrc : hasRoot ? atRoot : null;
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/cf/local-env.ts
|
|
248
|
+
function renderWranglerEnvFile(keys, environment) {
|
|
249
|
+
return keys.flatMap((key) => {
|
|
250
|
+
const value = environment[key];
|
|
251
|
+
return value === void 0 ? [] : [`${key}='${value}'`];
|
|
252
|
+
}).join("\n") + "\n";
|
|
253
|
+
}
|
|
254
|
+
/** The app's declared keys, deduped and sorted, from the given entries or the
|
|
255
|
+
* loaded registry.
|
|
256
|
+
*
|
|
257
|
+
* `DEPLOY_ENV` and `NODE_ENV` are excluded BY NAME, not by any registry-meta
|
|
258
|
+
* heuristic. Their committed source is wrangler.jsonc's per-env `vars` blocks
|
|
259
|
+
* (and the framework), never an env file — see each key's `define()` doc.
|
|
260
|
+
* Materializing them into the temp `.dev.vars` this file feeds to `wrangler
|
|
261
|
+
* dev` lets a stray or empty `.env` value OVERRIDE the tier's wrangler var,
|
|
262
|
+
* which surfaced as a Workflow isolate reading a blank `DEPLOY_ENV` and
|
|
263
|
+
* throwing "has no HYPERDRIVE binding".
|
|
264
|
+
*
|
|
265
|
+
* A `scope: "default"` + `commented: true` filter was tried first and is
|
|
266
|
+
* WRONG: that shape also matches `GITHUB_COMPETITION_REPO`, an opt-in
|
|
267
|
+
* override a contributor sets deliberately in their `.env` (its wrangler
|
|
268
|
+
* config defines no such var), and the heuristic silently stripped it from
|
|
269
|
+
* `wrangler dev`'s environment. Wrangler-ownership is a fact about
|
|
270
|
+
* wrangler.jsonc, not about registry metadata, so the two keys it is true
|
|
271
|
+
* for are named outright. */
|
|
272
|
+
const WRANGLER_OWNED_KEYS = /* @__PURE__ */ new Set(["DEPLOY_ENV", "NODE_ENV"]);
|
|
273
|
+
async function scopedKeys(app, entries) {
|
|
274
|
+
if (!entries) {
|
|
275
|
+
await loadRegistry();
|
|
276
|
+
entries = (await loadEnv()).declarations();
|
|
277
|
+
}
|
|
278
|
+
return [...new Set(entries.filter((entry) => entry.source === app).filter((entry) => !WRANGLER_OWNED_KEYS.has(entry.key)).map((entry) => entry.key))].sort();
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The process env for a `vinext dev` child, scoped the way the temp
|
|
282
|
+
* `.dev.vars` is for `wrangler dev`.
|
|
283
|
+
*
|
|
284
|
+
* `@cloudflare/vite-plugin` has no `--env-file`: it reads the app dir's own
|
|
285
|
+
* `.dev.vars`/`.env`, or — with `CLOUDFLARE_INCLUDE_PROCESS_ENV` — its whole
|
|
286
|
+
* `process.env`, as Worker vars that override wrangler.jsonc's `vars`. So the
|
|
287
|
+
* scoping happens on the child's env instead: every key some OTHER app
|
|
288
|
+
* declares (and this app doesn't) is dropped, `NODE_ENV` is left to Vite, and
|
|
289
|
+
* `DEPLOY_ENV` is pinned to the tier rather than dropped, because the Vite
|
|
290
|
+
* process's own `next.config.ts` reads it too. Undeclared keys (PATH, HOME,
|
|
291
|
+
* pnpm's own) stay; the child needs them and they carry no app secrets.
|
|
292
|
+
*/
|
|
293
|
+
async function scopedProcessEnv(app, environment, tier, entries) {
|
|
294
|
+
if (!entries) {
|
|
295
|
+
await loadRegistry();
|
|
296
|
+
entries = (await loadEnv()).declarations();
|
|
297
|
+
}
|
|
298
|
+
const own = new Set(await scopedKeys(app, entries));
|
|
299
|
+
const scoped = { ...environment };
|
|
300
|
+
for (const entry of entries) if (entry.source !== app && !own.has(entry.key)) delete scoped[entry.key];
|
|
301
|
+
delete scoped.NODE_ENV;
|
|
302
|
+
scoped.DEPLOY_ENV = tier;
|
|
303
|
+
scoped.CLOUDFLARE_INCLUDE_PROCESS_ENV = "true";
|
|
304
|
+
return scoped;
|
|
305
|
+
}
|
|
306
|
+
/** Writes the mode-0600 `.dev.vars` into a fresh private temp directory. */
|
|
307
|
+
function materializeEnvFile(keys, environment) {
|
|
308
|
+
const directory = mkdtempSync(join(tmpdir(), "devtools-wrangler-env-"));
|
|
309
|
+
const path = join(directory, ".dev.vars");
|
|
310
|
+
writeFileSync(path, renderWranglerEnvFile(keys, environment), {
|
|
311
|
+
encoding: "utf8",
|
|
312
|
+
mode: 384
|
|
313
|
+
});
|
|
314
|
+
return {
|
|
315
|
+
directory,
|
|
316
|
+
path
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Create an app-scoped, mode-0600 env file for a local Worker runtime whose
|
|
321
|
+
* lifetime a single bracket callback cannot express.
|
|
322
|
+
*
|
|
323
|
+
* ⚠️ KEPT DELIBERATELY, not an oversight: `workflows/commands.ts` holds this
|
|
324
|
+
* file open across a long-lived `wrangler dev` child process, and in the
|
|
325
|
+
* `workflows run` temporary-session path that span crosses a `finally` that
|
|
326
|
+
* is unrelated to starting Wrangler at all — it also triggers a Workflow and
|
|
327
|
+
* polls for its completion before the session stops. Squeezing that into a
|
|
328
|
+
* single `withWranglerEnv` callback would mean merging two previously
|
|
329
|
+
* independent concerns (spinning up a dev session; triggering-and-waiting)
|
|
330
|
+
* into one control path, which is a real redesign of a 700-line orchestrator,
|
|
331
|
+
* not a mechanical bracket swap — and duplicating this function's
|
|
332
|
+
* retry/readiness loop across a bracket-shaped variant just to convert the
|
|
333
|
+
* `workflows serve` half would fragment one shared, tested implementation
|
|
334
|
+
* into two for no behavioural gain.
|
|
335
|
+
*
|
|
336
|
+
* `env` mirrors `withWranglerEnv`'s `options.env`: pass a tier's loaded map to
|
|
337
|
+
* materialize a scoped file from THAT tier rather than the inherited process
|
|
338
|
+
* environment; omit it to keep today's behavior.
|
|
339
|
+
*/
|
|
340
|
+
async function createTemporaryWranglerEnv(app, env) {
|
|
341
|
+
const { directory, path } = materializeEnvFile(await scopedKeys(app), env ?? process.env);
|
|
342
|
+
return {
|
|
343
|
+
path,
|
|
344
|
+
remove: () => rmSync(directory, {
|
|
345
|
+
recursive: true,
|
|
346
|
+
force: true
|
|
347
|
+
})
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
export { loadRegistry as a, assertRegistryLoaded as i, renderWranglerEnvFile as n, scopedProcessEnv as r, createTemporaryWranglerEnv as t };
|