@akanjs/devkit 3.3.0-rc.60 → 3.3.0-rc.62

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.
@@ -11,6 +11,8 @@ import { AkanAppConfig, AkanLibConfig, deriveDefaultAppId } from "./akanConfig";
11
11
  import {
12
12
  BUN_IMAGE_PIN,
13
13
  DEFAULT_DOCKER_IMAGE,
14
+ DOCKER_BASE_PACKAGES,
15
+ DOCKER_BASE_RUNS,
14
16
  DOCKER_INIT,
15
17
  DOCKERFILE_FORMAT,
16
18
  dockerfileLayoutOf,
@@ -488,6 +490,7 @@ describe("AkanAppConfig", () => {
488
490
  postRuns: ["echo post"],
489
491
  command: ["bun", "main.js"],
490
492
  crossBuild: true,
493
+ baseSetup: true,
491
494
  env: { REGION: "seoul", EDGE_MODE: "camera", AKAN_PUBLIC_OPERATION_MODE: "edge" },
492
495
  },
493
496
  });
@@ -541,6 +544,34 @@ describe("AkanAppConfig", () => {
541
544
  expect(later?.sections.get("warm")).toEqual(["RUN true"]);
542
545
  });
543
546
 
547
+ test("baseSetup false leaves the base step to the image, which then has to be named for every architecture", () => {
548
+ const configOf = (docker: object) => new AkanAppConfig(app, [], packageJson, { docker }, baseDevEnv);
549
+ const baseOf = (docker: object) => dockerfileLayoutOf(configOf(docker).dockerfile)?.sections.get("base");
550
+
551
+ expect(baseOf({})).toEqual([
552
+ `FROM ${DEFAULT_DOCKER_IMAGE}`,
553
+ `RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ${DOCKER_BASE_PACKAGES.join(" ")} && rm -rf /var/lib/apt/lists/*`,
554
+ "RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime",
555
+ "ARG TARGETARCH",
556
+ ]);
557
+ expect(baseOf({})?.slice(1, -1)).toEqual(DOCKER_BASE_RUNS.map((run) => `RUN ${run}`));
558
+ expect(baseOf({ image: "registry.example.com/akan-base:1", baseSetup: false })).toEqual([
559
+ "FROM registry.example.com/akan-base:1",
560
+ "ARG TARGETARCH",
561
+ ]);
562
+ const edge = configOf({ variants: { edge: { image: "registry.example.com/akan-base:1", baseSetup: false } } });
563
+ expect(edge.dockerfile).toContain("apt-get update");
564
+ expect(edge.dockerfileFor("main", { variant: "edge" })).not.toContain("apt-get");
565
+
566
+ expect(() => configOf({ baseSetup: false })).toThrow("docker.baseSetup is false, so docker.image has to name");
567
+ expect(() => configOf({ baseSetup: false, image: { amd64: "registry.example.com/akan-base:1" } })).toThrow(
568
+ "for every architecture",
569
+ );
570
+ expect(() => configOf({ variants: { edge: { baseSetup: false } } })).toThrow(
571
+ "docker.variants.edge.baseSetup is false",
572
+ );
573
+ });
574
+
544
575
  test("the akanConfig entry carries the generator, for a tool that checks its edits against the installed one", async () => {
545
576
  const entry = await import("./index");
546
577
  expect(entry.dockerfileOf).toBe(dockerfileOf);
@@ -568,6 +599,7 @@ describe("AkanAppConfig", () => {
568
599
  postRuns: [],
569
600
  command: ["bun", "main.js"],
570
601
  crossBuild: false,
602
+ baseSetup: true,
571
603
  env: {},
572
604
  });
573
605
  });
