@cosmicdrift/kumiko-dev-server 0.328.1 → 0.330.0

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.
Files changed (125) hide show
  1. package/README.md +17 -0
  2. package/bin/kumiko-build.ts +3 -2
  3. package/bin/kumiko-dev.ts +1 -1
  4. package/bin/kumiko-init-deploy.ts +1 -1
  5. package/bin/kumiko-schema-check.ts +4 -1
  6. package/dist/build-server-bundle.d.ts +31 -0
  7. package/dist/build-server-bundle.js +282 -0
  8. package/dist/build.d.ts +2 -0
  9. package/dist/build.js +5 -0
  10. package/dist/cli.d.ts +5 -0
  11. package/dist/cli.js +9 -0
  12. package/dist/codegen/index.d.ts +4 -0
  13. package/dist/codegen/index.js +4 -0
  14. package/dist/codegen/render.d.ts +55 -0
  15. package/dist/codegen/render.js +273 -0
  16. package/dist/codegen/run-codegen.d.ts +20 -0
  17. package/dist/codegen/run-codegen.js +219 -0
  18. package/dist/codegen/scan-events.d.ts +76 -0
  19. package/dist/codegen/scan-events.js +447 -0
  20. package/dist/codegen/watch.d.ts +33 -0
  21. package/dist/codegen/watch.js +112 -0
  22. package/dist/compose-stacks.d.ts +60 -0
  23. package/dist/compose-stacks.js +127 -0
  24. package/dist/crash-tracker.d.ts +17 -0
  25. package/dist/crash-tracker.js +37 -0
  26. package/dist/create-kumiko-server.d.ts +195 -0
  27. package/dist/create-kumiko-server.js +1040 -0
  28. package/dist/env-schema.d.ts +15 -0
  29. package/dist/env-schema.js +60 -0
  30. package/dist/few-shot-corpus.d.ts +72 -0
  31. package/dist/few-shot-corpus.js +262 -0
  32. package/dist/framework-version.d.ts +1 -0
  33. package/dist/framework-version.js +31 -0
  34. package/dist/index.d.ts +22 -0
  35. package/dist/index.js +33 -0
  36. package/dist/init-deploy-cli.d.ts +10 -0
  37. package/dist/init-deploy-cli.js +111 -0
  38. package/dist/kebab.d.ts +1 -0
  39. package/{src/kebab.ts → dist/kebab.js} +2 -3
  40. package/dist/run-dev-app.d.ts +174 -0
  41. package/dist/run-dev-app.js +403 -0
  42. package/dist/scaffold-app-feature.d.ts +16 -0
  43. package/dist/scaffold-app-feature.js +240 -0
  44. package/dist/scaffold-app.d.ts +45 -0
  45. package/dist/scaffold-app.js +852 -0
  46. package/dist/scaffold-demo-tasks.d.ts +8 -0
  47. package/{src/scaffold-demo-tasks.ts → dist/scaffold-demo-tasks.js} +69 -98
  48. package/dist/scaffold-deploy.d.ts +92 -0
  49. package/dist/scaffold-deploy.js +254 -0
  50. package/dist/scaffold-feature.d.ts +26 -0
  51. package/dist/scaffold-feature.js +163 -0
  52. package/dist/schema-apply.d.ts +11 -0
  53. package/dist/schema-apply.js +95 -0
  54. package/dist/schema-check-core.d.ts +2 -0
  55. package/{src/schema-check-core.ts → dist/schema-check-core.js} +8 -10
  56. package/dist/schema-tables-auth-mode.d.ts +2 -0
  57. package/{src/schema-tables-auth-mode.ts → dist/schema-tables-auth-mode.js} +2 -10
  58. package/dist/schema-tables-minimal.d.ts +2 -0
  59. package/{src/schema-tables-minimal.ts → dist/schema-tables-minimal.js} +2 -11
  60. package/dist/setup-test-stack-from-features.d.ts +11 -0
  61. package/dist/setup-test-stack-from-features.js +42 -0
  62. package/dist/welcome-banner.d.ts +15 -0
  63. package/dist/welcome-banner.js +27 -0
  64. package/package.json +71 -24
  65. package/src/changes.json +6 -0
  66. package/src/__tests__/build-prod-bundle.integration.test.ts +0 -282
  67. package/src/__tests__/build-server-bundle.test.ts +0 -228
  68. package/src/__tests__/classify-change.test.ts +0 -87
  69. package/src/__tests__/compose-stacks.test.ts +0 -273
  70. package/src/__tests__/config-resolver-default.integration.test.ts +0 -165
  71. package/src/__tests__/crash-tracker.test.ts +0 -89
  72. package/src/__tests__/create-kumiko-server-errors.test.ts +0 -54
  73. package/src/__tests__/create-kumiko-server-options.test.ts +0 -33
  74. package/src/__tests__/create-kumiko-server.integration.test.ts +0 -1007
  75. package/src/__tests__/discover-format.test.ts +0 -32
  76. package/src/__tests__/env-schema.integration.test.ts +0 -248
  77. package/src/__tests__/env-schema.test.ts +0 -132
  78. package/src/__tests__/few-shot-corpus.test.ts +0 -316
  79. package/src/__tests__/framework-version.test.ts +0 -45
  80. package/src/__tests__/init-deploy-cli.test.ts +0 -113
  81. package/src/__tests__/kumiko-schema-check.test.ts +0 -56
  82. package/src/__tests__/merge-extra-context.test.ts +0 -67
  83. package/src/__tests__/resolve-stylesheet.test.ts +0 -132
  84. package/src/__tests__/run-dev-app-boot-validation.test.ts +0 -38
  85. package/src/__tests__/run-dev-app.integration.test.ts +0 -290
  86. package/src/__tests__/runtime-classification.test.ts +0 -26
  87. package/src/__tests__/saas-identity-wire.integration.test.ts +0 -427
  88. package/src/__tests__/scaffold-app-feature.test.ts +0 -216
  89. package/src/__tests__/scaffold-app.test.ts +0 -630
  90. package/src/__tests__/scaffold-demo-tasks.test.ts +0 -47
  91. package/src/__tests__/scaffold-deploy.test.ts +0 -464
  92. package/src/__tests__/scaffold-dev-cycle.integration.test.ts +0 -109
  93. package/src/__tests__/scaffold-feature.test.ts +0 -143
  94. package/src/__tests__/schema-apply.integration.test.ts +0 -191
  95. package/src/__tests__/setup-test-stack-from-features.integration.test.ts +0 -30
  96. package/src/__tests__/setup-test-stack-job-run-logger.integration.test.ts +0 -72
  97. package/src/__tests__/walkthrough.integration.test.ts +0 -140
  98. package/src/__tests__/welcome-banner.test.ts +0 -42
  99. package/src/build-server-bundle.ts +0 -346
  100. package/src/build.ts +0 -28
  101. package/src/codegen/__tests__/render-codegen.test.ts +0 -100
  102. package/src/codegen/__tests__/run-codegen.test.ts +0 -665
  103. package/src/codegen/__tests__/strict-mode-diagnostics.test.ts +0 -347
  104. package/src/codegen/__tests__/watch.test.ts +0 -222
  105. package/src/codegen/index.ts +0 -19
  106. package/src/codegen/render.ts +0 -305
  107. package/src/codegen/run-codegen.ts +0 -278
  108. package/src/codegen/scan-events.ts +0 -565
  109. package/src/codegen/watch.ts +0 -140
  110. package/src/compose-stacks.ts +0 -193
  111. package/src/crash-tracker.ts +0 -56
  112. package/src/create-kumiko-server.ts +0 -1397
  113. package/src/env-schema.ts +0 -72
  114. package/src/few-shot-corpus.ts +0 -370
  115. package/src/framework-version.ts +0 -39
  116. package/src/index.ts +0 -105
  117. package/src/init-deploy-cli.ts +0 -148
  118. package/src/run-dev-app.ts +0 -694
  119. package/src/scaffold-app-feature.ts +0 -283
  120. package/src/scaffold-app.ts +0 -1033
  121. package/src/scaffold-deploy.ts +0 -393
  122. package/src/scaffold-feature.ts +0 -226
  123. package/src/schema-apply.ts +0 -123
  124. package/src/setup-test-stack-from-features.ts +0 -80
  125. package/src/welcome-banner.ts +0 -43
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @cosmicdrift/kumiko-dev-server
2
+
3
+ Dev tooling for Kumiko apps: local dev server (`runDevApp`), scaffolding and codegen, plus the `kumiko-*` build and schema commands.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ bun add @cosmicdrift/kumiko-dev-server
9
+ ```
10
+
11
+ ```ts
12
+ import { runDevApp } from "@cosmicdrift/kumiko-dev-server";
13
+ ```
14
+
15
+ Bun is required for the bundled commands.
16
+
17
+ Documentation: https://kumiko.rocks
@@ -23,12 +23,13 @@ import {
23
23
  buildServerBundle,
24
24
  discoverServerEntry,
25
25
  formatBuildResult,
26
+ formatScanWarning,
26
27
  formatServerBuildResult,
27
28
  readClientEntriesConfig,
28
29
  readExtraRuntimeExternals,
29
30
  resolveClientEntries,
30
- } from "../src/build";
31
- import { formatScanWarning, runCodegen } from "../src/codegen";
31
+ runCodegen,
32
+ } from "@cosmicdrift/kumiko-dev-server/cli";
32
33
 
33
34
  const explicit = process.argv[2];
34
35
  const cwd = explicit ? resolve(process.cwd(), explicit) : process.cwd();
package/bin/kumiko-dev.ts CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  import { spawn } from "node:child_process";
21
21
  import process from "node:process";
22
- import { createCrashTracker } from "../src/crash-tracker";
22
+ import { createCrashTracker } from "@cosmicdrift/kumiko-dev-server/cli";
23
23
 
24
24
  const SCHEMA_RESTART_EXIT_CODE = 75;
25
25
  const MAX_CRASHES = 5;
@@ -7,7 +7,7 @@
7
7
  // bunx kumiko-init-deploy --app <name> [--port <n>] [--github-org <org>] [--out <dir>] [--force]
8
8
  // bunx kumiko-init-deploy --check # drift check, exit 1 if deploy/ is stale
9
9
 
10
- import { runInitDeployCli } from "../src/init-deploy-cli";
10
+ import { runInitDeployCli } from "@cosmicdrift/kumiko-dev-server/cli";
11
11
 
12
12
  // Only run when executed as a CLI, not when imported (e.g. from tests that
13
13
  // exercise runInitDeployCli directly).
@@ -25,7 +25,10 @@
25
25
 
26
26
  import { existsSync, readFileSync } from "node:fs";
27
27
  import { resolve } from "node:path";
28
- import { implicitAuthModeFeatureNames, resolveGeneratePath } from "../src/schema-check-core";
28
+ import {
29
+ implicitAuthModeFeatureNames,
30
+ resolveGeneratePath,
31
+ } from "@cosmicdrift/kumiko-dev-server/cli";
29
32
 
30
33
  type Args = {
31
34
  readonly runConfigPath: string;
@@ -0,0 +1,31 @@
1
+ export type BuildServerBundleOptions = {
2
+ /** App-Root. Default: process.cwd(). */
3
+ readonly cwd?: string;
4
+ /** Output-Folder relativ zu cwd. Default: "dist-server". */
5
+ readonly outDir?: string;
6
+ /** Zusätzliche Pakete die zur Laufzeit installiert sein müssen
7
+ * (beyond RUNTIME_EXTERNALS). App-spezifisch — Default leer. */
8
+ readonly extraRuntimeExternals?: readonly string[];
9
+ /** Zusätzliche Build-only-Externals. App-spezifisch — Default leer. */
10
+ readonly extraBuildOnlyExternals?: readonly string[];
11
+ };
12
+ export type BuildServerBundleEntry = {
13
+ readonly file: string;
14
+ readonly sizeBytes: number;
15
+ };
16
+ export type BuildServerBundleResult = {
17
+ readonly outDir: string;
18
+ /** Benannte Entry-Files (server.js, ggf. kumiko.js). */
19
+ readonly entries: readonly BuildServerBundleEntry[];
20
+ /** Geteilte Framework-Chunks (von splitting). */
21
+ readonly chunks: readonly BuildServerBundleEntry[];
22
+ /** Gesamt-Größe aller Outputs (entries + chunks) in Bytes. */
23
+ readonly totalBytes: number;
24
+ readonly runtimeDeps: Readonly<Record<string, string>>;
25
+ };
26
+ export declare function buildServerBundle(options?: BuildServerBundleOptions): Promise<BuildServerBundleResult>;
27
+ export declare function discoverServerEntry(cwd: string): string | undefined;
28
+ /** Read `package.json#kumiko.extraRuntimeExternals` for kumiko-build (#1484).
29
+ * Invalid / missing shapes → empty list (CLI stays convention-driven). */
30
+ export declare function readExtraRuntimeExternals(cwd: string): readonly string[];
31
+ export declare function formatServerBuildResult(result: BuildServerBundleResult, durationMs: number): string;
@@ -0,0 +1,282 @@
1
+ // buildServerBundle — Production-Server-Bundle für Kumiko-Apps. Pendant zu
2
+ // buildProdBundle (Client). Convention-Driven Discovery liest bin/main.ts
3
+ // (+ optional <repo>/bin/kumiko.ts) und produziert ein runtime-self-contained
4
+ // dist-server/ aus dem ein Bun-Alpine-Container ohne Monorepo bootet.
5
+ //
6
+ // Convention:
7
+ //
8
+ // bin/main.ts → dist-server/server.js (App-Boot, ruft runProdApp)
9
+ // <repo>/bin/kumiko.ts → dist-server/kumiko.js (Migrate-CLI: `schema apply`,
10
+ // gefunden via walk-up bis bin/kumiko.ts)
11
+ // dist-server/package.json → runtime-deps mit gepinnten Versionen
12
+ //
13
+ // Beide Entries werden in EINEM Bun.build-Call mit `splitting` gebaut: das
14
+ // Framework landet als geteilte chunk-*.js, server.js + kumiko.js sind schlanke
15
+ // Entries die sie importieren — statt das Framework pro Entry neu zu inlinen
16
+ // (vorher ~14 MB × N separate Bundles).
17
+ //
18
+ // Output:
19
+ //
20
+ // dist-server/
21
+ // server.js ← App-Boot-Entry
22
+ // kumiko.js ← Migrate-CLI-Entry (wenn bin/kumiko.ts gefunden)
23
+ // chunk-*.js ← geteilte Framework-Chunks
24
+ // package.json ← runtime-deps mit gepinnten Versionen
25
+ //
26
+ // Externals — Pakete die NICHT ins Bundle gebakt werden, sondern via
27
+ // `bun install` im Runtime-Container nachgeholt werden:
28
+ //
29
+ // RUNTIME_EXTERNALS — wird zur Laufzeit gebraucht (native bindings,
30
+ // worker-threads, dynamic-require). Landet in
31
+ // dist-server/package.json#dependencies.
32
+ //
33
+ // BUILD_ONLY_EXTERNALS — referenziert nur transitiv im Framework, vom
34
+ // App-Code aber nie. Tree-Shake wirft sie aus dem
35
+ // Bundle, der external-Marker schaltet nur das
36
+ // resolution-during-build ab. NICHT in runtime-deps.
37
+ import { existsSync, readFileSync, statSync } from "node:fs";
38
+ import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
39
+ import { dirname, join, resolve } from "node:path";
40
+ import { parseJsonOrThrow, parseJsonSafe } from "@cosmicdrift/kumiko-framework/utils";
41
+ const hasBun = typeof globalThis.Bun !== "undefined";
42
+ // Pakete die das Bundle zur Laufzeit weiter referenziert (`from "<pkg>"` nach
43
+ // Tree-Shake). Native bindings (argon2), worker-thread-Loader (bullmq,
44
+ // ioredis), dynamic-require (postgres, temporal-polyfill) — alles was unter
45
+ // Bun-bundling bricht. (drizzle-kit/drizzle-orm sind raus: der Migrate-Pfad
46
+ // nutzt jetzt den framework-eigenen runMigrationsFromDir, kein drizzle-kit.)
47
+ // meilisearch: deliberately here, not in BUILD_ONLY_EXTERNALS below — apps
48
+ // that import createMeilisearchAdapter (kumiko-framework/search/meilisearch)
49
+ // reference the package at runtime (no native binding, plain HTTP client,
50
+ // but a real runtime import). Found 2026-07-19: money-horse prod crash
51
+ // "Cannot find package 'meilisearch'" because it used to sit in
52
+ // BUILD_ONLY_EXTERNALS instead.
53
+ const RUNTIME_EXTERNALS = [
54
+ "@node-rs/argon2",
55
+ "sharp",
56
+ "bullmq",
57
+ "ioredis",
58
+ "postgres",
59
+ "temporal-polyfill",
60
+ "pino",
61
+ "pino-pretty",
62
+ "meilisearch",
63
+ ];
64
+ // Pakete die nur im Build-Stack erscheinen (transitive Imports im Framework),
65
+ // aber vom App-Code nicht referenziert werden. Ohne external-Markierung
66
+ // scheitert bun build an dynamic-imports. Tree-Shake wirft sie eh aus dem
67
+ // Bundle — der Marker schaltet nur das resolution-during-build ab. NICHT in
68
+ // runtime-deps.
69
+ const BUILD_ONLY_EXTERNALS = [
70
+ "@planetscale/database",
71
+ "@libsql/client",
72
+ "better-sqlite3",
73
+ "@neondatabase/serverless",
74
+ "@vercel/postgres",
75
+ "mysql2",
76
+ // ink (kumiko-tui) hat react-devtools-core als dev-only transitive import.
77
+ "react-devtools-core",
78
+ ];
79
+ // Bun benennt Entries nach Source-Basename (bin/main.ts → main.js). server.js
80
+ // ist die Runtime-Convention; der Entry wird von nichts importiert (nur die
81
+ // chunks werden referenziert, per relativem Pfad), darum ist der Rename sicher.
82
+ const ENTRY_RENAMES = { "main.js": "server.js" };
83
+ export async function buildServerBundle(options = {}) {
84
+ if (!hasBun) {
85
+ throw new Error("buildServerBundle requires Bun runtime (Bun.build is missing).");
86
+ }
87
+ const cwd = options.cwd ?? process.cwd();
88
+ const outDir = resolve(cwd, options.outDir ?? "dist-server");
89
+ const serverEntry = discoverServerEntry(cwd);
90
+ if (!serverEntry) {
91
+ throw new Error(`[buildServerBundle] Kein bin/main.ts in ${cwd}.\n Convention: bin/main.ts ist der Server-Bootstrap.`);
92
+ }
93
+ const repoRoot = findRepoRoot(cwd);
94
+ const kumikoCli = repoRoot ? join(repoRoot, "bin/kumiko.ts") : undefined;
95
+ if (kumikoCli && !existsSync(kumikoCli)) {
96
+ throw new Error(`[buildServerBundle] Repo-Root erkannt (${repoRoot}), aber bin/kumiko.ts fehlt — kann Migrate-CLI nicht bündeln.`);
97
+ }
98
+ const externals = [
99
+ ...RUNTIME_EXTERNALS,
100
+ ...BUILD_ONLY_EXTERNALS,
101
+ ...(options.extraRuntimeExternals ?? []),
102
+ ...(options.extraBuildOnlyExternals ?? []),
103
+ ];
104
+ await rm(outDir, { recursive: true, force: true });
105
+ await mkdir(outDir, { recursive: true });
106
+ // Ein Bun.build-Call mit allen Entries + splitting → das Framework wird
107
+ // einmal als shared chunk abgelegt statt pro Entry inlined.
108
+ const entrypoints = kumikoCli ? [serverEntry, kumikoCli] : [serverEntry];
109
+ const result = await Bun.build({
110
+ entrypoints,
111
+ outdir: outDir,
112
+ target: "bun",
113
+ external: externals,
114
+ splitting: true,
115
+ sourcemap: "none",
116
+ naming: { entry: "[name].js", chunk: "chunk-[hash].js" },
117
+ minify: false,
118
+ });
119
+ if (!result.success) {
120
+ const logs = result.logs.map(String).join("\n");
121
+ throw new Error(`[buildServerBundle] build FAILED:\n${logs}`);
122
+ }
123
+ // Größe von Disk lesen, nicht aus out.size — letzteres ist für gesplittete
124
+ // Entry-Points unzuverlässig (meldet teils ~0 für den Entry-Stub).
125
+ const entries = [];
126
+ const chunks = [];
127
+ for (const out of result.outputs) {
128
+ const base = out.path.split("/").pop() ?? out.path;
129
+ if (out.kind === "entry-point") {
130
+ const desired = ENTRY_RENAMES[base] ?? base;
131
+ if (desired !== base) {
132
+ await rename(join(outDir, base), join(outDir, desired));
133
+ }
134
+ entries.push({ file: desired, sizeBytes: statSync(join(outDir, desired)).size });
135
+ }
136
+ else if (out.kind === "chunk") {
137
+ chunks.push({ file: base, sizeBytes: statSync(join(outDir, base)).size });
138
+ }
139
+ }
140
+ entries.sort((a, b) => a.file.localeCompare(b.file));
141
+ const totalBytes = [...entries, ...chunks].reduce((sum, e) => sum + e.sizeBytes, 0);
142
+ const runtimeDeps = await resolveRuntimeDepsVersions(cwd, repoRoot, [
143
+ ...RUNTIME_EXTERNALS,
144
+ ...(options.extraRuntimeExternals ?? []),
145
+ ]);
146
+ const runtimePkg = {
147
+ name: derivePkgName(cwd),
148
+ private: true,
149
+ type: "module",
150
+ scripts: { start: "bun run server.js" },
151
+ dependencies: runtimeDeps,
152
+ };
153
+ await writeFile(join(outDir, "package.json"), `${JSON.stringify(runtimePkg, null, 2)}\n`);
154
+ return { outDir, entries, chunks, totalBytes, runtimeDeps };
155
+ }
156
+ export function discoverServerEntry(cwd) {
157
+ const tsEntry = join(cwd, "bin/main.ts");
158
+ if (existsSync(tsEntry))
159
+ return tsEntry;
160
+ const jsEntry = join(cwd, "bin/main.js");
161
+ if (existsSync(jsEntry))
162
+ return jsEntry;
163
+ return undefined;
164
+ }
165
+ // Walking up vom App-cwd bis ein Verzeichnis mit `bin/kumiko.ts` gefunden wird.
166
+ // Failsafe: nach 8 Levels aufgeben — nichts gefunden, kein Repo-Root, dann
167
+ // liefert die Funktion undefined und der Caller skippt das CLI-Bundle.
168
+ function findRepoRoot(start) {
169
+ let cur = start;
170
+ for (let i = 0; i < 8; i++) {
171
+ if (existsSync(join(cur, "bin/kumiko.ts")))
172
+ return cur;
173
+ const parent = dirname(cur);
174
+ if (parent === cur)
175
+ return undefined;
176
+ cur = parent;
177
+ }
178
+ return undefined;
179
+ }
180
+ /** Read `package.json#kumiko.extraRuntimeExternals` for kumiko-build (#1484).
181
+ * Invalid / missing shapes → empty list (CLI stays convention-driven). */
182
+ export function readExtraRuntimeExternals(cwd) {
183
+ const pkgJson = join(cwd, "package.json");
184
+ if (!existsSync(pkgJson))
185
+ return [];
186
+ let raw;
187
+ try {
188
+ raw = readFileSync(pkgJson, "utf-8");
189
+ }
190
+ catch {
191
+ return [];
192
+ }
193
+ const parsed = parseJsonSafe(raw, {});
194
+ const list = parsed.kumiko?.extraRuntimeExternals;
195
+ if (!Array.isArray(list))
196
+ return [];
197
+ return list.filter((x) => typeof x === "string" && x.trim().length > 0);
198
+ }
199
+ // Versionen für RUNTIME_EXTERNALS auflösen: erst aus den installierten
200
+ // node_modules/@cosmicdrift/*-Packages (relativ zu cwd — funktioniert für
201
+ // jede Consumer-App), dann als Zusatz aus packages/framework + bundled-
202
+ // features (Workspace-Checkout des Frameworks selbst). Fallback auf "*"
203
+ // wenn keine Quelle den Namen kennt.
204
+ async function resolveRuntimeDepsVersions(cwd, repoRoot, packages) {
205
+ const out = {};
206
+ const pinSources = [
207
+ ...(repoRoot
208
+ ? [
209
+ join(repoRoot, "packages/framework/package.json"),
210
+ join(repoRoot, "packages/bundled-features/package.json"),
211
+ ]
212
+ : []),
213
+ // node_modules applied last among framework sources so installed versions
214
+ // win over the repo-root fallback (#1217).
215
+ join(cwd, "node_modules/@cosmicdrift/kumiko-framework/package.json"),
216
+ join(cwd, "node_modules/@cosmicdrift/kumiko-bundled-features/package.json"),
217
+ ];
218
+ const allDeps = {};
219
+ for (const path of pinSources) {
220
+ if (!existsSync(path))
221
+ continue;
222
+ const raw = await readFile(path, "utf-8");
223
+ const parsed = parseJsonOrThrow(raw, path);
224
+ Object.assign(allDeps, parsed.dependencies ?? {}, parsed.optionalDependencies ?? {});
225
+ }
226
+ // App package.json fills gaps only — pins extraRuntimeExternals without
227
+ // overriding framework-native pins the app may also list (#1484 / review).
228
+ const appPkg = join(cwd, "package.json");
229
+ if (existsSync(appPkg)) {
230
+ const raw = await readFile(appPkg, "utf-8");
231
+ const parsed = parseJsonOrThrow(raw, appPkg);
232
+ for (const [name, ver] of Object.entries({
233
+ ...(parsed.dependencies ?? {}),
234
+ ...(parsed.optionalDependencies ?? {}),
235
+ })) {
236
+ if (allDeps[name] === undefined)
237
+ allDeps[name] = ver;
238
+ }
239
+ }
240
+ for (const pkg of packages) {
241
+ out[pkg] = allDeps[pkg] ?? "*";
242
+ }
243
+ return out;
244
+ }
245
+ function derivePkgName(cwd) {
246
+ const pkgJson = join(cwd, "package.json");
247
+ if (!existsSync(pkgJson))
248
+ return "kumiko-app-runtime";
249
+ // existsSync/readFileSync race (deleted between the two calls) or a
250
+ // permission error must fall back like a missing file, not crash the
251
+ // build — read here too, not just the JSON.parse below.
252
+ let raw;
253
+ try {
254
+ raw = readFileSync(pkgJson, "utf-8");
255
+ }
256
+ catch {
257
+ return "kumiko-app-runtime";
258
+ }
259
+ const parsed = parseJsonSafe(raw, {});
260
+ return parsed.name ? `${parsed.name}-runtime` : "kumiko-app-runtime";
261
+ }
262
+ export function formatServerBuildResult(result, durationMs) {
263
+ const cyan = "\x1b[36m";
264
+ const dim = "\x1b[2m";
265
+ const green = "\x1b[32m";
266
+ const reset = "\x1b[0m";
267
+ // @wrapper-known semantic-alias
268
+ const mb = (bytes) => (bytes / 1024 / 1024).toFixed(2);
269
+ const lines = [];
270
+ lines.push("");
271
+ lines.push(` ${green}✓${reset} server bundle ${dim}(${durationMs}ms)${reset}`);
272
+ for (const entry of result.entries) {
273
+ lines.push(` ${cyan}→${reset} ${entry.file} ${mb(entry.sizeBytes)} MB`);
274
+ }
275
+ if (result.chunks.length > 0) {
276
+ const chunkBytes = result.chunks.reduce((sum, c) => sum + c.sizeBytes, 0);
277
+ lines.push(` ${cyan}→${reset} ${result.chunks.length} shared chunk(s) ${mb(chunkBytes)} MB`);
278
+ }
279
+ const depCount = Object.keys(result.runtimeDeps).length;
280
+ lines.push(` ${dim}total: ${mb(result.totalBytes)} MB · runtime-deps: ${depCount} packages${reset}`);
281
+ return lines.join("\n");
282
+ }
@@ -0,0 +1,2 @@
1
+ export { ASSETS_DIR, type BuildManifest, type BuildProdBundleOptions, type BuildResult, buildProdBundle, type ClientEntry, type ClientEntryDeclaration, discoverHtmlTemplate, formatBuildResult, injectAssetTags, readClientEntriesConfig, resolveClientEntries, } from "@cosmicdrift/kumiko-server-runtime/build-prod-bundle";
2
+ export { type BuildServerBundleEntry, type BuildServerBundleOptions, type BuildServerBundleResult, buildServerBundle, discoverServerEntry, formatServerBuildResult, readExtraRuntimeExternals, } from "./build-server-bundle.js";
package/dist/build.js ADDED
@@ -0,0 +1,5 @@
1
+ // Build-Toolchain Public-API. Eigener Sub-Path-Export `@cosmicdrift/kumiko-dev-server/build`
2
+ // damit der Main-Barrel kein Bun-Toolchain-Bundle in Production-Reads zieht
3
+ // (z.B. wenn drizzle-kit die App-Config unter Node lädt).
4
+ export { ASSETS_DIR, buildProdBundle, discoverHtmlTemplate, formatBuildResult, injectAssetTags, readClientEntriesConfig, resolveClientEntries, } from "@cosmicdrift/kumiko-server-runtime/build-prod-bundle";
5
+ export { buildServerBundle, discoverServerEntry, formatServerBuildResult, readExtraRuntimeExternals, } from "./build-server-bundle.js";
package/dist/cli.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { buildProdBundle, buildServerBundle, discoverServerEntry, formatBuildResult, formatServerBuildResult, readClientEntriesConfig, readExtraRuntimeExternals, resolveClientEntries, } from "./build.js";
2
+ export { formatScanWarning, runCodegen } from "./codegen/index.js";
3
+ export { createCrashTracker } from "./crash-tracker.js";
4
+ export { runInitDeployCli } from "./init-deploy-cli.js";
5
+ export { implicitAuthModeFeatureNames, resolveGeneratePath } from "./schema-check-core.js";
package/dist/cli.js ADDED
@@ -0,0 +1,9 @@
1
+ // Surface used by the `bin/*.ts` entrypoints. The bins import this through
2
+ // the package self-reference (`@cosmicdrift/kumiko-dev-server/cli`) so they
3
+ // resolve to src in the workspace and to dist once installed from the
4
+ // tarball, where `src` is not shipped.
5
+ export { buildProdBundle, buildServerBundle, discoverServerEntry, formatBuildResult, formatServerBuildResult, readClientEntriesConfig, readExtraRuntimeExternals, resolveClientEntries, } from "./build.js";
6
+ export { formatScanWarning, runCodegen } from "./codegen/index.js";
7
+ export { createCrashTracker } from "./crash-tracker.js";
8
+ export { runInitDeployCli } from "./init-deploy-cli.js";
9
+ export { implicitAuthModeFeatureNames, resolveGeneratePath } from "./schema-check-core.js";
@@ -0,0 +1,4 @@
1
+ export { renderDefineFile, renderInlineSchemasFile, renderTypesAugmentation, renderWriteHandlerTypes, } from "./render.js";
2
+ export { type CodegenOptions, type CodegenResult, runCodegen } from "./run-codegen.js";
3
+ export { formatScanWarning, qualifiedNameToConstName, rewriteImportPath, type ScannedEvent, type ScanOptions, type ScanResult, type ScanWarning, type SchemaSource, scanEvents, } from "./scan-events.js";
4
+ export { type WatchHandle, type WatchOptions, watchAndRegenerate } from "./watch.js";
@@ -0,0 +1,4 @@
1
+ export { renderDefineFile, renderInlineSchemasFile, renderTypesAugmentation, renderWriteHandlerTypes, } from "./render.js";
2
+ export { runCodegen } from "./run-codegen.js";
3
+ export { formatScanWarning, qualifiedNameToConstName, rewriteImportPath, scanEvents, } from "./scan-events.js";
4
+ export { watchAndRegenerate } from "./watch.js";
@@ -0,0 +1,55 @@
1
+ import type { ScannedEvent } from "./scan-events.js";
2
+ /**
3
+ * Start-of-block markers for the two handler-derived sections that
4
+ * `run-codegen.ts` may need to carry forward verbatim from a previous
5
+ * run (when the current run has no `handlerQns` to render a fresh
6
+ * block from). Each marker is always the last thing its renderer
7
+ * emits, so a caller can locate it in a previously-written file and
8
+ * slice from the marker to EOF to recover the whole block.
9
+ */
10
+ export declare const WRITE_HANDLER_QN_MARKER = "// --- WriteHandlerQn (generated from live registry / feature-manifest.json) ---";
11
+ export declare const TYPED_DISPATCHER_MARKER = "// --- TypedDispatcher (generated from live registry / feature-manifest.json) ---";
12
+ /**
13
+ * Render `types.generated.d.ts`. Imports the schema-identifiers as
14
+ * type-only — sources can be either named exports of feature-events
15
+ * files (kind: "imported") or extracted const-exports of the
16
+ * co-generated schemas.generated.ts (kind: "inline"). Result is wired
17
+ * via `z.infer<typeof X>` into the augmentation. Empty events list →
18
+ * minimal but valid file (still augmentable, just no entries yet —
19
+ * useful first-time scaffold).
20
+ */
21
+ export declare function renderTypesAugmentation(events: readonly ScannedEvent[], outputDirAbs: string): string;
22
+ /**
23
+ * Render `schemas.generated.ts`. One `export const` per inline-schema
24
+ * event, named via the qualifiedName-derived stable identifier. The
25
+ * source-text of the original `z.*(...)` expression is replayed — we
26
+ * don't try to be cleverer than the zod compiler about reconstructing
27
+ * the schema. Returns undefined when no inline-schemas exist (so the
28
+ * runner can skip writing the file entirely).
29
+ */
30
+ export declare function renderInlineSchemasFile(events: readonly ScannedEvent[], appRootAbs: string): string | undefined;
31
+ /**
32
+ * Render `define.ts` — local thin wrappers that fix TMap to
33
+ * KumikoEventTypeMap. Apps import `defineWriteHandler` /
34
+ * `defineQueryHandler` from this file; framework's strict-overload
35
+ * becomes the only matching overload because TMap is no longer the
36
+ * eager-resolved default.
37
+ *
38
+ * The wrappers are intentionally *thin* — same signature as the
39
+ * framework's, just with TMap pre-bound. Apps stay portable: switch
40
+ * the import back to "@cosmicdrift/kumiko-framework/engine" and you're back on the
41
+ * loose default. Migration is reversible, no behavioural surface change.
42
+ */
43
+ export declare function renderDefineFile(handlerQns?: readonly string[]): string;
44
+ /**
45
+ * Render `WriteHandlerQn` type lines — exports a union of all registered
46
+ * write handler QNs so custom-screen code can type-check dispatcher.write
47
+ * calls at compile time:
48
+ *
49
+ * ```ts
50
+ * import type { WriteHandlerQn } from "@app/define";
51
+ * dispatcher.write<WriteHandlerQn>("tenant:write:create", payload); // ✓
52
+ * dispatcher.write<WriteHandlerQn>("tenant:write:creat", payload); // ✗ TS error
53
+ * ```
54
+ */
55
+ export declare function renderWriteHandlerTypes(handlerQns: readonly string[]): string;