@akanjs/cli 3.3.0-rc.11 → 3.3.0-rc.13

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 (101) hide show
  1. package/.build-stamp +2 -2
  2. package/{CodeAgent-cqbf9gsv.js → CodeAgent-zkr3s3xy.js} +2 -2
  3. package/{CodeTui-ehdr4hgw.js → CodeTui-1qvrzfmy.js} +1 -1
  4. package/TunnelShare-8j95ta3w.js +16 -0
  5. package/{agent.command-x55ncdjm.js → agent.command-dejgb8vz.js} +18 -17
  6. package/akanCode.js +2 -2
  7. package/{appExecutor-1ctzymwa.js → appExecutor-nj95a6en.js} +3 -3
  8. package/{application.command-xpntxnh8.js → application.command-3tnq1587.js} +45 -15
  9. package/{applicationBuildRunner-19c76791.js → applicationBuildRunner-cbjy05yg.js} +75 -12
  10. package/buildBatch.proc.js +10 -10
  11. package/{cloud.command-p3ybjes7.js → cloud.command-qae6et2e.js} +19 -18
  12. package/cloud.script-34xmprty.js +31 -0
  13. package/{code.command-m6skj1kj.js → code.command-xrh506zf.js} +10 -10
  14. package/commandManifest.json +1 -1
  15. package/{context.command-3c3nv0d6.js → context.command-fxyzkwg5.js} +18 -18
  16. package/context.runner-bz1jwxkk.js +32 -0
  17. package/{csrArtifactBuilder-mdh9ykn2.js → csrArtifactBuilder-rqg85wbg.js} +2 -2
  18. package/{guideline.command-725fq5p0.js → guideline.command-7dgscqjq.js} +6 -6
  19. package/guidelines/akanApi/akanApi.instruction.md +10 -0
  20. package/guidelines/conventions/rules/config.md +5 -0
  21. package/guidelines/conventions/rules/page.md +4 -3
  22. package/guidelines/conventions/rules/server.md +21 -81
  23. package/guidelines/conventions/rules/ssr.md +4 -25
  24. package/guidelines/conventions/rules/style.md +9 -32
  25. package/guidelines/cssRule/cssRule.instruction.md +11 -4
  26. package/guidelines/errorCodes/errorCodes.instruction.md +4 -0
  27. package/guidelines/pageRule/pageRule.instruction.md +19 -0
  28. package/guidelines/recipeRule/recipeRule.instruction.md +3 -3
  29. package/guidelines/runtimeRule/runtimeRule.instruction.md +109 -6
  30. package/guidelines/ssrRule/ssrRule.instruction.md +3 -0
  31. package/guidelines/transportRule/transportRule.instruction.md +4 -0
  32. package/incrementalBuilder.proc.js +8 -8
  33. package/{index-3mj5trqc.js → index-0bzrcv91.js} +1 -1
  34. package/{index-q63nbpv7.js → index-0zkxsdsg.js} +3 -3
  35. package/{index-wxqp1amd.js → index-1c52g4st.js} +11 -9
  36. package/{index-vnk1qwgr.js → index-22h6vq3f.js} +4 -4
  37. package/index-35p43f33.js +16 -0
  38. package/{index-fagjtk6m.js → index-3q7ectss.js} +2 -2
  39. package/{index-se7n78fh.js → index-54g085ty.js} +1 -1
  40. package/{index-rt7q20sj.js → index-5sa1tr7w.js} +1 -1
  41. package/{index-h8w1n11r.js → index-6a3rmwxx.js} +4 -4
  42. package/{index-yey1envc.js → index-741xbhes.js} +1 -1
  43. package/{index-9a9t77hz.js → index-77627y32.js} +2 -2
  44. package/{index-4r8dgm4x.js → index-8javbznc.js} +3 -3
  45. package/{index-hxg6ctk2.js → index-a2a3nh57.js} +3 -3
  46. package/{index-j2wq064m.js → index-aezpcphy.js} +121 -15
  47. package/{index-3r1crbct.js → index-ay4vkwr8.js} +1 -1
  48. package/{index-t23dgyaf.js → index-b4m7bjbx.js} +7 -7
  49. package/{index-rdcgz02t.js → index-bma8tmgb.js} +4 -4
  50. package/{index-3zkhg65e.js → index-c4g8egm2.js} +40 -13
  51. package/{index-9gjcbp2g.js → index-c8kj74zz.js} +1 -1
  52. package/{index-fjqapyex.js → index-es2wkn41.js} +40 -5
  53. package/{index-pyjkbg8e.js → index-extg77rx.js} +2 -2
  54. package/{index-nmdmkjt2.js → index-fey1dd49.js} +4 -4
  55. package/{index-c669pbyb.js → index-fjzeak0t.js} +68 -37
  56. package/{index-f4jydw2x.js → index-gdgbgn82.js} +1 -1
  57. package/{index-4yvtqcme.js → index-gyyscjzx.js} +16 -4
  58. package/{index-qecrqpt6.js → index-hxcefw29.js} +1 -1
  59. package/{index-a4gcdffy.js → index-k380ww64.js} +3 -3
  60. package/index-kqxs1d7z.js +377 -0
  61. package/{index-nnmw56fz.js → index-mv3ke0fc.js} +5 -5
  62. package/{index-m303nhv6.js → index-mvdmb73w.js} +6 -6
  63. package/{index-cbm9gzgx.js → index-pa53zktp.js} +5 -5
  64. package/{index-3a3vy2xy.js → index-psvxwemh.js} +8 -8
  65. package/{index-ckcc9ab3.js → index-r24mj2pw.js} +8 -8
  66. package/{index-8bta5pnr.js → index-serpfvat.js} +2 -2
  67. package/{index-kbnvyhy4.js → index-shjjjdte.js} +3 -3
  68. package/{index-pr9nypg7.js → index-sjmk7wp7.js} +2 -2
  69. package/{index-wkwe91sn.js → index-th7qbjfz.js} +11 -11
  70. package/{index-5ahe641t.js → index-vgd07z61.js} +8 -8
  71. package/{index-crd99zqs.js → index-wzvvqkcy.js} +1 -1
  72. package/{index-v16gj2as.js → index-ys1sjp6m.js} +90 -51
  73. package/{index-22bwg8hy.js → index-zc43cyg8.js} +1 -1
  74. package/index.js +27 -27
  75. package/{libExecutor-n8hpm8s7.js → libExecutor-mqxnn0h6.js} +2 -2
  76. package/{library.command-8abb26pg.js → library.command-4kefxh8z.js} +7 -7
  77. package/{localRegistry.command-sa211m1z.js → localRegistry.command-phgrhkks.js} +18 -17
  78. package/{module.command-z3cwjf0p.js → module.command-8476gwze.js} +9 -9
  79. package/{package.command-akynhtee.js → package.command-ygxm5pp9.js} +8 -8
  80. package/package.json +2 -2
  81. package/{page.command-3fpdavk9.js → page.command-f7fwkj8y.js} +7 -7
  82. package/{pipeline.command-ca95n8rd.js → pipeline.command-9htjbrdm.js} +6 -6
  83. package/{pkgExecutor-a73q41vx.js → pkgExecutor-6a91xng5.js} +2 -2
  84. package/{primitive.command-xwe9ggnf.js → primitive.command-0k0h0cm0.js} +10 -10
  85. package/{projectTypecheck-7g542ymk.js → projectTypecheck-7kakbacs.js} +1 -1
  86. package/{quality.command-7wz7y8z1.js → quality.command-frsfdfc5.js} +9 -8
  87. package/{repair.command-dej1qtfq.js → repair.command-yag3bpq2.js} +9 -9
  88. package/{scalar.command-z9qfxnvm.js → scalar.command-qtyrywvt.js} +8 -8
  89. package/skills/akan-err/SKILL.md +11 -2
  90. package/skills/akan-page/SKILL.md +4 -14
  91. package/skills/akan-runtime/SKILL.md +20 -0
  92. package/{subspace.command-9wekm4gn.js → subspace.command-kr53abzt.js} +10 -10
  93. package/{tunnel.command-cxc4h3j8.js → tunnel.command-pswe6nye.js} +9 -9
  94. package/{typeChecker-7jt6abrs.js → typeChecker-epg7ebfy.js} +2 -1
  95. package/typecheck.proc.js +2 -1
  96. package/{verify.command-j0w9dr5c.js → verify.command-ghhhzgrw.js} +15 -14
  97. package/{workflow.command-yt4sz04b.js → workflow.command-fpwqth4w.js} +14 -14
  98. package/{workspace.command-8mp4mcp2.js → workspace.command-6bbmtn3w.js} +33 -31
  99. package/TunnelShare-0p4dy89e.js +0 -16
  100. package/cloud.script-0dsyd10v.js +0 -30
  101. package/context.runner-yyp7a112.js +0 -32
