@akanjs/devkit 3.3.0-rc.4 → 3.3.0-rc.6

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 CHANGED
@@ -11,6 +11,7 @@
11
11
  The key defaults to false, so existing apps are unchanged. The api report lists one new optional `AkanNativeIosConfig` property; no upgrade step is needed.
12
12
 
13
13
  - 4732186: `akan --version` loads no command module, and `akan tunnel`, `akan subspace` and the package commands such as `akan version` no longer load the TypeScript compiler unless a step compiles.
14
+ - 6ea7242: `akan build`, `akan verify` and `akan start` stop with an error naming the import chain when the server pages bundle would import `react-dom/server` as it loads, instead of building a bundle whose RSC worker throws "react-dom/server is not supported in React Server Components" at boot. A module in the page graph that dynamically imports the app's `server.ts` is the usual cause: it brings the whole server, SSR renderer included, into the pages bundle.
14
15
  - 0d5e75e: A stylesheet whose imports use no Tailwind (no `@import "tailwindcss"`, Tailwind at-rule or `theme()` function anywhere in its import graph) is no longer run through the Tailwind compiler: its imports are inlined and it ships without the `/*! tailwindcss … */` banner. A stylesheet that uses Tailwind compiles exactly as before.
15
16
  - 98931e4: `akan start` boots the backend while the first base build runs: the backend loads its server graph beside the build and mounts the web surface as soon as the build's artifact is on disk, so the dev server is ready sooner.
16
17
 
@@ -20,6 +21,7 @@
20
21
  - 98931e4: `akan start` prints one line when the dev server is ready that says where the start's time went: what the CLI did before the builder, the base build and its parts, the backend's boot, and when the first artifact was on disk.
21
22
  - 694444d: `akan verify` writes its build check to `dist/verify/<app>` and leaves `dist/apps/<app>` as `akan build` left it, so running `akan verify` after `akan build` no longer stops `cd dist/apps/<app> && bun main.js` from starting. The check no longer copies the app's `public/` and `private/` folders either.
22
23
  - Updated dependencies [c44d068]
24
+ - Updated dependencies [af09c4f]
23
25
  - Updated dependencies [24315d1]
24
26
  - Updated dependencies [bf582c1]
25
27
  - Updated dependencies [90d740f]
@@ -28,6 +30,7 @@
28
30
  - Updated dependencies [c10f7cf]
29
31
  - Updated dependencies [045699c]
30
32
  - Updated dependencies [5c7e083]
33
+ - Updated dependencies [4040f2d]
31
34
  - Updated dependencies [aead1aa]
32
35
  - Updated dependencies [5c6d039]
33
36
  - Updated dependencies [0492e0b]
@@ -13,6 +13,7 @@ import { createUseClientBundlePlugin } from "../transforms/useClientBundlePlugin
13
13
  import { bundleDefine } from "./bundleDefine";
14
14
  import { CsrDevPaths } from "./csrDevPaths";
15
15
  import { PagesEntrySourceGenerator } from "./pagesEntrySourceGenerator";
16
+ import { RscServerRendererGuard } from "./rscServerRendererGuard";
16
17
  import { ServerGraphFile } from "./serverGraphFile";
17
18
 
