@akanjs/cli 3.2.0-rc.3 → 3.2.0-rc.30
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/.build-stamp +2 -1
- package/CodeAgent-c17abdbf.js +11 -0
- package/{CodeTui-wv9yf7eq.js → CodeTui-jed1nj82.js} +822 -666
- package/README.ko.md +26 -1
- package/README.md +26 -1
- package/TunnelShare-mbfcaqg0.js +18 -0
- package/agent.command-9whnc6vb.js +56 -0
- package/akanCode.js +12 -12
- package/appExecutor-020cyesq.js +11 -0
- package/{application.command-6515t682.js → application.command-4eqvyxkw.js} +77 -36
- package/{applicationBuildRunner-bqbyeg84.js → applicationBuildRunner-frtcrqfd.js} +18 -13
- package/buildBatch.proc.js +26 -11
- package/{cloud.command-32esk0v1.js → cloud.command-hbvmeezn.js} +31 -28
- package/cloud.script-9kmbr3d6.js +35 -0
- package/{code.command-xk7rwq2x.js → code.command-0ayrenk4.js} +14 -9
- package/{context.command-jwenkkf0.js → context.command-php852kf.js} +28 -23
- package/context.runner-nngmn7c0.js +34 -0
- package/{dependencyScanner-78sq8m4q.js → dependencyScanner-ge10gb52.js} +2 -2
- package/{devTui-cd03z4mx.js → devTui-rf374y2w.js} +1 -1
- package/{fileSys-zpvt5gtf.js → fileSys-q22646yc.js} +1 -1
- package/{guideline.command-w6yqpdec.js → guideline.command-w1grfwh7.js} +9 -4
- package/guidelines/agentRule/agentRule.instruction.md +29 -12
- package/guidelines/akanApi/akanApi.instruction.md +5 -3
- package/guidelines/conventions/core.md +23 -5
- package/guidelines/conventions/rules/app.md +4 -1
- package/guidelines/conventions/rules/page.md +5 -0
- package/guidelines/conventions/rules/ts.md +3 -3
- package/guidelines/errorCodes/errorCodes.instruction.md +158 -0
- package/guidelines/fieldRule/fieldRule.instruction.md +2 -1
- package/guidelines/mcpRule/mcpRule.instruction.md +96 -2
- package/guidelines/pageRule/pageRule.instruction.md +15 -1
- package/guidelines/runtimeRule/runtimeRule.instruction.md +12 -6
- package/guidelines/transportRule/transportRule.instruction.md +8 -1
- package/incrementalBuilder.proc.js +574 -410
- package/{index-w15mg3km.js → index-0dm25wvf.js} +1 -1
- package/{index-xrmrvafh.js → index-0gaj78wn.js} +808 -694
- package/{index-j1hjb477.js → index-11d7nh8a.js} +1 -1
- package/{index-hj6w4ka1.js → index-1p81ecbz.js} +1 -1
- package/{index-ygrdw6jw.js → index-1pjwsh2g.js} +65 -8
- package/{index-43acpsc7.js → index-28nk8w3j.js} +12 -12
- package/{index-qd7xn2bk.js → index-2ny1e95c.js} +2 -2
- package/{index-8gm4yag8.js → index-42jhx2ya.js} +6 -6
- package/{index-2rqyrvcy.js → index-4st0hq72.js} +62 -33
- package/{index-bak9f2br.js → index-5d57kx0s.js} +15 -11
- package/{index-bdmgqzb5.js → index-6469101k.js} +58 -29
- package/{index-7kmbqp0b.js → index-6pxmcaq8.js} +1 -1
- package/{index-54s6knqe.js → index-6zb17wcm.js} +12 -10
- package/{index-0ba8nj4d.js → index-7bs463x7.js} +50 -38
- package/{index-y725zb1a.js → index-7v7tvgt7.js} +196 -168
- package/{index-r0a604h4.js → index-99kjwyma.js} +1 -1
- package/{index-2mrn1mrg.js → index-9f3reh2y.js} +1 -1
- package/{index-386canwe.js → index-9rv2zt48.js} +186 -121
- package/{index-20wvskt8.js → index-9wab2ngg.js} +1 -1
- package/{index-2eym1yjb.js → index-9wjrwjgz.js} +288 -209
- package/{index-kcpk2d20.js → index-at6haq2x.js} +1474 -1139
- package/{index-6h775rv3.js → index-ba2xd32s.js} +53 -12
- package/{index-yf9wc28h.js → index-bejy9zyc.js} +1 -1
- package/{index-ngpt3zz3.js → index-bj8s07s7.js} +525 -440
- package/{index-bns3wcpc.js → index-by2tvsq6.js} +1 -1
- package/{index-vbhx60x5.js → index-cb91b6d8.js} +2140 -2165
- package/index-dss3ds74.js +127 -0
- package/{index-e22zedc2.js → index-f16kr6vj.js} +3 -3
- package/{index-ny2k80mv.js → index-ffa52fwf.js} +1 -1
- package/{index-djc5nxpy.js → index-fp5xf6ef.js} +6 -6
- package/{index-qrk06tfp.js → index-g45y5f3e.js} +2 -2
- package/{index-8jpc5fqv.js → index-g7jgd4xs.js} +2 -2
- package/index-j4yvgfhr.js +70 -0
- package/{index-ytpmk3pb.js → index-jgj31xvw.js} +18 -11
- package/{index-j6eeh5d7.js → index-knpm8sdm.js} +5 -5
- package/{index-s34v3y28.js → index-m3t28rt3.js} +11 -11
- package/{index-dpgywgeq.js → index-m5gg0wzv.js} +27 -16
- package/index-na8r4a27.js +30 -0
- package/{index-h0p6n4k1.js → index-nm7nt9vm.js} +3 -3
- package/{index-j4hkbzj6.js → index-p06kfhdf.js} +6 -6
- package/{index-35j83zkd.js → index-p5zh7pmc.js} +2 -2
- package/{index-cmg5ngqa.js → index-p7beqww9.js} +2 -2
- package/{index-zhkcab5a.js → index-prgvqqxe.js} +580 -364
- package/{index-wfmpxke3.js → index-qssq2d41.js} +2775 -3677
- package/{index-sc0g6zbm.js → index-rwgqba9p.js} +24 -11
- package/{index-zcdmnfrf.js → index-s3m89wt2.js} +9 -9
- package/{index-v50xjbbe.js → index-t4d0ckde.js} +1 -1
- package/{index-9p260r4e.js → index-trffs83s.js} +538 -250
- package/{index-ddk49ypz.js → index-v929w7j7.js} +133 -49
- package/index-va90m8nd.js +25 -0
- package/index-vjbne22r.js +80 -0
- package/{index-h7hehkw6.js → index-xczjdng6.js} +3 -1
- package/{index-39jz41jb.js → index-xs9a3ddt.js} +3 -3
- package/{index-84c2pgak.js → index-yvzm8mby.js} +94 -82
- package/{index-wr9magsr.js → index-yxkjsyx8.js} +3 -3
- package/index-ze48c0vd.js +788 -0
- package/{index-ygdbn9jn.js → index-zyb0ebm4.js} +1 -1
- package/index.js +29 -24
- package/libExecutor-tq994592.js +10 -0
- package/{library.command-qs8beggh.js → library.command-x219mhcx.js} +9 -4
- package/{localRegistry.command-hz4ged9n.js → localRegistry.command-zvdcejhn.js} +30 -24
- package/{module.command-z9js77m2.js → module.command-k6cwcm7g.js} +17 -8
- package/{package.command-zqenq8c0.js → package.command-vw7x09f8.js} +13 -8
- package/package.json +2 -2
- package/{page.command-t0nx1jat.js → page.command-gf06paq2.js} +9 -4
- package/{pipeline.command-2yjeas7m.js → pipeline.command-y07dgj9b.js} +14 -8
- package/pkgExecutor-stde3yc3.js +10 -0
- package/{primitive.command-v5kypwy4.js → primitive.command-edydvh07.js} +13 -8
- package/{projectTypecheck-s9hhe5sa.js → projectTypecheck-mk8wefvd.js} +2 -1
- package/{prompter-qrwx1p17.js → prompter-qyggfhqd.js} +2 -2
- package/{quality.command-q55j2htd.js → quality.command-mdb45vyr.js} +23 -16
- package/{recipeScanner-4b69ybe0.js → recipeScanner-rrx69awy.js} +1 -1
- package/{repair.command-7ssbbdq2.js → repair.command-kvtaeecy.js} +13 -8
- package/{routeSourceValidator-4h947v7c.js → routeSourceValidator-8n6j1vn7.js} +4 -2
- package/{scalar.command-p5jb7z57.js → scalar.command-sjt9p5e1.js} +11 -6
- package/skills/akan-debug/SKILL.md +10 -3
- package/skills/akan-err/SKILL.md +7 -0
- package/skills/akan-mcp/SKILL.md +14 -2
- package/skills/akan-scaffold/SKILL.md +2 -2
- package/skills/akan-transport/SKILL.md +2 -0
- package/skills/akan-validate/SKILL.md +1 -0
- package/{subspace.command-7wxy6ptj.js → subspace.command-mkkqync4.js} +29 -23
- package/templates/app/page/_layout.tsx +13 -0
- package/templates/app/page/styles.css.template +40 -0
- package/templates/appSample/page/_index.tsx +9 -9
- package/templates/appSample/page/_layout.tsx +1 -0
- package/templates/appSample/page/styles.css.template +40 -5
- package/templates/appSample/ui/Recipe/jellyButton.ts +1 -1
- package/templates/biomeForm.ts +1 -1
- package/templates/env/_env.server.type.ts +1 -1
- package/templates/facetIndex/index.ts +2 -37
- package/templates/lib/sig.ts +0 -4
- package/templates/lib/useClient.ts +1 -1
- package/templates/workspaceRoot/AGENTS.md.template +2 -1
- package/{tunnel.command-22g11n0x.js → tunnel.command-tr5b3030.js} +17 -12
- package/{typeChecker-s640r6c0.js → typeChecker-bfrd1n9n.js} +1 -1
- package/typecheck.proc.js +6 -3
- package/{verify.command-m0wnndd7.js → verify.command-0p9h8tpp.js} +26 -20
- package/{workflow.command-jx8dqs9n.js → workflow.command-9mfcwqzj.js} +37 -19
- package/{workspace.command-ca9kfyt3.js → workspace.command-5hjtmcfs.js} +61 -54
- package/CodeAgent-e9c712an.js +0 -11
- package/TunnelShare-zkfkrw8w.js +0 -14
- package/agent.command-9erafkcb.js +0 -51
- package/cloud.script-arsagnq6.js +0 -30
- package/context.runner-mqpp67br.js +0 -29
- package/index-x3x31df8.js +0 -14
- /package/templates/{appSample → app}/public/fonts/Pretendard-Bold.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Medium.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-Regular.woff2 +0 -0
- /package/templates/{appSample → app}/public/fonts/Pretendard-SemiBold.woff2 +0 -0
|
@@ -0,0 +1,788 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import {
|
|
3
|
+
execEmoji,
|
|
4
|
+
Executor,
|
|
5
|
+
SysExecutor,
|
|
6
|
+
WorkspaceExecutor,
|
|
7
|
+
AkanAppConfig,
|
|
8
|
+
increaseBuildNum,
|
|
9
|
+
decreaseBuildNum
|
|
10
|
+
} from "./index-qssq2d41.js";
|
|
11
|
+
import {
|
|
12
|
+
FileSys2
|
|
13
|
+
} from "./index-by2tvsq6.js";
|
|
14
|
+
import {
|
|
15
|
+
LibExecutor2
|
|
16
|
+
} from "./index-na8r4a27.js";
|
|
17
|
+
|
|
18
|
+
// pkgs/@akanjs/devkit/executors/appExecutor.ts
|
|
19
|
+
import { cp as cpEntry, lstat, mkdir, readdir as readDirEntries, realpath, symlink } from "fs/promises";
|
|
20
|
+
import path3 from "path";
|
|
21
|
+
import { pathToFileURL } from "url";
|
|
22
|
+
import { isRouteSourceFile, parseRouteModuleKey, validatePageSourceFile, validateSubRoutePageKey } from "akanjs/common";
|
|
23
|
+
|
|
24
|
+
// pkgs/@akanjs/devkit/artifact/implicitRootLayout.ts
|
|
25
|
+
import { readdir, rm } from "fs/promises";
|
|
26
|
+
import path2 from "path";
|
|
27
|
+
|
|
28
|
+
// pkgs/@akanjs/devkit/transforms/asyncDefaultExportDetector.ts
|
|
29
|
+
import fs from "fs";
|
|
30
|
+
import path from "path";
|
|
31
|
+
|
|
32
|
+
class AsyncDefaultExportDetector {
|
|
33
|
+
static #typescriptLoad;
|
|
34
|
+
static #loadTypescript() {
|
|
35
|
+
AsyncDefaultExportDetector.#typescriptLoad ??= import("typescript").then((mod) => mod.default ?? mod);
|
|
36
|
+
return AsyncDefaultExportDetector.#typescriptLoad;
|
|
37
|
+
}
|
|
38
|
+
static async detect(moduleAbsPath) {
|
|
39
|
+
try {
|
|
40
|
+
const typescript = await AsyncDefaultExportDetector.#loadTypescript();
|
|
41
|
+
const source = fs.readFileSync(path.resolve(moduleAbsPath), "utf8");
|
|
42
|
+
const sourceFile = typescript.createSourceFile(moduleAbsPath, source, typescript.ScriptTarget.Latest, true, /\.[tj]sx$/.test(moduleAbsPath) ? typescript.ScriptKind.TSX : typescript.ScriptKind.TS);
|
|
43
|
+
return new AsyncDefaultExportDetector(typescript).detectInSourceFile(sourceFile);
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
#ts;
|
|
49
|
+
constructor(typescript) {
|
|
50
|
+
this.#ts = typescript;
|
|
51
|
+
}
|
|
52
|
+
detectInSourceFile(sourceFile) {
|
|
53
|
+
const ts = this.#ts;
|
|
54
|
+
const asyncBindings = new Map;
|
|
55
|
+
let defaultIdentifier = null;
|
|
56
|
+
for (const statement of sourceFile.statements) {
|
|
57
|
+
if (ts.isFunctionDeclaration(statement)) {
|
|
58
|
+
if (this.#hasModifier(statement, ts.SyntaxKind.DefaultKeyword)) {
|
|
59
|
+
return this.#hasModifier(statement, ts.SyntaxKind.AsyncKeyword);
|
|
60
|
+
}
|
|
61
|
+
if (statement.name) {
|
|
62
|
+
asyncBindings.set(statement.name.text, this.#hasModifier(statement, ts.SyntaxKind.AsyncKeyword));
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (ts.isVariableStatement(statement)) {
|
|
67
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
68
|
+
if (!ts.isIdentifier(declaration.name))
|
|
69
|
+
continue;
|
|
70
|
+
asyncBindings.set(declaration.name.text, this.#isAsyncFunctionExpression(declaration.initializer));
|
|
71
|
+
}
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (ts.isExportAssignment(statement)) {
|
|
75
|
+
if (this.#isAsyncFunctionExpression(statement.expression))
|
|
76
|
+
return true;
|
|
77
|
+
if (ts.isCallExpression(statement.expression))
|
|
78
|
+
return true;
|
|
79
|
+
if (ts.isIdentifier(statement.expression))
|
|
80
|
+
defaultIdentifier = statement.expression.text;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
84
|
+
for (const specifier of statement.exportClause.elements) {
|
|
85
|
+
if (specifier.name.text !== "default")
|
|
86
|
+
continue;
|
|
87
|
+
defaultIdentifier = specifier.propertyName?.text ?? specifier.name.text;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return defaultIdentifier ? asyncBindings.get(defaultIdentifier) === true : false;
|
|
92
|
+
}
|
|
93
|
+
#hasModifier(node, kind) {
|
|
94
|
+
const ts = this.#ts;
|
|
95
|
+
return ts.canHaveModifiers(node) && (ts.getModifiers(node)?.some((modifier) => modifier.kind === kind) ?? false);
|
|
96
|
+
}
|
|
97
|
+
#isAsyncFunctionExpression(node) {
|
|
98
|
+
const ts = this.#ts;
|
|
99
|
+
return Boolean(node && (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) && this.#hasModifier(node, ts.SyntaxKind.AsyncKeyword));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// pkgs/@akanjs/devkit/artifact/storeBootstrap.ts
|
|
104
|
+
class StoreBootstrap {
|
|
105
|
+
static importLines(appName) {
|
|
106
|
+
return StoreBootstrap.#lines([`@apps/${appName}/lib/useClient`, `@apps/${appName}/lib/st`]);
|
|
107
|
+
}
|
|
108
|
+
static source(appName) {
|
|
109
|
+
return `${StoreBootstrap.importLines(appName).join(`
|
|
110
|
+
`)}
|
|
111
|
+
`;
|
|
112
|
+
}
|
|
113
|
+
static ofClientBarrel(specifier, exports) {
|
|
114
|
+
if (!/^@(?:apps|libs)\/[^/]+\/client$/.test(specifier))
|
|
115
|
+
return null;
|
|
116
|
+
const runtime = exports.get("usePage");
|
|
117
|
+
const store = exports.get("st");
|
|
118
|
+
if (!runtime || runtime.namespace || !store || store.namespace)
|
|
119
|
+
return [specifier];
|
|
120
|
+
return [...new Set([runtime.subpath, store.subpath])];
|
|
121
|
+
}
|
|
122
|
+
static #lines(specifiers) {
|
|
123
|
+
return specifiers.map((specifier) => `import ${JSON.stringify(specifier)};`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// pkgs/@akanjs/devkit/artifact/implicitRootLayout.ts
|
|
128
|
+
var LAYOUT_KEY_RE = /^\.\/(.+\/)?_layout\.(tsx|ts|jsx|js)$/;
|
|
129
|
+
var IMPLICIT_LAYOUT_DIR = path2.join(".akan", "generated", "root-layouts");
|
|
130
|
+
var IMPLICIT_DICT_DIR = path2.join(".akan", "generated", "dict");
|
|
131
|
+
var IMPLICIT_OVERRIDES_DIR = path2.join(".akan", "generated", "overrides");
|
|
132
|
+
var OVERRIDES_KEY_RE = /^\.\/(.+\/)?_overrides\.(tsx|ts|jsx|js)$/;
|
|
133
|
+
var posixRelative = (fromDir, toAbsPath) => path2.relative(fromDir, toAbsPath).split(path2.sep).join("/");
|
|
134
|
+
var importSpecifier = (fromAbsPath, toAbsPath) => {
|
|
135
|
+
const rel = posixRelative(path2.dirname(fromAbsPath), toAbsPath);
|
|
136
|
+
return rel.startsWith(".") ? rel : `./${rel}`;
|
|
137
|
+
};
|
|
138
|
+
async function writeGeneratedOverridesLayoutFile(opts) {
|
|
139
|
+
const filename = `${opts.key.replace(/^\.\//, "").replace(/[^a-zA-Z0-9]+/g, "_")}.tsx`;
|
|
140
|
+
const absPath = path2.join(path2.resolve(opts.appCwdPath), IMPLICIT_OVERRIDES_DIR, filename);
|
|
141
|
+
const source = `"use client";
|
|
142
|
+
import { UiOverrideProvider } from "akanjs/ui/UiOverride/UiOverride.tsx";
|
|
143
|
+
import { createElement, type ReactNode } from "react";
|
|
144
|
+
import value from ${JSON.stringify(importSpecifier(absPath, opts.userAbsPath))};
|
|
145
|
+
|
|
146
|
+
export default function AkanUiOverridesLayout({ children }: { children?: ReactNode }) {
|
|
147
|
+
return createElement(UiOverrideProvider, { value }, children);
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
await Bun.write(absPath, source);
|
|
151
|
+
return absPath;
|
|
152
|
+
}
|
|
153
|
+
async function pruneGeneratedFiles(dirAbsPath, keepAbsPaths) {
|
|
154
|
+
const keep = new Set(keepAbsPaths);
|
|
155
|
+
const names = await readdir(dirAbsPath).catch(() => []);
|
|
156
|
+
await Promise.all(names.map((name) => path2.join(dirAbsPath, name)).filter((absPath) => !keep.has(absPath)).map((absPath) => rm(absPath, { force: true })));
|
|
157
|
+
}
|
|
158
|
+
function getRootBoundarySegments(key) {
|
|
159
|
+
const match = LAYOUT_KEY_RE.exec(key);
|
|
160
|
+
if (!match)
|
|
161
|
+
return null;
|
|
162
|
+
const prefix = match[1]?.replace(/\/$/, "");
|
|
163
|
+
if (!prefix)
|
|
164
|
+
return [];
|
|
165
|
+
return prefix.split("/").filter(Boolean);
|
|
166
|
+
}
|
|
167
|
+
var ROOT_LAYOUT_SYSTEM = {
|
|
168
|
+
specifier: "akanjs/ui/System/index.tsx",
|
|
169
|
+
ssrShell: "akanjs/ui/System/SSR.tsx",
|
|
170
|
+
importsNoSsrPageRenders: ["./CSR", "./App"]
|
|
171
|
+
};
|
|
172
|
+
function implicitRootLayoutKey(segments) {
|
|
173
|
+
return `./${[...segments, "__root_layout"].join("/")}.tsx`;
|
|
174
|
+
}
|
|
175
|
+
function isImplicitRootLayoutKey(key) {
|
|
176
|
+
return key.endsWith("/__root_layout.tsx");
|
|
177
|
+
}
|
|
178
|
+
function implicitRootLayoutAbsPath(appCwdPath, segments) {
|
|
179
|
+
const filename = segments.length ? `${segments.join("__")}__root_layout.tsx` : "__root_layout.tsx";
|
|
180
|
+
return path2.join(path2.resolve(appCwdPath), IMPLICIT_LAYOUT_DIR, filename);
|
|
181
|
+
}
|
|
182
|
+
function isRootBoundarySegments(segments, basePaths) {
|
|
183
|
+
const firstVisibleIndex = segments.findIndex((segment) => !/^\(.+\)$/.test(segment));
|
|
184
|
+
if (firstVisibleIndex === -1)
|
|
185
|
+
return segments.length <= 1;
|
|
186
|
+
if (segments.slice(firstVisibleIndex + 1).some((segment) => /^\(.+\)$/.test(segment)))
|
|
187
|
+
return false;
|
|
188
|
+
const visible = segments.slice(firstVisibleIndex);
|
|
189
|
+
const allowedBasePaths = new Set([...basePaths].map((basePath) => basePath.trim()).filter(Boolean));
|
|
190
|
+
return visible.length === 1 && (firstVisibleIndex > 0 || allowedBasePaths.has(visible[0] ?? ""));
|
|
191
|
+
}
|
|
192
|
+
function findRootBoundaries(pageKeys, appCwdPath, basePaths) {
|
|
193
|
+
const boundaries = new Map;
|
|
194
|
+
for (const key of pageKeys) {
|
|
195
|
+
const segments = getRootBoundarySegments(key);
|
|
196
|
+
if (!segments)
|
|
197
|
+
continue;
|
|
198
|
+
if (!isRootBoundarySegments(segments, basePaths))
|
|
199
|
+
continue;
|
|
200
|
+
const id = segments.join("/");
|
|
201
|
+
boundaries.set(id, {
|
|
202
|
+
sourceKey: key,
|
|
203
|
+
sourceAbsPath: path2.resolve(appCwdPath, "page", key.replace(/^\.\//, "")),
|
|
204
|
+
segments
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
if (boundaries.size === 0)
|
|
208
|
+
boundaries.set("", { sourceKey: null, sourceAbsPath: null, segments: [] });
|
|
209
|
+
return [...boundaries.values()].sort((a, b) => a.segments.join("/").localeCompare(b.segments.join("/")));
|
|
210
|
+
}
|
|
211
|
+
function hasAncestorRootBoundary(boundary, boundaries) {
|
|
212
|
+
return boundaries.some((candidate) => candidate !== boundary && candidate.segments.length < boundary.segments.length && candidate.segments.every((segment, index) => boundary.segments[index] === segment));
|
|
213
|
+
}
|
|
214
|
+
function findExplicitRootLayoutAbsPath(pageKeys, appCwdPath) {
|
|
215
|
+
const rootLayoutKey = pageKeys.find((key) => {
|
|
216
|
+
const segments = getRootBoundarySegments(key);
|
|
217
|
+
return segments !== null && segments.length === 0;
|
|
218
|
+
});
|
|
219
|
+
return rootLayoutKey ? path2.resolve(appCwdPath, "page", rootLayoutKey.replace(/^\.\//, "")) : null;
|
|
220
|
+
}
|
|
221
|
+
async function assertEnvClientConvention(appCwdPath, appName) {
|
|
222
|
+
const envPath = path2.join(appCwdPath, "env", "env.client.ts");
|
|
223
|
+
if (!await Bun.file(envPath).exists()) {
|
|
224
|
+
throw new Error(`[route-convention] app "${appName}" must provide env/env.client.ts exporting "env" for generated System.Provider`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function writeGeneratedDictionaryMacroFile(appCwdPath, appName) {
|
|
228
|
+
const absPath = path2.join(path2.resolve(appCwdPath), IMPLICIT_DICT_DIR, "useDict.ts");
|
|
229
|
+
await Bun.write(absPath, `import { getAllDictionary } from "@apps/${appName}/lib/dict" with { type: "macro" };
|
|
230
|
+
|
|
231
|
+
export const allDictionary = getAllDictionary();
|
|
232
|
+
`);
|
|
233
|
+
return absPath;
|
|
234
|
+
}
|
|
235
|
+
async function writeGeneratedRootLayoutFile(opts) {
|
|
236
|
+
await assertEnvClientConvention(opts.appCwdPath, opts.appName);
|
|
237
|
+
const dictMacroAbsPath = opts.includeSystemProvider ? await writeGeneratedDictionaryMacroFile(opts.appCwdPath, opts.appName) : null;
|
|
238
|
+
const absPath = implicitRootLayoutAbsPath(opts.appCwdPath, opts.boundary.segments);
|
|
239
|
+
const dictMacroSpecifier = dictMacroAbsPath ? importSpecifier(absPath, dictMacroAbsPath) : null;
|
|
240
|
+
const sourceSpecifier = opts.boundary.sourceAbsPath ? importSpecifier(absPath, opts.boundary.sourceAbsPath) : null;
|
|
241
|
+
const inheritedSourceAbsPath = opts.rootSourceAbsPath && opts.rootSourceAbsPath !== opts.boundary.sourceAbsPath ? opts.rootSourceAbsPath : null;
|
|
242
|
+
const inheritedSourceSpecifier = inheritedSourceAbsPath ? importSpecifier(absPath, inheritedSourceAbsPath) : null;
|
|
243
|
+
const storeImport = opts.includeStoreBootstrap ? StoreBootstrap.source(opts.appName) : "";
|
|
244
|
+
const inheritedLabel = inheritedSourceAbsPath ? posixRelative(opts.appCwdPath, inheritedSourceAbsPath) : "";
|
|
245
|
+
const inheritedImport = inheritedSourceSpecifier ? `import * as inheritedModule from ${JSON.stringify(inheritedSourceSpecifier)};
|
|
246
|
+
const inheritedLayout = assertGuardOnChain(${JSON.stringify(inheritedLabel)}, resolveRouteModule(inheritedModule as never, ${JSON.stringify(inheritedLabel)})).module as LayoutModule;
|
|
247
|
+
` : `const inheritedLayout: LayoutModule = {};
|
|
248
|
+
`;
|
|
249
|
+
const prefix = opts.boundary.segments.find((segment) => !/^\(.+\)$/.test(segment)) ?? null;
|
|
250
|
+
const userLabel = opts.boundary.sourceAbsPath ? posixRelative(opts.appCwdPath, opts.boundary.sourceAbsPath) : "";
|
|
251
|
+
const userImport = sourceSpecifier ? `import * as userModule from ${JSON.stringify(sourceSpecifier)};
|
|
252
|
+
const userLayout = assertGuardOnChain(${JSON.stringify(userLabel)}, resolveRouteModule(userModule as never, ${JSON.stringify(userLabel)})).module as LayoutModule;
|
|
253
|
+
const UserLayout = userLayout.default as (props: LayoutProps) => ReactNode | Promise<ReactNode>;
|
|
254
|
+
` : `const UserLayout = ({ children }: LayoutProps) => children;
|
|
255
|
+
const userLayout: LayoutModule = {};
|
|
256
|
+
`;
|
|
257
|
+
const isAsyncUserLayout = opts.boundary.sourceAbsPath ? await AsyncDefaultExportDetector.detect(opts.boundary.sourceAbsPath) : false;
|
|
258
|
+
const userLayoutElement = "<UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>";
|
|
259
|
+
const layoutSignature = isAsyncUserLayout ? "export default async function GeneratedLayout" : "export default function GeneratedLayout";
|
|
260
|
+
const layoutBinding = isAsyncUserLayout ? ` const layout =
|
|
261
|
+
process.env.AKAN_PUBLIC_RENDER_ENV === "csr"
|
|
262
|
+
? await UserLayout({ params, searchParams, children })
|
|
263
|
+
: ${userLayoutElement};
|
|
264
|
+
` : opts.includeSystemProvider ? ` const layout = ${userLayoutElement};
|
|
265
|
+
` : "";
|
|
266
|
+
const layoutReturn = isAsyncUserLayout ? "layout" : userLayoutElement;
|
|
267
|
+
const headLayouts = opts.includeSystemProvider ? "[inheritedLayout, userLayout]" : "[userLayout]";
|
|
268
|
+
const guardExport = opts.includeSystemProvider ? "export const guard = RouteGuards.compose(inheritedLayout.guard, userLayout.guard);" : "export const guard = userLayout.guard;";
|
|
269
|
+
const layoutExports = `export async function generateHead(props: PageProps) {
|
|
270
|
+
const heads = await Promise.all(
|
|
271
|
+
${headLayouts}.map((layout) => (layout.generateHead ? layout.generateHead(props) : layout.head)),
|
|
272
|
+
);
|
|
273
|
+
return RouteHead.mergeNodes(heads);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
export const NotFound = userLayout.NotFound ?? inheritedLayout.NotFound;
|
|
277
|
+
export const Error = userLayout.Error ?? inheritedLayout.Error;
|
|
278
|
+
export const pageConfig = userLayout.pageConfig ?? inheritedLayout.pageConfig;
|
|
279
|
+
export const Loading = userLayout.Loading;
|
|
280
|
+
${guardExport}
|
|
281
|
+
|
|
282
|
+
${layoutSignature}({ children, params, searchParams }: LayoutProps) {
|
|
283
|
+
${layoutBinding} return `;
|
|
284
|
+
const source = opts.includeSystemProvider ? `import type { LayoutModule, LayoutProps, PageProps } from "akanjs/client";
|
|
285
|
+
import { assertGuardOnChain, loadFonts, RouteGuards, resolveRouteModule, RouteHead } from "akanjs/client";
|
|
286
|
+
import type { ReactNode } from "react";
|
|
287
|
+
import { System } from "${ROOT_LAYOUT_SYSTEM.specifier}";
|
|
288
|
+
import type { McpAppRootProps } from "akanjs/webkit";
|
|
289
|
+
import { RouteLevelBoundary } from "akanjs/webkit/RouteLevelBoundary.tsx";
|
|
290
|
+
import { env } from "@apps/${opts.appName}/env/env.client";
|
|
291
|
+
import { allDictionary } from ${JSON.stringify(dictMacroSpecifier)};
|
|
292
|
+
${storeImport}${inheritedImport}${userImport}
|
|
293
|
+
const userFonts = userLayout.fonts ?? inheritedLayout.fonts ?? [];
|
|
294
|
+
const defaultFonts = userFonts.filter((font) => font.default);
|
|
295
|
+
if (defaultFonts.length > 1) throw new Error("[route-convention] only one default font is allowed per root layout");
|
|
296
|
+
const defaultFont = defaultFonts[0];
|
|
297
|
+
const defaultFontClassName = defaultFont ? (defaultFont.className ?? \`font-\${defaultFont.name}\`) : undefined;
|
|
298
|
+
export const theme = userLayout.theme ?? inheritedLayout.theme;
|
|
299
|
+
export const viewport = userLayout.viewport ?? inheritedLayout.viewport;
|
|
300
|
+
export const manifest = userLayout.manifest ?? inheritedLayout.manifest;
|
|
301
|
+
export const LevelBoundary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? undefined : RouteLevelBoundary;
|
|
302
|
+
|
|
303
|
+
${layoutExports}(
|
|
304
|
+
<System.Provider
|
|
305
|
+
of={GeneratedLayout as never}
|
|
306
|
+
appName=${JSON.stringify(opts.appName)}
|
|
307
|
+
${prefix ? `prefix=${JSON.stringify(prefix)}
|
|
308
|
+
` : ""}params={params}
|
|
309
|
+
manifest={manifest}
|
|
310
|
+
env={env}
|
|
311
|
+
theme={theme}
|
|
312
|
+
viewport={viewport}
|
|
313
|
+
fonts={loadFonts(userFonts)}
|
|
314
|
+
className={defaultFontClassName}
|
|
315
|
+
layoutStyle={userLayout.layoutStyle ?? inheritedLayout.layoutStyle}
|
|
316
|
+
reconnect={userLayout.reconnect ?? inheritedLayout.reconnect ?? false}
|
|
317
|
+
wsConnect={userLayout.wsConnect ?? inheritedLayout.wsConnect}
|
|
318
|
+
allDictionary={process.env.AKAN_PUBLIC_RENDER_ENV === "ssr" ? allDictionary : undefined}
|
|
319
|
+
>
|
|
320
|
+
{process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}
|
|
321
|
+
</System.Provider>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export function McpAppRoot({ children, params, path }: McpAppRootProps) {
|
|
326
|
+
return (
|
|
327
|
+
<System.App
|
|
328
|
+
params={params}
|
|
329
|
+
path={path}
|
|
330
|
+
env={env}
|
|
331
|
+
theme={theme}
|
|
332
|
+
viewport={viewport}
|
|
333
|
+
fonts={loadFonts(userFonts)}
|
|
334
|
+
className={defaultFontClassName}
|
|
335
|
+
>
|
|
336
|
+
{children}
|
|
337
|
+
</System.App>
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
` : `import type { LayoutModule, LayoutProps, PageProps } from "akanjs/client";
|
|
341
|
+
import { assertGuardOnChain, resolveRouteModule, RouteHead } from "akanjs/client";
|
|
342
|
+
import type { ReactNode } from "react";
|
|
343
|
+
${inheritedImport}${userImport}
|
|
344
|
+
${layoutExports}${layoutReturn};
|
|
345
|
+
}
|
|
346
|
+
`;
|
|
347
|
+
await Bun.write(absPath, source);
|
|
348
|
+
return absPath;
|
|
349
|
+
}
|
|
350
|
+
async function resolveSsrPageEntries(opts) {
|
|
351
|
+
const absPageDir = path2.resolve(opts.appCwdPath, "page");
|
|
352
|
+
const hasSt = await Bun.file(path2.join(opts.appCwdPath, "lib", "st.ts")).exists();
|
|
353
|
+
const basePaths = opts.basePaths ?? [];
|
|
354
|
+
const rootSourceAbsPath = findExplicitRootLayoutAbsPath(opts.pageKeys, opts.appCwdPath);
|
|
355
|
+
const rootBoundaries = findRootBoundaries(opts.pageKeys, opts.appCwdPath, basePaths);
|
|
356
|
+
const rootLayoutKeys = new Set(opts.pageKeys.filter((key) => {
|
|
357
|
+
const segments = getRootBoundarySegments(key);
|
|
358
|
+
return segments !== null && isRootBoundarySegments(segments, basePaths);
|
|
359
|
+
}));
|
|
360
|
+
const base = await Promise.all(opts.pageKeys.filter((key) => !rootLayoutKeys.has(key)).map(async (key) => {
|
|
361
|
+
const userAbsPath = path2.resolve(absPageDir, key);
|
|
362
|
+
if (OVERRIDES_KEY_RE.test(key)) {
|
|
363
|
+
const moduleAbsPath = await writeGeneratedOverridesLayoutFile({
|
|
364
|
+
appCwdPath: opts.appCwdPath,
|
|
365
|
+
key,
|
|
366
|
+
userAbsPath
|
|
367
|
+
});
|
|
368
|
+
return { key, moduleAbsPath, seedAbsPaths: [userAbsPath] };
|
|
369
|
+
}
|
|
370
|
+
return { key, moduleAbsPath: userAbsPath };
|
|
371
|
+
}));
|
|
372
|
+
const generated = await Promise.all(rootBoundaries.map(async (boundary) => ({
|
|
373
|
+
key: implicitRootLayoutKey(boundary.segments),
|
|
374
|
+
moduleAbsPath: await writeGeneratedRootLayoutFile({
|
|
375
|
+
appCwdPath: opts.appCwdPath,
|
|
376
|
+
appName: opts.appName,
|
|
377
|
+
boundary,
|
|
378
|
+
rootSourceAbsPath,
|
|
379
|
+
includeStoreBootstrap: hasSt,
|
|
380
|
+
includeSystemProvider: !hasAncestorRootBoundary(boundary, rootBoundaries)
|
|
381
|
+
}),
|
|
382
|
+
seedAbsPaths: [...new Set([boundary.sourceAbsPath, rootSourceAbsPath].filter((absPath) => absPath !== null))]
|
|
383
|
+
})));
|
|
384
|
+
const appCwdAbsPath = path2.resolve(opts.appCwdPath);
|
|
385
|
+
await Promise.all([
|
|
386
|
+
pruneGeneratedFiles(path2.join(appCwdAbsPath, IMPLICIT_OVERRIDES_DIR), base.filter(({ key }) => OVERRIDES_KEY_RE.test(key)).map(({ moduleAbsPath }) => moduleAbsPath)),
|
|
387
|
+
pruneGeneratedFiles(path2.join(appCwdAbsPath, IMPLICIT_LAYOUT_DIR), generated.map(({ moduleAbsPath }) => moduleAbsPath))
|
|
388
|
+
]);
|
|
389
|
+
return [...base, ...generated].sort((a, b) => a.key.localeCompare(b.key));
|
|
390
|
+
}
|
|
391
|
+
async function resolveSsrPageEntriesForApp(app, pageKeys) {
|
|
392
|
+
const config = await app.getConfig();
|
|
393
|
+
return resolveSsrPageEntries({ appCwdPath: app.cwdPath, appName: app.name, pageKeys, basePaths: config.basePaths });
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// pkgs/@akanjs/devkit/executors/appExecutor.ts
|
|
397
|
+
class AppExecutor2 extends SysExecutor {
|
|
398
|
+
static #routeSourceValidator = null;
|
|
399
|
+
static async#getRouteSourceValidator() {
|
|
400
|
+
AppExecutor2.#routeSourceValidator ??= (await import("./routeSourceValidator-8n6j1vn7.js")).RouteSourceValidator;
|
|
401
|
+
return AppExecutor2.#routeSourceValidator;
|
|
402
|
+
}
|
|
403
|
+
dist;
|
|
404
|
+
emoji = execEmoji.app;
|
|
405
|
+
constructor({ workspace, name }) {
|
|
406
|
+
super({ workspace, name, type: "app" });
|
|
407
|
+
this.dist = new Executor(`dist/${name}`, `${this.workspace.workspaceRoot}/dist/apps/${name}`);
|
|
408
|
+
}
|
|
409
|
+
static from(executor, name) {
|
|
410
|
+
return new AppExecutor2({ workspace: executor instanceof WorkspaceExecutor ? executor : executor.workspace, name });
|
|
411
|
+
}
|
|
412
|
+
static #keptOnStart = [path3.join(".akan", "cache", "bin")];
|
|
413
|
+
static #legacyNative = path3.join(".akan", "native");
|
|
414
|
+
async#removeDevOutput(dir = ".akan") {
|
|
415
|
+
const entries = await readDirEntries(this.getPath(dir)).catch(() => []);
|
|
416
|
+
await Promise.all(entries.map(async (name) => {
|
|
417
|
+
const entry = path3.join(dir, name);
|
|
418
|
+
if (entry === AppExecutor2.#legacyNative) {
|
|
419
|
+
this.logger.warn(`apps/${this.name}/.akan/native holds native builds from before they moved to dist/native/${this.name}: upload any release waiting in its updates folders, then delete it.`);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (AppExecutor2.#keptOnStart.includes(entry))
|
|
423
|
+
return;
|
|
424
|
+
if (AppExecutor2.#keptOnStart.some((kept) => kept.startsWith(`${entry}${path3.sep}`)))
|
|
425
|
+
return await this.#removeDevOutput(entry);
|
|
426
|
+
await this.removeDir(entry);
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
getEnv() {
|
|
430
|
+
return WorkspaceExecutor.getBaseDevEnv().env;
|
|
431
|
+
}
|
|
432
|
+
async getDevPort() {
|
|
433
|
+
const pinned = Number(process.env.AKAN_DEV_PORT);
|
|
434
|
+
if (Number.isInteger(pinned) && pinned > 0 && pinned <= 65535)
|
|
435
|
+
return pinned;
|
|
436
|
+
const basePort = 8282;
|
|
437
|
+
const appNames = (await this.workspace.getApps()).sort((a, b) => a.localeCompare(b));
|
|
438
|
+
const appIndex = Math.max(appNames.indexOf(this.name), 0);
|
|
439
|
+
const portOffset = WorkspaceExecutor.getBaseDevEnv().portOffset;
|
|
440
|
+
return basePort + appIndex + portOffset;
|
|
441
|
+
}
|
|
442
|
+
getCommandEnv(env = {}) {
|
|
443
|
+
const { portOffset, repoName, serveDomain } = WorkspaceExecutor.getBaseDevEnv();
|
|
444
|
+
const PORT = (8282 + portOffset).toString();
|
|
445
|
+
return {
|
|
446
|
+
...process.env,
|
|
447
|
+
AKAN_PUBLIC_REPO_NAME: repoName,
|
|
448
|
+
AKAN_PUBLIC_SERVE_DOMAIN: serveDomain,
|
|
449
|
+
AKAN_PUBLIC_APP_NAME: this.name,
|
|
450
|
+
AKAN_WORKSPACE_ROOT: this.workspace.workspaceRoot,
|
|
451
|
+
NODE_NO_WARNINGS: "1",
|
|
452
|
+
PORT,
|
|
453
|
+
AKAN_PUBLIC_CLIENT_PORT: PORT,
|
|
454
|
+
...portOffset ? { AKAN_PUBLIC_SERVER_PORT: PORT } : {},
|
|
455
|
+
...env
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
async getDatabaseModeEnv() {
|
|
459
|
+
const akanConfig = await this.getConfig();
|
|
460
|
+
return {
|
|
461
|
+
AKAN_DATABASE_MODE: akanConfig.resolveDatabaseMode(),
|
|
462
|
+
AKAN_DATABASE_MODES: akanConfig.database.modes.join(",")
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
async prepareCommand(type) {
|
|
466
|
+
const akanConfig = await this.getConfig();
|
|
467
|
+
const routeEnv = {
|
|
468
|
+
AKAN_PUBLIC_BASE_PATHS: [...akanConfig.basePaths].join(","),
|
|
469
|
+
AKAN_PUBLIC_API_PREFIX: akanConfig.api.prefix,
|
|
470
|
+
AKAN_PUBLIC_WS_PREFIX: akanConfig.api.websocketPrefix,
|
|
471
|
+
...await this.getDatabaseModeEnv()
|
|
472
|
+
};
|
|
473
|
+
Object.assign(process.env, routeEnv);
|
|
474
|
+
if (type === "build") {
|
|
475
|
+
this.#excludeDevOnlyPages = true;
|
|
476
|
+
this.#pageKeys = null;
|
|
477
|
+
await this.dist.removeDir(this.dist.cwdPath);
|
|
478
|
+
await Promise.all([this.dist.mkdir("private"), this.dist.mkdir("public")]);
|
|
479
|
+
await Promise.all([
|
|
480
|
+
this.cp("private", `${this.dist.cwdPath}/private`, { dereference: true }),
|
|
481
|
+
...akanConfig.web.ssr ? [this.cp("public", `${this.dist.cwdPath}/public`, { dereference: true })] : []
|
|
482
|
+
]);
|
|
483
|
+
} else {
|
|
484
|
+
await this.#removeDevOutput();
|
|
485
|
+
if (!akanConfig.web.ssr || !akanConfig.web.csr)
|
|
486
|
+
this.logger.verbose(`akan.config.ts disables web.${!akanConfig.web.ssr ? "ssr" : "csr"}; \`akan start\` still serves it, \`akan build\` will not`);
|
|
487
|
+
}
|
|
488
|
+
if (type === "start")
|
|
489
|
+
process.env.NODE_ENV = "development";
|
|
490
|
+
const devPort = type === "start" ? (await this.getDevPort()).toString() : undefined;
|
|
491
|
+
const env = this.getCommandEnv({
|
|
492
|
+
AKAN_COMMAND_TYPE: type,
|
|
493
|
+
...routeEnv,
|
|
494
|
+
...devPort ? { PORT: devPort, AKAN_PUBLIC_CLIENT_PORT: devPort, AKAN_PUBLIC_SERVER_PORT: devPort } : {}
|
|
495
|
+
});
|
|
496
|
+
if (type === "build") {
|
|
497
|
+
const buildEnv = { ...env };
|
|
498
|
+
for (const key of ["AKAN_PUBLIC_CLIENT_PORT", "AKAN_PUBLIC_SERVER_PORT", "AKAN_PUBLIC_OPERATION_MODE"]) {
|
|
499
|
+
delete buildEnv[key];
|
|
500
|
+
delete process.env[key];
|
|
501
|
+
}
|
|
502
|
+
Object.assign(process.env, buildEnv);
|
|
503
|
+
}
|
|
504
|
+
return { env };
|
|
505
|
+
}
|
|
506
|
+
#publicEnv = null;
|
|
507
|
+
getPublicEnv(...patterns) {
|
|
508
|
+
if (this.#publicEnv)
|
|
509
|
+
return this.#publicEnv;
|
|
510
|
+
const searchPatterns = [...patterns, "AKAN_PUBLIC_*"];
|
|
511
|
+
const regexes = searchPatterns.map((pattern) => new RegExp(`^${pattern.split("*").map((part) => part.replace(/[.+^${}()|[\]\\?]/g, "\\$&")).join(".*")}$`));
|
|
512
|
+
const publicEnv = {};
|
|
513
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
514
|
+
if (typeof v !== "string")
|
|
515
|
+
continue;
|
|
516
|
+
if (regexes.some((r) => r.test(k)))
|
|
517
|
+
publicEnv[k] = v;
|
|
518
|
+
}
|
|
519
|
+
this.#publicEnv = publicEnv;
|
|
520
|
+
return publicEnv;
|
|
521
|
+
}
|
|
522
|
+
#akanConfig = null;
|
|
523
|
+
async getConfig({ refresh } = {}) {
|
|
524
|
+
if (this.#akanConfig && !refresh)
|
|
525
|
+
return this.#akanConfig;
|
|
526
|
+
this.#akanConfig = await AkanAppConfig.from(this, { bustImportCache: refresh });
|
|
527
|
+
return this.#akanConfig;
|
|
528
|
+
}
|
|
529
|
+
#pageKeys = null;
|
|
530
|
+
#routeSources = [];
|
|
531
|
+
#excludeDevOnlyPages = false;
|
|
532
|
+
async getPageKeys({ refresh } = {}) {
|
|
533
|
+
if (this.#pageKeys && !refresh)
|
|
534
|
+
return this.#pageKeys;
|
|
535
|
+
const akanConfig = await this.getConfig();
|
|
536
|
+
const glob = new Bun.Glob("**/*");
|
|
537
|
+
const pageKeys = [];
|
|
538
|
+
const owners = new Map;
|
|
539
|
+
const devOnlyKeys = new Set;
|
|
540
|
+
const devOnlyDirs = [];
|
|
541
|
+
const pageRoots = await this.getPageRoots();
|
|
542
|
+
const routeSources = [];
|
|
543
|
+
const libKeyPrefixes = pageRoots.map((root) => root.keyPrefix).filter(Boolean);
|
|
544
|
+
for (const root of pageRoots) {
|
|
545
|
+
if (!await FileSys2.dirExists(root.dir))
|
|
546
|
+
continue;
|
|
547
|
+
for await (const rel of glob.scan({
|
|
548
|
+
cwd: root.dir,
|
|
549
|
+
absolute: false,
|
|
550
|
+
onlyFiles: true
|
|
551
|
+
})) {
|
|
552
|
+
const segments = rel.split(path3.sep);
|
|
553
|
+
if (segments.some((s) => s === "node_modules"))
|
|
554
|
+
continue;
|
|
555
|
+
const posix = `${root.keyPrefix}${segments.join("/")}`;
|
|
556
|
+
if (!root.keyPrefix && libKeyPrefixes.some((prefix) => posix.startsWith(prefix)))
|
|
557
|
+
continue;
|
|
558
|
+
const absPath = path3.join(root.dir, ...segments);
|
|
559
|
+
validatePageSourceFile(posix, { filePath: absPath });
|
|
560
|
+
if (!isRouteSourceFile(posix))
|
|
561
|
+
continue;
|
|
562
|
+
const key = `./${posix}`;
|
|
563
|
+
validateSubRoutePageKey(key, akanConfig.basePaths, {
|
|
564
|
+
appName: this.name,
|
|
565
|
+
filePath: absPath
|
|
566
|
+
});
|
|
567
|
+
const parsed = parseRouteModuleKey(key);
|
|
568
|
+
if (parsed.isInternalRootLayout) {
|
|
569
|
+
throw new Error(`[route-convention] __root_layout is reserved for Akan.js generated root layout: ${absPath}`);
|
|
570
|
+
}
|
|
571
|
+
const fromLib = !!root.keyPrefix;
|
|
572
|
+
const routeId = `${parsed.kind}:${parsed.pattern}`;
|
|
573
|
+
const owner = owners.get(routeId);
|
|
574
|
+
if (owner && (owner.fromLib || fromLib)) {
|
|
575
|
+
throw new Error(`[route-convention] duplicate ${parsed.kind} route "${parsed.pattern}" in app "${this.name}":
|
|
576
|
+
- ${owner.absPath}
|
|
577
|
+
- ${absPath}`);
|
|
578
|
+
}
|
|
579
|
+
if (!owner)
|
|
580
|
+
owners.set(routeId, { absPath, fromLib });
|
|
581
|
+
const layoutSegments = getRootBoundarySegments(key);
|
|
582
|
+
const isRootLayout = layoutSegments !== null && isRootBoundarySegments(layoutSegments, akanConfig.basePaths);
|
|
583
|
+
const routeSource = await Bun.file(absPath).text();
|
|
584
|
+
const validator = await AppExecutor2.#getRouteSourceValidator();
|
|
585
|
+
if (parsed.kind === "overrides")
|
|
586
|
+
validator.validateOverridesSourceExports(routeSource, absPath);
|
|
587
|
+
else {
|
|
588
|
+
const info = validator.validateRouteSourceExports(routeSource, absPath, parsed.kind, {
|
|
589
|
+
rootLayout: isRootLayout,
|
|
590
|
+
pattern: parsed.pattern
|
|
591
|
+
});
|
|
592
|
+
routeSources.push({ key, absPath, info });
|
|
593
|
+
if (info.devOnly) {
|
|
594
|
+
devOnlyKeys.add(key);
|
|
595
|
+
if (parsed.kind === "layout")
|
|
596
|
+
devOnlyDirs.push(key.replace(/[^/]+$/, ""));
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
pageKeys.push(key);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
pageKeys.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
|
|
603
|
+
this.#routeSources = routeSources.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
604
|
+
this.#pageKeys = this.#excludeDevOnlyPages ? this.#dropDevOnlyPages(pageKeys, devOnlyKeys, devOnlyDirs) : pageKeys;
|
|
605
|
+
return this.#pageKeys;
|
|
606
|
+
}
|
|
607
|
+
async getRouteSources({ refresh } = {}) {
|
|
608
|
+
await this.getPageKeys({ refresh });
|
|
609
|
+
return this.#routeSources;
|
|
610
|
+
}
|
|
611
|
+
#dropDevOnlyPages(pageKeys, devOnlyKeys, devOnlyDirs) {
|
|
612
|
+
if (!devOnlyKeys.size)
|
|
613
|
+
return pageKeys;
|
|
614
|
+
const isDevOnly = (key) => devOnlyKeys.has(key) || devOnlyDirs.some((dir) => key.startsWith(dir));
|
|
615
|
+
const dropped = pageKeys.filter(isDevOnly);
|
|
616
|
+
this.verbose(`[route] excluded ${dropped.length} dev-only route file(s) from the build: ${dropped.join(", ")}`);
|
|
617
|
+
return pageKeys.filter((key) => !isDevOnly(key));
|
|
618
|
+
}
|
|
619
|
+
async getPageRoots() {
|
|
620
|
+
const akanConfig = await this.getConfig();
|
|
621
|
+
const pageDir = `${this.cwdPath}/page`;
|
|
622
|
+
const roots = [{ dir: pageDir, realDir: pageDir, keyPrefix: "" }];
|
|
623
|
+
for (const parent of AppExecutor2.#pageLibParents(akanConfig.basePaths)) {
|
|
624
|
+
const libsDir = `${pageDir}/${parent}${AppExecutor2.#pageLibsDir}`;
|
|
625
|
+
const entries = await readDirEntries(libsDir).catch(() => []);
|
|
626
|
+
for (const entry of entries.sort()) {
|
|
627
|
+
const dir = `${libsDir}/${entry}`;
|
|
628
|
+
if (!await FileSys2.dirExists(dir))
|
|
629
|
+
continue;
|
|
630
|
+
roots.push({ dir, realDir: await realpath(dir), keyPrefix: `${parent}${AppExecutor2.#pageLibsDir}/${entry}/` });
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return roots;
|
|
634
|
+
}
|
|
635
|
+
setPageKeys(pageKeys) {
|
|
636
|
+
this.#pageKeys = pageKeys;
|
|
637
|
+
}
|
|
638
|
+
static #pageLibsDir = "(libs)";
|
|
639
|
+
static #pageLibParents(basePaths) {
|
|
640
|
+
const parents = [...basePaths].map((basePath) => `${basePath}/`);
|
|
641
|
+
return parents.length ? parents : [""];
|
|
642
|
+
}
|
|
643
|
+
async syncPages(libDeps) {
|
|
644
|
+
const akanConfig = await this.getConfig();
|
|
645
|
+
const parents = AppExecutor2.#pageLibParents(akanConfig.basePaths);
|
|
646
|
+
const libs = await this.#resolvePageLibs(akanConfig.syncPageLibs, libDeps);
|
|
647
|
+
const linked = (await Promise.all(parents.map(async (parent) => {
|
|
648
|
+
const libsDir = `${this.cwdPath}/page/${parent}${AppExecutor2.#pageLibsDir}`;
|
|
649
|
+
const entries = await readDirEntries(libsDir).catch(() => []);
|
|
650
|
+
return entries.map((entry) => `${parent}${AppExecutor2.#pageLibsDir}/${entry}/`);
|
|
651
|
+
}))).flat();
|
|
652
|
+
const wanted = parents.flatMap((parent) => libs.map((lib) => `${parent}${AppExecutor2.#pageLibsDir}/(${lib})/`));
|
|
653
|
+
const isLink = async (key) => (await lstat(`${this.cwdPath}/page/${key.slice(0, -1)}`).catch(() => null))?.isSymbolicLink() ?? false;
|
|
654
|
+
if (linked.sort().join(",") === wanted.sort().join(",") && (await Promise.all(linked.map(isLink))).every(Boolean))
|
|
655
|
+
return false;
|
|
656
|
+
await Promise.all(parents.map((parent) => this.removeDir(`${this.cwdPath}/page/${parent}${AppExecutor2.#pageLibsDir}`)));
|
|
657
|
+
for (const parent of parents) {
|
|
658
|
+
if (!libs.length)
|
|
659
|
+
break;
|
|
660
|
+
const libsDir = `${this.cwdPath}/page/${parent}${AppExecutor2.#pageLibsDir}`;
|
|
661
|
+
await this.mkdir(libsDir);
|
|
662
|
+
await Promise.all(libs.map((lib) => AppExecutor2.#linkLibAsset(`${this.workspace.workspaceRoot}/libs/${lib}/page`, `${libsDir}/(${lib})`)));
|
|
663
|
+
}
|
|
664
|
+
this.#pageKeys = null;
|
|
665
|
+
return true;
|
|
666
|
+
}
|
|
667
|
+
async#resolvePageLibs(syncPageLibs, libDeps) {
|
|
668
|
+
if (!syncPageLibs)
|
|
669
|
+
return [];
|
|
670
|
+
const hasPageDir = async (lib) => await FileSys2.dirExists(`${this.workspace.workspaceRoot}/libs/${lib}/page`);
|
|
671
|
+
if (syncPageLibs === true) {
|
|
672
|
+
const libs = [];
|
|
673
|
+
for (const lib of libDeps)
|
|
674
|
+
if (await hasPageDir(lib))
|
|
675
|
+
libs.push(lib);
|
|
676
|
+
return libs;
|
|
677
|
+
}
|
|
678
|
+
for (const lib of syncPageLibs) {
|
|
679
|
+
if (!libDeps.includes(lib))
|
|
680
|
+
throw new Error(`[syncPageLibs] app "${this.name}" lists lib "${lib}" but does not depend on it (deps: ${libDeps.join(", ") || "none"})`);
|
|
681
|
+
if (!await hasPageDir(lib))
|
|
682
|
+
throw new Error(`[syncPageLibs] app "${this.name}" lists lib "${lib}" but libs/${lib}/page does not exist`);
|
|
683
|
+
}
|
|
684
|
+
return [...syncPageLibs];
|
|
685
|
+
}
|
|
686
|
+
async syncAssets(libDeps) {
|
|
687
|
+
await Promise.all(["public", "private"].map((facet) => this.#syncLibAssets(facet, libDeps)));
|
|
688
|
+
}
|
|
689
|
+
async#syncLibAssets(facet, libDeps) {
|
|
690
|
+
const libLinkPath = `${this.cwdPath}/${facet}/libs`;
|
|
691
|
+
await this.removeDir(libLinkPath);
|
|
692
|
+
const targetDeps = [];
|
|
693
|
+
for (const dep of libDeps) {
|
|
694
|
+
if (await this.exists(`${this.workspace.workspaceRoot}/libs/${dep}/${facet}`))
|
|
695
|
+
targetDeps.push(dep);
|
|
696
|
+
}
|
|
697
|
+
if (!targetDeps.length)
|
|
698
|
+
return;
|
|
699
|
+
await this.mkdir(libLinkPath);
|
|
700
|
+
await Promise.all(targetDeps.map((dep) => AppExecutor2.#linkLibAsset(`${this.workspace.workspaceRoot}/libs/${dep}/${facet}`, `${libLinkPath}/${dep}`)));
|
|
701
|
+
}
|
|
702
|
+
static async#linkLibAsset(targetPath, linkPath) {
|
|
703
|
+
const isWindows = process.platform === "win32";
|
|
704
|
+
try {
|
|
705
|
+
const target = isWindows ? targetPath : path3.relative(path3.dirname(linkPath), targetPath);
|
|
706
|
+
await symlink(target, linkPath, isWindows ? "junction" : "dir");
|
|
707
|
+
} catch (error) {
|
|
708
|
+
if (!isWindows)
|
|
709
|
+
throw error;
|
|
710
|
+
await mkdir(linkPath, { recursive: true });
|
|
711
|
+
await cpEntry(targetPath, linkPath, { recursive: true, dereference: true, force: true });
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
async scanSync({ refresh = false, write = true } = {}) {
|
|
715
|
+
const scanInfo = await this.scan({
|
|
716
|
+
refresh,
|
|
717
|
+
write,
|
|
718
|
+
writeLib: write
|
|
719
|
+
});
|
|
720
|
+
if (write)
|
|
721
|
+
await this.syncAssets(scanInfo.getScanResult().libDeps);
|
|
722
|
+
if (write && await this.syncPages(scanInfo.getScanResult().libDeps))
|
|
723
|
+
scanInfo.setRoutes(await this.getPageKeys({ refresh: true }));
|
|
724
|
+
if (write)
|
|
725
|
+
await this.#runPluginSyncAssets();
|
|
726
|
+
return scanInfo;
|
|
727
|
+
}
|
|
728
|
+
async#runPluginSyncAssets() {
|
|
729
|
+
const plugins = await this.collectPlugins();
|
|
730
|
+
if (!plugins.some((plugin) => plugin.syncAssets))
|
|
731
|
+
return;
|
|
732
|
+
const ctx = this.#makeSyncContext();
|
|
733
|
+
for (const plugin of plugins)
|
|
734
|
+
await plugin.syncAssets?.(ctx);
|
|
735
|
+
}
|
|
736
|
+
#makeSyncContext() {
|
|
737
|
+
return {
|
|
738
|
+
appName: this.name,
|
|
739
|
+
appPath: this.cwdPath,
|
|
740
|
+
executor: this,
|
|
741
|
+
getPath: (rel) => this.getPath(rel),
|
|
742
|
+
fileExists: (rel) => FileSys2.fileExists(this.getPath(rel)),
|
|
743
|
+
readFile: (rel) => this.readFile(rel),
|
|
744
|
+
writeFile: async (rel, content, opts) => {
|
|
745
|
+
await this.writeFile(rel, content, opts);
|
|
746
|
+
},
|
|
747
|
+
readEnvClient: async () => {
|
|
748
|
+
const envClientPath = path3.join(this.cwdPath, "env", "env.client.ts");
|
|
749
|
+
if (!await FileSys2.fileExists(envClientPath))
|
|
750
|
+
return null;
|
|
751
|
+
try {
|
|
752
|
+
const envUrl = pathToFileURL(envClientPath);
|
|
753
|
+
envUrl.searchParams.set("t", String(Date.now()));
|
|
754
|
+
const envModule = await import(envUrl.href);
|
|
755
|
+
return envModule.env ?? null;
|
|
756
|
+
} catch {
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async collectPlugins() {
|
|
763
|
+
const scanInfo = await this.scan({ write: false });
|
|
764
|
+
const libDeps = scanInfo.getLibs();
|
|
765
|
+
const appConfig = await this.getConfig();
|
|
766
|
+
const collected = [...appConfig.plugins];
|
|
767
|
+
for (const libName of libDeps) {
|
|
768
|
+
const libConfig = await LibExecutor2.from(this, libName).getConfig().catch(() => null);
|
|
769
|
+
if (libConfig)
|
|
770
|
+
collected.push(...libConfig.plugins);
|
|
771
|
+
}
|
|
772
|
+
const seen = new Set;
|
|
773
|
+
return collected.filter((plugin) => {
|
|
774
|
+
if (seen.has(plugin.name))
|
|
775
|
+
return false;
|
|
776
|
+
seen.add(plugin.name);
|
|
777
|
+
return true;
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
async increaseBuildNum() {
|
|
781
|
+
await increaseBuildNum(this);
|
|
782
|
+
}
|
|
783
|
+
async decreaseBuildNum() {
|
|
784
|
+
await decreaseBuildNum(this);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
export { AsyncDefaultExportDetector, StoreBootstrap, ROOT_LAYOUT_SYSTEM, isImplicitRootLayoutKey, resolveSsrPageEntriesForApp, AppExecutor2 };
|