@@ -19,6 +19,12 @@ export const DEFAULT_DOCKER_IMAGE = `oven/bun:${BUN_IMAGE_PIN.version}-slim@${BU
19
19
  export const DOCKER_RUN_USER = "1000:1000";
20
20
  //? Bun as PID 1 never waits for a process re-parented to it, which stays defunct; `-s` reaps under another init too.
21
21
  export const DOCKER_INIT = ["tini", "-s", "--"];
22
+ export const DOCKER_BASE_PACKAGES = ["ca-certificates", "tzdata", "tini"] as const;
23
+ //? Every generated image runs these on its base; an image built with them is one `baseSetup: false` can start from.
24
+ export const DOCKER_BASE_RUNS = [
25
+ `apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ${DOCKER_BASE_PACKAGES.join(" ")} && rm -rf /var/lib/apt/lists/*`,
26
+ "ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime",
27
+ ];
22
28
  //? The directories the server writes, its code staying read-only; an empty named volume mounted on one takes its owner.
23
29
  export const DOCKER_WRITE_DIRS = [
24
30
  "/workspace/sqlite",
@@ -100,7 +106,7 @@ const dockerfileSectionOf = (section: DockerfileSection, instructions: string[])
100
106
  instructions.length ? [`${DOCKERFILE_MARK}${section}`, ...instructions] : [];
101
107
 
102
108
  export const dockerfileOf = (docker: DockerImageConfig, { env, lockfile, guard }: DockerfileParts) => {
103
- const { image, preRuns, postRuns, command, crossBuild } = docker;
109
+ const { image, preRuns, postRuns, command, crossBuild, baseSetup } = docker;
104
110
  const install = dockerInstallScripts(docker, lockfile);
105
111
  return [
106
112
  `${DOCKERFILE_HEAD}${DOCKERFILE_FORMAT}`,
@@ -118,8 +124,7 @@ export const dockerfileOf = (docker: DockerImageConfig, { env, lockfile, guard }
118
124
  ...dockerfileSectionOf("base", [
119
125
  dockerImageScript(image),
120
126
  ...(guard ? [guard] : []),
121
- "RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends ca-certificates tzdata tini && rm -rf /var/lib/apt/lists/*",
122
- "RUN ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime",
127
+ ...(baseSetup ? dockerRunScripts(DOCKER_BASE_RUNS) : []),
123
128
  "ARG TARGETARCH",
124
129
  ]),
125
130
  ...dockerfileSectionOf("pre-runs", dockerRunScripts(preRuns)),
@@ -173,29 +178,37 @@ const dockerVariantNamePattern = /^[a-z][a-z0-9-]*$/;
173
178
  const resolveDockerImage = (
174
179
  docker: Partial<DockerImageConfig>,
175
180
  libDocker: LibDockerConfig,
176
- envOwner: string,
181
+ owner: string,
177
182
  ): DockerImageConfig => {
178
183
  const env = docker.env ?? {};
179
184
  for (const [key, value] of Object.entries(env)) {
180
185
  if (!dockerEnvKeyPattern.test(key))
181
- throw new Error(`[docker] ${envOwner} names "${key}", which is not an environment variable name`);
186
+ throw new Error(`[docker] ${owner}.env names "${key}", which is not an environment variable name`);
182
187
  if (/[\r\n]/.test(value))
183
- throw new Error(`[docker] ${envOwner}.${key} holds a line break, which an ENV line cannot carry`);
188
+ throw new Error(`[docker] ${owner}.env.${key} holds a line break, which an ENV line cannot carry`);
184
189
  }
190
+ const { image } = docker;
191
+ const baseSetup = docker.baseSetup ?? true;
192
+ //? The pinned default has no tini, the entrypoint: an image skipping the base step without one never starts.
193
+ if (!baseSetup && (!image || (typeof image !== "string" && archs.some((arch) => !image[arch]))))
194
+ throw new Error(
195
+ `[docker] ${owner}.baseSetup is false, so ${owner}.image has to name an image built with the base step, for every architecture`,
196
+ );
185
197
  return {
186
- image: docker.image ?? DEFAULT_DOCKER_IMAGE,
198
+ image: image ?? DEFAULT_DOCKER_IMAGE,
187
199
  preRuns: dedupeDockerRuns([...libDocker.preRuns, ...(docker.preRuns ?? [])]),
188
200
  installRuns: dedupeDockerRuns([...libDocker.installRuns, ...(docker.installRuns ?? [])]),
189
201
  postRuns: dedupeDockerRuns([...libDocker.postRuns, ...(docker.postRuns ?? [])]),
190
202
  command: docker.command ?? ["bun", "main.js"],
191
203
  crossBuild: docker.crossBuild ?? false,
204
+ baseSetup,
192
205
  env,
193
206
  };
194
207
  };
195
208
 
196
209
  /** A declared Dockerfile string is verbatim, so a lib's steps are dropped rather than silently unapplied. */
197
210
  export const resolveDocker = (docker: DockerOption | undefined, libDocker: LibDockerConfig): DockerConfig =>
198
- typeof docker === "string" ? docker : resolveDockerImage(docker ?? {}, libDocker, "docker.env");
211
+ typeof docker === "string" ? docker : resolveDockerImage(docker ?? {}, libDocker, "docker");
199
212
 