18
19
  export interface BuildPagesBundleResult {
@@ -74,7 +75,7 @@ export class PagesBundleBuilder {
74
75
  asset: "assets/[name]-[hash].[ext]",
75
76
  },
76
77
  define: bundleDefine(this.#app, this.#command, "ssr"),
77
- metafile: dev,
78
+ metafile: true,
78
79
  plugins: [
79
80
  //? First: the use-client plugins below load every module, and an env file must be swapped before they do.
80
81
  ...(this.#serverEnv ? [this.#serverEnv] : []),
@@ -96,6 +97,7 @@ export class PagesBundleBuilder {
96
97
  });
97
98
 
98
99
  if (!result.success) throw new AggregateError(result.logs, "[PagesBundleBuilder] Bun.build failed");
100
+ RscServerRendererGuard.assert(result.metafile, workspaceRoot);
99
101
 
100
102
  const entryArtifact = result.outputs.find((a) => a.kind === "entry-point");
101
103
  if (!entryArtifact) throw new Error("[PagesBundleBuilder] Bun.build emitted no entry-point artifact");
@@ -0,0 +1,60 @@
1
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
2
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { RscServerRendererGuard } from "./rscServerRendererGuard";
6
+
7
+ let root = "";
8
+
9
+ const files = {
10
+ "renderer.ts": `import { renderToReadableStream } from "react-dom/server.edge";\nexport const render = () => renderToReadableStream;\n`,
11
+ "server.ts": `import { render } from "./renderer";\nexport const boot = () => render;\nexport const migrations = ["m1"];\n`,
12
+ "service.ts": `export const report = async () => (await import("./server")).migrations;\n`,
13
+ "dynamicPage.ts": `import { report } from "./service";\nexport const page = () => report;\n`,
14
+ "lazyRenderer.ts": `export const render = async () => (await import("react-dom/server.browser")).renderToReadableStream;\n`,
15
+ "lazyPage.ts": `import { render } from "./lazyRenderer";\nexport const page = () => render;\n`,
16
+ "plainPage.ts": `export const page = () => "plain";\n`,
17
+ };
18
+
19
+ const metafileOf = async (entry: string) => {
20
+ const result = await Bun.build({
21
+ entrypoints: [path.join(root, entry)],
22
+ outdir: path.join(root, "out", entry),
23
+ target: "bun",
24
+ format: "esm",
25
+ metafile: true,
26
+ external: ["react-dom/*"],
27
+ });
28
+ expect(result.success).toBe(true);
29
+ return result.metafile;
30
+ };
31
+
32
+ beforeAll(async () => {
33
+ root = await mkdtemp(path.join(tmpdir(), "rsc-guard-"));
34
+ for (const [file, source] of Object.entries(files)) await writeFile(path.join(root, file), source);
35
+ });
36
+
37
+ afterAll(async () => {
38
+ await rm(root, { recursive: true, force: true });
39
+ });
40
+
41
+ describe("RscServerRendererGuard", () => {
42
+ test("names the chain from the page through the dynamic import of the server entry to the renderer", async () => {
43
+ const assertion = (async () => RscServerRendererGuard.assert(await metafileOf("dynamicPage.ts"), root))();
44
+
45
+ await expect(assertion).rejects.toThrow(
46
+ [
47
+ "where that import throws. It is reached through:",
48
+ " dynamicPage.ts",
49
+ " → service.ts",
50
+ " → import() server.ts",
51
+ " → renderer.ts",
52
+ ].join("\n"),
53
+ );
54
+ });
55
+
56
+ test("passes a page whose renderer import waits inside a function, and one that reaches no renderer", async () => {
57
+ for (const entry of ["lazyPage.ts", "plainPage.ts"])
58
+ expect(RscServerRendererGuard.offenders((await metafileOf(entry)) as Bun.BuildMetafile)).toEqual([]);
59
+ });
60
+ });
@@ -0,0 +1,68 @@
1
+ import { realpathSync } from "node:fs";
2
+ import path from "node:path";
3
+
4
+ interface ImportEdge {
5
+ from: string;
6
+ dynamic: boolean;
7
+ }
8
+
9
+ //? Every `react-dom/server` entry resolves to `server.react-server.js` under the react-server condition, which throws.
10
+ const SERVER_RENDERER_RE = /^react-dom\/server(?:\.\w+)?$/;
11
+
12
+ export class RscServerRendererGuard {
13
+ //? Bun keeps an external `import` after tree-shaking drops its bindings, and hoists one out of a lazily wrapped module.
14
+ static offenders(metafile: Bun.BuildMetafile): { input: string; specifier: string }[] {
15
+ const offenders: { input: string; specifier: string }[] = [];
16
+ const included = new Set(
17
+ Object.values(metafile.outputs).flatMap((output) =>
18
+ Object.entries(output.inputs)
19
+ .filter(([, { bytesInOutput }]) => bytesInOutput > 0)
20
+ .map(([input]) => input),
21
+ ),
22
+ );
23
+ for (const input of included)
24
+ for (const edge of metafile.inputs[input]?.imports ?? [])
25
+ if (edge.external && edge.kind === "import-statement" && SERVER_RENDERER_RE.test(edge.path))
26
+ offenders.push({ input, specifier: edge.path });
27
+ return offenders;
28
+ }
29
+
30
+ static chain(metafile: Bun.BuildMetafile, target: string): { input: string; dynamic: boolean }[] {
31
+ const entries = Object.values(metafile.outputs).flatMap((output) => (output.entryPoint ? [output.entryPoint] : []));
32
+ const reached = new Map<string, ImportEdge | null>(entries.map((entry) => [entry, null]));
33
+ const queue = [...entries];
34
+ for (let input = queue.shift(); input !== undefined && !reached.has(target); input = queue.shift())
35
+ for (const edge of metafile.inputs[input]?.imports ?? []) {
36
+ if (edge.external || reached.has(edge.path)) continue;
37
+ reached.set(edge.path, {
38
+ from: input,
39
+ dynamic: edge.kind === "dynamic-import" || edge.kind === "require-call",
40
+ });
41
+ queue.push(edge.path);
42
+ }
43
+ const chain: { input: string; dynamic: boolean }[] = [];
44
+ for (let input: string | undefined = target; input !== undefined; ) {
45
+ const edge: ImportEdge | null | undefined = reached.get(input);
46
+ chain.unshift({ input, dynamic: edge?.dynamic ?? false });
47
+ input = edge?.from;
48
+ }
49
+ return chain;
50
+ }
51
+
52
+ static assert(metafile: Bun.BuildMetafile | undefined, workspaceRoot: string) {
53
+ const [offender] = metafile ? RscServerRendererGuard.offenders(metafile) : [];
54
+ if (!metafile || !offender) return;
55
+ const root = realpathSync(workspaceRoot);
56
+ const shown = (input: string) => path.relative(root, path.resolve(input)) || input;
57
+ const lines = RscServerRendererGuard.chain(metafile, offender.input).map(
58
+ ({ input, dynamic }, idx) => ` ${idx === 0 ? "" : dynamic ? "→ import() " : "→ "}${shown(input)}`,
59
+ );
60
+ throw new Error(
61
+ [
62
+ `[PagesBundleBuilder] The server pages bundle imports ${offender.specifier} as it loads, and the RSC worker runs under the react-server condition, where that import throws. It is reached through:`,
63
+ ...lines,
64
+ "A module in the page graph that imports the app's server entry, or anything that starts the server, brings the SSR renderer with it: import only what that module uses, or hand it in from the code that boots the server.",
65
+ ].join("\n"),
66
+ );
67
+ }
68
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.3.0-rc.4",
3
+ "version": "3.3.0-rc.6",
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.4",
208
+ "@akanjs/language": "3.3.0-rc.6",
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.4",
217
+ "akanjs": "3.3.0-rc.6",
218
218
  "chalk": "^6.0.1",
219
219
  "commander": "^15.0.0",
220
220
  "dayjs": "^1.11.23",