@@ -0,0 +1,377 @@
1
+ // @bun
2
+ import {
3
+ ServerEnvEvaluationError,
4
+ ServerEnvProfile
5
+ } from "./index-ys1sjp6m.js";
6
+
7
+ // pkgs/@akanjs/devkit/transforms/secretEnvDeclaration.ts
8
+ import { existsSync } from "fs";
9
+ import path2 from "path";
10
+ import { Logger as Logger2 } from "akanjs/common";
11
+
12
+ // pkgs/@akanjs/devkit/transforms/secretEnvName.ts
13
+ class SecretEnvName {
14
+ static #existing = {
15
+ "security.jwtSecret": "JWT_SECRET",
16
+ "database.postgres.url": "POSTGRES_URL",
17
+ "database.postgres.password": "POSTGRES_PASSWORD",
18
+ "database.postgres.insightUrl": "POSTGRES_INSIGHT_URL"
19
+ };
20
+ static #platform = new Set(["PATH", "HOME", "HOSTNAME", "PORT", "USER", "PWD", "TZ", "NODE_ENV"]);
21
+ static of(keys) {
22
+ return SecretEnvName.#existing[keys.join(".")] ?? keys.map((key) => SecretEnvName.#segment(key)).join("__");
23
+ }
24
+ static #segment(key) {
25
+ return key.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[^A-Za-z0-9]/g, "_").toUpperCase();
26
+ }
27
+ static refusal(name) {
28
+ if (!/^[A-Z_][A-Z0-9_]*$/.test(name))
29
+ return "which is not a name an environment variable can take";
30
+ if (SecretEnvName.#platform.has(name))
31
+ return "a variable the platform sets";
32
+ if (/^(?:AKAN|BUN)_/.test(name))
33
+ return "a name akan and Bun keep for their own settings";
34
+ return null;
35
+ }
36
+ }
37
+
38
+ // pkgs/@akanjs/devkit/transforms/secretEnvSource.ts
39
+ import path from "path";
40
+ import { Logger } from "akanjs/common";
41
+ import ts from "typescript";
42
+ class SecretEnvSource {
43
+ static markKey = "__akanSecretEnv";
44
+ static #runtime = "akanjs/server/lifecycle/secretEnv";
45
+ static #binding = "__akanSecretEnv";
46
+ static #dynamic = Symbol("dynamic");
47
+ #file;
48
+ #source;
49
+ #mode;
50
+ #edits = [];
51
+ #pathOfName = new Map;
52
+ constructor(file, contents, mode) {
53
+ this.#file = file;
54
+ this.#source = ts.createSourceFile(file, contents, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
55
+ this.#mode = mode;
56
+ }
57
+ static rewrite(file, contents, mode) {
58
+ return new SecretEnvSource(file, contents, mode).#rewritten(contents);
59
+ }
60
+ #rewritten(contents) {
61
+ for (const statement of this.#source.statements) {
62
+ if (!ts.isVariableStatement(statement))
63
+ continue;
64
+ if (!statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword))
65
+ continue;
66
+ for (const declaration of statement.declarationList.declarations)
67
+ if (ts.isIdentifier(declaration.name) && declaration.name.text === "env" && declaration.initializer)
68
+ this.#visit(declaration.initializer, [], false);
69
+ }
70
+ if (!this.#edits.length)
71
+ return contents;
72
+ const rewritten = this.#edits.toSorted((a, b) => b.start - a.start).reduce((text, edit) => `${text.slice(0, edit.start)}${edit.text}${text.slice(edit.end)}`, contents);
73
+ if (this.#mode === "mark")
74
+ return rewritten;
75
+ return `import { SecretEnv as ${SecretEnvSource.#binding} } from ${JSON.stringify(this.#runtimePath())}; ${rewritten}`;
76
+ }
77
+ #runtimePath() {
78
+ for (const from of [path.dirname(this.#file), import.meta.dir]) {
79
+ try {
80
+ return Bun.resolveSync(SecretEnvSource.#runtime, from);
81
+ } catch {}
82
+ }
83
+ throw new Error(`${this.#file} holds secret values, which the build reads from the process env through ${SecretEnvSource.#runtime}, and the installed akanjs has no such module. Install the akanjs of this akan version.`);
84
+ }
85
+ static #unwrap(node) {
86
+ return ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node) || ts.isTypeAssertionExpression(node) ? SecretEnvSource.#unwrap(node.expression) : node;
87
+ }
88
+ static #keyOf(name) {
89
+ return ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name) ? name.text : null;
90
+ }
91
+ #visit(expression, keys, underSecret, beside) {
92
+ const node = SecretEnvSource.#unwrap(expression);
93
+ if (ts.isObjectLiteralExpression(node)) {
94
+ for (const property of node.properties) {
95
+ const key = ts.isPropertyAssignment(property) ? SecretEnvSource.#keyOf(property.name) : null;
96
+ if (key !== null && ts.isPropertyAssignment(property))
97
+ this.#visit(property.initializer, [...keys, key], underSecret || Logger.isSecretKey(key));
98
+ }
99
+ return;
100
+ }
101
+ if (!keys.length)
102
+ return;
103
+ if (ts.isBinaryExpression(node)) {
104
+ const { kind } = node.operatorToken;
105
+ if (kind === ts.SyntaxKind.QuestionQuestionToken || kind === ts.SyntaxKind.BarBarToken)
106
+ this.#visit(node.right, keys, underSecret, beside ?? expression);
107
+ return;
108
+ }
109
+ if (ts.isStringLiteralLike(node)) {
110
+ if (ServerEnvProfile.isSecret(node.text, underSecret))
111
+ this.#replace(node, keys, node.text.includes(`
112
+ `) ? "multiline" : "string", beside);
113
+ return;
114
+ }
115
+ if (!ts.isArrayLiteralExpression(node))
116
+ return;
117
+ const value = SecretEnvSource.#literal(node);
118
+ if (value !== SecretEnvSource.#dynamic && ServerEnvProfile.secretPaths(value, underSecret).length)
119
+ this.#replace(node, keys, "json", beside);
120
+ }
121
+ static #literal(expression) {
122
+ const node = SecretEnvSource.#unwrap(expression);
123
+ if (ts.isStringLiteralLike(node))
124
+ return node.text;
125
+ if (ts.isNumericLiteral(node))
126
+ return Number(node.text);
127
+ if (node.kind === ts.SyntaxKind.TrueKeyword)
128
+ return true;
129
+ if (node.kind === ts.SyntaxKind.FalseKeyword)
130
+ return false;
131
+ if (node.kind === ts.SyntaxKind.NullKeyword)
132
+ return null;
133
+ if (ts.isPrefixUnaryExpression(node) && node.operator === ts.SyntaxKind.MinusToken) {
134
+ const operand = SecretEnvSource.#literal(node.operand);
135
+ return typeof operand === "number" ? -operand : SecretEnvSource.#dynamic;
136
+ }
137
+ if (ts.isArrayLiteralExpression(node)) {
138
+ const items = node.elements.map((element) => SecretEnvSource.#literal(element));
139
+ return items.includes(SecretEnvSource.#dynamic) ? SecretEnvSource.#dynamic : items;
140
+ }
141
+ if (!ts.isObjectLiteralExpression(node))
142
+ return SecretEnvSource.#dynamic;
143
+ const entries = [];
144
+ for (const property of node.properties) {
145
+ const key = ts.isPropertyAssignment(property) ? SecretEnvSource.#keyOf(property.name) : null;
146
+ if (key === null || !ts.isPropertyAssignment(property))
147
+ return SecretEnvSource.#dynamic;
148
+ const value = SecretEnvSource.#literal(property.initializer);
149
+ if (value === SecretEnvSource.#dynamic)
150
+ return SecretEnvSource.#dynamic;
151
+ entries.push([key, value]);
152
+ }
153
+ return Object.fromEntries(entries);
154
+ }
155
+ #replace(node, keys, kind, beside) {
156
+ const at = keys.join(".");
157
+ const name = SecretEnvName.of(keys);
158
+ const refusal = SecretEnvName.refusal(name);
159
+ if (refusal)
160
+ throw new Error(`${this.#file} \`${at}\` is a secret a build would read from the environment variable ${name}, ${refusal}. Rename the key, or write \`process.env.<NAME>\` there yourself, which a build leaves as it is.`);
161
+ const taken = this.#pathOfName.get(name);
162
+ if (taken !== undefined && taken !== at)
163
+ throw new Error(`${this.#file} \`${taken}\` and \`${at}\` are secrets a build would both read from the environment variable ${name}. Rename one of the keys.`);
164
+ this.#pathOfName.set(name, at);
165
+ const start = node.getStart(this.#source);
166
+ const written = this.#source.text.slice(start, node.end);
167
+ const read = `${SecretEnvSource.#binding}.${kind === "json" ? "json" : "read"}`;
168
+ const text = this.#mode === "mark" ? `({ ${SecretEnvSource.markKey}: [${JSON.stringify(name)}, ${JSON.stringify(kind)}, ${written}] })` : this.#mode === "inline" ? `${read}(${JSON.stringify(name)}, ${written})` : `${read}(${JSON.stringify(name)})`;
169
+ const marked = this.#mode === "mark" && beside ? beside : node;
170
+ this.#edits.push({ start: marked.getStart(this.#source), end: marked.end, text });
171
+ }
172
+ }
173
+
174
+ // pkgs/@akanjs/devkit/transforms/secretEnvDeclaration.ts
175
+ class SecretEnvDeclaration {
176
+ static #unset = "akanownenvunset7q3x9";
177
+ static #set = "akanownenvset5k8w2";
178
+ static async of(envDir, environment) {
179
+ const file = path2.join(envDir, "env.server.ts");
180
+ if (!existsSync(file))
181
+ throw new Error(`${file} is missing: \`akan sync\` writes the app's env files where it has none.`);
182
+ const loaded = await SecretEnvDeclaration.#loaded(file, envDir, environment);
183
+ const found = { variables: [], computed: [], plain: [] };
184
+ SecretEnvDeclaration.#collect(loaded.value, "", [], false, found);
185
+ const variables = new Map;
186
+ for (const variable of found.variables) {
187
+ const taken = variables.get(variable.name);
188
+ if (taken && taken.path !== variable.path)
189
+ throw new Error(`${file} holds \`${taken.path}\` and \`${variable.path}\`, secrets a build would both read from the environment variable ${variable.name}. Rename one of the keys.`);
190
+ variables.set(variable.name, variable);
191
+ }
192
+ const computed = await SecretEnvDeclaration.#notRead(found.computed, file, envDir, environment, loaded);
193
+ return {
194
+ variables: [...variables.values()].map(({ name, kind, path: at, value }) => ({ name, kind, path: at, value })),
195
+ unmoved: [...new Set(computed.map(({ at }) => at))],
196
+ moved: [...variables.values()].flatMap(({ name, path: at, literal, underSecret }) => ServerEnvProfile.movedTexts(literal, underSecret).map((value) => ({
197
+ path: at,
198
+ name,
199
+ value,
200
+ twins: [
201
+ ...new Set(found.plain.filter((plain) => plain.value === value || value.length >= 8 && plain.value.includes(value)).map((plain) => plain.at))
202
+ ]
203
+ })))
204
+ };
205
+ }
206
+ static async#evaluate(file, envDir, environment, variables) {
207
+ return await ServerEnvProfile.evaluateReads(file, path2.dirname(envDir), (envFile) => SecretEnvDeclaration.source(envFile, "mark"), { environment, loads: ServerEnvProfile.envModulePattern, variables });
208
+ }
209
+ static async#loaded(file, envDir, environment) {
210
+ try {
211
+ return { ...await SecretEnvDeclaration.#evaluate(file, envDir, environment, {}), variables: {} };
212
+ } catch (error) {
213
+ if (!(error instanceof ServerEnvEvaluationError) || error.reason === "timedOut")
214
+ throw error;
215
+ }
216
+ const variables = Object.fromEntries(Object.entries(process.env).flatMap(([name, value]) => value === undefined ? [] : [[name, value]]));
217
+ return { ...await SecretEnvDeclaration.#evaluate(file, envDir, environment, variables), variables };
218
+ }
219
+ static async#notRead(computed, file, envDir, environment, loaded) {
220
+ const given = Object.values(loaded.variables).filter((value) => value !== "");
221
+ const kept = computed.filter(({ value }) => !given.some((own) => own === value || own.length >= 8 && value.includes(own)));
222
+ if (!kept.length)
223
+ return kept;
224
+ const names = loaded.reads.filter((name) => SecretEnvName.refusal(name) === null);
225
+ const probe = async (probed) => await SecretEnvDeclaration.#evaluate(file, envDir, environment, {
226
+ ...loaded.variables,
227
+ ...Object.fromEntries(probed.map((name) => [
228
+ name,
229
+ Object.hasOwn(loaded.variables, name) ? `${loaded.variables[name]}${SecretEnvDeclaration.#set}` : SecretEnvDeclaration.#unset
230
+ ]))
231
+ }).then(({ value }) => [value], (error) => {
232
+ if (error instanceof ServerEnvEvaluationError)
233
+ return [];
234
+ throw error;
235
+ });
236
+ const all = names.length ? await probe(names) : [];
237
+ const probes = all.length ? all : (await Promise.all(names.slice(0, 32).map((name) => probe([name])))).flat();
238
+ return kept.filter(({ segments, value }) => !probes.some((probed) => SecretEnvDeclaration.#followsRead(value, segments.reduce((node, key) => node?.[key], probed))));
239
+ }
240
+ static #followsRead(value, probed) {
241
+ if (typeof probed !== "string")
242
+ return false;
243
+ const lower = probed.toLowerCase();
244
+ if (!lower.includes(SecretEnvDeclaration.#set) && !lower.includes(SecretEnvDeclaration.#unset))
245
+ return false;
246
+ const given = probed.replace(new RegExp(SecretEnvDeclaration.#set, "gi"), "");
247
+ const unset = new RegExp(SecretEnvDeclaration.#unset, "gi");
248
+ return ["undefined", "", "null"].some((gone) => given.replace(unset, gone) === value);
249
+ }
250
+ static async source(file, mode) {
251
+ const contents = await Bun.file(file).text();
252
+ const name = path2.basename(file, ".ts").slice("env.server.".length);
253
+ if (name === "type" || name === "example")
254
+ return { loader: "ts", contents };
255
+ return { loader: "ts", contents: SecretEnvSource.rewrite(file, contents, mode) };
256
+ }
257
+ static #collect(value, at, segments, underSecret, found) {
258
+ if (typeof value === "string") {
259
+ found.plain.push({ at, value });
260
+ if (ServerEnvProfile.isSecret(value, underSecret))
261
+ found.computed.push({ at, segments, value });
262
+ return;
263
+ }
264
+ if (!value || typeof value !== "object")
265
+ return;
266
+ if (Array.isArray(value)) {
267
+ for (const [index, item] of value.entries())
268
+ SecretEnvDeclaration.#collect(item, at, [...segments, String(index)], underSecret, found);
269
+ return;
270
+ }
271
+ const mark = value[SecretEnvSource.markKey];
272
+ if (Array.isArray(mark)) {
273
+ const [name, kind, literal] = mark;
274
+ const held = underSecret || typeof literal === "string";
275
+ const value = typeof literal === "string" ? literal : JSON.stringify(literal);
276
+ found.variables.push({ name, kind, path: at, value, literal, underSecret: held });
277
+ return;
278
+ }
279
+ for (const [key, child] of Object.entries(value))
280
+ SecretEnvDeclaration.#collect(child, at ? `${at}.${key}` : key, [...segments, key], underSecret || Logger2.isSecretKey(key), found);
281
+ }
282
+ }
283
+
284
+ // pkgs/@akanjs/devkit/transforms/secretEnvFile.ts
285
+ import { existsSync as existsSync2 } from "fs";
286
+ import { mkdir, rm, writeFile } from "fs/promises";
287
+ import path3 from "path";
288
+ import { SecretEnv } from "akanjs/server/lifecycle/secretEnv";
289
+
290
+ class SecretEnvFile {
291
+ static formats = ["k8s", "dotenv"];
292
+ static listing({ variables, unmoved }) {
293
+ if (!variables.length && !unmoved.length)
294
+ return "The server env holds no secret value, so a build reads none.";
295
+ const rows = [
296
+ ["VARIABLE", "KIND", "SHELL", "ENV FILE KEY"],
297
+ ...variables.map(({ name, kind, path: at }) => [name, kind, SecretEnv.read(name) ? "set" : "unset", at])
298
+ ];
299
+ const widths = [0, 1, 2].map((column) => Math.max(...rows.map((row) => row[column]?.length ?? 0)));
300
+ const table = variables.length ? rows.map((row) => row.map((cell, column) => cell.padEnd(widths[column] ?? 0)).join(" ").trimEnd()) : [];
301
+ return [...table, ...unmoved.length ? [SecretEnvFile.unmovedNote(unmoved)] : []].join(`
302
+ `);
303
+ }
304
+ static unmovedNote(unmoved) {
305
+ if (!unmoved.length)
306
+ return "";
307
+ return `\`akan build\` stops at ${unmoved.join(", ")}: ${unmoved.length === 1 ? "a secret value" : "secret values"} the env file computes or imports. Write the string at the key, or read it there yourself as \`process.env.<NAME>\`.`;
308
+ }
309
+ static unmovedStop(app, environment, envFile, unmoved) {
310
+ const one = unmoved.length === 1;
311
+ return `The server env of ${app} (${environment}) holds ${one ? "a secret value" : `${unmoved.length} secret values`} this build cannot leave out, so it stops here: ${unmoved.join(", ")} (${envFile} and what it imports).
312
+ A build turns a secret written as a string at its key into a read from the server's process env, and ${one ? "this one is" : "these are"} computed or imported. Write the string at the key, or read it there yourself as \`process.env.<NAME>\` and set that variable where the server is deployed. \`akan build --inline-secrets\` builds with the env files as written until akanjs 3.5.0 removes it.`;
313
+ }
314
+ static render(format, variables, name) {
315
+ return format === "k8s" ? SecretEnvFile.#k8s(variables, name) : SecretEnvFile.#dotenv(variables);
316
+ }
317
+ static #k8s(variables, name) {
318
+ if (name.length > 253 || !/^[a-z0-9](?:[-a-z0-9.]*[a-z0-9])?$/.test(name))
319
+ throw new Error(`--name ${name} is not a name a Kubernetes Secret can take: lowercase letters, digits, "-" and ".", starting and ending with a letter or digit.`);
320
+ const data = variables.map(({ name: key, value }) => ` ${key}: ${Buffer.from(value, "utf8").toString("base64")}`);
321
+ return [
322
+ "apiVersion: v1",
323
+ "kind: Secret",
324
+ "metadata:",
325
+ ` name: ${name}`,
326
+ "type: Opaque",
327
+ ...data.length ? ["data:", ...data] : ["data: {}"],
328
+ ""
329
+ ].join(`
330
+ `);
331
+ }
332
+ static #dotenv(variables) {
333
+ return variables.map(({ name, value }) => `${name}=${SecretEnvFile.#dotenvValue(name, value)}
334
+ `).join("");
335
+ }
336
+ static #dotenvValue(name, value) {
337
+ if (/^[A-Za-z0-9_./:@%+=,-]+$/.test(value))
338
+ return value;
339
+ const dollars = value.replaceAll("$", "\\$");
340
+ if (!/[\r\n]/.test(value) && !value.endsWith("\\")) {
341
+ for (const quote of ["'", "`"])
342
+ if (!value.includes(quote))
343
+ return `${quote}${dollars}${quote}`;
344
+ }
345
+ if (!value.includes('"') && !value.includes("\\"))
346
+ return `"${dollars.replaceAll("\r", "\\r").replaceAll(`
347
+ `, "\\n")}"`;
348
+ throw new Error(`${name} holds a mix of line breaks, quotes and backslashes no dotenv line carries unchanged. Write it with --format k8s, which keeps every byte.`);
349
+ }
350
+ static async write(file, contents, { workspaceRoot, force = false }) {
351
+ const target = path3.resolve(file);
352
+ const inWorkspace = path3.relative(path3.resolve(workspaceRoot), target);
353
+ if (inWorkspace.split(path3.sep)[0] === "dist")
354
+ throw new Error(`--out ${file} is under dist/, and an image copies the whole of dist/apps/<app>, so the secrets would ship in it. Write the file outside dist/.`);
355
+ if (SecretEnvFile.#gitWouldTrack(target))
356
+ throw new Error(`--out ${file} is inside a git repository that does not ignore it, so the secrets could be committed. Write it to a git-ignored path or outside the repository.`);
357
+ if (existsSync2(target)) {
358
+ if (!force)
359
+ throw new Error(`--out ${file} exists. Pass --force to replace it.`);
360
+ await rm(target);
361
+ }
362
+ await mkdir(path3.dirname(target), { recursive: true });
363
+ await writeFile(target, contents, { mode: 384, flag: "wx" });
364
+ }
365
+ static #gitWouldTrack(target) {
366
+ let dir = path3.dirname(target);
367
+ while (!existsSync2(dir) && dir !== path3.dirname(dir))
368
+ dir = path3.dirname(dir);
369
+ try {
370
+ return Bun.spawnSync(["git", "check-ignore", "-q", "--", target], { cwd: dir }).exitCode === 1;
371
+ } catch {
372
+ return false;
373
+ }
374
+ }
375
+ }
376
+
377
+ export { SecretEnvDeclaration, SecretEnvFile };
@@ -5,24 +5,24 @@ import {
5
5
  import {
6
6
  Executor,
7
7
  WorkspaceExecutor
8
- } from "./index-v16gj2as.js";
8
+ } from "./index-ys1sjp6m.js";
9
9
  import {
10
10
  getDirname2,
11
11
  FileSys2
12
12
  } from "./index-zyjztrvc.js";