200
213
  export const resolveDockerVariants = (
201
214
  docker: DockerOption | undefined,
@@ -210,7 +223,7 @@ export const resolveDockerVariants = (
210
223
  `[docker] docker.variants names "${name}", which cannot end a file name: use lowercase letters, digits and "-"`,
211
224
  );
212
225
  const env = { ...base.env, ...variant.env };
213
- return [name, resolveDockerImage({ ...base, ...variant, env }, libDocker, `docker.variants.${name}.env`)];
226
+ return [name, resolveDockerImage({ ...base, ...variant, env }, libDocker, `docker.variants.${name}`)];
214
227
  }),
215
228
  );
216
229
  };
@@ -73,15 +73,22 @@ File names, stages, the `.render()` order and what a route file must never do ar
73
73
  locale under `i18n.localePrefix: "as-needed"`. It renders an `<a>` and takes its attributes; `activeClassName`
74
74
  marks the current one from the press, before its page arrives; an `active` prop from a layout's render is late.
75
75
  - An SSR page still loading: `pendingClassName` / `data-pending` on its `Link`, and `usePendingNavigation()`
76
- (`akanjs/client`) for its `{ path, searchParams }`, `null` once the page is drawn.
76
+ (`akanjs/client`) for its `{ path, searchParams }`, `null` once the page is drawn and for a page already held.
77
77
  - From a handler: `router.push(href)` / `router.replace(href)`; in a server stage, `router.redirect(href)`.
78
78
  - A page state a push opens in the query (a record in `?id=`): close it with `router.backOrReplace(href)`, never
79
79
  `router.back()` or a `renderMode` branch. A CSR or native stack rewrites a push that keeps the pathname rather than
80
80
  stacking it, and the address may be opened directly.
81
- - A client filter kept in the URL without reloading the page: ``router.replace(`/books?q=${q}`, { shallow: true,
82
- scrollToTop: false })`` in a `"use client"` component, read back with `usePageLocation().searchParams`, which
83
- follows the replace and the back and forward buttons. Shallow holds only while the path stays the same; a server
84
- `.search()` sees the value at the next full navigation.
81
+ - A client filter kept in the URL without reloading the page: the URL is the state, in a `"use client"` component.
82
+
83
+ ```tsx
84
+ const { searchParams } = usePageLocation(); // akanjs/webkit
85
+ const genre = typeof searchParams.genre === "string" ? searchParams.genre : "all";
86
+ const setGenre = (next: string) => router.replace(`/books?genre=${next}`, { shallow: true, scrollToTop: false });
87
+ ```
88
+
89
+ `searchParams` follows the replace and the back and forward buttons. Never keep the filter in `useState`: a shallow
90
+ back draws no page, so the copy stays on the old value while the URL moves. Shallow holds only while the path stays
91
+ the same; a server `.search()` sees the value at the next full navigation.
85
92
  - On a web page's first render `st.use.searchParams()` is still the server's empty snapshot, synced right after
86
93
  hydration, so an effect that needs the query on its first run takes the page's `.search()` value as a prop.
87
94
  - A `Link` renders its page ahead of the click, guards included: on hover, on keyboard focus, or as it shows with
@@ -15,7 +15,7 @@ the agent guide's Path Rules table.
15
15
  | --- | --- |
16
16
  | API only, or no CSR bundle for native apps | `web: false`, `web: { csr: false }` |
17
17
  | Move the API or websocket mount | `new AkanApp({ prefix, websocketPrefix })` in `main.ts`, mirrored in `api: { … }`; read with `getApiPrefix()` / `getWsPrefix()` |
18
- | The production image | `docker: string \| { image, preRuns, installRuns, postRuns, command, crossBuild, env, variants }` |
18
+ | The production image | `docker: string \| { image, preRuns, installRuns, postRuns, command, crossBuild, baseSetup, env, variants }` |
19
19
  | iOS, Android, desktop | the `native` section; `desktop: { server: true }` carries the server |
20
20
  | SQLite, several databases, a cluster | `database: { modes: [...] }` (`single`, `multiple`, `cluster`), picked by `AKAN_DATABASE_MODE` |
21
21
  | A secret of `env/env.server.<env>.ts` in a deployed server | nothing to declare: `akan build` leaves it out and the server reads it from a variable named after its key path; `akan secret-env <app> --env <env>` lists them |
@@ -28,6 +28,16 @@ describe("ApiReference", () => {
28
28
  expect(rendered).toMatch(/^\/\*\* .+ \*\/\nserverMode\?: "batch" \| "federation";$/m);
29
29
  });
30
30
 
