@akanjs/cli 3.1.0-rc.21 → 3.1.0-rc.23

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 (73) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-gzfc5t52.js → CodeAgent-fee0pnwp.js} +2 -2
  3. package/{CodeTui-bpsjs8wz.js → CodeTui-xh71b2k8.js} +1 -1
  4. package/TunnelShare-s7bpe55e.js +14 -0
  5. package/{agent.command-67ysh3n6.js → agent.command-tge9rvmt.js} +5 -5
  6. package/akanCode.js +2 -2
  7. package/{application.command-q0tqw5pc.js → application.command-j5b8yrcf.js} +9 -9
  8. package/{applicationBuildRunner-wsszr305.js → applicationBuildRunner-s41mgz21.js} +21 -7
  9. package/buildBatch.proc.js +9 -9
  10. package/{cloud.command-e7tkxyx6.js → cloud.command-q9srng6e.js} +13 -13
  11. package/cloud.script-vfsd4gxs.js +24 -0
  12. package/{code.command-ttk8tje2.js → code.command-n6r6zt97.js} +6 -6
  13. package/{context.command-bdsk2z2r.js → context.command-1je84w1b.js} +16 -16
  14. package/context.runner-xg0ngz93.js +25 -0
  15. package/{guideline.command-man90n70.js → guideline.command-0e0sx2vg.js} +2 -2
  16. package/guidelines/conventions/conventions.instruction.md +18 -12
  17. package/guidelines/mcpRule/mcpRule.instruction.md +88 -47
  18. package/guidelines/pageRule/pageRule.instruction.md +55 -8
  19. package/guidelines/runtimeRule/runtimeRule.instruction.md +8 -1
  20. package/guidelines/ssrRule/ssrRule.instruction.md +8 -5
  21. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +1 -1
  22. package/incrementalBuilder.proc.js +3 -3
  23. package/{index-p2r64bpa.js → index-1bhv9dh4.js} +4 -4
  24. package/{index-h6czey01.js → index-1xqq3va9.js} +9 -9
  25. package/{index-27y8t17p.js → index-3xhak9e0.js} +1 -1
  26. package/{index-ta1dychm.js → index-4fe4qqgn.js} +3 -3
  27. package/{index-35m6bzm7.js → index-551gh8h2.js} +5 -5
  28. package/{index-033wne2j.js → index-5m0s0gdv.js} +1 -1
  29. package/index-6mprvdt8.js +566 -0
  30. package/{index-h3r3nr9y.js → index-6nqnqzv1.js} +1 -1
  31. package/{index-cae9m5jz.js → index-73esn3y2.js} +1 -1
  32. package/{index-8jehkey8.js → index-7xy30jev.js} +4 -4
  33. package/{index-75n5q4ph.js → index-85h3dhe0.js} +7 -7
  34. package/{index-54wc2phm.js → index-8abyrfw8.js} +5 -4
  35. package/{index-g9ks2k8c.js → index-94jq9cbz.js} +2 -2
  36. package/{index-jrmzcp66.js → index-9h0z0tjr.js} +2 -2
  37. package/{index-844q7f8z.js → index-c9rfak6r.js} +7 -7
  38. package/{index-1r5a8bzx.js → index-cgyqx6q1.js} +2 -2
  39. package/{index-zv5s8x58.js → index-cq5x7a9k.js} +8 -8
  40. package/{index-ebarbgba.js → index-deckcwbg.js} +2 -2
  41. package/{index-4v43h00g.js → index-ex35dg39.js} +2 -1
  42. package/{index-xsd96yzw.js → index-f9118j70.js} +1 -1
  43. package/{index-vkb9m4z7.js → index-g5px5pxd.js} +1 -1
  44. package/{index-g6ax17x4.js → index-gxqvev8w.js} +28 -8
  45. package/{index-rc51f9ht.js → index-hagw9c94.js} +3 -3
  46. package/{index-9mt4smfy.js → index-p44jnjfr.js} +2 -2
  47. package/{index-4393nb4b.js → index-rp9anyeb.js} +4 -4
  48. package/{index-pg1t468s.js → index-t8npm331.js} +3 -3
  49. package/{index-nv79n88g.js → index-tbmtmkhx.js} +2 -2
  50. package/{index-2w8j2fnv.js → index-vyh8kemm.js} +3 -3
  51. package/{index-48edp6q4.js → index-x7bny3wv.js} +1 -1
  52. package/index.js +22 -22
  53. package/{library.command-6amzsrb8.js → library.command-ys9s0mtc.js} +3 -3
  54. package/{localRegistry.command-yqc0nyhh.js → localRegistry.command-kmp3sd47.js} +12 -12
  55. package/{module.command-10x6jv6c.js → module.command-5sx9453y.js} +5 -5
  56. package/{package.command-pwfvecjf.js → package.command-s0d3417k.js} +3 -3
  57. package/package.json +2 -2
  58. package/{page.command-ahhgx9y1.js → page.command-zsa03pmc.js} +3 -3
  59. package/{pipeline.command-1ptr3e9y.js → pipeline.command-j8h6qsha.js} +2 -2
  60. package/{primitive.command-g5xwv6tj.js → primitive.command-n2978nmw.js} +6 -6
  61. package/{projectTypecheck-fx8x7cat.js → projectTypecheck-qg2jf80j.js} +1 -1
  62. package/{quality.command-fw9ck061.js → quality.command-7kgz46st.js} +2 -2
  63. package/{repair.command-g8kecj96.js → repair.command-2sszcckw.js} +5 -5
  64. package/{routeSourceValidator-7ycnfz0e.js → routeSourceValidator-6jd0q6r6.js} +47 -14
  65. package/{scalar.command-fprap51w.js → scalar.command-230jrhzf.js} +4 -4
  66. package/{subspace.command-sc0t527y.js → subspace.command-y5v4ypd3.js} +8 -8
  67. package/{tunnel.command-mqnsqbwf.js → tunnel.command-ja29zghd.js} +7 -7
  68. package/{workflow.command-j0jgkr13.js → workflow.command-0eg8czt5.js} +10 -10
  69. package/{workspace.command-1r9hvvw0.js → workspace.command-zcym1dk5.js} +24 -24
  70. package/TunnelShare-tfrnftgr.js +0 -14
  71. package/cloud.script-krzh3d7k.js +0 -24
  72. package/context.runner-bxzv0gm0.js +0 -25
  73. package/index-nx64dz92.js +0 -271
