@akanjs/cli 3.1.0-rc.9 → 3.1.1-rc.0

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 (91) hide show
  1. package/.build-stamp +1 -1
  2. package/{CodeAgent-rkjyxgec.js → CodeAgent-4pnxwptq.js} +2 -2
  3. package/{CodeAgentRpcHost-p7h6n2hp.js → CodeAgentRpcHost-9g27hmer.js} +1 -1
  4. package/{CodeTui-h7pyj6xa.js → CodeTui-hhndze8h.js} +47 -4
  5. package/README.ko.md +1 -1
  6. package/README.md +1 -1
  7. package/TunnelShare-zmq6bbar.js +14 -0
  8. package/{agent.command-3qxf4xcj.js → agent.command-p02330r6.js} +5 -5
  9. package/akanCode.js +7 -5
  10. package/{application.command-m1kcd7jf.js → application.command-ywks5ywm.js} +35 -9
  11. package/{applicationBuildRunner-dj0xkrep.js → applicationBuildRunner-9cnnsdm5.js} +23 -8
  12. package/buildBatch.proc.js +9 -9
  13. package/{cloud.command-9cp1t0f5.js → cloud.command-1tzkvje1.js} +13 -13
  14. package/cloud.script-8g83xqdg.js +24 -0
  15. package/{code.command-0ad6gw2a.js → code.command-16pm1p2v.js} +25 -12
  16. package/commandManifest.json +1 -1
  17. package/{context.command-0qx447mb.js → context.command-6ys86sqf.js} +16 -16
  18. package/context.runner-3jrypwe3.js +25 -0
  19. package/{guideline.command-cv5bmrx2.js → guideline.command-3zay3d8g.js} +2 -2
  20. package/guidelines/agentRule/agentRule.instruction.md +25 -10
  21. package/guidelines/conventions/conventions.instruction.md +71 -24
  22. package/guidelines/fieldRule/fieldRule.instruction.md +17 -0
  23. package/guidelines/mcpRule/mcpRule.instruction.md +93 -48
  24. package/guidelines/modelDocument/modelDocument.instruction.md +2 -1
  25. package/guidelines/modelStore/modelStore.instruction.md +7 -0
  26. package/guidelines/pageRule/pageRule.instruction.md +55 -8
  27. package/guidelines/queryRule/queryRule.instruction.md +24 -10
  28. package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -4
  29. package/guidelines/ssrRule/ssrRule.instruction.md +9 -6
  30. package/guidelines/transportRule/transportRule.instruction.md +36 -5
  31. package/guidelines/workspaceOnboarding/workspaceOnboarding.instruction.md +5 -3
  32. package/guidelines/workspaceRecipes/workspaceRecipes.instruction.md +28 -8
  33. package/incrementalBuilder.proc.js +3 -3
  34. package/{index-cpb3nvma.js → index-1f33g2z5.js} +2 -2
  35. package/{index-tamvyvj3.js → index-1mfyyxh5.js} +3 -3
  36. package/{index-wa5jbxj1.js → index-2mrn1mrg.js} +1 -0
  37. package/{index-8fp3b47h.js → index-4w3skd33.js} +281 -46
  38. package/{index-bspm21y1.js → index-68c3gzvg.js} +7 -7
  39. package/{index-20bxxyvn.js → index-9hbhm6cs.js} +40 -2
  40. package/{index-d2242ksy.js → index-at7bz0xq.js} +3 -0
  41. package/{index-fmzcs8v6.js → index-b5vptvnt.js} +4 -4
  42. package/{index-d72hfmdm.js → index-bb4hj03s.js} +8 -8
  43. package/{index-9z426msb.js → index-e9e9cebg.js} +78 -27
  44. package/{index-vk0pa0mn.js → index-ekpp5tax.js} +2 -1
  45. package/{index-35hc95h5.js → index-fmder14z.js} +1 -1
  46. package/{index-86jt2a0e.js → index-g2s33373.js} +1 -1
  47. package/{index-4mhy6qme.js → index-jaa81e9r.js} +4 -4
  48. package/{index-192ha4xh.js → index-jgs8z8xb.js} +3 -3
  49. package/{index-qwa5k1j8.js → index-kcbq2qcf.js} +1 -1
  50. package/{index-w44cy4vs.js → index-ngpn9hzy.js} +6 -4
  51. package/{index-jw1zm273.js → index-p4dnj2wc.js} +54 -10
  52. package/index-q8age5az.js +643 -0
  53. package/{index-j4mkhz93.js → index-qfzfaq96.js} +3 -3
  54. package/{index-pydbnfez.js → index-qkcwsg6r.js} +35 -9
  55. package/{index-d47ypebv.js → index-qtkycaqn.js} +75 -19
  56. package/{index-va06nr10.js → index-rr7jk14m.js} +65 -20
  57. package/{index-1xj2t7cb.js → index-sh9mmp5v.js} +7 -7
  58. package/{index-1p98exm2.js → index-sng3vt0p.js} +2 -2
  59. package/{index-j237xtew.js → index-tk3jg2bm.js} +25 -8
  60. package/{index-fyq1z6kt.js → index-vg28jsf9.js} +3 -3
  61. package/{index-trpasv9q.js → index-ynqxpwx6.js} +1 -1
  62. package/{index-5edzv8fn.js → index-z6v7k9sb.js} +2 -2
  63. package/{index-g1mbppa9.js → index-z9xepn8t.js} +5 -5
  64. package/{index-awbdfcf2.js → index-zn6bn1s2.js} +4 -4
  65. package/index.js +40 -22
  66. package/{library.command-erp2f56n.js → library.command-a8n9h8j4.js} +3 -3
  67. package/{localRegistry.command-y176p558.js → localRegistry.command-1e6m7w2f.js} +12 -12
  68. package/{module.command-gs2r615e.js → module.command-b6f1p1xa.js} +5 -5
  69. package/{package.command-j10r76ax.js → package.command-tc27ftmy.js} +3 -3
  70. package/package.json +16 -16
  71. package/{page.command-4h4a8pnh.js → page.command-m5wyqfkd.js} +3 -3
  72. package/{pipeline.command-a2nrk26m.js → pipeline.command-4qxyafpz.js} +2 -2
  73. package/{primitive.command-w6t0asqz.js → primitive.command-9yaatk0d.js} +6 -6
  74. package/{projectTypecheck-f534enqj.js → projectTypecheck-87k6z6ab.js} +1 -1
  75. package/{quality.command-77x7vbbx.js → quality.command-ht1wjhv8.js} +2 -2
  76. package/{repair.command-y6sstev7.js → repair.command-evg9g911.js} +5 -5
  77. package/{routeSourceValidator-7ycnfz0e.js → routeSourceValidator-6jd0q6r6.js} +47 -14
  78. package/{scalar.command-20b8cy0k.js → scalar.command-xsejjeq1.js} +4 -4
  79. package/skills/akan-code/SKILL.md +4 -0
  80. package/skills/akan-store/SKILL.md +4 -2
  81. package/{subspace.command-5c7yasd7.js → subspace.command-ps12q5y7.js} +8 -17
  82. package/templates/migration/__migrationId__.ts +23 -0
  83. package/templates/server.ts +8 -1
  84. package/templates/workspaceRoot/biome.json.template +1 -1
  85. package/{tunnel.command-2kw8vt9g.js → tunnel.command-khzgvrj8.js} +7 -7
  86. package/{workflow.command-2djwmpqf.js → workflow.command-qpyq0ya5.js} +10 -10
  87. package/{workspace.command-ms84ykse.js → workspace.command-3dq7e9g2.js} +30 -28
  88. package/TunnelShare-661cxz5e.js +0 -14
  89. package/cloud.script-dgstqt1m.js +0 -24
  90. package/context.runner-1vsjztjg.js +0 -25
  91. package/index-665zp9rs.js +0 -271