31
+ test("says under an entry what its signature cannot: a search is always optional, an adaptor has a logger and hooks", () => {
32
+ expect(rendered).toMatch(/^\.search<.+option\?: Omit<EndpointArgProps, "nullable">\)$/m);
33
+ expect(rendered).toMatch(
34
+ /^```\n\n`\.search\(\)` is always optional and takes no `nullable`: .+`T \| undefined`\./m,
35
+ );
36
+ expect(rendered).toMatch(
37
+ /^```\n\nA class extending `adapt\(name\)` has `this\.logger`; .+`onInit\(\)` .+`onDestroy\(\)` .+\.$/m,
38
+ );
39
+ });
40
+
31
41
  test("says what each listed subpath holds, and lists only subpaths the package exports", async () => {
32
42
  const exports = Object.keys((await Bun.file(path.join(akanjsDir, "package.json")).json()).exports);
33
43
  const listed = [...rendered.matchAll(/^- `akanjs\/([^`]+)` — .+\.$/gm)].map(([, subpath]) => `./${subpath}`);
@@ -12,6 +12,7 @@ interface Item {
12
12
  from?: string;
13
13
  file?: string;
14
14
  show: Show;
15
+ note?: string;
15
16
  }
16
17
 
17
18
  interface Section {
@@ -58,7 +59,12 @@ const sections: Section[] = [
58
59
  {
59
60
  title: "Services and adapters (`lib/_<service>/`, `srvkit/`)",
60
61
  items: [
61
- { name: "adapt", from: "akanjs/service", show: { kind: "signature" } },
62
+ {
63
+ name: "adapt",
64
+ from: "akanjs/service",
65
+ show: { kind: "signature" },
66
+ note: "A class extending `adapt(name)` has `this.logger`; the server awaits its `onInit()` before the app serves and its `onDestroy()` when it stops.",
67
+ },
62
68
  { name: "serve", from: "akanjs/service", show: { kind: "signature" } },
63
69
  { name: "ServiceOptions", file: "service/serve.ts", show: { kind: "props" } },
64
70
  ],
@@ -74,6 +80,7 @@ const sections: Section[] = [
74
80
  name: "EndpointInfo",
75
81
  file: "signal/endpointInfo.ts",
76
82
  show: { kind: "members", only: ["param", "search", "body", "room", "msg", "with", "exec"] },
83
+ note: "`.search()` is always optional and takes no `nullable`: the caller may omit it or pass `null`, and the handler gets `T | undefined`.",
77
84
  },
78
85
  { name: "EndpointArgProps", file: "signal/endpointInfo.ts", show: { kind: "props" } },
79
86
  {
@@ -194,18 +201,19 @@ export class ApiReference {
194
201
  const symbol = item.from ? reader.exported(item.from, item.name) : reader.declared(item.file ?? "", item.name);
195
202
  const where = item.from ? ` · \`${item.from}\`` : "";
196
203
  const heading = `### \`${item.name}\`${where}`;
204
+ const note = item.note ? ["", item.note] : [];
197
205
  if (item.show.kind === "declaration")
198
- return [heading, "", "```ts", reader.declarationText(symbol), "```"].join("\n");
206
+ return [heading, "", "```ts", reader.declarationText(symbol), "```", ...note].join("\n");
199
207
  if (item.show.kind === "signature")
200
- return [heading, "", "```ts", ...reader.signatures(symbol, item.name), "```"].join("\n");
208
+ return [heading, "", "```ts", ...reader.signatures(symbol, item.name), "```", ...note].join("\n");
201
209
  if (item.show.kind === "props") {
202
210
  const bases = reader.foreignBases(symbol).map((base) => `\`${base}\``);
203
211
  const inherits = bases.length ? ["", `Every prop of ${bases.join(" and ")}, and:`] : [];
204
212
  const props = reader.props(reader.declaredType(symbol), item.show.omit);
205
- return [heading, ...inherits, "", "```ts", ...props, "```"].join("\n");
213
+ return [heading, ...inherits, "", "```ts", ...props, "```", ...note].join("\n");
206
214
  }
207
215
  const members = reader.members(reader.instanceType(symbol), item.show);
208
- return [heading, "", "```ts", ...members.map(([, line]) => line), "```"].join("\n");
216
+ return [heading, "", "```ts", ...members.map(([, line]) => line), "```", ...note].join("\n");
209
217
  }
210
218
 
211
219
  static #routeStages(reader: DeclarationReader): string {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akanjs/devkit",
3
- "version": "3.3.0-rc.60",
3
+ "version": "3.3.0-rc.62",
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.60",
53
+ "@akanjs/language": "3.3.0-rc.62",
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.60",
62
+ "akanjs": "3.3.0-rc.62",
63
63
  "chalk": "^6.0.1",
64
64
  "commander": "^15.0.0",
65
65
  "dayjs": "^1.11.23",