@akanjs/devkit 3.2.0 → 3.2.1-rc.1

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.
@@ -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;
@@ -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.2.0",
3
+ "version": "3.2.1-rc.1",
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.2.0",
208
+ "@akanjs/language": "3.2.1-rc.1",
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.2.0",
217
+ "akanjs": "3.2.1-rc.1",
218
218
  "chalk": "^6.0.1",
219
219
  "commander": "^15.0.0",
220
220
  "dayjs": "^1.11.23",
@@ -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}.${Date.now().toString(36)}.tmp`;
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);