13
13
  import {
14
14
  AppExecutor2
15
- } from "./index-9a9t77hz.js";
15
+ } from "./index-77627y32.js";
16
16
  import {
17
17
  LibExecutor2
18
- } from "./index-yey1envc.js";
18
+ } from "./index-741xbhes.js";
19
19
  import {
20
20
  PkgExecutor2
21
- } from "./index-crd99zqs.js";
21
+ } from "./index-wzvvqkcy.js";
22
22
  import {
23
23
  ModuleExecutor,
24
24
  ErrorReport
25
- } from "./index-3r1crbct.js";
25
+ } from "./index-ay4vkwr8.js";
26
26
 
27
27
  // pkgs/@akanjs/devkit/commandDecorators/camelToKebabCase.ts
28
28
  var camelToKebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase();
@@ -1,13 +1,13 @@
1
1
  // @bun
2
2
  import {
3
3
  script
4
- } from "./index-nnmw56fz.js";
4
+ } from "./index-mv3ke0fc.js";
5
5
  import {
6
6
  AppExecutor2
7
- } from "./index-9a9t77hz.js";
7
+ } from "./index-77627y32.js";
8
8
  import {
9
9
  LibExecutor2
10
- } from "./index-yey1envc.js";
10
+ } from "./index-741xbhes.js";
11
11
  import {
12
12
  InteractionScaffold,
13
13
  workflowStatus,
@@ -46,16 +46,16 @@ import {
46
46
  nextActionsForTarget,
47
47
  createPrimitiveWriteReport,
48
48
  insertTemplateField
49
- } from "./index-q63nbpv7.js";
49
+ } from "./index-0zkxsdsg.js";
50
50
  import {
51
51
  ModuleScript
52
- } from "./index-rdcgz02t.js";
52
+ } from "./index-bma8tmgb.js";
53
53
  import {
54
54
  plainNameProblem
55
55
  } from "./index-va90m8nd.js";
