@akanjs/devkit 3.0.0-alpha.95 → 3.0.0-alpha.96

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.
@@ -1,5 +1,6 @@
1
1
  import { describe, expect, test } from "bun:test";
2
- import { AKAN_OPTIONAL_BACKEND_EXTERNALS } from "./applicationBuildRunner";
2
+ import { rm } from "node:fs/promises";
3
+ import { AKAN_BACKEND_MINIFY, AKAN_OPTIONAL_BACKEND_EXTERNALS } from "./applicationBuildRunner";
3
4
 
4
5
  describe("ApplicationBuildRunner", () => {
5
6
  test("externalizes Akan optional backend dependencies", () => {
@@ -7,4 +8,38 @@ describe("ApplicationBuildRunner", () => {
7
8
  expect.arrayContaining(["@libsql/client", "bullmq", "ioredis", "postgres", "protobufjs"]),
8
9
  );
9
10
  });
11
+
12
+ test("keeps backend identifiers so a class names its own logger and stack frames", () => {
13
+ expect(AKAN_BACKEND_MINIFY.identifiers).toBe(false);
14
+ expect(AKAN_BACKEND_MINIFY.whitespace).toBe(true);
15
+ expect(AKAN_BACKEND_MINIFY.syntax).toBe(true);
16
+ });
17
+
18
+ test("a bundler that mangles identifiers loses the class name a Logger reads", async () => {
19
+ const dir = `${process.env.TMPDIR ?? "/tmp"}/akan-minify-${Bun.randomUUIDv7()}`;
20
+ const entry = `${dir}/entry.ts`;
21
+ await Bun.write(
22
+ entry,
23
+ `const serve = () => class Service { readonly name = this.constructor.name; };
24
+ export class SampleService extends serve() {}
25
+ console.info(new SampleService().name);
26
+ `,
27
+ );
28
+ const build = async (minify: Bun.BuildConfig["minify"]) => {
29
+ const result = await Bun.build({ entrypoints: [entry], target: "bun", minify, outdir: `${dir}/out` });
30
+ expect(result.success).toBe(true);
31
+ const proc = Bun.spawn([process.execPath, result.outputs[0].path], { stdout: "pipe" });
32
+ return (await new Response(proc.stdout).text()).trim();
33
+ };
34
+ try {
35
+ expect(await build(AKAN_BACKEND_MINIFY)).toBe("SampleService");
36
+ expect(await build(true)).not.toBe("SampleService");
37
+ // Bun 1.4.2 accepts `keepNames` and ignores it; drop this expectation once it keeps the name.
38
+ expect(await build({ whitespace: true, syntax: true, identifiers: true, keepNames: true })).not.toBe(
39
+ "SampleService",
40
+ );
41
+ } finally {
42
+ await rm(dir, { recursive: true, force: true });
43
+ }
44
+ });
10
45
  });
@@ -60,6 +60,11 @@ const SSR_RENDER_EXTERNALS = [
60
60
  "react-server-dom-webpack/client.browser",
61
61
  ] as const;
62
62
 
63
+ // Identifier mangling renames every class, and `this.constructor.name` is what names a service's logger, an
64
+ // `Exception`, a guard, and every frame of a stack trace — for ~2% of boot on server bytes nothing downloads.
65
+ // `minify.keepNames` typechecks and does nothing as of Bun 1.4.2.
66
+ export const AKAN_BACKEND_MINIFY = { whitespace: true, syntax: true, identifiers: false } as const;
67
+
63
68
  export const AKAN_OPTIONAL_BACKEND_EXTERNALS = [
64
69
  "@libsql/client",
65
70
  "bullmq",
@@ -68,16 +73,6 @@ export const AKAN_OPTIONAL_BACKEND_EXTERNALS = [
68
73
  "protobufjs",
69
74
  ] as const;
70
75
 
71
- const MINIFY_PROBE = ((): { minify: Bun.BuildConfig["minify"]; sourcemap?: Bun.BuildConfig["sourcemap"] } => {
72
- const mode = process.env.AKAN_MINIFY_PROBE ?? "all";
73
- if (mode === "noident") return { minify: { whitespace: true, syntax: true, identifiers: false } };
74
- if (mode === "noident-map")
75
- return { minify: { whitespace: true, syntax: true, identifiers: false }, sourcemap: "linked" };
76
- if (mode === "syntax-map") return { minify: { whitespace: false, syntax: true, identifiers: false }, sourcemap: "linked" };
77
- if (mode === "none") return { minify: false, sourcemap: "linked" };
78
- return { minify: true };
79
- })();
80
-
81
76
  export class ApplicationBuildRunner {
82
77
  #app: App;
83
78
  #fast: boolean;
@@ -213,7 +208,7 @@ export class ApplicationBuildRunner {
213
208
  entrypoints: backendEntryPoints,
214
209
  outdir: this.#app.dist.cwdPath,
215
210
  target: "bun",
216
- ...MINIFY_PROBE,
211
+ minify: AKAN_BACKEND_MINIFY,
217
212
  naming: { entry: "[name].[ext]", chunk: "chunk-[hash].[ext]" },
218
213
  define: { "process.env.NODE_ENV": JSON.stringify("production") },
219
214
  plugins: backendExternals.length > 0 ? [this.#createExternalSpecifiersPlugin(backendExternals)] : [],
@@ -224,7 +219,7 @@ export class ApplicationBuildRunner {
224
219
  entrypoints: [this.#resolveRscWorkerBuildEntry()],
225
220
  outdir: this.#app.dist.cwdPath,
226
221
  target: "bun",
227
- ...MINIFY_PROBE,
222
+ minify: AKAN_BACKEND_MINIFY,
228
223
  naming: { entry: "[name].[ext]", chunk: "chunk-[hash].[ext]" },
229
224
  conditions: ["react-server"],
230
225
  // `akan build` must embed production react-server-dom regardless of the shell's NODE_ENV.
@@ -236,7 +231,7 @@ export class ApplicationBuildRunner {
236
231
  entrypoints: [this.#resolveConsoleRuntimeBuildEntry()],
237
232
  outdir: this.#app.dist.cwdPath,
238
233
  target: "bun",
239
- ...MINIFY_PROBE,
234
+ minify: AKAN_BACKEND_MINIFY,
240
235
  naming: { entry: "console-runtime.[ext]", chunk: "chunk-[hash].[ext]" },
241
236
  define: { "process.env.NODE_ENV": JSON.stringify("production") },
242
237
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.0.0-alpha.95",
3
+ "version": "3.0.0-alpha.96",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -44,7 +44,7 @@
44
44
  "@langchain/openai": "^1.4.6",
45
45
  "@tailwindcss/node": "^4.3.0",
46
46
  "@trapezedev/project": "^7.1.4",
47
- "akanjs": "3.0.0-alpha.95",
47
+ "akanjs": "3.0.0-alpha.96",
48
48
  "chalk": "^5.6.2",
49
49
  "commander": "^14.0.3",
50
50
  "dayjs": "^1.11.20",