@geekmidas/cli 10.0.0-alpha.62 → 10.0.0-alpha.63
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 +2 -0
- package/dist/{HostingerProvider-B92qH4dC.mjs → HostingerProvider-DBBwpDjn.mjs} +2 -2
- package/dist/{HostingerProvider-B92qH4dC.mjs.map → HostingerProvider-DBBwpDjn.mjs.map} +1 -1
- package/dist/{HostingerProvider-DyD1Hin8.cjs → HostingerProvider-mJ7YruxH.cjs} +2 -2
- package/dist/{HostingerProvider-DyD1Hin8.cjs.map → HostingerProvider-mJ7YruxH.cjs.map} +1 -1
- package/dist/{LegacyStateStore-UHJEBLdn.cjs → LegacyStateStore-CP7SZwTP.cjs} +2 -2
- package/dist/{LegacyStateStore-UHJEBLdn.cjs.map → LegacyStateStore-CP7SZwTP.cjs.map} +1 -1
- package/dist/{LegacyStateStore-A8d2GdT7.mjs → LegacyStateStore-Q3GmKOdw.mjs} +2 -2
- package/dist/{LegacyStateStore-A8d2GdT7.mjs.map → LegacyStateStore-Q3GmKOdw.mjs.map} +1 -1
- package/dist/{LocalStateStore-B51rnfgn.mjs → LocalStateStore-BGIXcrvX.mjs} +2 -2
- package/dist/{LocalStateStore-B51rnfgn.mjs.map → LocalStateStore-BGIXcrvX.mjs.map} +1 -1
- package/dist/{LocalStateStore-COW3Ldwa.cjs → LocalStateStore-sS8mvLeq.cjs} +2 -2
- package/dist/{LocalStateStore-COW3Ldwa.cjs.map → LocalStateStore-sS8mvLeq.cjs.map} +1 -1
- package/dist/{OpenApiTsGenerator-BSrgw7B0.cjs → OpenApiTsGenerator-CjHWFRDd.cjs} +2 -2
- package/dist/{OpenApiTsGenerator-BSrgw7B0.cjs.map → OpenApiTsGenerator-CjHWFRDd.cjs.map} +1 -1
- package/dist/{OpenApiTsGenerator-q5B0z8Xg.mjs → OpenApiTsGenerator-CnAwhGxi.mjs} +2 -2
- package/dist/{OpenApiTsGenerator-q5B0z8Xg.mjs.map → OpenApiTsGenerator-CnAwhGxi.mjs.map} +1 -1
- package/dist/{S3StateStore-WUJGdRNL.cjs → S3StateStore-6jqITH2F.cjs} +2 -2
- package/dist/{S3StateStore-WUJGdRNL.cjs.map → S3StateStore-6jqITH2F.cjs.map} +1 -1
- package/dist/{S3StateStore-CJewPhgz.mjs → S3StateStore-D7l_lWJ3.mjs} +2 -2
- package/dist/{S3StateStore-CJewPhgz.mjs.map → S3StateStore-D7l_lWJ3.mjs.map} +1 -1
- package/dist/{SSMStateStore-Zejt42V8.cjs → SSMStateStore-B__F7IJa.cjs} +2 -2
- package/dist/{SSMStateStore-Zejt42V8.cjs.map → SSMStateStore-B__F7IJa.cjs.map} +1 -1
- package/dist/{SSMStateStore-iK5UKp9d.mjs → SSMStateStore-CAQDVpoc.mjs} +2 -2
- package/dist/{SSMStateStore-iK5UKp9d.mjs.map → SSMStateStore-CAQDVpoc.mjs.map} +1 -1
- package/dist/{bundler-CfH9frOS.cjs → bundler-DLfOn0ls.cjs} +3 -3
- package/dist/{bundler-CfH9frOS.cjs.map → bundler-DLfOn0ls.cjs.map} +1 -1
- package/dist/{bundler-DN5r4x5b.mjs → bundler-DyWI41Iy.mjs} +2 -2
- package/dist/{bundler-DN5r4x5b.mjs.map → bundler-DyWI41Iy.mjs.map} +1 -1
- package/dist/{cli-DOAUp80L.cjs → cli-D-ZM-X2s.cjs} +4 -4
- package/dist/{cli-DOAUp80L.cjs.map → cli-D-ZM-X2s.cjs.map} +1 -1
- package/dist/{cli-DYwxmfsW.mjs → cli-PkVF28LM.mjs} +4 -4
- package/dist/{cli-DYwxmfsW.mjs.map → cli-PkVF28LM.mjs.map} +1 -1
- package/dist/{config-BYh9S0cZ.cjs → config-BEJYKd4s.cjs} +132 -18
- package/dist/config-BEJYKd4s.cjs.map +1 -0
- package/dist/config-C2BUosLm.d.mts +256 -0
- package/dist/config-C2BUosLm.d.mts.map +1 -0
- package/dist/config-CemHVcIr.d.cts +256 -0
- package/dist/config-CemHVcIr.d.cts.map +1 -0
- package/dist/{config-Bf4-bROQ.mjs → config-LKKCVCnC.mjs} +109 -19
- package/dist/config-LKKCVCnC.mjs.map +1 -0
- package/dist/config.cjs +6 -2
- package/dist/config.d.cts +3 -210
- package/dist/config.d.mts +3 -210
- package/dist/config.mjs +3 -3
- package/dist/deploy/public.cjs +151 -5
- package/dist/deploy/public.cjs.map +1 -0
- package/dist/deploy/public.d.cts +186 -1
- package/dist/deploy/public.d.cts.map +1 -1
- package/dist/deploy/public.d.mts +186 -1
- package/dist/deploy/public.d.mts.map +1 -1
- package/dist/deploy/public.mjs +134 -6
- package/dist/deploy/public.mjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.cjs +54 -0
- package/dist/deploy/sniffer-envparser-worker.cjs.map +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.cts +1 -0
- package/dist/deploy/sniffer-envparser-worker.d.mts +1 -0
- package/dist/deploy/sniffer-envparser-worker.mjs +55 -0
- package/dist/deploy/sniffer-envparser-worker.mjs.map +1 -0
- package/dist/{deploy-DSaCYvcO.cjs → deploy-ABBI0lf1.cjs} +7 -7
- package/dist/{deploy-DSaCYvcO.cjs.map → deploy-ABBI0lf1.cjs.map} +1 -1
- package/dist/{deploy-D8Qr-Xto.cjs → deploy-BiMrP9i7.cjs} +11 -9
- package/dist/deploy-BiMrP9i7.cjs.map +1 -0
- package/dist/{deploy-B7jvUORo.mjs → deploy-CG8bfFij.mjs} +7 -7
- package/dist/{deploy-B7jvUORo.mjs.map → deploy-CG8bfFij.mjs.map} +1 -1
- package/dist/{deploy-Cg9fae7a.mjs → deploy-CGW-QY9D.mjs} +11 -9
- package/dist/deploy-CGW-QY9D.mjs.map +1 -0
- package/dist/discover-B6yPpvRV.d.mts +99 -0
- package/dist/discover-B6yPpvRV.d.mts.map +1 -0
- package/dist/discover-B_IkPukx.d.cts +99 -0
- package/dist/discover-B_IkPukx.d.cts.map +1 -0
- package/dist/discover-BaT6bpnA.mjs +614 -0
- package/dist/discover-BaT6bpnA.mjs.map +1 -0
- package/dist/discover-C_6COHEv.cjs +729 -0
- package/dist/discover-C_6COHEv.cjs.map +1 -0
- package/dist/{dokploy-CD9PY-3D.mjs → dokploy-CwdmlyQL.mjs} +2 -2
- package/dist/{dokploy-CD9PY-3D.mjs.map → dokploy-CwdmlyQL.mjs.map} +1 -1
- package/dist/{dokploy-Ey2foJLv.cjs → dokploy-QJxMhxdf.cjs} +2 -2
- package/dist/{dokploy-Ey2foJLv.cjs.map → dokploy-QJxMhxdf.cjs.map} +1 -1
- package/dist/{encryption-CVwvGbsL.mjs → encryption-CbQG_ayW.mjs} +4 -4
- package/dist/{encryption-CVwvGbsL.mjs.map → encryption-CbQG_ayW.mjs.map} +1 -1
- package/dist/{encryption-ChBk3hTj.cjs → encryption-DXw3jj0c.cjs} +4 -4
- package/dist/{encryption-ChBk3hTj.cjs.map → encryption-DXw3jj0c.cjs.map} +1 -1
- package/dist/fakes-C9RiT6XG.mjs.map +1 -1
- package/dist/fakes-zW-jNAbQ.cjs.map +1 -1
- package/dist/{github-OUgPDlqg.cjs → github-BH_mETav.cjs} +3 -3
- package/dist/{github-OUgPDlqg.cjs.map → github-BH_mETav.cjs.map} +1 -1
- package/dist/{github-BCB3_LBX.mjs → github-ciwbIwVa.mjs} +3 -3
- package/dist/{github-BCB3_LBX.mjs.map → github-ciwbIwVa.mjs.map} +1 -1
- package/dist/index.cjs +55 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +52 -45
- package/dist/index.mjs.map +1 -1
- package/dist/{migrate-dnaFMvOm.cjs → migrate-6oa9y_f2.cjs} +5 -5
- package/dist/{migrate-dnaFMvOm.cjs.map → migrate-6oa9y_f2.cjs.map} +1 -1
- package/dist/{migrate-BoHMqdCu.mjs → migrate-ImBKTBcW.mjs} +5 -5
- package/dist/{migrate-BoHMqdCu.mjs.map → migrate-ImBKTBcW.mjs.map} +1 -1
- package/dist/openapi.cjs +3 -3
- package/dist/openapi.mjs +3 -3
- package/dist/{ready-XlNx-Gbo.cjs → ready-BiG0rt4h.cjs} +3 -3
- package/dist/{ready-XlNx-Gbo.cjs.map → ready-BiG0rt4h.cjs.map} +1 -1
- package/dist/{ready-DQIy21W5.mjs → ready-Bpdnn2ON.mjs} +3 -3
- package/dist/{ready-DQIy21W5.mjs.map → ready-Bpdnn2ON.mjs.map} +1 -1
- package/dist/reconcile/public.cjs +1 -1
- package/dist/reconcile/public.d.cts +3 -76
- package/dist/reconcile/public.d.cts.map +1 -1
- package/dist/reconcile/public.d.mts +3 -76
- package/dist/reconcile/public.d.mts.map +1 -1
- package/dist/reconcile/public.mjs +1 -1
- package/dist/{resolve-CFCIkm7m.mjs → resolve-B1T0hUaR.mjs} +2 -2
- package/dist/{resolve-CFCIkm7m.mjs.map → resolve-B1T0hUaR.mjs.map} +1 -1
- package/dist/{resolve-wbv66HjD.cjs → resolve-xytBTtG4.cjs} +2 -2
- package/dist/{resolve-wbv66HjD.cjs.map → resolve-xytBTtG4.cjs.map} +1 -1
- package/dist/sandbox/config-worker.cjs +43 -0
- package/dist/sandbox/config-worker.cjs.map +1 -0
- package/dist/sandbox/config-worker.d.cts +1 -0
- package/dist/sandbox/config-worker.d.mts +1 -0
- package/dist/sandbox/config-worker.mjs +44 -0
- package/dist/sandbox/config-worker.mjs.map +1 -0
- package/dist/sandbox/discover-worker.cjs +44 -0
- package/dist/sandbox/discover-worker.cjs.map +1 -0
- package/dist/sandbox/discover-worker.d.cts +1 -0
- package/dist/sandbox/discover-worker.d.mts +1 -0
- package/dist/sandbox/discover-worker.mjs +45 -0
- package/dist/sandbox/discover-worker.mjs.map +1 -0
- package/dist/sandbox-M8UnLhXE.d.cts +126 -0
- package/dist/sandbox-M8UnLhXE.d.cts.map +1 -0
- package/dist/sandbox-M8UnLhXE.d.mts +126 -0
- package/dist/sandbox-M8UnLhXE.d.mts.map +1 -0
- package/dist/{workspace-BFe57es7.mjs → schemas-Ckm_aBnF.cjs} +71 -982
- package/dist/schemas-Ckm_aBnF.cjs.map +1 -0
- package/dist/{workspace-B6zQO6RY.cjs → schemas-D2LCF689.mjs} +2 -1168
- package/dist/schemas-D2LCF689.mjs.map +1 -0
- package/dist/{sniffer-BsfPa-GA.cjs → sniffer-D_SYc_pO.cjs} +369 -207
- package/dist/sniffer-D_SYc_pO.cjs.map +1 -0
- package/dist/{sniffer-DHE2Nafd.mjs → sniffer-aO_-s5vq.mjs} +336 -204
- package/dist/sniffer-aO_-s5vq.mjs.map +1 -0
- package/dist/target/public.cjs +1 -1
- package/dist/target/public.mjs +1 -1
- package/dist/{terminal-6oL0vANs.cjs → terminal-D0f1u0LG.cjs} +6 -6
- package/dist/{terminal-6oL0vANs.cjs.map → terminal-D0f1u0LG.cjs.map} +1 -1
- package/dist/{terminal-ByZNjuig.mjs → terminal-gMxAo9Dj.mjs} +6 -6
- package/dist/{terminal-ByZNjuig.mjs.map → terminal-gMxAo9Dj.mjs.map} +1 -1
- package/dist/vitest.cjs +2 -2
- package/dist/vitest.mjs +2 -2
- package/dist/workerRuntime-BXfhbe13.cjs +108 -0
- package/dist/workerRuntime-BXfhbe13.cjs.map +1 -0
- package/dist/workerRuntime-CsOyBRx2.mjs +79 -0
- package/dist/workerRuntime-CsOyBRx2.mjs.map +1 -0
- package/dist/workspace/index.cjs +1 -1
- package/dist/workspace/index.mjs +1 -1
- package/dist/workspace-Dh7rr7l4.mjs +1024 -0
- package/dist/workspace-Dh7rr7l4.mjs.map +1 -0
- package/dist/workspace-Kl4NG9IH.cjs +1196 -0
- package/dist/workspace-Kl4NG9IH.cjs.map +1 -0
- package/package.json +13 -13
- package/dist/config-BYh9S0cZ.cjs.map +0 -1
- package/dist/config-Bf4-bROQ.mjs.map +0 -1
- package/dist/config.d.cts.map +0 -1
- package/dist/config.d.mts.map +0 -1
- package/dist/deploy-Cg9fae7a.mjs.map +0 -1
- package/dist/deploy-D8Qr-Xto.cjs.map +0 -1
- package/dist/discover-Bc-4eA_p.cjs +0 -299
- package/dist/discover-Bc-4eA_p.cjs.map +0 -1
- package/dist/discover-FrYvzkeC.mjs +0 -262
- package/dist/discover-FrYvzkeC.mjs.map +0 -1
- package/dist/sniffer-BsfPa-GA.cjs.map +0 -1
- package/dist/sniffer-DHE2Nafd.mjs.map +0 -1
- package/dist/workspace-B6zQO6RY.cjs.map +0 -1
- package/dist/workspace-BFe57es7.mjs.map +0 -1
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BhDjJH2R.mjs";
|
|
2
|
+
import { a as discriminatedUnion, c as object, l as record, n as array, o as literal, u as string } from "./schemas-D2LCF689.mjs";
|
|
3
|
+
import { t as WORKER_RESULT_MARKER } from "./workerRuntime-CsOyBRx2.mjs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
6
|
+
import { existsSync, realpathSync } from "node:fs";
|
|
7
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
+
import { format } from "node:util";
|
|
9
|
+
import { assertDerivations, canonicalId } from "@geekmidas/manifest";
|
|
10
|
+
import fg from "fast-glob";
|
|
11
|
+
import kebabCase$1 from "lodash.kebabcase";
|
|
12
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
13
|
+
//#region src/output.ts
|
|
14
|
+
/**
|
|
15
|
+
* Where the CLI's progress lines go.
|
|
16
|
+
*
|
|
17
|
+
* Commands write their progress through `output` rather than `console`. Run
|
|
18
|
+
* from the terminal that is the same thing. Run inside `deploy()`, each line
|
|
19
|
+
* goes to the run that wrote it instead — as an event its caller can iterate,
|
|
20
|
+
* and to the logger it was handed — so a deploy embedded in another program
|
|
21
|
+
* does not print over that program's own output.
|
|
22
|
+
*
|
|
23
|
+
* Carried by `AsyncLocalStorage` rather than passed down, because the lines
|
|
24
|
+
* come from everywhere a deploy reaches — the Dockerfile generator, the env
|
|
25
|
+
* sniffer, construct discovery — and two deploys running in one process must
|
|
26
|
+
* not hear each other.
|
|
27
|
+
*/
|
|
28
|
+
const current = new AsyncLocalStorage();
|
|
29
|
+
/** Runs `fn` with every line written through `output` sent to `sink`. */
|
|
30
|
+
function withOutput(sink, fn) {
|
|
31
|
+
return current.run(sink, fn);
|
|
32
|
+
}
|
|
33
|
+
function write(level, fallback) {
|
|
34
|
+
return (...args) => {
|
|
35
|
+
const sink = current.getStore();
|
|
36
|
+
if (sink) sink(level, format(...args));
|
|
37
|
+
else fallback(...args);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* `console`, for the methods the CLI logs through — routed to the current
|
|
42
|
+
* run's sink when there is one.
|
|
43
|
+
*/
|
|
44
|
+
const output = {
|
|
45
|
+
log: write("info", (...args) => console.log(...args)),
|
|
46
|
+
info: write("info", (...args) => console.info(...args)),
|
|
47
|
+
warn: write("warn", (...args) => console.warn(...args)),
|
|
48
|
+
error: write("error", (...args) => console.error(...args))
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/generators/Generator.ts
|
|
52
|
+
/**
|
|
53
|
+
* Zod v4 maintains a process-wide registry of schemas registered via
|
|
54
|
+
* `.meta({ id })`. When we cache-bust user module imports (by appending a
|
|
55
|
+
* `?t=timestamp` query), those modules re-execute and try to register the
|
|
56
|
+
* same ids again, which throws `ID X already exists in the registry`.
|
|
57
|
+
*
|
|
58
|
+
* Clearing the registry in the CLI process is safe: the user's running
|
|
59
|
+
* server lives in a subprocess and has its own isolated registry.
|
|
60
|
+
*
|
|
61
|
+
* Exported for tests.
|
|
62
|
+
*/
|
|
63
|
+
function clearZodGlobalRegistry() {
|
|
64
|
+
const registry = globalThis.__zod_globalRegistry;
|
|
65
|
+
if (registry && typeof registry.clear === "function") registry.clear();
|
|
66
|
+
}
|
|
67
|
+
var ConstructGenerator = class {
|
|
68
|
+
static async build(context, outputDir, generator, patterns, options) {
|
|
69
|
+
const constructs = await generator.load(patterns);
|
|
70
|
+
return generator.build(context, constructs, outputDir, options);
|
|
71
|
+
}
|
|
72
|
+
async load(patterns, cwd = process.cwd(), bustCache = false) {
|
|
73
|
+
const logger = console;
|
|
74
|
+
const globPatterns = Array.isArray(patterns) ? patterns : patterns ? [patterns] : [];
|
|
75
|
+
const files = fg.stream(globPatterns, {
|
|
76
|
+
cwd,
|
|
77
|
+
absolute: true
|
|
78
|
+
});
|
|
79
|
+
if (bustCache) clearZodGlobalRegistry();
|
|
80
|
+
const constructs = [];
|
|
81
|
+
for await (const f of files) try {
|
|
82
|
+
const file = f.toString();
|
|
83
|
+
const module = await (bustCache ? import(`${file}?t=${Date.now()}`) : import(file));
|
|
84
|
+
for (const [key, construct] of Object.entries(module)) if (this.isConstruct(construct)) constructs.push({
|
|
85
|
+
key,
|
|
86
|
+
name: kebabCase$1(key),
|
|
87
|
+
construct,
|
|
88
|
+
path: {
|
|
89
|
+
absolute: file,
|
|
90
|
+
relative: relative(process.cwd(), file)
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
} catch (error) {
|
|
94
|
+
const err = error;
|
|
95
|
+
logger.error(`Failed to load ${f}: ${err.message}`);
|
|
96
|
+
if (err.stack) logger.error(err.stack);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
return constructs;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/sandbox/sandbox.ts
|
|
104
|
+
/**
|
|
105
|
+
* Where a deploy runs the project's own code.
|
|
106
|
+
*
|
|
107
|
+
* A deploy holds credentials — Dokploy's token, a registry login, an AWS key —
|
|
108
|
+
* and loading `gkm.config.ts`, sniffing an app's environment and building it
|
|
109
|
+
* all execute code from the repository being deployed. On a developer's own
|
|
110
|
+
* laptop that is the developer's code. On a CI job for a fork, or a shared
|
|
111
|
+
* build runner, it is not, and that code should not be able to read the
|
|
112
|
+
* credentials used to deploy it, hang the deploy, or reach outside the
|
|
113
|
+
* checkout.
|
|
114
|
+
*
|
|
115
|
+
* So every step that runs project code goes through a `Sandbox`: one call,
|
|
116
|
+
* with an argument array rather than a shell line, the complete environment
|
|
117
|
+
* the step needs rather than the host's, a timeout it cannot outlive, secrets
|
|
118
|
+
* as files rather than variables, and a working directory inside the project.
|
|
119
|
+
* The steps that need credentials — provisioning, pushing, releasing — are
|
|
120
|
+
* the deploy's own code and never run in one.
|
|
121
|
+
*
|
|
122
|
+
* `LocalSandbox` is the default: a child process on this machine with an
|
|
123
|
+
* allowlisted environment. A host that builds repositories it does not trust
|
|
124
|
+
* passes its own — a container per build, a VM — through `deploy()`'s
|
|
125
|
+
* `sandbox`.
|
|
126
|
+
*/
|
|
127
|
+
/** The variable naming the directory a command's secrets are mounted in. */
|
|
128
|
+
const SECRETS_DIR_ENV = "GKM_SECRETS_DIR";
|
|
129
|
+
/** A command was asked to run outside the project. */
|
|
130
|
+
var SandboxCwdEscape = class extends Error {
|
|
131
|
+
cwd;
|
|
132
|
+
root;
|
|
133
|
+
constructor(cwd, root) {
|
|
134
|
+
super(`Refusing to run in '${cwd}': it is outside the project at '${root}'. A sandboxed step only runs inside the project it was given — check the app paths in gkm.config.ts for \`..\` or an absolute path.`);
|
|
135
|
+
this.cwd = cwd;
|
|
136
|
+
this.root = root;
|
|
137
|
+
this.name = "SandboxCwdEscape";
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
/** A path with its symlinks resolved where it exists — `/tmp` is `/private/tmp`. */
|
|
141
|
+
function real(path) {
|
|
142
|
+
return existsSync(path) ? realpathSync(path) : path;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* `cwd` as an absolute directory inside `root`, or {@link SandboxCwdEscape}.
|
|
146
|
+
*
|
|
147
|
+
* Symlinks are resolved on both sides first, so a link inside the project
|
|
148
|
+
* that points out of it is an escape, and a project reached through a link
|
|
149
|
+
* (`/tmp` on macOS) is still itself. For a sandbox of a host's own to call
|
|
150
|
+
* before it runs anything.
|
|
151
|
+
*/
|
|
152
|
+
function confineCwd(root, cwd) {
|
|
153
|
+
const absolute = resolve(root, cwd);
|
|
154
|
+
const from = relative(real(resolve(root)), real(absolute));
|
|
155
|
+
if (from === ".." || from.startsWith(`..${sep}`) || isAbsolute(from)) throw new SandboxCwdEscape(cwd, root);
|
|
156
|
+
return absolute;
|
|
157
|
+
}
|
|
158
|
+
/** A secret's file name: one path segment, so it cannot be written elsewhere. */
|
|
159
|
+
var SecretNameInvalid = class extends Error {
|
|
160
|
+
secretName;
|
|
161
|
+
constructor(secretName) {
|
|
162
|
+
super(`'${secretName}' cannot be a secret's name: it becomes a file name in the secrets directory, so it must be one segment of letters, digits, '.', '-' or '_' and not start with '.'.`);
|
|
163
|
+
this.secretName = secretName;
|
|
164
|
+
this.name = "SecretNameInvalid";
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const SECRET_NAME = /^[A-Za-z0-9_-][A-Za-z0-9._-]*$/;
|
|
168
|
+
/** Every secret name, checked before anything is written. */
|
|
169
|
+
function assertSecretNames(secrets) {
|
|
170
|
+
for (const name of Object.keys(secrets ?? {})) if (!SECRET_NAME.test(name)) throw new SecretNameInvalid(name);
|
|
171
|
+
}
|
|
172
|
+
const active = new AsyncLocalStorage();
|
|
173
|
+
/**
|
|
174
|
+
* Run `fn` with `sandbox` as the one its steps use.
|
|
175
|
+
*
|
|
176
|
+
* Per run rather than global, as `withOutput` routes a run's lines: two
|
|
177
|
+
* deploys in one host process each build in their own sandbox. A step deep in
|
|
178
|
+
* the engine — discovering constructs, sniffing an app — asks
|
|
179
|
+
* {@link activeSandbox} rather than every function between `deploy()` and it
|
|
180
|
+
* taking one more parameter.
|
|
181
|
+
*/
|
|
182
|
+
function withSandbox(sandbox, fn) {
|
|
183
|
+
return active.run({
|
|
184
|
+
sandbox,
|
|
185
|
+
answers: /* @__PURE__ */ new Map()
|
|
186
|
+
}, fn);
|
|
187
|
+
}
|
|
188
|
+
/** The sandbox of the run this is part of, if it was started with one. */
|
|
189
|
+
function activeSandbox() {
|
|
190
|
+
return active.getStore()?.sandbox;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* `ask()`'s answer, asked once per run.
|
|
194
|
+
*
|
|
195
|
+
* A deploy loads its config and discovers its constructs from several places
|
|
196
|
+
* — the first load, the engine, the Dockerfile generator — and in a sandbox
|
|
197
|
+
* each was a child process of its own, for the same answer: the checkout does
|
|
198
|
+
* not change while it deploys. Within a run in `sandbox`, the first answer
|
|
199
|
+
* for `key` is the one every later ask gets. Outside one, or for another
|
|
200
|
+
* sandbox, `ask()` runs each time.
|
|
201
|
+
*/
|
|
202
|
+
function oncePerRun(sandbox, key, ask) {
|
|
203
|
+
const run = active.getStore();
|
|
204
|
+
if (!run || run.sandbox !== sandbox) return ask();
|
|
205
|
+
let answer = run.answers.get(key);
|
|
206
|
+
if (!answer) {
|
|
207
|
+
answer = ask();
|
|
208
|
+
run.answers.set(key, answer);
|
|
209
|
+
answer.catch(() => run.answers.delete(key));
|
|
210
|
+
}
|
|
211
|
+
return answer;
|
|
212
|
+
}
|
|
213
|
+
//#endregion
|
|
214
|
+
//#region src/owningTsconfigJsx.ts
|
|
215
|
+
const REGISTER = "owning-tsconfig-jsx-register.mjs";
|
|
216
|
+
/** The CLI's `bin/` was not found above the module looking for it. */
|
|
217
|
+
var OwningTsconfigJsxHookMissing = class extends Error {
|
|
218
|
+
from;
|
|
219
|
+
constructor(from) {
|
|
220
|
+
super(`Could not find bin/${REGISTER} in any directory above '${from}'. It ships with @geekmidas/cli beside bin/gkm.mjs; reinstall the package if it is missing.`);
|
|
221
|
+
this.from = from;
|
|
222
|
+
this.name = "OwningTsconfigJsxHookMissing";
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* The CLI's `bin/owning-tsconfig-jsx-register.mjs`, as a file URL. Searched
|
|
227
|
+
* upward because this module runs from `src/` in the repo and from a chunk in
|
|
228
|
+
* `dist/` once built, and `bin/` sits beside both.
|
|
229
|
+
*/
|
|
230
|
+
function registerUrl() {
|
|
231
|
+
const from = dirname(fileURLToPath(import.meta.url));
|
|
232
|
+
for (let dir = from;; dir = dirname(dir)) {
|
|
233
|
+
const candidate = join(dir, "bin", REGISTER);
|
|
234
|
+
if (existsSync(candidate)) return pathToFileURL(candidate).href;
|
|
235
|
+
if (dirname(dir) === dir) throw new OwningTsconfigJsxHookMissing(from);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* `NODE_OPTIONS` for a process that runs app code through tsx, with the hook
|
|
240
|
+
* that compiles each `.tsx` with its own tsconfig's JSX settings (see
|
|
241
|
+
* `bin/owning-tsconfig-jsx.mjs`) put in front of every other `--import`, so it
|
|
242
|
+
* is registered before tsx and reads the source on tsx's behalf.
|
|
243
|
+
*
|
|
244
|
+
* `bin/gkm.mjs` already starts the CLI this way, and its children inherit it;
|
|
245
|
+
* this is for those that set `NODE_OPTIONS` themselves, or whose CLI was
|
|
246
|
+
* started with tsx already imported.
|
|
247
|
+
*/
|
|
248
|
+
function withOwningTsconfigJsx(nodeOptions = "") {
|
|
249
|
+
if (nodeOptions.includes(REGISTER)) return nodeOptions;
|
|
250
|
+
return [`--import=${registerUrl()}`, nodeOptions].filter(Boolean).join(" ");
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/sandbox/worker.ts
|
|
254
|
+
/**
|
|
255
|
+
* Running one of the CLI's own worker scripts inside a sandbox, and reading
|
|
256
|
+
* back the one JSON value it answers with.
|
|
257
|
+
*
|
|
258
|
+
* The worker imports the project's TypeScript — `gkm.config.ts`, construct
|
|
259
|
+
* modules, an app's entry — so it starts with the CLI's own tsx and the two
|
|
260
|
+
* hooks `gkm` itself runs with (JSX by the owning tsconfig, path aliases by
|
|
261
|
+
* the adjacent one). The host process needs none of them loaded: a program
|
|
262
|
+
* calling `deploy()` without `--import tsx` still loads a TypeScript config.
|
|
263
|
+
*/
|
|
264
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
265
|
+
/**
|
|
266
|
+
* A worker's file: `dist/sandbox/<name>.mjs` once built — whether this module
|
|
267
|
+
* was bundled into `dist/` or sits beside it — or the `.ts` source under tsx.
|
|
268
|
+
*/
|
|
269
|
+
function workerFile(name) {
|
|
270
|
+
return [
|
|
271
|
+
join(here, "sandbox", `${name}.mjs`),
|
|
272
|
+
join(here, `${name}.mjs`),
|
|
273
|
+
join(here, "..", "sandbox", `${name}.mjs`),
|
|
274
|
+
join(here, `${name}.ts`)
|
|
275
|
+
].find((path) => existsSync(path)) ?? join(here, `${name}.ts`);
|
|
276
|
+
}
|
|
277
|
+
/** tsx, from the CLI's own dependencies — never the project's. */
|
|
278
|
+
function tsxUrl() {
|
|
279
|
+
return pathToFileURL(createRequire(import.meta.url).resolve("tsx")).href;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* `node`'s arguments for `script`: the CLI's TypeScript loaders, then any
|
|
283
|
+
* further `imports`, then the script and its `args` — an argument array, so
|
|
284
|
+
* nothing about a path is read by a shell.
|
|
285
|
+
*/
|
|
286
|
+
function nodeWithTsx(script, args, imports = []) {
|
|
287
|
+
return [
|
|
288
|
+
...withOwningTsconfigJsx(`--import=${tsxUrl()}`).split(" "),
|
|
289
|
+
...imports.map((path) => `--import=${pathToFileURL(path).href}`),
|
|
290
|
+
script,
|
|
291
|
+
...args
|
|
292
|
+
];
|
|
293
|
+
}
|
|
294
|
+
/** A worker ended without the answer it exists to give. */
|
|
295
|
+
var SandboxWorkerFailed = class extends Error {
|
|
296
|
+
step;
|
|
297
|
+
exitCode;
|
|
298
|
+
stderr;
|
|
299
|
+
constructor(step, exitCode, stderr) {
|
|
300
|
+
super(`The sandboxed ${step} ended (exit code ${exitCode}) without an answer.${stderr.trim() ? `\n${stderr.trim()}` : ""}\nIts output above says why; the sandbox must be able to run \`node\` with the CLI's own files at the paths they have here.`);
|
|
301
|
+
this.step = step;
|
|
302
|
+
this.exitCode = exitCode;
|
|
303
|
+
this.stderr = stderr;
|
|
304
|
+
this.name = "SandboxWorkerFailed";
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
/**
|
|
308
|
+
* Run worker `name` in `sandbox`, and parse its answer with `schema`.
|
|
309
|
+
*
|
|
310
|
+
* The answer is the last marked line on stdout. Anything else the project's
|
|
311
|
+
* code printed is ignored, and an answer the schema refuses is a failure
|
|
312
|
+
* rather than data — a worker in an isolating sandbox runs code the host does
|
|
313
|
+
* not trust.
|
|
314
|
+
*
|
|
315
|
+
* Within a run (`withSandbox`), the same worker asked the same question is
|
|
316
|
+
* started once; every ask gets its own copy of the answer, and its stderr, as
|
|
317
|
+
* though it had run again.
|
|
318
|
+
*/
|
|
319
|
+
async function runWorker(sandbox, step, options) {
|
|
320
|
+
const answer = await oncePerRun(sandbox, JSON.stringify([
|
|
321
|
+
options.name,
|
|
322
|
+
options.cwd,
|
|
323
|
+
options.args,
|
|
324
|
+
options.env ?? {}
|
|
325
|
+
]), () => startWorker(sandbox, step, options));
|
|
326
|
+
return structuredClone(answer);
|
|
327
|
+
}
|
|
328
|
+
async function startWorker(sandbox, step, options) {
|
|
329
|
+
const result = await sandbox.exec("node", nodeWithTsx(workerFile(options.name), options.args), {
|
|
330
|
+
cwd: options.cwd,
|
|
331
|
+
env: {
|
|
332
|
+
...sandbox.env,
|
|
333
|
+
...options.env
|
|
334
|
+
},
|
|
335
|
+
timeoutMs: options.timeoutMs,
|
|
336
|
+
output: "capture",
|
|
337
|
+
...options.signal ? { signal: options.signal } : {}
|
|
338
|
+
});
|
|
339
|
+
const line = result.stdout.split("\n").reverse().find((l) => l.startsWith(WORKER_RESULT_MARKER));
|
|
340
|
+
if (line) try {
|
|
341
|
+
const parsed = options.schema.safeParse(JSON.parse(line.slice(WORKER_RESULT_MARKER.length)));
|
|
342
|
+
if (parsed.success) return {
|
|
343
|
+
value: parsed.data,
|
|
344
|
+
stderr: result.stderr
|
|
345
|
+
};
|
|
346
|
+
} catch {}
|
|
347
|
+
throw new SandboxWorkerFailed(step, result.exitCode, result.stderr);
|
|
348
|
+
}
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/reconcile/discover.ts
|
|
351
|
+
/**
|
|
352
|
+
* Discovery — one glob, one structural test.
|
|
353
|
+
*
|
|
354
|
+
* A glob per kind is the same specialness the construct model removes, and
|
|
355
|
+
* resources have no kind to be listed under: a declared `ObjectStorage` would
|
|
356
|
+
* never be found by `routes:` or `crons:`. So there is one `constructs` glob,
|
|
357
|
+
* every export of every matching module is inspected, and the per-kind
|
|
358
|
+
* `isConstruct` checks collapse into a single question — does it have an id and
|
|
359
|
+
* can it declare?
|
|
360
|
+
*
|
|
361
|
+
* Structural rather than `instanceof` on purpose. A construct from a different
|
|
362
|
+
* copy of `@geekmidas/constructs` — a linked workspace, two versions in a
|
|
363
|
+
* lockfile — is still a construct, and `instanceof` is exactly the check that
|
|
364
|
+
* says otherwise.
|
|
365
|
+
*/
|
|
366
|
+
var discover_exports = /* @__PURE__ */ __exportAll({
|
|
367
|
+
ConstructDiscoveryFailed: () => ConstructDiscoveryFailed,
|
|
368
|
+
ConstructsNotSerializable: () => ConstructsNotSerializable,
|
|
369
|
+
DuplicateConstruct: () => DuplicateConstruct,
|
|
370
|
+
LiveConstructsUnavailable: () => LiveConstructsUnavailable,
|
|
371
|
+
discover: () => discover,
|
|
372
|
+
isDeclarable: () => isDeclarable
|
|
373
|
+
});
|
|
374
|
+
/** `console`, or the deploy run discovering the manifest. */
|
|
375
|
+
const logger = output;
|
|
376
|
+
/**
|
|
377
|
+
* Whether a module export is a construct.
|
|
378
|
+
*
|
|
379
|
+
* Deliberately loose about what else it carries — a construct that also has a
|
|
380
|
+
* `service` is still a construct, and requiring one would exclude the kinds that
|
|
381
|
+
* own no address.
|
|
382
|
+
*/
|
|
383
|
+
function isDeclarable(value) {
|
|
384
|
+
if (typeof value !== "object" || value === null) return false;
|
|
385
|
+
const candidate = value;
|
|
386
|
+
return typeof candidate.id === "string" && candidate.id.length > 0 && typeof candidate.declare === "function";
|
|
387
|
+
}
|
|
388
|
+
/** What the discovery worker answers. Checked: the worker ran project code. */
|
|
389
|
+
const DiscoverAnswer = discriminatedUnion("reason", [
|
|
390
|
+
object({
|
|
391
|
+
reason: literal("discovered"),
|
|
392
|
+
manifest: record(string(), object({
|
|
393
|
+
id: string(),
|
|
394
|
+
kind: string()
|
|
395
|
+
}).loose()),
|
|
396
|
+
runnables: record(string(), array(string()))
|
|
397
|
+
}),
|
|
398
|
+
object({
|
|
399
|
+
reason: literal("live"),
|
|
400
|
+
paths: array(string())
|
|
401
|
+
}),
|
|
402
|
+
object({
|
|
403
|
+
reason: literal("failed"),
|
|
404
|
+
error: object({
|
|
405
|
+
name: string(),
|
|
406
|
+
message: string(),
|
|
407
|
+
id: string().optional(),
|
|
408
|
+
sources: array(string()).optional()
|
|
409
|
+
}).loose()
|
|
410
|
+
})
|
|
411
|
+
]);
|
|
412
|
+
/**
|
|
413
|
+
* The manifest, discovered in `sandbox` and handed back as JSON — or
|
|
414
|
+
* `undefined` when it holds something JSON cannot carry and the sandbox is
|
|
415
|
+
* not isolating, for the caller to discover here as before.
|
|
416
|
+
*/
|
|
417
|
+
async function discoverInSandbox(sandbox, options) {
|
|
418
|
+
const cwd = options.cwd ?? sandbox.root;
|
|
419
|
+
const patterns = typeof options.patterns === "string" ? [options.patterns] : [...options.patterns];
|
|
420
|
+
const { value, stderr } = await runWorker(sandbox, "construct discovery", {
|
|
421
|
+
name: "discover-worker",
|
|
422
|
+
args: [JSON.stringify({
|
|
423
|
+
patterns,
|
|
424
|
+
cwd
|
|
425
|
+
})],
|
|
426
|
+
cwd,
|
|
427
|
+
timeoutMs: DISCOVER_TIMEOUT_MS,
|
|
428
|
+
schema: DiscoverAnswer
|
|
429
|
+
});
|
|
430
|
+
if (stderr.trim()) logger.warn(stderr.replace(/\n$/, ""));
|
|
431
|
+
switch (value.reason) {
|
|
432
|
+
case "discovered":
|
|
433
|
+
if (options.runnables) for (const [owner, edges] of Object.entries(value.runnables)) options.runnables[owner] = edges;
|
|
434
|
+
return value.manifest;
|
|
435
|
+
case "failed":
|
|
436
|
+
if (value.error.name === "DuplicateConstruct" && value.error.id) throw new DuplicateConstruct(value.error.id, value.error.sources ?? []);
|
|
437
|
+
throw new ConstructDiscoveryFailed(value.error.name, value.error.message);
|
|
438
|
+
case "live":
|
|
439
|
+
if (sandbox.isolating) throw new ConstructsNotSerializable(value.paths);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* A caller asked for the construct objects (`sources`) or a watcher's
|
|
445
|
+
* re-import under an isolating sandbox, where only data comes back.
|
|
446
|
+
*/
|
|
447
|
+
var LiveConstructsUnavailable = class extends Error {
|
|
448
|
+
constructor() {
|
|
449
|
+
super("Discovery was asked for the construct objects themselves under an isolating sandbox, which hands back only data. Run this step without one, or ask only for the manifest.");
|
|
450
|
+
this.name = "LiveConstructsUnavailable";
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
/** How long discovering a project's constructs may take in a sandbox. */
|
|
454
|
+
const DISCOVER_TIMEOUT_MS = 6e4;
|
|
455
|
+
/** Importing a construct module, or declaring one, threw in the sandbox. */
|
|
456
|
+
var ConstructDiscoveryFailed = class extends Error {
|
|
457
|
+
errorName;
|
|
458
|
+
detail;
|
|
459
|
+
constructor(errorName, detail) {
|
|
460
|
+
super(`Discovering constructs failed (${errorName}): ${detail}`);
|
|
461
|
+
this.errorName = errorName;
|
|
462
|
+
this.detail = detail;
|
|
463
|
+
this.name = "ConstructDiscoveryFailed";
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* The constructs' declarations hold something that is not data, and the
|
|
468
|
+
* sandbox they were discovered in hands the deploy nothing but data.
|
|
469
|
+
*/
|
|
470
|
+
var ConstructsNotSerializable = class extends Error {
|
|
471
|
+
paths;
|
|
472
|
+
constructor(paths) {
|
|
473
|
+
super(`The construct manifest holds values that are not plain data at: ${paths.join(", ")}. Under an isolating sandbox the deploy only receives what JSON can carry; deploy with a sandbox that is not isolating if the host trusts this project.`);
|
|
474
|
+
this.paths = paths;
|
|
475
|
+
this.name = "ConstructsNotSerializable";
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* Build the construct manifest for a project.
|
|
480
|
+
*
|
|
481
|
+
* Runs the manifest's own validation before returning, so an app is wrong here
|
|
482
|
+
* — where the error names a file — rather than at deploy.
|
|
483
|
+
*
|
|
484
|
+
* @throws {DuplicateConstruct} when two exports claim one id.
|
|
485
|
+
*/
|
|
486
|
+
async function discover(options) {
|
|
487
|
+
const sandbox = options.sandbox ?? activeSandbox();
|
|
488
|
+
if (sandbox) {
|
|
489
|
+
if (!options.sources && !options.bustCache) {
|
|
490
|
+
const sandboxed = await discoverInSandbox(sandbox, options);
|
|
491
|
+
if (sandboxed) return sandboxed;
|
|
492
|
+
} else if (sandbox.isolating) throw new LiveConstructsUnavailable();
|
|
493
|
+
}
|
|
494
|
+
const { patterns, cwd = process.cwd(), bustCache = false, sources: out } = options;
|
|
495
|
+
if (bustCache) clearZodGlobalRegistry();
|
|
496
|
+
const manifest = {};
|
|
497
|
+
/** Which file declared each id, for the error when two of them do. */
|
|
498
|
+
const sources = {};
|
|
499
|
+
/**
|
|
500
|
+
* Constructs already seen, by identity.
|
|
501
|
+
*
|
|
502
|
+
* A re-export is the *same object* reached through a second file — ESM
|
|
503
|
+
* bindings are live, so `export * from './database.js'` hands back the
|
|
504
|
+
* binding rather than a copy. Without this, a barrel file made every
|
|
505
|
+
* construct in it appear declared twice, and `constructs/index.ts` is the
|
|
506
|
+
* first thing anyone writes in a shared folder.
|
|
507
|
+
*
|
|
508
|
+
* Identity rather than file is also the more honest rule: what may not
|
|
509
|
+
* happen twice is two *different* constructs claiming one id, and that is
|
|
510
|
+
* still an error below.
|
|
511
|
+
*/
|
|
512
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
513
|
+
const globs = Array.isArray(patterns) ? [...patterns] : [patterns];
|
|
514
|
+
const files = fg.stream(globs, {
|
|
515
|
+
cwd,
|
|
516
|
+
absolute: true
|
|
517
|
+
});
|
|
518
|
+
/** Matched files, for the diagnostic below. */
|
|
519
|
+
let matched = 0;
|
|
520
|
+
for await (const found of files) {
|
|
521
|
+
matched++;
|
|
522
|
+
const file = found.toString();
|
|
523
|
+
const module = await (bustCache ? import(`${file}?t=${Date.now()}`) : import(file));
|
|
524
|
+
for (const [exportName, exported] of Object.entries(module)) {
|
|
525
|
+
if (!isDeclarable(exported)) {
|
|
526
|
+
if (options.runnables) recordRunnable(options.runnables, exported);
|
|
527
|
+
continue;
|
|
528
|
+
}
|
|
529
|
+
if (seen.has(exported)) continue;
|
|
530
|
+
seen.add(exported);
|
|
531
|
+
if (options.runnables && typeof exported.owner === "string") recordRunnable(options.runnables, exported);
|
|
532
|
+
for (const declaration of exported.declare()) {
|
|
533
|
+
const id = canonicalId(declaration.id);
|
|
534
|
+
const source = relative(cwd, file);
|
|
535
|
+
const claimed = sources[id];
|
|
536
|
+
if (claimed !== void 0 && claimed !== source) throw new DuplicateConstruct(id, [claimed, source]);
|
|
537
|
+
manifest[id] = {
|
|
538
|
+
...declaration,
|
|
539
|
+
id
|
|
540
|
+
};
|
|
541
|
+
sources[id] = source;
|
|
542
|
+
if (out) out[id] = {
|
|
543
|
+
file,
|
|
544
|
+
exportName,
|
|
545
|
+
construct: exported
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
assertDerivations(manifest);
|
|
551
|
+
warnIfNothingFound(globs, matched, Object.keys(manifest).length);
|
|
552
|
+
return manifest;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Record a runnable's edges under the construct that owns it — the surface an
|
|
556
|
+
* endpoint was built from, or the worker a cron or subscriber was. Anything
|
|
557
|
+
* with no owner, or that is not a runnable at all, is left alone.
|
|
558
|
+
*/
|
|
559
|
+
function recordRunnable(runnables, exported) {
|
|
560
|
+
if (typeof exported !== "object" || exported === null) return;
|
|
561
|
+
const runnable = exported;
|
|
562
|
+
const owner = typeof runnable.surface?.id === "string" ? runnable.surface.id : typeof runnable.owner === "string" ? runnable.owner : void 0;
|
|
563
|
+
if (!owner || !Array.isArray(runnable.constructs)) return;
|
|
564
|
+
const key = canonicalId(owner);
|
|
565
|
+
const edges = runnables[key] ?? [];
|
|
566
|
+
runnables[key] = edges;
|
|
567
|
+
for (const id of runnable.constructs) {
|
|
568
|
+
if (typeof id !== "string") continue;
|
|
569
|
+
const target = canonicalId(id);
|
|
570
|
+
if (!edges.includes(target)) edges.push(target);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Say so when a glob was configured and found nothing.
|
|
575
|
+
*
|
|
576
|
+
* The glob is not a filter over declarations already known — it is *how they
|
|
577
|
+
* are found*, by importing what it matches. So a file it misses is a
|
|
578
|
+
* declaration that does not exist, and every symptom of that appears somewhere
|
|
579
|
+
* other than the cause: no container starts, no env key is written, and the
|
|
580
|
+
* application fails on first use against a resource it can see in its own
|
|
581
|
+
* source.
|
|
582
|
+
*
|
|
583
|
+
* Nothing reported it before, because an unmatched file is indistinguishable
|
|
584
|
+
* from a file nobody wrote. These two cases are the ones that are *not*
|
|
585
|
+
* ambiguous — a glob was configured, so something was expected.
|
|
586
|
+
*
|
|
587
|
+
* Silent when no glob is configured at all: that is a project which has not
|
|
588
|
+
* adopted constructs, and has nothing to be missing.
|
|
589
|
+
*/
|
|
590
|
+
function warnIfNothingFound(globs, matched, declared) {
|
|
591
|
+
if (globs.length === 0) return;
|
|
592
|
+
if (matched === 0) {
|
|
593
|
+
logger.warn(`\n⚠️ The constructs glob matched no files, so nothing was declared.\n Patterns: ${globs.join(", ")}\n Nothing will be provisioned — no containers, no env keys, no resources.\n A common cause is depth: '*.ts' matches one level, '**/*.ts' matches any.`);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
if (declared === 0) logger.warn(`\n⚠️ The constructs glob matched ${matched} file(s) but none declared anything.\n Patterns: ${globs.join(", ")}\n Discovery keeps exports with an 'id' that can 'declare()'. A construct that is\n built but never exported is invisible to it.`);
|
|
597
|
+
}
|
|
598
|
+
/** Two constructs claiming one id. */
|
|
599
|
+
var DuplicateConstruct = class extends Error {
|
|
600
|
+
/** The id claimed twice. */
|
|
601
|
+
id;
|
|
602
|
+
/** The files that claimed it. */
|
|
603
|
+
sources;
|
|
604
|
+
constructor(id, sources) {
|
|
605
|
+
super("Two constructs declare the same id");
|
|
606
|
+
this.name = "DuplicateConstruct";
|
|
607
|
+
this.id = id;
|
|
608
|
+
this.sources = sources;
|
|
609
|
+
}
|
|
610
|
+
};
|
|
611
|
+
//#endregion
|
|
612
|
+
export { ConstructGenerator as _, isDeclarable as a, runWorker as c, SandboxCwdEscape as d, SecretNameInvalid as f, withSandbox as g, confineCwd as h, discover_exports as i, withOwningTsconfigJsx as l, assertSecretNames as m, ConstructsNotSerializable as n, SandboxWorkerFailed as o, activeSandbox as p, discover as r, nodeWithTsx as s, ConstructDiscoveryFailed as t, SECRETS_DIR_ENV as u, output as v, withOutput as y };
|
|
613
|
+
|
|
614
|
+
//# sourceMappingURL=discover-BaT6bpnA.mjs.map
|