56
56
  import {
57
57
  ModuleExecutor
58
- } from "./index-3r1crbct.js";
58
+ } from "./index-ay4vkwr8.js";
59
59
 
60
60
  // pkgs/@akanjs/cli/primitive/primitive.script.ts
61
61
  import { capitalize, lowerlize } from "akanjs/common";
@@ -6,23 +6,23 @@ import {
6
6
  CloudApi,
7
7
  CloudUpdates,
8
8
  PipelineSecrets
9
- } from "./index-pyjkbg8e.js";
9
+ } from "./index-extg77rx.js";
10
10
  import {
11
11
  resolveMobileTargets
12
12
  } from "./index-m9jj544v.js";
13
13
  import {
14
14
  WorkspaceExecutor
15
- } from "./index-v16gj2as.js";
15
+ } from "./index-ys1sjp6m.js";
16
16
  import {
17
17
  AppExecutor2
18
- } from "./index-9a9t77hz.js";
18
+ } from "./index-77627y32.js";
19
19
  import {
20
20
  NativeApp
21
- } from "./index-fjqapyex.js";
21
+ } from "./index-es2wkn41.js";
22
22
  import {
23
23
  runner,
24
24
  assertPromptable
25
- } from "./index-nnmw56fz.js";
25
+ } from "./index-mv3ke0fc.js";
26
26
  import {
27
27
  getNpmRegistryUrl,
28
28
  getPublishedVersions,
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  CommandContainer,
4
4
  runner
5
- } from "./index-nnmw56fz.js";
5
+ } from "./index-mv3ke0fc.js";
6
6
  import {
7
7
  WorkspaceExecutor
8
- } from "./index-v16gj2as.js";
8
+ } from "./index-ys1sjp6m.js";
9
9
  import {
10
10
  jsonText,
11
11
  workflowPlanApproval,
@@ -31,23 +31,23 @@ import {
31
31
  renderWorkflowApply,
32
32
  renderWorkflowValidation,
33
33
  renderWorkflowRunArtifact
34
- } from "./index-q63nbpv7.js";
34
+ } from "./index-0zkxsdsg.js";
35
35
  import {
36
36
  AkanContextAnalyzer
37
- } from "./index-h8w1n11r.js";
37
+ } from "./index-6a3rmwxx.js";
38
38
  import {
39
39
  ModuleScript
40
- } from "./index-rdcgz02t.js";
40
+ } from "./index-bma8tmgb.js";
41
41
  import {
42
42
  PrimitiveScript
43
- } from "./index-m303nhv6.js";
43
+ } from "./index-mvdmb73w.js";
44
44
  import {
45
45
  spawnAkan,
46
46
  isWorkspaceTarget
47
- } from "./index-kbnvyhy4.js";
47
+ } from "./index-shjjjdte.js";
48
48
  import {
49
49
  ScalarScript
50
- } from "./index-fagjtk6m.js";
50
+ } from "./index-3q7ectss.js";
51
51
  import {
52
52
  workflowSpecs
53
53
  } from "./index-t4d0ckde.js";