@@ -0,0 +1,23 @@
1
+ import type { AppInfo, LibInfo } from "akanjs";
2
+
3
+ interface Dict {
4
+ migrationId: string;
5
+ title: string;
6
+ }
7
+ export default function getContent(scanInfo: AppInfo | LibInfo | null, dict: Dict) {
8
+ return `import { migration } from "akanjs/server";
9
+
10
+ export default migration(${JSON.stringify(dict.title)})
11
+ .plan(async ({ table }) => {
12
+ // TODO: count the rows apply changes, and list each decision a person approves
13
+ return { summary: {}, items: [] };
14
+ })
15
+ .apply(async ({ table }, { items }) => {
16
+ // TODO: write through table(refName), so every change is logged and a rollback can undo it
17
+ })
18
+ .verify(async ({ table }) => {
19
+ // TODO: one line per row apply left wrong; none means the data is as intended
20
+ return [];
21
+ });
22
+ `;
23
+ }
@@ -6,7 +6,7 @@ export default function getContent(scanInfo: AppInfo | LibInfo | null, dict: { [
6
6
  const databaseModules = [...scanInfo.database.entries()].filter(([_, files]) => files.has("service"));
7
7
  const serviceModules = [...scanInfo.service.entries()].filter(([_, files]) => files.has("service"));
8
8
  const scalarModules = [...scanInfo.scalar.entries()];
9
- return `import { ${scanInfo.type === "app" ? "AkanServer, " : ""}AkanLib } from "akanjs/server";
9
+ return `import { ${scanInfo.type === "app" ? "AkanServer, " : ""}AkanLib${scanInfo.type === "app" ? ", Migrations" : ""} } from "akanjs/server";
10
10
  import * as cnst from "./lib/cnst";
11
11
  import * as db from "./lib/db";
12
12
  import * as sig from "./lib/sig";
@@ -29,6 +29,13 @@ ${scalarModules.map(([model]) => ` { constant: cnst.${model}, database: db.${
29
29
  });
30
30
 
31
31
  ${scanInfo.type === "app" ? `export const server = new AkanServer("${scanInfo.name}", env, undefined${libs.length ? `, ${libs.join(", ")}` : ""}, lib);` : ""}
32
+ ${
33
+ scanInfo.type === "app"
34
+ ? `export const migrations = new Migrations([
35
+ ${scanInfo.migrations.map(({ id, checksum }) => ` { id: "${id}", checksum: "${checksum}", load: () => import("./script/migration/${id}") },`).join("\n")}
36
+ ]);`
37
+ : ""
38
+ }
32
39
 
33
40
  ${scanInfo.type === "lib" ? `export { env } from "./env/env.server.testing";` : ""}
34
41
  export * as db from "./lib/db";
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.5.12/schema.json",
2
+ "$schema": "https://biomejs.dev/schemas/2.5.14/schema.json",
3
3
  "extends": ["@akanjs/devkit/biome.base.json"],
4
4
  "files": {
5
5
  "includes": [
@@ -4,25 +4,25 @@ import {
4
4
  runner,
5
5
  script,
6
6
  command
7
- } from "./index-jw1zm273.js";
7
+ } from "./index-p4dnj2wc.js";
8
8
  import"./index-52w0fvh8.js";
9
9
  import {
10
10
  AppExecutor
11
- } from "./index-va06nr10.js";
11
+ } from "./index-rr7jk14m.js";
12
12
  import {
13
13
  GlobalConfig,
14
14
  CloudApi
15
- } from "./index-cpb3nvma.js";
15
+ } from "./index-1f33g2z5.js";
16
16
  import"./index-m9jj544v.js";
17
- import"./index-g1mbppa9.js";
18
- import"./index-192ha4xh.js";
17
+ import"./index-z9xepn8t.js";
18
+ import"./index-q8age5az.js";
19
+ import"./index-jgs8z8xb.js";
19
20
  import {
20
21
  TunnelShare2
21
- } from "./index-qwa5k1j8.js";
22
+ } from "./index-kcbq2qcf.js";
22
23
  import {
23
24
  writeClipboard
24
25
  } from "./index-p6pbz9n5.js";
25
- import"./index-665zp9rs.js";
26
26
 
27
27
  // pkgs/@akanjs/cli/tunnel/tunnel.script.ts
28
28
  import { select } from "@inquirer/prompts";
@@ -3,20 +3,20 @@ import {
3
3
  Workspace,
4
4
  script,
5
5
  command
6
- } from "./index-jw1zm273.js";
6
+ } from "./index-p4dnj2wc.js";
7
7
  import"./index-52w0fvh8.js";
8
- import"./index-va06nr10.js";
8
+ import"./index-rr7jk14m.js";
9
9
  import"./index-hj6w4ka1.js";
10
- import"./index-trpasv9q.js";
11
- import"./index-5edzv8fn.js";
12
- import"./index-86jt2a0e.js";
13
- import"./index-fmzcs8v6.js";
14
- import"./index-awbdfcf2.js";
15
- import"./index-j4mkhz93.js";
16
- import"./index-1p98exm2.js";
10
+ import"./index-ynqxpwx6.js";
11
+ import"./index-z6v7k9sb.js";
12
+ import"./index-g2s33373.js";
13
+ import"./index-b5vptvnt.js";
14
+ import"./index-zn6bn1s2.js";
15
+ import"./index-qfzfaq96.js";
16
+ import"./index-sng3vt0p.js";
17
17
  import {
18
18
  WorkflowRunner
19
- } from "./index-1xj2t7cb.js";
19
+ } from "./index-sh9mmp5v.js";
20
20
 
21
21
  // pkgs/@akanjs/cli/workflow/workflow.script.ts
22
22
  import { Logger } from "akanjs/common";
@@ -5,7 +5,7 @@ import {
5
5
  runner,
6
6
  script,
7
7
  command
8
- } from "./index-jw1zm273.js";
8
+ } from "./index-p4dnj2wc.js";
9
9
  import {
10
10
  FileSys2
11
11
  } from "./index-52w0fvh8.js";
@@ -19,7 +19,7 @@ import {
19
19
  AppExecutor,
20
20
  LibExecutor,
21
21
  PkgExecutor
22
- } from "./index-va06nr10.js";
22
+ } from "./index-rr7jk14m.js";
23
23
  import {
24
24
  countBlocking,
25
25
  formatStyleContract,
@@ -29,55 +29,55 @@ import {
29
29
  collectRecipeSources2,
30
30
  scanRecipes2
31
31
  } from "./index-hj6w4ka1.js";
32
- import"./index-trpasv9q.js";
33
- import"./index-5edzv8fn.js";
32
+ import"./index-ynqxpwx6.js";
33
+ import"./index-z6v7k9sb.js";
34
34
  import"./index-zzvvc845.js";
35
35
  import {
36
36
  AgentScript
37
- } from "./index-tamvyvj3.js";
37
+ } from "./index-1mfyyxh5.js";
38
38
  import"./index-5nd1wtkv.js";
39
- import"./index-vk0pa0mn.js";
39
+ import"./index-ekpp5tax.js";
40
40
  import"./index-m9jj544v.js";
41
- import"./index-g1mbppa9.js";
42
- import"./index-192ha4xh.js";
41
+ import"./index-z9xepn8t.js";
42
+ import"./index-q8age5az.js";
43
+ import"./index-jgs8z8xb.js";
43
44
  import {
44
45
  LibraryScript
45
- } from "./index-pydbnfez.js";
46
+ } from "./index-qkcwsg6r.js";
46
47
  import {
47
48
  ApplicationScript
48
- } from "./index-d47ypebv.js";
49
+ } from "./index-qtkycaqn.js";
49
50
  import"./index-7md2g9vw.js";
50
- import"./index-cpb3nvma.js";
51
+ import"./index-1f33g2z5.js";
51
52
  import"./index-tvehn2sp.js";
52
53
  import {
53
54
  PackageScript
54
- } from "./index-j237xtew.js";
55
+ } from "./index-tk3jg2bm.js";
55
56
  import {
56
57
  getNpmRegistryUrl,
57
58
  getLatestPackageVersion
58
- } from "./index-fyq1z6kt.js";
59
+ } from "./index-vg28jsf9.js";
59
60
  import {
60
61
  CloudScript2
61
- } from "./index-bspm21y1.js";
62
- import"./index-d72hfmdm.js";
63
- import"./index-j4mkhz93.js";
64
- import"./index-86jt2a0e.js";
65
- import"./index-fmzcs8v6.js";
66
- import"./index-awbdfcf2.js";
67
- import"./index-1p98exm2.js";
68
- import"./index-1xj2t7cb.js";
62
+ } from "./index-68c3gzvg.js";
63
+ import"./index-bb4hj03s.js";
64
+ import"./index-qfzfaq96.js";
65
+ import"./index-g2s33373.js";
66
+ import"./index-b5vptvnt.js";
67
+ import"./index-zn6bn1s2.js";
68
+ import"./index-sng3vt0p.js";
69
+ import"./index-sh9mmp5v.js";
69
70
  import {
70
71
  ContextScript
71
- } from "./index-4mhy6qme.js";
72
- import"./index-35hc95h5.js";
73
- import"./index-665zp9rs.js";
72
+ } from "./index-jaa81e9r.js";
73
+ import"./index-fmder14z.js";
74
74
 
75
75
  // pkgs/@akanjs/cli/workspace/workspace.runner.ts
76
76
  import { mkdir, writeFile } from "fs/promises";
77
77
  import path from "path";
78
78
 
79
79
  // pkgs/@akanjs/devkit/biomeBase.ts
80
- var biomeVersion = "2.5.12";
80
+ var biomeVersion = "2.5.14";
81
81
 
82
82
  // pkgs/@akanjs/cli/workspace/workspace.runner.ts
83
83
  import { Ed25519Key } from "akanjs/server/ed25519Key";
@@ -96,6 +96,7 @@ var defaultWorkspacePeerDependencies = new Set([
96
96
  "tailwindcss",
97
97
  "typescript"
98
98
  ]);
99
+ var defaultWorkspaceTypeDependencies = { "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0" };
99
100
  var defaultMaxDiagnostics = 200;
100
101
 
101
102
  class WorkspaceRunner extends runner("workspace") {
@@ -163,6 +164,7 @@ class WorkspaceRunner extends runner("workspace") {
163
164
  ...rootPackageJson.devDependencies,
164
165
  "@biomejs/biome": biomeVersion,
165
166
  "@types/bun": latestTypesBunVersion,
167
+ ...defaultWorkspaceTypeDependencies,
166
168
  "@akanjs/devkit": akanVersion,
167
169
  ...typescript ? { typescript } : {}
168
170
  }
@@ -256,7 +258,7 @@ class WorkspaceRunner extends runner("workspace") {
256
258
  const actual = existing ? extractAgentBlock(existing) : null;
257
259
  if (actual === expected.trim())
258
260
  return;
259
- throw new Error(`[agentsIndex] ${scope.type}s/${scope.name}/AGENTS.md \uC758 recipe \uC0C9\uC778\uC774 \uC18C\uC2A4\uC640 \uB2E4\uB985\uB2C8\uB2E4(stale). ` + `\`akan sync ${scope.name}\` \uC744 \uC2E4\uD589\uD574 \uC7AC\uC0DD\uC131\uD558\uC138\uC694.`);
261
+ throw new Error(`[agentsIndex] The recipe index in ${scope.type}s/${scope.name}/AGENTS.md is stale: it differs from the recipe ` + `sources. Run \`akan sync ${scope.name}\` to regenerate it.`);
260
262
  }
261
263
  async#enforceRecipeGate(exec) {
262
264
  const cwdPath = exec.cwdPath;
@@ -272,8 +274,8 @@ class WorkspaceRunner extends runner("workspace") {
272
274
  const offenders = scanRecipes2(sources).filter((recipe) => !Object.values(recipe.variants).some((values) => values.length >= 2 || values.length === 1 && values[0] === "true"));
273
275
  if (offenders.length === 0)
274
276
  return;
275
- throw new Error(`[recipeGate] variant-less recipe(s): ${offenders.map((recipe) => recipe.name).join(", ")}
276
- ` + "\uACE0\uB97C \uC635\uC158 \uC5C6\uB294 look \uC740 recipe \uB85C \uB450\uC9C0 \uB9C8\uC138\uC694 \u2014 \uC790\uAE30 \uB9C8\uD06C\uC5C5\uC774 \uC788\uC73C\uBA74 \uCEF4\uD3EC\uB10C\uD2B8\uB85C \uC2B9\uACA9\uD558\uACE0, " + "\uB2E4\uB978 \uCEF4\uD3EC\uB10C\uD2B8\uC758 className \uC5D0 \uC8FC\uC785\uD558\uB294 \uC2A4\uD0A8\uC774\uBA74 \uACF5\uC720 \uD074\uB798\uC2A4 \uC0C1\uC218\uB85C \uB450\uC138\uC694.");
277
+ throw new Error(`[recipeGate] variant-less recipe(s): ${[...new Set(offenders.map((recipe) => recipe.name))].join(", ")}
278
+ ` + "A look with nothing to pick is not a recipe: promote one that has its own markup to a component, and keep " + "a skin passed into another component's className as a shared class constant.");
277
279
  }
278
280
  async#enforceStyleContract(exec) {
279
281
  const cwdPath = exec.cwdPath;
@@ -1,14 +0,0 @@
1
- // @bun
2
- import {
3
- TunnelShare2
4
- } from "./index-qwa5k1j8.js";
5
- import"./index-cpb3nvma.js";
6
- import"./index-g1mbppa9.js";
7
- import"./index-m9jj544v.js";
8
- import"./index-665zp9rs.js";
9
- import"./index-192ha4xh.js";
10
- import"./index-va06nr10.js";
11
- import"./index-52w0fvh8.js";
12
- export {
13
- TunnelShare2 as TunnelShare
14
- };
@@ -1,24 +0,0 @@
1
- // @bun
2
- import {
3
- CloudScript2
4
- } from "./index-bspm21y1.js";
5
- import"./index-fyq1z6kt.js";
6
- import"./index-d47ypebv.js";
7
- import"./index-35hc95h5.js";
8
- import"./index-pydbnfez.js";
9
- import"./index-j237xtew.js";
10
- import"./index-vk0pa0mn.js";
11
- import"./index-cpb3nvma.js";
12
- import"./index-g1mbppa9.js";
13
- import"./index-m9jj544v.js";
14
- import"./index-jw1zm273.js";
15
- import"./index-7md2g9vw.js";
16
- import"./index-665zp9rs.js";
17
- import"./index-5nd1wtkv.js";
18
- import"./index-192ha4xh.js";
19
- import"./index-va06nr10.js";
20
- import"./index-tvehn2sp.js";
21
- import"./index-52w0fvh8.js";
22
- export {
23
- CloudScript2 as CloudScript
24
- };
@@ -1,25 +0,0 @@
1
- // @bun
2
- import {
3
- ContextRunner2
4
- } from "./index-d72hfmdm.js";
5
- import"./index-1xj2t7cb.js";
6
- import"./index-1p98exm2.js";
7
- import"./index-awbdfcf2.js";
8
- import"./index-j4mkhz93.js";
9
- import"./index-fmzcs8v6.js";
10
- import"./index-86jt2a0e.js";
11
- import"./index-vk0pa0mn.js";
12
- import"./index-g1mbppa9.js";
13
- import"./index-m9jj544v.js";
14
- import"./index-5edzv8fn.js";
15
- import"./index-trpasv9q.js";
16
- import"./index-zzvvc845.js";
17
- import"./index-jw1zm273.js";
18
- import"./index-665zp9rs.js";
19
- import"./index-192ha4xh.js";
20
- import"./index-va06nr10.js";
21
- import"./index-hj6w4ka1.js";
22
- import"./index-52w0fvh8.js";
23
- export {
24
- ContextRunner2 as ContextRunner
25
- };
package/index-665zp9rs.js DELETED
@@ -1,271 +0,0 @@
1
- // @bun
2
- import {
3
- resolveSsrPageEntriesForApp
4
- } from "./index-va06nr10.js";
5
- import {
6
- bundleDefine,
7
- CsrEntryFiles,
8
- PagesEntrySourceGenerator,
9
- PagesBundleBuilder
10
- } from "./index-192ha4xh.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 };