@akanjs/devkit 3.3.0-rc.25 → 3.3.0-rc.27
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/CHANGELOG.md +300 -0
- package/akanApp/akanApp.host.ts +11 -0
- package/akanConfig/akanBin.ts +4 -0
- package/akanConfig/akanConfig.test.ts +11 -0
- package/akanConfig/akanConfig.ts +39 -137
- package/akanConfig/akanWorkers.test.ts +39 -0
- package/akanConfig/akanWorkers.ts +32 -0
- package/akanConfig/desktopServerConfig.ts +96 -0
- package/akanConfig/dockerImage.ts +20 -0
- package/akanConfig/types.ts +1 -0
- package/app/appBin.test.ts +63 -0
- package/app/appBin.ts +50 -0
- package/app/applicationBuildReporter.test.ts +32 -0
- package/app/applicationBuildReporter.ts +4 -0
- package/app/applicationBuildRunner.test.ts +3 -0
- package/app/applicationBuildRunner.ts +40 -4
- package/app/dictionarySizes.ts +94 -0
- package/artifact/implicitRootLayout.test.ts +19 -0
- package/artifact/implicitRootLayout.ts +16 -2
- package/artifact/storeBootstrap.test.ts +28 -0
- package/artifact/storeBootstrap.ts +60 -8
- package/biome.base.json +5 -1
- package/codeAgent/skills/akan-agent/SKILL.md +2 -2
- package/codeAgent/skills/akan-deps/SKILL.md +3 -2
- package/codeAgent/skills/akan-err/SKILL.md +2 -6
- package/codeAgent/skills/akan-mcp/SKILL.md +1 -1
- package/codeAgent/skills/akan-module/SKILL.md +2 -2
- package/codeAgent/skills/akan-query/SKILL.md +13 -20
- package/codeAgent/skills/akan-service/SKILL.md +2 -5
- package/codeAgent/skills/akan-transport/SKILL.md +5 -14
- package/codeAgent/skills/akan-ui/SKILL.md +2 -5
- package/context/akanContext.ts +2 -0
- package/executors/clientRuntimeKeyOrder.fixture.json +682 -0
- package/executors/clientRuntimeKeys.fixture.json +393 -0
- package/executors/clientRuntimeKeys.test.ts +1591 -0
- package/executors/executors.test.ts +2 -0
- package/executors/sysExecutor.ts +66 -3
- package/frontendBuild/allRoutesBuilder.ts +72 -3
- package/frontendBuild/autoImportSync.ts +3 -2
- package/frontendBuild/buildRouteClient.test.ts +513 -5
- package/frontendBuild/clientBuildTypes.ts +15 -0
- package/frontendBuild/clientEntriesBundler.ts +38 -0
- package/frontendBuild/clientEntryDiscovery.test.ts +60 -1
- package/frontendBuild/clientEntryDiscovery.ts +72 -4
- package/frontendBuild/csrDevModuleCompiler.test.ts +86 -0
- package/frontendBuild/csrDevModuleCompiler.ts +44 -8
- package/frontendBuild/csrDevPatcher.ts +33 -7
- package/frontendBuild/csrDevTypes.ts +9 -0
- package/frontendBuild/devBarrelImports.test.ts +70 -0
- package/frontendBuild/devBarrelImports.ts +80 -21
- package/frontendBuild/devRegistryBundler.ts +4 -2
- package/frontendBuild/devRouteRuntime.test.ts +492 -0
- package/frontendBuild/devRouteRuntime.ts +167 -0
- package/frontendBuild/dictionaryAssetBuilder.test.ts +316 -0
- package/frontendBuild/dictionaryAssetBuilder.ts +152 -16
- package/frontendBuild/dictionaryConstants.ts +82 -0
- package/frontendBuild/dictionaryPacking.test.ts +84 -0
- package/frontendBuild/dictionaryPacking.ts +92 -0
- package/frontendBuild/dictionaryRoutes.test.ts +186 -0
- package/frontendBuild/dictionaryRoutes.ts +225 -0
- package/frontendBuild/pagesBundleBuilder.test.ts +84 -0
- package/frontendBuild/pagesBundleBuilder.ts +78 -2
- package/frontendBuild/precompressArtifacts.ts +7 -0
- package/frontendBuild/registryMetadataFingerprint.ts +3 -3
- package/frontendBuild/routeClientBuilder.ts +288 -15
- package/frontendBuild/routeHandoffs.test.ts +145 -0
- package/frontendBuild/routeHandoffs.ts +115 -0
- package/frontendBuild/routeRuntimeCheck.test.ts +257 -0
- package/frontendBuild/routeRuntimeCheck.ts +241 -0
- package/frontendBuild/routeRuntimePays.test.ts +137 -0
- package/frontendBuild/routeRuntimePays.ts +117 -0
- package/frontendBuild/ssrBaseArtifactBuilder.ts +24 -34
- package/frontendBuild/ssrDevBundler.test.ts +150 -1
- package/frontendBuild/ssrDevBundler.ts +66 -11
- package/frontendBuild/vendorFileImports.test.ts +254 -0
- package/frontendBuild/vendorFileImports.ts +163 -0
- package/frontendBuild/vendorNarrowing.ts +28 -0
- package/frontendBuild/vendorSpecifiers.ts +2 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +79 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +20 -1
- package/mobile/desktopBin.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -0
- package/package.json +4 -3
- package/quality/dictionaryKeys.test.ts +173 -0
- package/quality/dictionaryKeys.ts +415 -0
- package/quality/objectImportReport.test.ts +36 -0
- package/quality/objectImportReport.ts +102 -0
- package/quality/qualityScanner.ts +1 -1
- package/quality/routeRuntimeReport.test.ts +91 -0
- package/quality/routeRuntimeReport.ts +121 -0
- package/quality/runtimeConstantFacts.ts +71 -0
- package/quality/runtimeConstantGraph.ts +123 -0
- package/quality/runtimeConstantReads.ts +116 -0
- package/quality/runtimeImports.test.ts +190 -0
- package/quality/runtimeImports.ts +233 -0
- package/quality/runtimeKeyNames.ts +46 -0
- package/quality/runtimeLexicalScope.ts +132 -0
- package/quality/runtimeMarkerReach.test.ts +84 -0
- package/quality/runtimeMarkerReach.ts +255 -0
- package/quality/runtimeModuleFacts.ts +290 -0
- package/quality/runtimeNameTable.test.ts +172 -0
- package/quality/runtimeNameTable.ts +477 -0
- package/quality/runtimeScopeReport.test.ts +123 -0
- package/quality/runtimeScopeReport.ts +167 -0
- package/quality/runtimeSliceKey.ts +269 -0
- package/quality/runtimeSyntax.ts +133 -0
- package/quality/runtimeTable.fixture.ts +189 -0
- package/quality/runtimeUse.test.ts +737 -0
- package/quality/runtimeUse.ts +696 -0
- package/quality/runtimeUseReadable.test.ts +393 -0
- package/quality/ssrScanner.test.ts +13 -0
- package/quality/ssrScanner.ts +1 -1
- package/test/testHelpers.ts +11 -0
- package/transforms/barrelAnalyzer.ts +24 -2
- package/transforms/barrelImportsPlugin.ts +82 -14
- package/transforms/frameworkObjects.fixture.tsx +58 -0
- package/transforms/frameworkObjects.test.ts +54 -0
- package/transforms/modelReference.test.ts +196 -0
- package/transforms/modelReference.ts +39 -0
- package/transforms/objectImportEdits.ts +150 -0
- package/transforms/objectMemberImports.test.ts +347 -0
- package/transforms/objectMemberImports.ts +537 -0
- package/transforms/objectModule.test.ts +237 -0
- package/transforms/objectModule.ts +458 -0
- package/transforms/objectModuleAnalyzer.ts +104 -0
- package/transforms/reactIconImports.test.ts +231 -0
- package/transforms/reactIconImports.ts +325 -0
- package/transforms/routeConstants.ts +122 -0
- package/transforms/routeRuntime.test.ts +835 -0
- package/transforms/routeRuntime.ts +703 -0
- package/transforms/routeRuntimeEdits.ts +92 -0
- package/transforms/routeRuntimeGraph.ts +66 -0
- package/transforms/routeRuntimePlan.ts +244 -0
- package/transforms/signalDescriptors.test.ts +280 -0
- package/transforms/signalDescriptors.ts +227 -0
- package/transforms/thisFreeExports.ts +87 -0
- package/transforms/transforms.test.ts +177 -0
- package/transforms/tsconfigPackageResolver.test.ts +1 -0
- package/workflow/executor.ts +6 -2
- package/workflow/index.ts +1 -0
- package/workflow/plan.ts +36 -7
- package/workflow/types.ts +1 -1
- package/workflow/uiTarget.ts +50 -0
- package/workspace/scanInfo.ts +1 -1
- package/workspace/workspaceLayout.ts +1 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { BunPlugin } from "bun";
|
|
4
|
+
import ts from "typescript";
|
|
5
|
+
import { VendorNarrowing } from "./vendorNarrowing";
|
|
6
|
+
import { VENDOR_SPECIFIERS, type VendorSpecifier } from "./vendorSpecifiers";
|
|
7
|
+
|
|
8
|
+
const scriptExtensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
9
|
+
//? Only the vendor a page loaded twice: a file of another vendor reached by its path stays in the build, as before.
|
|
10
|
+
const fileVendors: readonly VendorSpecifier[] = ["akanjs/client"];
|
|
11
|
+
|
|
12
|
+
//? A route build bundles a file of a vendor package reached by its path, beside the copy the vendor carries and the
|
|
13
|
+
//? state that copy holds; a file the vendor's barrel re-exports whole, under the same names, comes from the vendor.
|
|
14
|
+
export class VendorFileImports {
|
|
15
|
+
readonly specifiers: readonly VendorSpecifier[];
|
|
16
|
+
readonly #akanjsRoots: readonly string[];
|
|
17
|
+
readonly #specifierByModule: ReadonlyMap<string, VendorSpecifier>;
|
|
18
|
+
readonly #realDirs = new Map<string, string>();
|
|
19
|
+
|
|
20
|
+
static async of(workspaceRoot: string): Promise<VendorFileImports> {
|
|
21
|
+
const akanServerPath = await VendorFileImports.#akanServerPath(workspaceRoot);
|
|
22
|
+
return akanServerPath
|
|
23
|
+
? new VendorFileImports(path.dirname(akanServerPath), VendorFileImports.#shippedIn(akanServerPath))
|
|
24
|
+
: new VendorFileImports(null, VENDOR_SPECIFIERS);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static async specifiersIn(workspaceRoot: string): Promise<readonly VendorSpecifier[]> {
|
|
28
|
+
const akanServerPath = await VendorFileImports.#akanServerPath(workspaceRoot);
|
|
29
|
+
return akanServerPath ? VendorFileImports.#shippedIn(akanServerPath) : VENDOR_SPECIFIERS;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//? Only the vendors this akanjs ships an entry for: an older one has no `akanjs/client` vendor to import from.
|
|
33
|
+
static #shippedIn(akanServerPath: string): VendorSpecifier[] {
|
|
34
|
+
return VendorNarrowing.entriesIn(akanServerPath).map(({ specifier }) => specifier);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static async #akanServerPath(workspaceRoot: string): Promise<string | null> {
|
|
38
|
+
try {
|
|
39
|
+
return await VendorNarrowing.akanServerPath(workspaceRoot);
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
constructor(akanjsRoot: string | null, specifiers: readonly VendorSpecifier[]) {
|
|
46
|
+
this.specifiers = specifiers;
|
|
47
|
+
this.#akanjsRoots = akanjsRoot ? [...new Set([path.resolve(akanjsRoot), fs.realpathSync(akanjsRoot)])] : [];
|
|
48
|
+
this.#specifierByModule = akanjsRoot ? this.#mapModules(akanjsRoot) : new Map();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
#mapModules(akanjsRoot: string): Map<string, VendorSpecifier> {
|
|
52
|
+
const specifierByModule = new Map<string, VendorSpecifier>();
|
|
53
|
+
const packaged = this.specifiers.filter((specifier) => fileVendors.includes(specifier));
|
|
54
|
+
for (const specifier of packaged) {
|
|
55
|
+
const barrel = VendorFileImports.#fileOf(path.join(akanjsRoot, specifier.slice("akanjs/".length)));
|
|
56
|
+
if (!barrel) continue;
|
|
57
|
+
for (const file of [barrel, ...VendorFileImports.wholeReexports(barrel)])
|
|
58
|
+
for (const root of this.#akanjsRoots)
|
|
59
|
+
for (const key of VendorFileImports.#moduleKeys(path.join(root, path.relative(akanjsRoot, file))))
|
|
60
|
+
if (!specifierByModule.has(key)) specifierByModule.set(key, specifier);
|
|
61
|
+
}
|
|
62
|
+
return specifierByModule;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
vendorOf(request: string, importer: string): VendorSpecifier | null {
|
|
66
|
+
const [akanjsRoot] = this.#akanjsRoots;
|
|
67
|
+
if (!akanjsRoot) return null;
|
|
68
|
+
const target = request.startsWith("akanjs/")
|
|
69
|
+
? path.join(akanjsRoot, request.slice("akanjs/".length))
|
|
70
|
+
: request.startsWith(".") || path.isAbsolute(request)
|
|
71
|
+
? path.resolve(path.dirname(importer), request)
|
|
72
|
+
: null;
|
|
73
|
+
if (!target) return null;
|
|
74
|
+
const extension = path.extname(target);
|
|
75
|
+
const module = scriptExtensions.includes(extension) ? target.slice(0, -extension.length) : target;
|
|
76
|
+
return this.#specifierByModule.get(module) ?? this.#specifierByModule.get(this.#realModule(module)) ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
//? A linked install reaches akanjs through a symlink, so an entry's path need not be the one Bun resolved.
|
|
80
|
+
#realModule(module: string): string {
|
|
81
|
+
const dir = path.dirname(module);
|
|
82
|
+
let realDir = this.#realDirs.get(dir);
|
|
83
|
+
if (realDir === undefined) {
|
|
84
|
+
realDir = fs.existsSync(dir) ? fs.realpathSync(dir) : dir;
|
|
85
|
+
this.#realDirs.set(dir, realDir);
|
|
86
|
+
}
|
|
87
|
+
return path.join(realDir, path.basename(module));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
//? A dynamic import stays a lazy chunk of the route build: `import("akanjs/client")` would load the whole vendor.
|
|
91
|
+
plugin(): BunPlugin {
|
|
92
|
+
return {
|
|
93
|
+
name: "akan-vendor-file-imports",
|
|
94
|
+
setup: (build) => {
|
|
95
|
+
build.onResolve({ filter: /^(\.|\/|akanjs\/)/ }, (args) => {
|
|
96
|
+
if (args.kind !== "import-statement" || !args.importer) return undefined;
|
|
97
|
+
const specifier = this.vendorOf(args.path, args.importer);
|
|
98
|
+
return specifier && specifier !== args.path ? { path: specifier, external: true } : undefined;
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
static wholeReexports(barrel: string): string[] {
|
|
105
|
+
const text = fs.readFileSync(barrel, "utf8");
|
|
106
|
+
const source = ts.createSourceFile(barrel, text, ts.ScriptTarget.Latest, false);
|
|
107
|
+
const sourceOfName = new Map<string, string | null>();
|
|
108
|
+
const starred = new Map<string, string | null>();
|
|
109
|
+
const files = new Set<string>();
|
|
110
|
+
for (const statement of source.statements) {
|
|
111
|
+
if (!ts.isExportDeclaration(statement) || statement.isTypeOnly) continue;
|
|
112
|
+
const { moduleSpecifier, exportClause } = statement;
|
|
113
|
+
if (!moduleSpecifier || !ts.isStringLiteral(moduleSpecifier)) continue;
|
|
114
|
+
const file = VendorFileImports.#fileOf(path.resolve(path.dirname(barrel), moduleSpecifier.text));
|
|
115
|
+
if (!file) continue;
|
|
116
|
+
files.add(file);
|
|
117
|
+
if (!exportClause) {
|
|
118
|
+
for (const name of VendorFileImports.#exportsOf(file) ?? [])
|
|
119
|
+
if (name !== "default") starred.set(name, starred.has(name) && starred.get(name) !== file ? null : file);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (!ts.isNamedExports(exportClause)) continue;
|
|
123
|
+
for (const element of exportClause.elements) {
|
|
124
|
+
if (element.isTypeOnly) continue;
|
|
125
|
+
const exported = element.name.text;
|
|
126
|
+
sourceOfName.set(exported, (element.propertyName ?? element.name).text === exported ? file : null);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//? A name the barrel exports itself shadows the one an `export *` brings in, so no starred file owns it.
|
|
130
|
+
for (const name of VendorFileImports.#scannedExports(barrel, text))
|
|
131
|
+
if (!sourceOfName.has(name)) sourceOfName.set(name, null);
|
|
132
|
+
const sourceOf = (name: string) => (sourceOfName.has(name) ? sourceOfName.get(name) : starred.get(name)) ?? null;
|
|
133
|
+
return [...files].filter((file) => {
|
|
134
|
+
const names = VendorFileImports.#exportsOf(file);
|
|
135
|
+
return !!names && names.length > 0 && names.every((name) => sourceOf(name) === file);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
//? `null` for a file that re-exports with `export *`: its names are not all in its own source.
|
|
140
|
+
static #exportsOf(file: string): string[] | null {
|
|
141
|
+
const source = fs.readFileSync(file, "utf8");
|
|
142
|
+
if (/^\s*export\s*\*/m.test(source)) return null;
|
|
143
|
+
return VendorFileImports.#scannedExports(file, source);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static #scannedExports(file: string, source: string): string[] {
|
|
147
|
+
const loader = file.endsWith(".tsx") || file.endsWith(".jsx") ? "tsx" : "ts";
|
|
148
|
+
return new Bun.Transpiler({ loader }).scan(source).exports;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static #fileOf(base: string): string | null {
|
|
152
|
+
for (const candidate of [...scriptExtensions.map((ext) => `${base}${ext}`), path.join(base, "index.ts")])
|
|
153
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) return candidate;
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
static #moduleKeys(file: string): string[] {
|
|
158
|
+
const withoutExtension = file.slice(0, -path.extname(file).length);
|
|
159
|
+
return path.basename(withoutExtension) === "index"
|
|
160
|
+
? [withoutExtension, path.dirname(withoutExtension)]
|
|
161
|
+
: [withoutExtension];
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -16,6 +16,34 @@ export class VendorNarrowing {
|
|
|
16
16
|
readonly #akanjsRoot: string;
|
|
17
17
|
readonly #vendorExports: Partial<Record<VendorSpecifier, readonly string[]>>;
|
|
18
18
|
|
|
19
|
+
static async akanServerPath(workspaceRoot: string): Promise<string> {
|
|
20
|
+
const candidates: string[] = [];
|
|
21
|
+
try {
|
|
22
|
+
candidates.push(path.dirname(Bun.resolveSync("akanjs/server", workspaceRoot)));
|
|
23
|
+
} catch {
|
|
24
|
+
// Source workspaces and bundled CLI execution have different resolution roots; try explicit candidates below.
|
|
25
|
+
}
|
|
26
|
+
candidates.push(
|
|
27
|
+
path.join(workspaceRoot, "pkgs/akanjs/server"),
|
|
28
|
+
path.join(workspaceRoot, "node_modules/akanjs/server"),
|
|
29
|
+
);
|
|
30
|
+
try {
|
|
31
|
+
candidates.push(path.dirname(Bun.resolveSync("akanjs/server", path.dirname(Bun.main))));
|
|
32
|
+
} catch {
|
|
33
|
+
// Published CLI installs may hoist dependencies differently; explicit Bun.main candidates cover that.
|
|
34
|
+
}
|
|
35
|
+
candidates.push(
|
|
36
|
+
path.join(path.dirname(Bun.main), "node_modules/akanjs/server"),
|
|
37
|
+
path.join(path.dirname(Bun.main), "../../akanjs/server"),
|
|
38
|
+
path.resolve(import.meta.dir, "../../server"),
|
|
39
|
+
path.resolve(import.meta.dir, "../server"),
|
|
40
|
+
);
|
|
41
|
+
for (const candidate of candidates) {
|
|
42
|
+
if (await Bun.file(path.join(candidate, "rscClient.tsx")).exists()) return candidate;
|
|
43
|
+
}
|
|
44
|
+
throw new Error(`[base-artifact] failed to locate akanjs/server; looked in: ${candidates.join(", ")}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
19
47
|
//? A devkit newer than the installed akanjs finds no agent vendor or deprecated re-export there, and builds that
|
|
20
48
|
//? akanjs's vendors whole, as the devkit it shipped with did.
|
|
21
49
|
static entriesIn(akanServerPath: string): VendorEntry[] {
|
|
@@ -10,6 +10,7 @@ export const VENDOR_SPECIFIERS = [
|
|
|
10
10
|
"akanjs/store",
|
|
11
11
|
"akanjs/store/agent",
|
|
12
12
|
"akanjs/base",
|
|
13
|
+
"akanjs/client",
|
|
13
14
|
"akanjs/common",
|
|
14
15
|
"akanjs/constant",
|
|
15
16
|
"akanjs/fetch",
|
|
@@ -24,6 +25,7 @@ export const NARROWABLE_VENDOR_SPECIFIERS = [
|
|
|
24
25
|
"akanjs/store",
|
|
25
26
|
"akanjs/store/agent",
|
|
26
27
|
"akanjs/base",
|
|
28
|
+
"akanjs/client",
|
|
27
29
|
"akanjs/common",
|
|
28
30
|
"akanjs/constant",
|
|
29
31
|
"akanjs/fetch",
|
|
@@ -645,6 +645,85 @@ else {
|
|
|
645
645
|
}
|
|
646
646
|
}, 60_000);
|
|
647
647
|
|
|
648
|
+
test("a route whose client entries an earlier route built still reads their dictionary groups, and one this builder never built loads the whole file", async () => {
|
|
649
|
+
const { root } = track(await createTempApp("demo", path.join(import.meta.dir, "..", "local")));
|
|
650
|
+
const appDir = path.join(root, "apps/demo");
|
|
651
|
+
await writeText(
|
|
652
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
653
|
+
`const { generation, needs } = JSON.parse(process.argv[2]);
|
|
654
|
+
if (needs.includes("ssr")) await import(${JSON.stringify(path.join(import.meta.dir, "buildBatch.proc.ts"))});
|
|
655
|
+
else {
|
|
656
|
+
process.once("disconnect", () => {});
|
|
657
|
+
process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] } } });
|
|
658
|
+
}
|
|
659
|
+
`,
|
|
660
|
+
);
|
|
661
|
+
await writeText(path.join(appDir, "akan.config.ts"), "export default {};\n");
|
|
662
|
+
await writeText(path.join(appDir, "env/env.client.ts"), "export const env = {} as const;\n");
|
|
663
|
+
const pages = {
|
|
664
|
+
first: path.join(appDir, "page/_index.tsx"),
|
|
665
|
+
same: path.join(appDir, "page/same.tsx"),
|
|
666
|
+
more: path.join(appDir, "page/more.tsx"),
|
|
667
|
+
lone: path.join(appDir, "page/lone.tsx"),
|
|
668
|
+
};
|
|
669
|
+
await writeText(pages.lone, 'import { Lone } from "../ui/Lone";\nexport default Lone;\n');
|
|
670
|
+
await writeText(pages.first, 'import { Card } from "../ui/Card";\nexport default Card;\n');
|
|
671
|
+
await writeText(pages.same, 'import { Card } from "../ui/Card";\nexport default Card;\n');
|
|
672
|
+
await writeText(
|
|
673
|
+
pages.more,
|
|
674
|
+
'import { Card } from "../ui/Card";\nimport { Note } from "../ui/Note";\nexport default () => [Card, Note];\n',
|
|
675
|
+
);
|
|
676
|
+
const card = path.join(appDir, "ui/Card.tsx");
|
|
677
|
+
await writeText(card, '"use client";\nimport { Label } from "./Label";\nexport const Card = () => Label();\n');
|
|
678
|
+
await writeText(
|
|
679
|
+
path.join(appDir, "ui/Label.tsx"),
|
|
680
|
+
'declare const l: (key: string) => string;\nexport const Label = () => l("memo.title");\n',
|
|
681
|
+
);
|
|
682
|
+
await writeText(path.join(appDir, "ui/Note.tsx"), '"use client";\nexport const Note = () => null;\n');
|
|
683
|
+
const lone = path.join(appDir, "ui/Lone.tsx");
|
|
684
|
+
await writeText(lone, '"use client";\nexport const Lone = () => null;\n');
|
|
685
|
+
|
|
686
|
+
const messages: BuilderMessage[] = [];
|
|
687
|
+
const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
|
|
688
|
+
cwd: appDir,
|
|
689
|
+
env: {
|
|
690
|
+
...process.env,
|
|
691
|
+
AKAN_WORKSPACE_ROOT: root,
|
|
692
|
+
AKAN_PUBLIC_APP_NAME: "demo",
|
|
693
|
+
AKAN_PUBLIC_REPO_NAME: "repo",
|
|
694
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
695
|
+
AKAN_PUBLIC_ENV: "local",
|
|
696
|
+
AKAN_WATCH: "0",
|
|
697
|
+
},
|
|
698
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
699
|
+
serialization: "advanced",
|
|
700
|
+
ipc: (message: BuilderMessage) => {
|
|
701
|
+
messages.push(message);
|
|
702
|
+
},
|
|
703
|
+
});
|
|
704
|
+
const buildRoute = async (id: number, routeId: string, seed: string, knownEntries: string[]) => {
|
|
705
|
+
proc.send({ type: "build-route", id, routeId, seeds: [seed], knownEntries, generation: 3 } satisfies BuilderReq);
|
|
706
|
+
await until(proc, `build-route-res ${id}`, () =>
|
|
707
|
+
messages.some((message) => message.type === "build-route-res" && message.id === id),
|
|
708
|
+
);
|
|
709
|
+
const res = messages.find((message) => message.type === "build-route-res" && message.id === id);
|
|
710
|
+
if (res?.type !== "build-route-res" || !res.ok) throw new Error(`route ${routeId} did not build`);
|
|
711
|
+
return res.data;
|
|
712
|
+
};
|
|
713
|
+
try {
|
|
714
|
+
await until(proc, "boot-armed", () => messages.some((message) => message.type === "boot-armed"));
|
|
715
|
+
const first = await buildRoute(1, "page:/", pages.first, []);
|
|
716
|
+
expect(first.newEntries).toEqual([card]);
|
|
717
|
+
expect(first.dictionaryGroups).toEqual(["base", "memo"]);
|
|
718
|
+
expect((await buildRoute(2, "page:/more", pages.more, [card])).dictionaryGroups).toEqual(["base", "memo"]);
|
|
719
|
+
expect((await buildRoute(3, "page:/same", pages.same, [card])).dictionaryGroups).toEqual(["base", "memo"]);
|
|
720
|
+
expect((await buildRoute(4, "page:/lone", pages.lone, [lone])).dictionaryGroups).toBeNull();
|
|
721
|
+
} finally {
|
|
722
|
+
proc.kill();
|
|
723
|
+
await proc.exited;
|
|
724
|
+
}
|
|
725
|
+
}, 60_000);
|
|
726
|
+
|
|
648
727
|
test("a failed boot build waits for the save that fixes it, and the builder it recovers continues the generation and watches", async () => {
|
|
649
728
|
const { root } = track(await createTempApp("demo"));
|
|
650
729
|
const appDir = path.join(root, "apps/demo");
|
|
@@ -15,8 +15,9 @@ import type {
|
|
|
15
15
|
import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
|
|
16
16
|
import type { App } from "../commandDecorators";
|
|
17
17
|
import { AppExecutor, type PageRoot, WorkspaceExecutor } from "../executors";
|
|
18
|
-
import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
|
|
18
|
+
import type { ClientEntryDiscovery, ClientModuleImport } from "../frontendBuild/clientBuildTypes";
|
|
19
19
|
import { GraphClientEntryDiscovery } from "../frontendBuild/clientEntryDiscovery";
|
|
20
|
+
import { DictionaryRoutes } from "../frontendBuild/dictionaryRoutes";
|
|
20
21
|
import { RouteClientBuilder } from "../frontendBuild/routeClientBuilder";
|
|
21
22
|
import type { BatchWork, BuildBatchRequest, BuildBatchResult, OptimizedFonts } from "./buildBatchProtocol";
|
|
22
23
|
import { BuildBatchRunner } from "./buildBatchRunner";
|
|
@@ -44,6 +45,8 @@ class IncrementalBuilder {
|
|
|
44
45
|
#discoveredThrough = 0;
|
|
45
46
|
/** How often each reason sent a registry save to a build worker this session: the resident patcher's miss rate. */
|
|
46
47
|
readonly #delegations = new Map<string, number>();
|
|
48
|
+
//? A route build bundles only entries no earlier route built: the dictionary walk reads every build's graph.
|
|
49
|
+
readonly #dictionaryGraph = new Map<string, readonly ClientModuleImport[]>();
|
|
47
50
|
readonly #lanes: BuilderLanes;
|
|
48
51
|
readonly #csr: CsrRegistry;
|
|
49
52
|
readonly #ssr: SsrRegistry;
|
|
@@ -113,6 +116,7 @@ class IncrementalBuilder {
|
|
|
113
116
|
browser: "registry",
|
|
114
117
|
}).build();
|
|
115
118
|
await this.#ssr.ensureSsrEntries(delta.registryEntries ?? []);
|
|
119
|
+
const dictionaryGroups = await this.#dictionaryGroupsOf(msg.seeds, delta);
|
|
116
120
|
this.#logger.verbose(`build-route ok routeId=${msg.routeId} newEntries=${delta.newEntries.length}`);
|
|
117
121
|
//? The builder's generation, not the route cache's: the cache's does not move when a fixed file maps to no entry,
|
|
118
122
|
//? so the rebuild's ok would carry the failure's own number.
|
|
@@ -131,6 +135,7 @@ class IncrementalBuilder {
|
|
|
131
135
|
routeId: msg.routeId,
|
|
132
136
|
generation: msg.generation,
|
|
133
137
|
seenGeneration,
|
|
138
|
+
dictionaryGroups,
|
|
134
139
|
} as BuildRouteResultPayload,
|
|
135
140
|
};
|
|
136
141
|
} catch (err) {
|
|
@@ -147,6 +152,20 @@ class IncrementalBuilder {
|
|
|
147
152
|
}
|
|
148
153
|
}
|
|
149
154
|
|
|
155
|
+
//? A route whose groups could not be read loads the whole page file, as one with a key no build can follow does.
|
|
156
|
+
async #dictionaryGroupsOf(
|
|
157
|
+
seeds: string[],
|
|
158
|
+
{ clientGraph, discoveredEntries, newEntries }: Awaited<ReturnType<RouteClientBuilder["build"]>>,
|
|
159
|
+
): Promise<string[] | null> {
|
|
160
|
+
for (const [module, imports] of clientGraph ?? []) this.#dictionaryGraph.set(module, imports);
|
|
161
|
+
const entries = discoveredEntries ?? newEntries;
|
|
162
|
+
const route = { seeds, entries, importsByModule: this.#dictionaryGraph, discovery: this.#discovery };
|
|
163
|
+
return DictionaryRoutes.ofBuiltRoute(this.#app, route).catch((error: unknown) => {
|
|
164
|
+
this.#logger.warn(`dictionary groups of the route could not be read: ${String(error)}`);
|
|
165
|
+
return null;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
150
169
|
// Exits so the OS reclaims the bundler arenas; the host spawns the replacement.
|
|
151
170
|
async shutdown(reason: string): Promise<void> {
|
|
152
171
|
if (this.#lanes.shuttingDown) return;
|
package/mobile/desktopBin.ts
CHANGED
|
@@ -94,7 +94,7 @@ export class DesktopBin {
|
|
|
94
94
|
throw new Error(
|
|
95
95
|
`${owner}: bin.${name} names no ${platform} file, the platform this desktop app is built for (it names ${Object.keys(platforms).join(", ") || "none"}).`,
|
|
96
96
|
);
|
|
97
|
-
const executable = await this
|
|
97
|
+
const executable = await this.executable(`${owner}: bin.${name}.${platform}`, source);
|
|
98
98
|
const target = path.join(dir, DesktopBin.fileName(name, executable));
|
|
99
99
|
await Bun.write(target, Bun.file(executable));
|
|
100
100
|
await chmod(target, 0o755);
|
|
@@ -103,7 +103,7 @@ export class DesktopBin {
|
|
|
103
103
|
return [...chosen.keys()];
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
async
|
|
106
|
+
async executable(at: string, source: AkanBinSource): Promise<string> {
|
|
107
107
|
const file = "url" in source ? await this.#download(at, source) : source.path;
|
|
108
108
|
if (!(await Bun.file(file).exists())) throw new Error(`${at}: ${file} does not exist`);
|
|
109
109
|
if (!source.file) return file;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@akanjs/devkit",
|
|
3
|
-
"version": "3.3.0-rc.
|
|
3
|
+
"version": "3.3.0-rc.27",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"./workspace/getRelatedCnsts": "./workspace/getRelatedCnsts.ts"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@akanjs/language": "3.3.0-rc.
|
|
53
|
+
"@akanjs/language": "3.3.0-rc.27",
|
|
54
54
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
55
55
|
"@earendil-works/pi-ai": "1.5.2",
|
|
56
56
|
"@earendil-works/pi-codemode": "1.5.2",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@earendil-works/pi-tui": "1.5.2",
|
|
60
60
|
"@inquirer/prompts": "^8.7.3",
|
|
61
61
|
"@tailwindcss/node": "^4.3.3",
|
|
62
|
-
"akanjs": "3.3.0-rc.
|
|
62
|
+
"akanjs": "3.3.0-rc.27",
|
|
63
63
|
"chalk": "^6.0.1",
|
|
64
64
|
"commander": "^15.0.0",
|
|
65
65
|
"dayjs": "^1.11.23",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"fonteditor-core": "^2.6.3",
|
|
68
68
|
"ignore": "^7.0.12",
|
|
69
69
|
"ora": "^9.4.1",
|
|
70
|
+
"react-server-dom-webpack": "^19.3.1",
|
|
70
71
|
"ssh2": "^1.17.0",
|
|
71
72
|
"subset-font": "^2.9.0",
|
|
72
73
|
"tailwind-scrollbar": "^4.0.2",
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { DictionaryKeys } from "./dictionaryKeys";
|
|
3
|
+
|
|
4
|
+
const read = (source: string, fileName = "apps/demo/lib/memo/Memo.Unit.tsx") => DictionaryKeys.read(source, fileName);
|
|
5
|
+
|
|
6
|
+
describe("DictionaryKeys", () => {
|
|
7
|
+
test("follows a literal key, a template whose group is written, and a key chosen from a table the file holds", () => {
|
|
8
|
+
const keys = read(`
|
|
9
|
+
import { usePage } from "akanjs/client";
|
|
10
|
+
const tabs = [{ id: "all", label: "memo.tab.all" }, { id: "mine", label: "comment.tab.mine" }] as const;
|
|
11
|
+
export const MemoTitle = ({ field }: { field: "title" | "content" }) => {
|
|
12
|
+
const { l } = usePage();
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{l("memo.modelName")}
|
|
16
|
+
{l(\`memo.\${field}\`)}
|
|
17
|
+
{tabs.map((tab) => l(tab.label))}
|
|
18
|
+
</>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
`);
|
|
22
|
+
expect(keys.unread).toEqual([]);
|
|
23
|
+
expect(keys.anyModule).toBeNull();
|
|
24
|
+
expect(keys.names).toEqual(expect.arrayContaining(["comment", "memo"]));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("follows a key typed as a union of written keys, and a prop of such a type", () => {
|
|
28
|
+
const keys = read(`
|
|
29
|
+
type MemoKey = "memo.title" | "memo.content";
|
|
30
|
+
interface Props { label: \`user.\${string}\`; fallback?: MemoKey }
|
|
31
|
+
export const Label = ({ label, fallback }: Props) => {
|
|
32
|
+
const { l } = usePage();
|
|
33
|
+
return <>{l(label)}{fallback ? l(fallback) : null}</>;
|
|
34
|
+
};
|
|
35
|
+
`);
|
|
36
|
+
expect(keys.unread).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("names the file's line and the reason for a key it cannot follow", () => {
|
|
40
|
+
const keys = read(
|
|
41
|
+
[
|
|
42
|
+
`import { usePage } from "akanjs/client";`,
|
|
43
|
+
`export const Any = ({ name }: { name: string }) => {`,
|
|
44
|
+
` const { l } = usePage();`,
|
|
45
|
+
` return <>{l(name)}</>;`,
|
|
46
|
+
`};`,
|
|
47
|
+
].join("\n"),
|
|
48
|
+
);
|
|
49
|
+
expect(keys.unread).toEqual([{ line: 4, why: "name is a parameter or prop whose type names no key" }]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("reads a key built from data, a call's result and an import as unread", () => {
|
|
53
|
+
const keys = read(`
|
|
54
|
+
import { keyOf } from "./keys";
|
|
55
|
+
export const View = ({ memo }: { memo: { status: string } }) => {
|
|
56
|
+
const { l } = usePage();
|
|
57
|
+
return <>{l(memo.status)}{l(keyOf(memo))}{l(keyOf)}</>;
|
|
58
|
+
};
|
|
59
|
+
`);
|
|
60
|
+
expect(keys.unread.map(({ why }) => why)).toEqual([
|
|
61
|
+
"memo.status is read from data at run time",
|
|
62
|
+
"keyOf(memo) is a call's result",
|
|
63
|
+
"keyOf is imported from another file",
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test("reads a translator handed to another function as unread, under any name it is destructured as", () => {
|
|
68
|
+
const keys = read(`
|
|
69
|
+
export const View = () => {
|
|
70
|
+
const { l: t } = usePage();
|
|
71
|
+
return <>{format(t, "memo.title")}</>;
|
|
72
|
+
};
|
|
73
|
+
`);
|
|
74
|
+
expect(keys.unread.map(({ why }) => why)).toEqual(["t passes the translator on"]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("counts the property names of an object the file holds when a key is built from them", () => {
|
|
78
|
+
const shapes = {
|
|
79
|
+
keys: `Object.keys(tabs).map((name) => l(\`\${name}.modelName\`))`,
|
|
80
|
+
entries: `Object.entries(tabs).map(([name]) => l(\`\${name}.modelName\`))`,
|
|
81
|
+
forIn: `(() => { for (const name in tabs) return l(\`\${name}.modelName\`); })()`,
|
|
82
|
+
};
|
|
83
|
+
for (const [shape, use] of Object.entries(shapes)) {
|
|
84
|
+
const keys = read(`
|
|
85
|
+
const tabs = { order: BiBox, "refund": BiUndo, [\`note\`]: 1, 7: 2 };
|
|
86
|
+
export const Nav = () => { const { l } = usePage(); return <>{${use}}</>; };
|
|
87
|
+
`);
|
|
88
|
+
expect(keys.unread, shape).toEqual([]);
|
|
89
|
+
expect(keys.names, shape).toEqual(expect.arrayContaining(["order", "refund", "note"]));
|
|
90
|
+
}
|
|
91
|
+
const typed = read(`
|
|
92
|
+
const tabs = { order: 1, refund: 2 };
|
|
93
|
+
export const Nav = ({ name }: { name: keyof typeof tabs }) => { const { l } = usePage(); return l(\`\${name}.modelName\`); };
|
|
94
|
+
`);
|
|
95
|
+
expect(typed.unread).toEqual([]);
|
|
96
|
+
expect(typed.names).toEqual(expect.arrayContaining(["order", "refund"]));
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("fails to the whole dictionary for property names it cannot count", () => {
|
|
100
|
+
const wrap = (table: string, use: string) =>
|
|
101
|
+
read(`
|
|
102
|
+
import { other } from "./other";
|
|
103
|
+
${table}
|
|
104
|
+
export const Nav = ({ name }: { name: keyof typeof tabs }) => { const { l } = usePage(); return <>{${use}}</>; };
|
|
105
|
+
`);
|
|
106
|
+
const use = `Object.keys(tabs).map((name) => l(\`\${name}.modelName\`))`;
|
|
107
|
+
expect(wrap("const tabs = { [dynamic()]: 1 };", use).unread).toHaveLength(1);
|
|
108
|
+
expect(wrap("const tabs = { ...other, order: 1 };", use).unread).toHaveLength(1);
|
|
109
|
+
expect(wrap("const tabs = other;", use).unread).toHaveLength(1);
|
|
110
|
+
expect(
|
|
111
|
+
wrap("const tabs = { order: 1 };", `Object.keys(other).map((name) => l(\`\${name}.modelName\`))`).unread,
|
|
112
|
+
).toHaveLength(1);
|
|
113
|
+
expect(
|
|
114
|
+
wrap("const tabs = { a: { order: 1 } };", `Object.keys(tabs.a).map((name) => l(\`\${name}.modelName\`))`).unread,
|
|
115
|
+
).toHaveLength(1);
|
|
116
|
+
expect(wrap("const tabs = { [dynamic()]: 1 };", `l(\`\${name}.modelName\`)`).unread).toHaveLength(1);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test("counts the literal head of a template type as its group, and fails a head with none", () => {
|
|
120
|
+
const keys = read(`
|
|
121
|
+
interface Props { label: \`memo.\${string}\` }
|
|
122
|
+
export const Label = ({ label }: Props) => { const { l } = usePage(); return l(label); };
|
|
123
|
+
`);
|
|
124
|
+
expect(keys.unread).toEqual([]);
|
|
125
|
+
expect(keys.names).toContain("memo");
|
|
126
|
+
const headless = read(`
|
|
127
|
+
export const Label = ({ label }: { label: \`\${string}.title\` }) => { const { l } = usePage(); return l(label); };
|
|
128
|
+
`);
|
|
129
|
+
expect(headless.unread).toHaveLength(1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("reads a translator used other than as a call or a member call it understands as unread", () => {
|
|
133
|
+
const uses = [
|
|
134
|
+
"const t = l; return t('memo.title');",
|
|
135
|
+
"const page = usePage(); const t = page.l; return t('memo.title');",
|
|
136
|
+
"return <Row t={l} />;",
|
|
137
|
+
"return helper({ l });",
|
|
138
|
+
"return [l];",
|
|
139
|
+
"return l._ ? 1 : 0;",
|
|
140
|
+
];
|
|
141
|
+
for (const use of uses) {
|
|
142
|
+
const keys = read(`export const A = () => { const { l } = usePage(); ${use} };`);
|
|
143
|
+
expect(keys.unread.length, use).toBeGreaterThan(0);
|
|
144
|
+
}
|
|
145
|
+
expect(read(`export const useT = () => { const { l } = usePage(); return l; };`).unread).toHaveLength(1);
|
|
146
|
+
const understood = read(`
|
|
147
|
+
export const A = ({ m }: { m: string }) => {
|
|
148
|
+
const page = usePage();
|
|
149
|
+
const { l } = page;
|
|
150
|
+
return <>{l("memo.title")}{l._("memo.title")}{l.rich("memo.title")}{l.trans({ en: "a", ko: "b" })}{page.l("memo.title")}{l.field(m, "title")}{l.enum(m, "x")}</>;
|
|
151
|
+
};
|
|
152
|
+
`);
|
|
153
|
+
expect(understood.unread).toEqual([]);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test("marks a framework surface that shows the texts of any module", () => {
|
|
157
|
+
expect(read(`import { Signal } from "akanjs/ui";`).anyModule).toContain("Signal from akanjs/ui");
|
|
158
|
+
expect(read(`import { Field } from "akanjs/ui/Constant";`).anyModule).toContain("Constant from akanjs/ui/Constant");
|
|
159
|
+
expect(read(`import { Data, Field } from "akanjs/ui";`).anyModule).toBeNull();
|
|
160
|
+
expect(read(`import type { Signal } from "akanjs/ui";`).anyModule).toBeNull();
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("collects the class names a constant table maps to groups, the one-name props, and the API keys", () => {
|
|
164
|
+
const keys = read(`
|
|
165
|
+
export const List = () => (
|
|
166
|
+
<Data.Dashboard modelName="memo" sliceName="memoInAdmin" filter={MemoStatus} title={l("memo.signal.getMemo.desc")} />
|
|
167
|
+
);
|
|
168
|
+
`);
|
|
169
|
+
expect(keys.classNames).toEqual(expect.arrayContaining(["MemoStatus"]));
|
|
170
|
+
expect(keys.propNames).toEqual(["memo", "memoInAdmin", "summary"]);
|
|
171
|
+
expect(keys.api).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
});
|