@@ -4,7 +4,7 @@ import {
4
4
  script,
5
5
  WorkspaceVersionCheck,
6
6
  markCliErrorPrinted
7
- } from "./index-nnmw56fz.js";
7
+ } from "./index-mv3ke0fc.js";
8
8
  import {
9
9
  CliError
10
10
  } from "./index-j4yvgfhr.js";
@@ -16,16 +16,16 @@ import {
16
16
  upsertAgentBlock,
17
17
  renderRecipeEntries,
18
18
  CLAUDE_COMMENT_RULE
19
- } from "./index-v16gj2as.js";
19
+ } from "./index-ys1sjp6m.js";
20
20
  import {
21
21
  AppExecutor2
22
- } from "./index-9a9t77hz.js";
22
+ } from "./index-77627y32.js";
23
23
  import {
24
24
  LibExecutor2
25
- } from "./index-yey1envc.js";
25
+ } from "./index-741xbhes.js";
26
26
  import {
27
27
  AkanContextAnalyzer
28
- } from "./index-h8w1n11r.js";
28
+ } from "./index-6a3rmwxx.js";
29
29
  import {
30
30
  collectRecipeSources2,
31
31
  scanRecipes2
@@ -40,15 +40,15 @@ import {
40
40
  import {
41
41
  ApplicationRunner,
42
42
  VerifyScope
43
- } from "./index-wkwe91sn.js";
43
+ } from "./index-th7qbjfz.js";
44
44
  import {
45
45
  WorkspaceRunner
46
- } from "./index-j2wq064m.js";
46
+ } from "./index-aezpcphy.js";
47
47
  import {
48
48
  VerifyComments,
49
49
  VerifyPipeline,
50
50
  VerifyReport
51
- } from "./index-wxqp1amd.js";
51
+ } from "./index-1c52g4st.js";
52
52
 
