@akanjs/devkit 3.3.0-rc.1 → 3.3.0-rc.3
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 +37 -2
- package/akanApp/akanApp.host.test.ts +21 -4
- package/akanApp/akanApp.host.ts +46 -9
- package/akanApp/akanApp.host.wiring.test.ts +206 -2
- package/akanApp/devBackend.ts +3 -1
- package/akanApp/devBuilder.ts +5 -1
- package/akanApp/devStartTimeline.test.ts +115 -0
- package/akanApp/devStartTimeline.ts +69 -0
- package/akanConfig/akanConfig.test.ts +2 -1
- package/akanConfig/akanConfig.ts +1 -1
- package/app/applicationBuildRunner.test.ts +49 -1
- package/app/applicationBuildRunner.ts +3 -1
- package/codeAgent/skills/akan-page/SKILL.md +18 -13
- package/codeAgent/skills/akan-runtime/SKILL.md +21 -16
- package/codeAgent/skills/akan-service/SKILL.md +2 -2
- package/docs/apiReference.test.ts +5 -0
- package/docs/apiReference.ts +7 -3
- package/docs/declarationReader.ts +28 -1
- package/executors/appExecutor.ts +35 -11
- package/executors/executors.test.ts +30 -3
- package/frontendBuild/buildCacheStamp.test.ts +42 -0
- package/frontendBuild/buildCacheStamp.ts +23 -0
- package/frontendBuild/cssCandidateCache.test.ts +70 -1
- package/frontendBuild/cssCandidateCache.ts +17 -10
- package/frontendBuild/cssCompiler.test.ts +112 -0
- package/frontendBuild/cssCompiler.ts +41 -21
- package/frontendBuild/fontOptimizer.test.ts +144 -3
- package/frontendBuild/fontOptimizer.ts +103 -18
- package/frontendBuild/plainStylesheet.test.ts +155 -0
- package/frontendBuild/plainStylesheet.ts +197 -0
- package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
- package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
- package/guideline/agentAssets.test.ts +10 -0
- package/guideline/agentAssets.ts +52 -11
- package/incrementalBuilder/buildBatch.proc.ts +2 -1
- package/incrementalBuilder/buildBatchProtocol.ts +1 -0
- package/incrementalBuilder/builderBoot.ts +9 -2
- package/incrementalBuilder/builderChannel.ts +8 -2
- package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
- package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +41 -0
- package/incrementalBuilder/incrementalBuilder.proc.ts +1 -0
- package/mobile/nativeConfig.test.ts +21 -0
- package/mobile/nativeConfig.ts +20 -10
- package/mobile/nativePublicEnv.ts +2 -1
- package/package.json +3 -3
- package/util/fileSys.test.ts +13 -0
- package/util/fileSys.ts +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rename } from "node:fs/promises";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import { optimize } from "@tailwindcss/node";
|
|
3
4
|
import type { AkanNativeAppId, AkanWebConfig } from "akanjs";
|
|
@@ -16,12 +17,15 @@ import type { RuntimeChunks } from "./routeModulePreloads";
|
|
|
16
17
|
import { VendorNarrowing } from "./vendorNarrowing";
|
|
17
18
|
import type { VendorSpecifier } from "./vendorSpecifiers";
|
|
18
19
|
|
|
20
|
+
export type BaseBuildPhase = "runtime" | "routes" | "styles" | "dictionary" | "pages" | "total";
|
|
21
|
+
|
|
19
22
|
export interface BuildSsrBaseArtifactResult {
|
|
20
23
|
artifact: BaseBuildArtifact;
|
|
21
24
|
seedIndex: RouteSeedIndex;
|
|
22
25
|
cssCompiler: CssCompiler;
|
|
23
26
|
optimizedFonts: Awaited<ReturnType<FontOptimizer["optimize"]>>;
|
|
24
27
|
runtimeChunks: RuntimeChunks;
|
|
28
|
+
phaseMs: Record<BaseBuildPhase, number>;
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export function prepareCssAsset(command: "build" | "start", basePath: string, cssText: string): string {
|
|
@@ -65,15 +69,31 @@ export class SsrBaseArtifactBuilder {
|
|
|
65
69
|
|
|
66
70
|
async build(): Promise<BuildSsrBaseArtifactResult> {
|
|
67
71
|
const akanConfig = await this.#app.getConfig();
|
|
68
|
-
const {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
const phaseMs = { runtime: 0, routes: 0, styles: 0, dictionary: 0, pages: 0, total: 0 };
|
|
73
|
+
const timed = async <T>(phase: BaseBuildPhase, run: () => Promise<T>): Promise<T> => {
|
|
74
|
+
const started = performance.now();
|
|
75
|
+
try {
|
|
76
|
+
return await run();
|
|
77
|
+
} finally {
|
|
78
|
+
phaseMs[phase] = Math.round(performance.now() - started);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const { rscClientUrl, rscRuntimeClientManifest, rscRuntimeSsrManifest, vendorMap, runtimeChunks } = await timed(
|
|
82
|
+
"runtime",
|
|
83
|
+
() => this.#buildRuntimeClientEntries(),
|
|
84
|
+
);
|
|
85
|
+
const pageEntries = await timed("routes", async () => {
|
|
86
|
+
const pageKeys = await this.#app.getPageKeys();
|
|
87
|
+
this.#app.verbose(`[base-artifact] discovered ${pageKeys.length} route files under ${this.#app.cwdPath}/page`);
|
|
88
|
+
return await resolveSsrPageEntriesForApp(this.#app, pageKeys);
|
|
89
|
+
});
|
|
90
|
+
const { cssCompiler, optimizedFonts, cssAssets } = await timed("styles", () => this.#buildStyleAssets());
|
|
91
|
+
const dictAssets = await timed("dictionary", () =>
|
|
92
|
+
new DictionaryAssetBuilder(this.#app, this.#absArtifactDir).build(akanConfig.i18n),
|
|
93
|
+
);
|
|
94
|
+
const pagesBundle = await timed("pages", () =>
|
|
95
|
+
new PagesBundleBuilder(this.#app, this.#command, pageEntries, this.#serverEnv).build(),
|
|
96
|
+
);
|
|
77
97
|
this.#app.verbose(
|
|
78
98
|
`[base-artifact] pages bundle -> ${pagesBundle.bundlePath} (buildId=${pagesBundle.buildId}, splitting=${pagesBundle.splitting}, entry=${pagesBundle.entryBytes} bytes, outputs=${pagesBundle.outputCount}, chunks=${pagesBundle.chunkCount}, total=${pagesBundle.outputBytes} bytes)`,
|
|
79
99
|
);
|
|
@@ -118,10 +138,18 @@ export class SsrBaseArtifactBuilder {
|
|
|
118
138
|
androidSha256CertFingerprints: target.android?.sha256CertFingerprints,
|
|
119
139
|
})),
|
|
120
140
|
};
|
|
121
|
-
await
|
|
122
|
-
|
|
141
|
+
await SsrBaseArtifactBuilder.writeArtifact(this.#absArtifactDir, artifact);
|
|
142
|
+
phaseMs.total = Date.now() - this.#started;
|
|
143
|
+
this.#app.verbose(`[base-artifact] complete in ${phaseMs.total}ms`);
|
|
144
|
+
|
|
145
|
+
return { artifact, seedIndex, cssCompiler, optimizedFonts, runtimeChunks, phaseMs };
|
|
146
|
+
}
|
|
123
147
|
|
|
124
|
-
|
|
148
|
+
//? Renamed into place, last: a dev backend booted beside this build starts on the file the moment it exists.
|
|
149
|
+
static async writeArtifact(absArtifactDir: string, artifact: BaseBuildArtifact): Promise<void> {
|
|
150
|
+
const artifactPath = path.join(absArtifactDir, "base-artifact.json");
|
|
151
|
+
await Bun.write(`${artifactPath}.tmp`, `${JSON.stringify(artifact, null, 2)}\n`);
|
|
152
|
+
await rename(`${artifactPath}.tmp`, artifactPath);
|
|
125
153
|
}
|
|
126
154
|
|
|
127
155
|
async #buildRuntimeClientEntries(): Promise<
|
|
@@ -46,6 +46,16 @@ describe("AgentAssets", () => {
|
|
|
46
46
|
expect(references.filter((asset) => asset.path.includes("/agentRule")).length).toBeGreaterThan(1);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
+
test("ships a guideline section on its own, and the skill's index names every entry in it", async () => {
|
|
50
|
+
const assets = await AgentAssets.skills();
|
|
51
|
+
const read = (file: string) => assets.find((asset) => asset.path === file)?.content ?? "";
|
|
52
|
+
const routes = read(".agents/skills/akan-page/references/akanApi-routes.md");
|
|
53
|
+
expect(read(".agents/skills/akan-page/SKILL.md")).toMatch(/akanApi-routes\.md` — Routes .*`Link`/);
|
|
54
|
+
expect(routes).toContain("### `Link` · `akanjs/ui`");
|
|
55
|
+
expect(routes).toContain("none of\nthem has to be looked up in `node_modules`");
|
|
56
|
+
expect(routes).not.toContain("## Endpoints");
|
|
57
|
+
});
|
|
58
|
+
|
|
49
59
|
test("names no rule or skill file that a new workspace's .gitignore would keep out of git", async () => {
|
|
50
60
|
const assets = [...(await AgentAssets.rules()), ...(await AgentAssets.skills())];
|
|
51
61
|
const root = await fsPromise.mkdtemp(path.join(os.tmpdir(), "akan-agent-ignore-"));
|
package/guideline/agentAssets.ts
CHANGED
|
@@ -31,7 +31,15 @@ export class AgentAssets {
|
|
|
31
31
|
"akan-scaffold": ["workspaceRecipes"],
|
|
32
32
|
"akan-module": ["moduleOverview", "modelConstant", "modelDictionary", "fieldRule"],
|
|
33
33
|
"akan-scalar": ["scalarModule", "scalarConstant", "scalarDictionary"],
|
|
34
|
-
"akan-service": [
|
|
34
|
+
"akan-service": [
|
|
35
|
+
"modelService",
|
|
36
|
+
"modelSignal",
|
|
37
|
+
"modelDocument",
|
|
38
|
+
"akanApi#imports",
|
|
39
|
+
"akanApi#services-and-adapters",
|
|
40
|
+
"akanApi#endpoints",
|
|
41
|
+
"akanApi#dictionaries",
|
|
42
|
+
],
|
|
35
43
|
"akan-store": ["modelStore"],
|
|
36
44
|
"akan-ui": [
|
|
37
45
|
"ssrRule",
|
|
@@ -48,7 +56,7 @@ export class AgentAssets {
|
|
|
48
56
|
"akan-err": ["errorCodes"],
|
|
49
57
|
"akan-deps": [],
|
|
50
58
|
"akan-debug": [],
|
|
51
|
-
"akan-page": ["pageRule", "akanApi"],
|
|
59
|
+
"akan-page": ["pageRule", "akanApi#imports", "akanApi#routes", "akanApi#app-config"],
|
|
52
60
|
"akan-query": ["queryRule"],
|
|
53
61
|
"akan-transport": ["transportRule"],
|
|
54
62
|
"akan-runtime": ["runtimeRule"],
|
|
@@ -101,14 +109,12 @@ ${AgentAssets.marker}
|
|
|
101
109
|
for (const [name, guidelines] of Object.entries(AgentAssets.skillReferences)) {
|
|
102
110
|
const source = await fsPromise.readFile(path.join(dir, name, "SKILL.md"), "utf-8");
|
|
103
111
|
const index: string[] = [];
|
|
104
|
-
for (const
|
|
105
|
-
const
|
|
106
|
-
parts.forEach((part, idx) => {
|
|
107
|
-
const file = parts.length === 1 ? `${guideline}.md` : `${guideline}-${idx + 1}.md`;
|
|
112
|
+
for (const reference of guidelines) {
|
|
113
|
+
for (const { file, text, summary } of await AgentAssets.#referenceFiles(reference)) {
|
|
108
114
|
const referencePath = `.agents/skills/${name}/references/${file}`;
|
|
109
|
-
assets.push({ path: referencePath, content: `${AgentAssets.marker}\n\n${
|
|
110
|
-
index.push(`- \`${referencePath}\` — ${
|
|
111
|
-
}
|
|
115
|
+
assets.push({ path: referencePath, content: `${AgentAssets.marker}\n\n${text.trim()}\n` });
|
|
116
|
+
index.push(`- \`${referencePath}\` — ${summary}`);
|
|
117
|
+
}
|
|
112
118
|
}
|
|
113
119
|
const skill = AgentAssets.#skillFile(source, index);
|
|
114
120
|
for (const root of AgentAssets.skillRoots) assets.push({ path: `${root}/${name}/SKILL.md`, content: skill });
|
|
@@ -116,7 +122,38 @@ ${AgentAssets.marker}
|
|
|
116
122
|
return assets;
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
static
|
|
125
|
+
static async #referenceFiles(reference: string) {
|
|
126
|
+
const [guideline = reference, slug] = reference.split("#");
|
|
127
|
+
const text = await Prompter.getInstruction(guideline);
|
|
128
|
+
if (slug) {
|
|
129
|
+
const sections = AgentAssets.sections(text);
|
|
130
|
+
const preamble = sections[0]?.headings.length === 0 ? sections[0].text : "";
|
|
131
|
+
const section = sections.find((each) => each.headings[0] && AgentAssets.slug(each.headings[0]) === slug);
|
|
132
|
+
if (!section) throw new Error(`Guideline ${guideline} has no section ${slug}`);
|
|
133
|
+
const entries = [...section.text.matchAll(/^### (.+?)(?: · .*)?$/gm)].map((match) => match[1]);
|
|
134
|
+
const title = section.headings[0];
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
file: `${guideline}-${slug}.md`,
|
|
138
|
+
text: preamble ? `${preamble.trim()}\n\n${section.text.trim()}` : section.text,
|
|
139
|
+
summary: entries.length ? `${title}: ${entries.join(", ")}` : title,
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
const parts = AgentAssets.split(text);
|
|
144
|
+
return parts.map((part, idx) => ({
|
|
145
|
+
file: parts.length === 1 ? `${guideline}.md` : `${guideline}-${idx + 1}.md`,
|
|
146
|
+
text: part.text,
|
|
147
|
+
summary: AgentAssets.#summarize(part.headings),
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static slug(heading: string) {
|
|
152
|
+
const paren = heading.indexOf("(");
|
|
153
|
+
return (paren === -1 ? heading : heading.slice(0, paren).trimEnd()).toLowerCase().replace(/[^a-z0-9]+/g, "-");
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
static sections(markdown: string): ReferencePart[] {
|
|
120
157
|
const sections: ReferencePart[] = [];
|
|
121
158
|
let fenced = false;
|
|
122
159
|
for (const line of markdown.trim().split("\n")) {
|
|
@@ -126,8 +163,12 @@ ${AgentAssets.marker}
|
|
|
126
163
|
if (heading !== null || !last) sections.push({ text: line, headings: heading === null ? [] : [heading] });
|
|
127
164
|
else last.text += `\n${line}`;
|
|
128
165
|
}
|
|
166
|
+
return sections;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static split(markdown: string): ReferencePart[] {
|
|
129
170
|
const parts: ReferencePart[] = [];
|
|
130
|
-
for (const section of sections) {
|
|
171
|
+
for (const section of AgentAssets.sections(markdown)) {
|
|
131
172
|
const last = parts.at(-1);
|
|
132
173
|
if (last && last.text.length + section.text.length + 1 <= AgentAssets.referenceLimit) {
|
|
133
174
|
last.text += `\n${section.text}`;
|
|
@@ -84,9 +84,10 @@ class BuildBatch {
|
|
|
84
84
|
async #buildBase(): Promise<void> {
|
|
85
85
|
const started = Date.now();
|
|
86
86
|
try {
|
|
87
|
-
const { artifact, optimizedFonts } = await new SsrBaseArtifactBuilder(this.#app).build();
|
|
87
|
+
const { artifact, optimizedFonts, phaseMs } = await new SsrBaseArtifactBuilder(this.#app).build();
|
|
88
88
|
this.#result.artifact = artifact;
|
|
89
89
|
this.#result.optimizedFonts = optimizedFonts;
|
|
90
|
+
this.#result.basePhaseMs = phaseMs;
|
|
90
91
|
this.#logger.verbose(`base-artifact ok buildId=${artifact.pagesBundleBuildId} (${Date.now() - started}ms)`);
|
|
91
92
|
} catch (err) {
|
|
92
93
|
this.#fail("base", "base-artifact", err);
|
|
@@ -32,6 +32,7 @@ export interface BuildBatchResult {
|
|
|
32
32
|
cssAssets?: PagesBatchCssAssets;
|
|
33
33
|
optimizedFonts?: OptimizedFonts;
|
|
34
34
|
artifact?: BaseBuildArtifact; // `base` batches only
|
|
35
|
+
basePhaseMs?: Record<string, number>;
|
|
35
36
|
errors: Partial<Record<BuildBatchNeed, string>>;
|
|
36
37
|
crashed?: boolean; // died before reporting its result
|
|
37
38
|
/** Of a crashed batch, the needs it died before reporting: the others streamed their build-status first. */
|
|
@@ -19,7 +19,9 @@ export interface IncrementalBuilderOptions {
|
|
|
19
19
|
initialGeneration?: number;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
type IncrementalBuilderBootDeps = Pick<IncrementalBuilderOptions, "artifact" | "optimizedFonts" | "discovery"
|
|
22
|
+
type IncrementalBuilderBootDeps = Pick<IncrementalBuilderOptions, "artifact" | "optimizedFonts" | "discovery"> & {
|
|
23
|
+
basePhaseMs: Record<string, number>;
|
|
24
|
+
};
|
|
23
25
|
|
|
24
26
|
export class BuilderBoot {
|
|
25
27
|
// Discovery stays in-process because route builds need it live; it is free at boot, building its graph lazily.
|
|
@@ -41,7 +43,12 @@ export class BuilderBoot {
|
|
|
41
43
|
if (!result.artifact || !result.optimizedFonts)
|
|
42
44
|
throw new Error("boot build reported success without an artifact; the build worker likely died");
|
|
43
45
|
const discovery = await GraphClientEntryDiscovery.create(app);
|
|
44
|
-
return {
|
|
46
|
+
return {
|
|
47
|
+
artifact: result.artifact,
|
|
48
|
+
optimizedFonts: result.optimizedFonts,
|
|
49
|
+
discovery,
|
|
50
|
+
basePhaseMs: result.basePhaseMs ?? {},
|
|
51
|
+
};
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
// A boot compile error must not kill the builder, the dev server's only file watcher: report it, emit builder-ready
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Logger } from "akanjs/common";
|
|
2
2
|
import type { BuilderMessage } from "akanjs/server";
|
|
3
3
|
|
|
4
|
+
//? For the host alone, never relayed: the boot artifact is on disk, and `builder-ready` follows once the watcher is up.
|
|
5
|
+
export interface BaseBuiltMessage {
|
|
6
|
+
type: "base-built";
|
|
7
|
+
phaseMs: Record<string, number>;
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
// `process.exit` drops an ipc write that has not flushed (a natural exit does not), and whether one survives
|
|
5
11
|
// depends on the message's shape as well as its size — so every send reports its flush and `shutdown` drains.
|
|
6
12
|
export class BuilderChannel {
|
|
@@ -8,7 +14,7 @@ export class BuilderChannel {
|
|
|
8
14
|
static readonly #flushTimeoutMs = 5_000;
|
|
9
15
|
static readonly #flushing = new Set<Promise<void>>();
|
|
10
16
|
|
|
11
|
-
static send(message: BuilderMessage): Promise<void> {
|
|
17
|
+
static send(message: BuilderMessage | BaseBuiltMessage): Promise<void> {
|
|
12
18
|
const send = process.send;
|
|
13
19
|
if (!send) return Promise.resolve();
|
|
14
20
|
const flushed = new Promise<void>((resolve) => {
|
|
@@ -25,7 +31,7 @@ export class BuilderChannel {
|
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
// Tracked like `send`: for an event nobody awaits, `drain` is all that stands between it and the exit.
|
|
28
|
-
static emit(message: BuilderMessage): void {
|
|
34
|
+
static emit(message: BuilderMessage | BaseBuiltMessage): void {
|
|
29
35
|
void BuilderChannel.send(message);
|
|
30
36
|
}
|
|
31
37
|
|
|
@@ -43,6 +43,22 @@ const startRecordingHost = () => {
|
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
describe("IncrementalBuilderHost", () => {
|
|
46
|
+
test("tells its starter the boot artifact is built, ahead of ready, and relays nothing for it", () => {
|
|
47
|
+
const spawns = mockSpawns();
|
|
48
|
+
const messages: unknown[] = [];
|
|
49
|
+
const onBaseBuilt = mock();
|
|
50
|
+
const host = createHost((message) => messages.push(message));
|
|
51
|
+
|
|
52
|
+
host.start({ onBaseBuilt });
|
|
53
|
+
spawns[0]?.options.ipc?.({ type: "base-built", phaseMs: { pages: 5, total: 9 } });
|
|
54
|
+
|
|
55
|
+
expect(onBaseBuilt).toHaveBeenCalledWith({ pages: 5, total: 9 });
|
|
56
|
+
expect(host.status).toBe("starting");
|
|
57
|
+
expect(messages).toEqual([]);
|
|
58
|
+
|
|
59
|
+
host.stop();
|
|
60
|
+
});
|
|
61
|
+
|
|
46
62
|
test("restarts after a ready builder exits", async () => {
|
|
47
63
|
const spawns = mockSpawns();
|
|
48
64
|
|
|
@@ -5,6 +5,7 @@ import type { BuilderMessage, BuilderRequest } from "akanjs/server";
|
|
|
5
5
|
import { CSR_DEV_DIRNAME, CSR_DEV_PATCHING_MARKER, SSR_DEV_DIRNAME } from "akanjs/server/hmr/csrDevManifest";
|
|
6
6
|
import { MemoryLimit } from "akanjs/server/memoryLimit";
|
|
7
7
|
import type { App } from "../commandDecorators";
|
|
8
|
+
import type { BaseBuiltMessage } from "./builderChannel";
|
|
8
9
|
|
|
9
10
|
const builderMsgTypeSet = new Set<BuilderMessage["type"]>([
|
|
10
11
|
"build-route-res",
|
|
@@ -41,6 +42,7 @@ export type IncrementalBuilderStatus = "starting" | "ready" | "recycling" | "res
|
|
|
41
42
|
interface IncrementalBuilderStartOptions {
|
|
42
43
|
onExit?: () => void;
|
|
43
44
|
onReady?: () => void;
|
|
45
|
+
onBaseBuilt?: (phaseMs: Record<string, number>) => void;
|
|
44
46
|
onRestartReady?: () => void;
|
|
45
47
|
/** The builder is gone and a replacement is coming (unwatched until then); `onExit` means it gave up. */
|
|
46
48
|
onAway?: () => void;
|
|
@@ -124,9 +126,13 @@ export class IncrementalBuilderHost {
|
|
|
124
126
|
...(this.#patcherOff ? { AKAN_DEV_CSR_PATCHER: "off" } : {}),
|
|
125
127
|
},
|
|
126
128
|
stdio: ["ignore", this.#stdio, this.#stdio],
|
|
127
|
-
ipc: (msg: BuilderMessage) => {
|
|
129
|
+
ipc: (msg: BuilderMessage | BaseBuiltMessage) => {
|
|
128
130
|
if (this.#proc !== proc) return;
|
|
129
131
|
if (!msg || typeof msg !== "object") return;
|
|
132
|
+
if (msg.type === "base-built") {
|
|
133
|
+
this.#startOptions.onBaseBuilt?.(msg.phaseMs);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
130
136
|
if (msg.type === "build-route-res" || msg.type === "build-csr-res" || msg.type === "build-graph-res")
|
|
131
137
|
this.#inFlight.delete(msg.id);
|
|
132
138
|
if (builderMsgTypeSet.has(msg.type)) this.#onMessage(msg);
|
|
@@ -86,6 +86,47 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
|
|
|
86
86
|
expect(log).toContain(reason);
|
|
87
87
|
}, 30_000);
|
|
88
88
|
|
|
89
|
+
test("says its boot artifact is built, with the build's parts, before it says it is ready", async () => {
|
|
90
|
+
const { root } = track(await createTempApp("demo"));
|
|
91
|
+
const appDir = path.join(root, "apps/demo");
|
|
92
|
+
await writeText(
|
|
93
|
+
path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
|
|
94
|
+
`const { generation } = JSON.parse(process.argv[2]);
|
|
95
|
+
process.once("disconnect", () => {});
|
|
96
|
+
process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] }, basePhaseMs: { styles: 7, pages: 5, total: 9 } } });
|
|
97
|
+
`,
|
|
98
|
+
);
|
|
99
|
+
await writeText(path.join(appDir, "page/_index.tsx"), "export default () => null;\n");
|
|
100
|
+
const messages: { type: string; phaseMs?: Record<string, number> }[] = [];
|
|
101
|
+
const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
|
|
102
|
+
cwd: appDir,
|
|
103
|
+
env: {
|
|
104
|
+
...process.env,
|
|
105
|
+
AKAN_WORKSPACE_ROOT: root,
|
|
106
|
+
AKAN_PUBLIC_APP_NAME: "demo",
|
|
107
|
+
AKAN_PUBLIC_REPO_NAME: "repo",
|
|
108
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
109
|
+
AKAN_PUBLIC_ENV: "local",
|
|
110
|
+
AKAN_WATCH: "0",
|
|
111
|
+
},
|
|
112
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
113
|
+
serialization: "advanced",
|
|
114
|
+
ipc: (message: { type: string; phaseMs?: Record<string, number> }) => {
|
|
115
|
+
messages.push(message);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
try {
|
|
119
|
+
await until(proc, "builder-ready", () => messages.some((message) => message.type === "builder-ready"));
|
|
120
|
+
} finally {
|
|
121
|
+
proc.kill();
|
|
122
|
+
await proc.exited;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const types = messages.map((message) => message.type);
|
|
126
|
+
expect(types.slice(0, 2)).toEqual(["base-built", "builder-ready"]);
|
|
127
|
+
expect(messages[0]).toEqual({ type: "base-built", phaseMs: { styles: 7, pages: 5, total: 9 } });
|
|
128
|
+
}, 30_000);
|
|
129
|
+
|
|
89
130
|
test("builds a view's shell once on request, answers with its failure, and reports it to no tab", async () => {
|
|
90
131
|
const { root } = track(await createTempApp("demo"));
|
|
91
132
|
const appDir = path.join(root, "apps/demo");
|
|
@@ -381,6 +381,7 @@ class IncrementalBuilder {
|
|
|
381
381
|
const initialGeneration = BuilderBoot.initialGeneration();
|
|
382
382
|
try {
|
|
383
383
|
const deps = await BuilderBoot.buildBootDeps(app, bootRunner);
|
|
384
|
+
BuilderChannel.emit({ type: "base-built", phaseMs: deps.basePhaseMs });
|
|
384
385
|
builder = new IncrementalBuilder({ app, watch, initialGeneration, ...deps });
|
|
385
386
|
} catch (err) {
|
|
386
387
|
if (!watch) throw err;
|
|
@@ -484,6 +484,27 @@ describe("NativeConfig.build", () => {
|
|
|
484
484
|
expect((await NativeApi.load(repoApp)).validateConfig(config, { appDir: root })).toEqual([]);
|
|
485
485
|
});
|
|
486
486
|
|
|
487
|
+
test("ios.hideFormAccessoryBar reaches the iOS shell, and the runtime accepts it; left out, the bar stays", async () => {
|
|
488
|
+
const root = await makeTempRoot();
|
|
489
|
+
const build = (ios?: { hideFormAccessoryBar?: boolean }) =>
|
|
490
|
+
NativeConfig.build({
|
|
491
|
+
appPath: root,
|
|
492
|
+
target: { ...minimalTarget, permissions: [], deepLinks: undefined, android: undefined, ios },
|
|
493
|
+
webDir: path.join(root, "web"),
|
|
494
|
+
contributions: [],
|
|
495
|
+
locales: ["en"],
|
|
496
|
+
platform: "ios",
|
|
497
|
+
}).config;
|
|
498
|
+
const config = build({ hideFormAccessoryBar: true });
|
|
499
|
+
|
|
500
|
+
expect(config.ios).toEqual({ hideFormAccessoryBar: true });
|
|
501
|
+
expect(build().ios).toBeUndefined();
|
|
502
|
+
expect(build({ hideFormAccessoryBar: false }).ios).toBeUndefined();
|
|
503
|
+
await mkdir(path.join(root, "web"), { recursive: true });
|
|
504
|
+
await writeFile(path.join(root, "web/index.html"), "<html><head></head><body></body></html>");
|
|
505
|
+
expect((await NativeApi.load(repoApp)).validateConfig(config, { appDir: root })).toEqual([]);
|
|
506
|
+
});
|
|
507
|
+
|
|
487
508
|
test("an app with updates ships the updates plugin and its settings", () => {
|
|
488
509
|
const updates = { url: "https://releases.example.com/board", publicKey: `${"a".repeat(43)}=`, channel: "pilot" };
|
|
489
510
|
const { config } = NativeConfig.build({
|
package/mobile/nativeConfig.ts
CHANGED
|
@@ -214,16 +214,7 @@ export class NativeConfig {
|
|
|
214
214
|
const native = NativeConfig.#compact({ ios, macos, android, resources });
|
|
215
215
|
const googleServices = target.android?.googleServices;
|
|
216
216
|
const pushAndroid = target.android?.push;
|
|
217
|
-
const desktop = NativeConfig.#
|
|
218
|
-
recovery: target.desktop?.recovery,
|
|
219
|
-
screenCapture: target.desktop?.screenCapture,
|
|
220
|
-
webview2: target.desktop?.webview2,
|
|
221
|
-
publisher: target.desktop?.publisher,
|
|
222
|
-
window: NativeConfig.#compact({ ...target.desktop?.window }),
|
|
223
|
-
server: desktopServer,
|
|
224
|
-
bin: desktopBin,
|
|
225
|
-
dmg: NativeConfig.#dmg(target.desktop?.dmg, abs),
|
|
226
|
-
});
|
|
217
|
+
const desktop = NativeConfig.#desktop(target.desktop, desktopServer, desktopBin, abs);
|
|
227
218
|
const background = target.backgroundColor;
|
|
228
219
|
const shell = NativeConfig.#compact<NonNullable<AkanNativeConfig["shell"]>>({
|
|
229
220
|
backgroundColor: typeof background === "string" ? background : background?.light,
|
|
@@ -270,6 +261,7 @@ export class NativeConfig {
|
|
|
270
261
|
}
|
|
271
262
|
: {}),
|
|
272
263
|
...(target.ios?.privacy ? { privacy: target.ios.privacy } : {}),
|
|
264
|
+
...(target.ios?.hideFormAccessoryBar ? { ios: { hideFormAccessoryBar: true } } : {}),
|
|
273
265
|
//? assetlinks.json vouches for `<appId>.debug` outside main, the suffix a debug build installs under.
|
|
274
266
|
android: {
|
|
275
267
|
debugAppIdSuffix: ".debug",
|
|
@@ -363,6 +355,24 @@ export class NativeConfig {
|
|
|
363
355
|
return { ...splash, ...(splash.image ? { image: abs(splash.image) } : {}) };
|
|
364
356
|
}
|
|
365
357
|
|
|
358
|
+
static #desktop(
|
|
359
|
+
desktop: AkanNativeTarget["desktop"],
|
|
360
|
+
server: DesktopServerBundle | undefined,
|
|
361
|
+
bin: string | undefined,
|
|
362
|
+
abs: (relative: string) => string,
|
|
363
|
+
) {
|
|
364
|
+
return NativeConfig.#compact<NonNullable<AkanNativeConfig["desktop"]>>({
|
|
365
|
+
recovery: desktop?.recovery,
|
|
366
|
+
screenCapture: desktop?.screenCapture,
|
|
367
|
+
webview2: desktop?.webview2,
|
|
368
|
+
publisher: desktop?.publisher,
|
|
369
|
+
window: NativeConfig.#compact({ ...desktop?.window }),
|
|
370
|
+
server,
|
|
371
|
+
bin,
|
|
372
|
+
dmg: NativeConfig.#dmg(desktop?.dmg, abs),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
|
|
366
376
|
static #dmg(dmg: AkanNativeDmgConfig | undefined, abs: (relative: string) => string) {
|
|
367
377
|
if (!dmg) return undefined;
|
|
368
378
|
const { background, background2x, ...layout } = dmg;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import type { App } from "../commandDecorators";
|
|
3
3
|
import { WorkspaceExecutor } from "../executors";
|
|
4
|
-
import { CsrArtifactBuilder } from "../frontendBuild/csrArtifactBuilder";
|
|
5
4
|
|
|
6
5
|
export type PublicEnv = Record<string, string>;
|
|
7
6
|
|
|
@@ -68,6 +67,7 @@ export class NativePublicEnv {
|
|
|
68
67
|
|
|
69
68
|
/** What the app's last `akan build` inlined, or null when it built no CSR bundle. */
|
|
70
69
|
static async built(app: App): Promise<PublicEnv | null> {
|
|
70
|
+
const { CsrArtifactBuilder } = await import("../frontendBuild/csrArtifactBuilder");
|
|
71
71
|
const file = Bun.file(CsrArtifactBuilder.publicEnvPath(app));
|
|
72
72
|
if (!(await file.exists())) return null;
|
|
73
73
|
return NativePublicEnv.of((await file.json()) as Record<string, unknown>);
|
|
@@ -75,6 +75,7 @@ export class NativePublicEnv {
|
|
|
75
75
|
|
|
76
76
|
/** Every `AKAN_PUBLIC_*` the last `akan build` inlined, derived keys included, else the ones this process has. */
|
|
77
77
|
static async inlined(app: App): Promise<PublicEnv> {
|
|
78
|
+
const { CsrArtifactBuilder } = await import("../frontendBuild/csrArtifactBuilder");
|
|
78
79
|
const file = Bun.file(CsrArtifactBuilder.publicEnvPath(app));
|
|
79
80
|
const env = (await file.exists()) ? ((await file.json()) as Record<string, unknown>) : process.env;
|
|
80
81
|
return Object.fromEntries(
|
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.3",
|
|
4
4
|
"sourceType": "module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
"./*": "./*.ts"
|
|
206
206
|
},
|
|
207
207
|
"dependencies": {
|
|
208
|
-
"@akanjs/language": "3.3.0-rc.
|
|
208
|
+
"@akanjs/language": "3.3.0-rc.3",
|
|
209
209
|
"@earendil-works/pi-agent-core": "1.5.2",
|
|
210
210
|
"@earendil-works/pi-ai": "1.5.2",
|
|
211
211
|
"@earendil-works/pi-codemode": "1.5.2",
|
|
@@ -214,7 +214,7 @@
|
|
|
214
214
|
"@earendil-works/pi-tui": "1.5.2",
|
|
215
215
|
"@inquirer/prompts": "^8.7.3",
|
|
216
216
|
"@tailwindcss/node": "^4.3.3",
|
|
217
|
-
"akanjs": "3.3.0-rc.
|
|
217
|
+
"akanjs": "3.3.0-rc.3",
|
|
218
218
|
"chalk": "^6.0.1",
|
|
219
219
|
"commander": "^15.0.0",
|
|
220
220
|
"dayjs": "^1.11.23",
|
package/util/fileSys.test.ts
CHANGED
|
@@ -47,3 +47,16 @@ describe("FileSys.ensurePrivateDir", () => {
|
|
|
47
47
|
},
|
|
48
48
|
);
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
describe("FileSys.writeTextAtomic", () => {
|
|
52
|
+
test("lands one whole write when two writes of one file start together", async () => {
|
|
53
|
+
const dir = mkdtempSync(path.join(tmpdir(), "akan-atomic-"));
|
|
54
|
+
try {
|
|
55
|
+
const file = path.join(dir, "cache.json");
|
|
56
|
+
await Promise.all([FileSys.writeTextAtomic(file, "first"), FileSys.writeTextAtomic(file, "second")]);
|
|
57
|
+
expect(["first", "second"]).toContain(await Bun.file(file).text());
|
|
58
|
+
} finally {
|
|
59
|
+
rmSync(dir, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
package/util/fileSys.ts
CHANGED
|
@@ -46,8 +46,8 @@ export class FileSys {
|
|
|
46
46
|
}
|
|
47
47
|
// One `rename`, so a watcher never reads a half-written barrel as a user edit. The temp is a sibling (rename is atomic
|
|
48
48
|
// only within a filesystem), and its `.tmp` suffix is what `HmrChangeClassifier` ignores it by.
|
|
49
|
-
static async writeTextAtomic(filePath: string, content: string) {
|
|
50
|
-
const temp = `${filePath}.${process.pid}.${
|
|
49
|
+
static async writeTextAtomic(filePath: string, content: string | Uint8Array) {
|
|
50
|
+
const temp = `${filePath}.${process.pid}.${crypto.randomUUID()}.tmp`;
|
|
51
51
|
try {
|
|
52
52
|
await Bun.write(temp, content);
|
|
53
53
|
await FileSys.replace(temp, filePath);
|