package/index-nx64dz92.js DELETED
@@ -1,271 +0,0 @@
1
- // @bun
2
- import {
3
- resolveSsrPageEntriesForApp
4
- } from "./index-g6ax17x4.js";
5
- import {
6
- bundleDefine,
7
- CsrEntryFiles,
8
- PagesEntrySourceGenerator,
9
- PagesBundleBuilder
10
- } from "./index-h3r3nr9y.js";
11
-
12
- // pkgs/@akanjs/devkit/frontendBuild/csrArtifactBuilder.ts
13
- import { mkdir, rm, unlink } from "fs/promises";
14
- import path2 from "path";
15
-
16
- // pkgs/@akanjs/devkit/transforms/browserDirnamePlugin.ts
17
- import path from "path";
18
- var vendorScript = /[\\/]node_modules[\\/].+\.[cm]?js$/;
19
- var createBrowserDirnamePlugin = () => ({
20
- name: "akan-browser-dirname",
21
- setup(build) {
22
- build.onLoad({ filter: vendorScript }, async (args) => {
23
- const source = await Bun.file(args.path).text();
24
- if (!source.includes("__dirname") && !source.includes("__filename"))
25
- return;
26
- const posixPath = args.path.replaceAll("\\", "/");
27
- const filename = posixPath.slice(posixPath.indexOf("/node_modules/"));
28
- const define = { __dirname: JSON.stringify(path.posix.dirname(filename)), __filename: JSON.stringify(filename) };
29
- return {
30
- loader: "js",
31
- contents: new Bun.Transpiler({ loader: "js", target: "browser", define }).transformSync(source)
32
- };
33
- });
34
- }
35
- });
36
-
37
- // pkgs/@akanjs/devkit/frontendBuild/csrArtifactBuilder.ts
38
- class CsrArtifactBuilder {
39
- #app;
40
- #command;
41
- #lang;
42
- #cssAssets;
43
- constructor(app, command = "start", lang = "en", { cssAssets = null } = {}) {
44
- this.#app = app;
45
- this.#command = command;
46
- this.#lang = lang;
47
- this.#cssAssets = cssAssets;
48
- }
49
- async build() {
50
- const pageKeys = await this.#app.getPageKeys();
51
- if (pageKeys.length === 0) {
52
- this.#app.log(`[cli] no route files under ${this.#app.cwdPath}/page \u2014 skipping CSR build`);
53
- return null;
54
- }
55
- const pageEntries = await resolveSsrPageEntriesForApp(this.#app, pageKeys);
56
- const akanConfig = await this.#app.getConfig();
57
- const cssAssets = await this.#loadCssAssets();
58
- const basePaths = [...akanConfig.basePaths];
59
- const htmlBasePaths = basePaths.length > 0 ? basePaths : [""];
60
- await rm(this.#outputDir, { recursive: true, force: true });
61
- await mkdir(this.#generatedDir, { recursive: true });
62
- const generatedFiles = Object.fromEntries((await Promise.all(htmlBasePaths.map(async (basePath) => [
63
- this.#createHtmlFile(basePath),
64
- await this.#createEntryFile(basePath, CsrArtifactBuilder.pageEntriesForBasePath(pageEntries, basePath, basePaths))
65
- ]))).flat());
66
- const options = CsrArtifactBuilder.bundleOptions(this.#app, this.#command, akanConfig.optimizeImports);
67
- const result = await Bun.build({
68
- ...options,
69
- entrypoints: htmlBasePaths.map((basePath) => this.#generatedPath(CsrArtifactBuilder.htmlFilename(basePath))),
70
- files: generatedFiles,
71
- root: this.#generatedDir,
72
- outdir: this.#outputDir
73
- });
74
- if (!result.success) {
75
- const logs = result.logs.map((log) => log.message).join(`
76
- `);
77
- throw new Error(`[csr-build] failed${logs ? `
78
- ${logs}` : ""}`);
79
- }
80
- await this.#inlineCsrArtifacts(cssAssets);
81
- if (this.#command === "build")
82
- await CsrArtifactBuilder.writePublicEnv(this.#app, options.define);
83
- this.#app.verbose(`[csr-build] output -> ${this.#outputDir}`);
84
- return { outputDir: this.#outputDir };
85
- }
86
- static bundleOptions(app, command, optimizeImports = []) {
87
- return {
88
- target: "browser",
89
- splitting: false,
90
- minify: true,
91
- define: bundleDefine(app, command, "csr"),
92
- optimizeImports,
93
- plugins: [PagesBundleBuilder.createCssStubPlugin(), createBrowserDirnamePlugin()]
94
- };
95
- }
96
- static publicEnvPath(app) {
97
- return path2.join(app.dist.cwdPath, ".akan", "artifact", "csr-public-env.json");
98
- }
99
- static async writePublicEnv(app, define) {
100
- const prefix = "process.env.";
101
- const publicEnv = Object.fromEntries(Object.entries(define).filter(([key]) => key.startsWith(`${prefix}AKAN_PUBLIC_`)).map(([key, value]) => [key.slice(prefix.length), JSON.parse(value)]));
102
- await Bun.write(CsrArtifactBuilder.publicEnvPath(app), `${JSON.stringify(publicEnv, null, 2)}
103
- `);
104
- }
105
- static pageEntriesForBasePath(pageEntries, basePath, basePaths) {
106
- return CsrEntryFiles.pageEntriesForBasePath(pageEntries, basePath, basePaths);
107
- }
108
- static htmlFilename(basePath) {
109
- return `${basePath || "index"}.html`;
110
- }
111
- static entryFilename(basePath) {
112
- return CsrEntryFiles.entryFilename(basePath);
113
- }
114
- static basePathOfHtml(htmlPath) {
115
- const name = path2.basename(htmlPath, ".html");
116
- return name === "index" ? "" : name;
117
- }
118
- get #outputDir() {
119
- return path2.join(this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath, this.#command === "build" ? "csr" : ".akan/artifact/csr");
120
- }
121
- get #generatedDir() {
122
- return path2.join(this.#app.cwdPath, ".akan/generated/csr");
123
- }
124
- get #artifactDir() {
125
- return path2.join(this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath, ".akan/artifact");
126
- }
127
- #generatedPath(filename) {
128
- return path2.join(this.#generatedDir, filename);
129
- }
130
- async#createEntryFile(basePath, pageEntries) {
131
- return [
132
- this.#generatedPath(CsrArtifactBuilder.entryFilename(basePath)),
133
- `import { bootCsr } from "akanjs/webkit";
134
- ${await PagesEntrySourceGenerator.generateStatic(pageEntries)}
135
- void bootCsr(pages);
136
- `
137
- ];
138
- }
139
- #createHtmlFile(basePath) {
140
- return [
141
- this.#generatedPath(CsrArtifactBuilder.htmlFilename(basePath)),
142
- `<!doctype html>
143
- <html lang="${this.#lang}">
144
- <head>
145
- <meta charset="utf-8" />
146
- <title>${this.#app.name}</title>
147
- <base href="/" />
148
- <meta name="viewport" content="width=device-width, initial-scale=1" />
149
- </head>
150
- <body>
151
- <div id="root"></div>
152
- <script type="module" src="./${CsrArtifactBuilder.entryFilename(basePath)}"></script>
153
- </body>
154
- </html>
155
- `
156
- ];
157
- }
158
- async#loadCssAssets() {
159
- if (this.#cssAssets)
160
- return this.#cssAssets;
161
- const artifactFile = Bun.file(path2.join(this.#artifactDir, "base-artifact.json"));
162
- if (!await artifactFile.exists())
163
- return {};
164
- const artifact = await artifactFile.json();
165
- return artifact.cssAssets ?? {};
166
- }
167
- async#inlineCsrArtifacts(cssAssets) {
168
- const jsFiles = new Set;
169
- for (const htmlPath of await this.#listOutputFiles((filePath) => filePath.endsWith(".html"))) {
170
- const htmlFile = Bun.file(htmlPath);
171
- if (!await htmlFile.exists())
172
- continue;
173
- const basePath = CsrArtifactBuilder.basePathOfHtml(htmlPath);
174
- const cssAsset = cssAssets[basePath];
175
- if (!cssAsset) {
176
- this.#app.logger.warn(`[csr-build] base-artifact.json has no compiled stylesheet for ${basePath || "root"}; ${path2.basename(htmlPath)} ships without CSS`);
177
- }
178
- const inlined = await this.#inlineHtmlAssets(await htmlFile.text(), htmlPath, cssAsset);
179
- for (const filePath of inlined.jsFiles)
180
- jsFiles.add(filePath);
181
- await Bun.write(htmlPath, inlined.html);
182
- }
183
- for (const filePath of jsFiles)
184
- await unlink(filePath).catch(() => {
185
- return;
186
- });
187
- const remainingAssets = await this.#listOutputFiles((filePath) => filePath.endsWith(".js") || filePath.endsWith(".css"));
188
- if (remainingAssets.length > 0) {
189
- throw new Error(`[csr-build] expected single-file HTML, but CSR assets remain:
190
- ${remainingAssets.join(`
191
- `)}`);
192
- }
193
- }
194
- async#inlineHtmlAssets(html, htmlPath, cssAsset) {
195
- let next = html;
196
- if (cssAsset) {
197
- const css = await Bun.file(path2.join(this.#artifactDir, cssAsset.cssRelPath)).text();
198
- next = CsrArtifactBuilder.injectBeforeHeadEnd(next, CsrArtifactBuilder.createInlineStyle(css));
199
- }
200
- const jsFiles = [];
201
- next = await CsrArtifactBuilder.replaceModuleScriptSrc(next, async (src) => {
202
- const jsPath = CsrArtifactBuilder.resolveHtmlAssetPath(htmlPath, src);
203
- jsFiles.push(jsPath);
204
- return await Bun.file(jsPath).text();
205
- });
206
- return { html: next, jsFiles };
207
- }
208
- async#listOutputFiles(predicate) {
209
- const glob = new Bun.Glob("**/*");
210
- const files = [];
211
- for await (const filePath of glob.scan({ cwd: this.#outputDir, absolute: true })) {
212
- if (predicate(filePath))
213
- files.push(filePath);
214
- }
215
- return files.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
216
- }
217
- static injectBeforeHeadEnd(html, snippet) {
218
- const scannable = CsrArtifactBuilder.blankEmbeddedContent(html);
219
- const headEnd = scannable.search(/<\/head\s*>/i);
220
- if (headEnd !== -1)
221
- return `${html.slice(0, headEnd)}${snippet}
222
- ${html.slice(headEnd)}`;
223
- const bodyStart = scannable.search(/<body(?:\s|>)/i);
224
- if (bodyStart !== -1)
225
- return `${html.slice(0, bodyStart)}${snippet}
226
- ${html.slice(bodyStart)}`;
227
- return `${html}
228
- ${snippet}`;
229
- }
230
- static blankEmbeddedContent(html) {
231
- return html.replace(/<script\b[^>]*>[\s\S]*?(?:<\/script(?:[\s/][^<>]*)?>|$)|<style\b[^>]*>[\s\S]*?(?:<\/style(?:[\s/][^<>]*)?>|$)|<!--[\s\S]*?(?:--!?>|$)/gi, (match) => " ".repeat(match.length));
232
- }
233
- static createInlineStyle(css) {
234
- return `<style data-akan-css="active">
235
- ${css.replace(/<\/style/gi, "<\\/style")}
236
- </style>`;
237
- }
238
- static async replaceModuleScriptSrc(html, loadScript) {
239
- const scriptRe = /<script\b(?=[^>]*\btype=["']module["'])(?=[^>]*\bsrc=["']([^"']+)["'])[^>]*>\s*<\/script>/gi;
240
- let result = "";
241
- let lastIndex = 0;
242
- let matched = false;
243
- for (const match of html.matchAll(scriptRe)) {
244
- const full = match[0];
245
- const src = match[1];
246
- if (match.index === undefined || !src)
247
- continue;
248
- matched = true;
249
- result += html.slice(lastIndex, match.index);
250
- result += `<script type="module">
251
- ${CsrArtifactBuilder.escapeInlineScript(await loadScript(src))}
252
- </script>`;
253
- lastIndex = match.index + full.length;
254
- }
255
- if (!matched)
256
- return html;
257
- return result + html.slice(lastIndex);
258
- }
259
- static escapeInlineScript(source) {
260
- return source.replace(/<\/script/gi, "<\\/script");
261
- }
262
- static resolveHtmlAssetPath(htmlPath, src) {
263
- if (/^[a-z][a-z0-9+.-]*:/i.test(src) || src.startsWith("//")) {
264
- throw new Error(`[csr-build] cannot inline external script: ${src}`);
265
- }
266
- const normalized = src.startsWith("/") ? src.slice(1) : src;
267
- return path2.resolve(path2.dirname(htmlPath), normalized);
268
- }
269
- }
270
-
271
- export { CsrArtifactBuilder };