53
53
  // pkgs/@akanjs/cli/agent/agent.script.ts
54
54
  import { Logger as Logger3 } from "akanjs/common";
@@ -5,10 +5,10 @@ import {
5
5
  import {
6
6
  JsonFormatter,
7
7
  AkanAppConfig
8
- } from "./index-v16gj2as.js";
8
+ } from "./index-ys1sjp6m.js";
9
9
  import {
10
10
  ErrorReport
11
- } from "./index-3r1crbct.js";
11
+ } from "./index-ay4vkwr8.js";
12
12
 
13
13
  // pkgs/@akanjs/devkit/app/applicationBuildReporter.ts
14
14
  import { Logger } from "akanjs/common";
@@ -1,17 +1,17 @@
1
1
  // @bun
2
2
  import {
3
3
  runner
4
- } from "./index-nnmw56fz.js";
4
+ } from "./index-mv3ke0fc.js";
5
5
  import {
6
6
  writeWorkflowRunArtifact,
7
7
  generatedFilePathsForTarget,
8
8
  writeGeneratedSyncState,
9
9
  createRepairReport,
10
10
  renderRepairReport
11
- } from "./index-q63nbpv7.js";
11
+ } from "./index-0zkxsdsg.js";
12
12
  import {
13
13
  AkanContextAnalyzer
14
- } from "./index-h8w1n11r.js";
14
+ } from "./index-6a3rmwxx.js";
15
15
  import {
16
16
  isWorkflowSysName,
17
17
  isWorkflowModuleName
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  resolveSsrPageEntriesForApp
4
- } from "./index-9a9t77hz.js";
4
+ } from "./index-77627y32.js";
5
5
  import {
6
6
  createBarrelImportsPlugin,
7
7
  workspaceBarrels,
@@ -10,7 +10,7 @@ import {
10
10
  CsrEntryFiles,
11
11
  PagesEntrySourceGenerator,
12
12
  PagesBundleBuilder
13
- } from "./index-3mj5trqc.js";
13
+ } from "./index-0bzrcv91.js";
14
14
 
15
15
  // pkgs/@akanjs/devkit/frontendBuild/csrArtifactBuilder.ts
16
16
  import { mkdir as mkdir2, rm as rm2, unlink as unlink2 } from "fs/promises";