@zenbujs/core 0.0.3 → 0.0.5

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 (89) hide show
  1. package/dist/{advice-config-CjgkEf2E.mjs → advice-config-QYB2qEd_.mjs} +32 -14
  2. package/dist/advice.mjs +1 -1
  3. package/dist/{base-window-BUt8pwbw.mjs → base-window-BbFRRhKP.mjs} +9 -4
  4. package/dist/{build-config-pbv0w4oN.mjs → build-config-C3a-o3_B.mjs} +8 -2
  5. package/dist/{build-electron-BzHa_hRi.mjs → build-electron-CNJ0dLND.mjs} +12 -6
  6. package/dist/{build-source-CnTfQBGK.mjs → build-source-C2puqEVr.mjs} +13 -8
  7. package/dist/chunk-DsiFFCwN.mjs +16 -0
  8. package/dist/cli/bin.mjs +12 -15
  9. package/dist/cli/build.d.mts +1 -52
  10. package/dist/cli/build.mjs +2 -47
  11. package/dist/cli/resolve-config.mjs +37 -0
  12. package/dist/{cli-BLbQQIVB.mjs → cli-C3R1LBMY.mjs} +5 -5
  13. package/dist/{config-CdVrW85P.mjs → config-DXRCDUxG.mjs} +1 -1
  14. package/dist/config.d.mts +3 -0
  15. package/dist/config.mjs +4 -0
  16. package/dist/{db-BXadETOb.mjs → db-xjvahRFJ.mjs} +47 -41
  17. package/dist/db.d.mts +1 -1
  18. package/dist/db.mjs +2 -2
  19. package/dist/env-bootstrap.d.mts +1 -1
  20. package/dist/env-bootstrap.mjs +52 -1
  21. package/dist/index-ClXLQ1fw.d.mts +1 -0
  22. package/dist/index.d.mts +5 -5
  23. package/dist/index.mjs +4 -4
  24. package/dist/{link-VOoGs-pY.mjs → link-c0_aLWQ3.mjs} +87 -120
  25. package/dist/load-config-xMf2wxH8.mjs +141 -0
  26. package/dist/loaders/zenbu.d.mts +17 -0
  27. package/dist/loaders/zenbu.mjs +144 -135
  28. package/dist/{monorepo-CQeQBIpa.mjs → monorepo-3avKJwzJ.mjs} +5 -2
  29. package/dist/node-loader.mjs +1 -1
  30. package/dist/{publish-source-BJdpDAFH.mjs → publish-source-Dill72NS.mjs} +12 -6
  31. package/dist/react.d.mts +3 -3
  32. package/dist/react.mjs +2 -2
  33. package/dist/{registry-Dh_e7HU1.d.mts → registry-eX6e2oql.d.mts} +1 -1
  34. package/dist/registry.d.mts +1 -1
  35. package/dist/{reloader-lLAJ3lqg.mjs → reloader-DzEO8kJr.mjs} +6 -4
  36. package/dist/{renderer-host-Bg8QdeeH.mjs → renderer-host-Cau9JK0v.mjs} +90 -212
  37. package/dist/{rpc-BwwQK6hD.mjs → rpc-JfGv-Wuw.mjs} +7 -5
  38. package/dist/rpc.d.mts +1 -1
  39. package/dist/rpc.mjs +1 -1
  40. package/dist/{runtime-CjqDr8Yf.d.mts → runtime-pCeVzj--.d.mts} +73 -1
  41. package/dist/runtime.d.mts +2 -2
  42. package/dist/runtime.mjs +522 -2
  43. package/dist/{schema-DMoSkwUx.d.mts → schema-Dl85YjXW.d.mts} +1 -1
  44. package/dist/schema.d.mts +1 -1
  45. package/dist/schema.mjs +27 -1
  46. package/dist/{server-BXwZEQ-n.mjs → server-y3PPbh3l.mjs} +5 -3
  47. package/dist/services/default.mjs +10 -10
  48. package/dist/services/index.d.mts +8 -4
  49. package/dist/services/index.mjs +6 -6
  50. package/dist/setup-gate.d.mts +1 -1
  51. package/dist/setup-gate.mjs +248 -1
  52. package/dist/{transform-DJH3vN4b.mjs → transform-CmFYPmt8.mjs} +1 -1
  53. package/dist/transforms-CuTODvDx.d.mts +145 -0
  54. package/dist/transforms-htxfTwsY.mjs +47 -0
  55. package/dist/{transport-BMSzG2-F.mjs → transport-F2hv_OEm.mjs} +1 -1
  56. package/dist/{vite-plugins-Bh3SCOw-.mjs → vite-plugins-Do7liKi_.mjs} +5 -19
  57. package/dist/vite.mjs +1 -1
  58. package/dist/{window-CmmpCVX6.mjs → window-o2NGUsIb.mjs} +10 -7
  59. package/dist/{write-9dRFczGJ.mjs → write-DgIRjo23.mjs} +1 -1
  60. package/package.json +11 -10
  61. package/dist/advice-config-Cy133IQP.mjs +0 -2
  62. package/dist/base-window-DEIAk618.mjs +0 -2
  63. package/dist/chunk-Dm34NbLt.mjs +0 -6
  64. package/dist/config-LK73dJmO.mjs +0 -2
  65. package/dist/db-ByKPbnP6.mjs +0 -2
  66. package/dist/env-bootstrap-rj7I-59x.mjs +0 -53
  67. package/dist/http-IBcLzbYu.mjs +0 -2
  68. package/dist/load-build-config-DozuRhAN.mjs +0 -40
  69. package/dist/reloader-BCkLjDhS.mjs +0 -2
  70. package/dist/renderer-host-DpvBPTHJ.mjs +0 -2
  71. package/dist/rpc-CqitnyR4.mjs +0 -2
  72. package/dist/runtime-DUFKDIe4.mjs +0 -409
  73. package/dist/schema-dGK6qkfR.mjs +0 -28
  74. package/dist/server-DjrZUbbu.mjs +0 -2
  75. package/dist/setup-gate-BcoqWu8S.mjs +0 -110
  76. package/dist/view-registry-BualWgAf.mjs +0 -2
  77. package/dist/window-CM2a9Kyc.mjs +0 -2
  78. package/dist/{index-FtE8MXJ_.d.mts → cli/resolve-config.d.mts} +0 -0
  79. package/dist/{dev-BU_llQh1.mjs → dev-Dazhu66l.mjs} +0 -0
  80. package/dist/{env-bootstrap-BtVME-CU.d.mts → env-bootstrap-DW2hVhSO.d.mts} +0 -0
  81. package/dist/{index-Bhlbyrn7.d.mts → index-C-ALz_SH.d.mts} +0 -0
  82. package/dist/{index-CPZ5d6Hl.d.mts → index-M_lSNBrq.d.mts} +0 -0
  83. package/dist/{log-CyKv8hQg.mjs → log-6rzaCV0I.mjs} +0 -0
  84. package/dist/{mirror-sync-BN59kMCG.mjs → mirror-sync-PDzxhf1w.mjs} +1 -1
  85. /package/dist/{node-D4M19_mV.mjs → node-_8xShqxr.mjs} +0 -0
  86. /package/dist/{schema-CIg4GzHQ.mjs → schema-Ca7SxXgS.mjs} +0 -0
  87. /package/dist/{setup-gate-BqOzm7zp.d.mts → setup-gate-Dcy8gGPJ.d.mts} +0 -0
  88. /package/dist/{src-pELM4_iH.mjs → src-Cven45mq.mjs} +0 -0
  89. /package/dist/{trace-DCB7qFzT.mjs → trace-BaVg0rnY.mjs} +0 -0
@@ -1,2 +0,0 @@
1
- import "./renderer-host-Bg8QdeeH.mjs";
2
- export {};
@@ -1,40 +0,0 @@
1
- import { n as resolveBuildConfig } from "./build-config-pbv0w4oN.mjs";
2
- import { createRequire } from "node:module";
3
- import fs from "node:fs";
4
- import path from "node:path";
5
- import { pathToFileURL } from "node:url";
6
- //#region src/cli/lib/load-build-config.ts
7
- const localRequire = createRequire(import.meta.url);
8
- const CONFIG_NAMES = [
9
- "zenbu.build.ts",
10
- "zenbu.build.mts",
11
- "zenbu.build.js",
12
- "zenbu.build.mjs"
13
- ];
14
- function findBuildConfig(projectDir) {
15
- for (const name of CONFIG_NAMES) {
16
- const candidate = path.join(projectDir, name);
17
- if (fs.existsSync(candidate)) return candidate;
18
- }
19
- throw new Error(`No zenbu.build config found at ${projectDir}. Expected one of: ${CONFIG_NAMES.join(", ")}`);
20
- }
21
- let tsxRegistered = null;
22
- function ensureTsxRegistered() {
23
- if (tsxRegistered) return tsxRegistered;
24
- tsxRegistered = (async () => {
25
- try {
26
- const tsxApi = localRequire("tsx/esm/api");
27
- if (typeof tsxApi.register === "function") tsxApi.register();
28
- } catch {}
29
- })();
30
- return tsxRegistered;
31
- }
32
- async function loadBuildConfig(configPath) {
33
- await ensureTsxRegistered();
34
- const mod = await import(pathToFileURL(path.resolve(configPath)).href);
35
- const config = mod.default ?? mod;
36
- if (!config || !Array.isArray(config.include)) throw new Error(`${path.basename(configPath)} must export a config object (via defineBuildConfig) with an 'include' array.`);
37
- return resolveBuildConfig(config);
38
- }
39
- //#endregion
40
- export { loadBuildConfig as n, findBuildConfig as t };
@@ -1,2 +0,0 @@
1
- import "./reloader-lLAJ3lqg.mjs";
2
- export {};
@@ -1,2 +0,0 @@
1
- import "./renderer-host-Bg8QdeeH.mjs";
2
- export {};
@@ -1,2 +0,0 @@
1
- import "./rpc-BwwQK6hD.mjs";
2
- export {};
@@ -1,409 +0,0 @@
1
- //#region src/runtime.ts
2
- function optional(ref) {
3
- return {
4
- __optional: true,
5
- ref
6
- };
7
- }
8
- function resolveDep(entry) {
9
- if (typeof entry === "string") return {
10
- key: entry,
11
- optional: false
12
- };
13
- if (typeof entry === "object" && entry !== null && "__optional" in entry) {
14
- const ref = entry.ref;
15
- return {
16
- key: typeof ref === "string" ? ref : ref.key,
17
- optional: true
18
- };
19
- }
20
- return {
21
- key: entry.key,
22
- optional: false
23
- };
24
- }
25
- var Service = class {
26
- static key;
27
- static deps;
28
- ctx;
29
- /** @internal */
30
- __setupCleanups = /* @__PURE__ */ new Map();
31
- evaluate() {}
32
- setup(key, fn) {
33
- const existing = this.__setupCleanups.get(key);
34
- if (existing) try {
35
- existing("reload");
36
- } catch (e) {
37
- console.error(`[hot] setup cleanup "${key}" failed:`, e);
38
- }
39
- const cleanup = fn();
40
- if (cleanup) this.__setupCleanups.set(key, cleanup);
41
- else this.__setupCleanups.delete(key);
42
- }
43
- /**
44
- * Run `fn` and return its result. Historically reported a boot-trace span;
45
- * now a thin wrapper preserved for caller ergonomics inside service
46
- * `evaluate()` bodies.
47
- */
48
- trace(_name, fn, _meta) {
49
- return Promise.resolve(fn());
50
- }
51
- traceSync(_name, fn, _meta) {
52
- return fn();
53
- }
54
- /** @internal */
55
- async __cleanupAllSetups(reason = "shutdown") {
56
- for (const [key, cleanup] of this.__setupCleanups) try {
57
- await cleanup(reason);
58
- } catch (e) {
59
- console.error(`[hot] setup cleanup "${key}" failed:`, e);
60
- }
61
- this.__setupCleanups.clear();
62
- }
63
- };
64
- /**
65
- * Declare a Service base class with typed deps. The returned class has
66
- * `static deps = <your map>` already set, and `this.ctx` is auto-typed
67
- * from the dep classes — no `declare ctx` needed in the subclass.
68
- *
69
- * export class WindowService extends serviceWithDeps({
70
- * baseWindow: BaseWindowService,
71
- * http: HttpService,
72
- * }) {
73
- * static key = "window"
74
- * evaluate() {
75
- * this.ctx.baseWindow // BaseWindowService
76
- * this.ctx.http // HttpService
77
- * }
78
- * }
79
- *
80
- * `optional(SomeService)` is supported and produces `Instance | undefined`.
81
- */
82
- function serviceWithDeps(deps) {
83
- class ServiceWithDeps extends Service {
84
- static deps = deps;
85
- }
86
- return ServiceWithDeps;
87
- }
88
- const SERVICE_BASE_METHODS = new Set(Object.getOwnPropertyNames(Service.prototype));
89
- var ServiceRuntime = class {
90
- definitions = /* @__PURE__ */ new Map();
91
- dependentsIndex = /* @__PURE__ */ new Map();
92
- dirtyKeys = /* @__PURE__ */ new Set();
93
- drainError = null;
94
- draining = null;
95
- registrationTokens = /* @__PURE__ */ new Map();
96
- slots = /* @__PURE__ */ new Map();
97
- onReconciledCallbacks = [];
98
- register(ServiceClass, importMeta) {
99
- const hot = importMeta?.hot ?? null;
100
- const baseKey = ServiceClass.key;
101
- if (!baseKey) throw new Error("Service must have a static key property");
102
- const slotKey = baseKey;
103
- this.definitions.set(slotKey, ServiceClass);
104
- const slot = this.slots.get(slotKey);
105
- if (slot) slot.ServiceClass = ServiceClass;
106
- else this.slots.set(slotKey, {
107
- error: null,
108
- instance: null,
109
- ServiceClass,
110
- status: "blocked"
111
- });
112
- this.rebuildDependentsIndex();
113
- hot?.accept();
114
- const token = Symbol(slotKey);
115
- this.registrationTokens.set(slotKey, token);
116
- hot?.prune?.(() => {
117
- this.unregister(slotKey, token);
118
- });
119
- this.scheduleReconcile([slotKey]);
120
- }
121
- getAllKeys() {
122
- return [...this.slots.keys()];
123
- }
124
- getSlot(key) {
125
- return this.slots.get(key);
126
- }
127
- async whenIdle() {
128
- while (this.draining) await this.draining;
129
- if (this.drainError) {
130
- const error = this.drainError;
131
- this.drainError = null;
132
- throw error;
133
- }
134
- }
135
- async reloadAll() {
136
- const keys = [...this.slots.keys()];
137
- if (keys.length === 0) return;
138
- await this.scheduleReconcile(keys);
139
- await this.whenIdle();
140
- }
141
- async shutdown() {
142
- try {
143
- await this.whenIdle();
144
- } catch (error) {
145
- console.error("[hot] runtime idle wait failed during shutdown:", error);
146
- }
147
- const keys = [...this.slots.keys()].reverse();
148
- for (const key of keys) await this.teardownService(key, { removeSlot: true });
149
- this.definitions.clear();
150
- this.dependentsIndex.clear();
151
- this.dirtyKeys.clear();
152
- this.registrationTokens.clear();
153
- }
154
- get(ref) {
155
- const slot = this.slots.get(ref.key);
156
- if (!slot || slot.status !== "ready" || !slot.instance) throw new Error(`Service "${ref.key}" not ready. Is it registered and evaluated?`);
157
- return slot.instance;
158
- }
159
- buildRouter() {
160
- const router = {};
161
- for (const [slotKey, slot] of this.slots) {
162
- if (slot.status !== "ready" || !slot.instance) continue;
163
- const proto = Object.getPrototypeOf(slot.instance);
164
- const methods = {};
165
- for (const name of Object.getOwnPropertyNames(proto)) {
166
- if (SERVICE_BASE_METHODS.has(name)) continue;
167
- if (name.startsWith("_")) continue;
168
- const desc = Object.getOwnPropertyDescriptor(proto, name);
169
- if (!desc || typeof desc.value !== "function") continue;
170
- const instance = slot.instance;
171
- methods[name] = (...args) => instance[name](...args);
172
- }
173
- if (Object.keys(methods).length > 0) router[slotKey] = methods;
174
- }
175
- return router;
176
- }
177
- onReconciled(cb) {
178
- this.onReconciledCallbacks.push(cb);
179
- return () => {
180
- const idx = this.onReconciledCallbacks.indexOf(cb);
181
- if (idx >= 0) this.onReconciledCallbacks.splice(idx, 1);
182
- };
183
- }
184
- resolveDepSlot(depKey) {
185
- return this.slots.get(depKey);
186
- }
187
- injectCtx(instance, ServiceClass) {
188
- const deps = ServiceClass.deps ?? {};
189
- const ctx = {};
190
- for (const [name, entry] of Object.entries(deps)) {
191
- const { key, optional: isOptional } = resolveDep(entry);
192
- const slot = this.resolveDepSlot(key);
193
- if (!slot || slot.status !== "ready" || !slot.instance) {
194
- if (isOptional) {
195
- ctx[name] = void 0;
196
- continue;
197
- }
198
- throw new Error(`Dependency "${key}" not ready for "${ServiceClass.key}"`);
199
- }
200
- ctx[name] = slot.instance;
201
- }
202
- instance.ctx = ctx;
203
- }
204
- rebuildDependentsIndex() {
205
- const next = /* @__PURE__ */ new Map();
206
- for (const [slotKey, ServiceClass] of this.definitions) {
207
- const deps = ServiceClass.deps ?? {};
208
- for (const entry of Object.values(deps)) {
209
- const { key: depKey } = resolveDep(entry);
210
- const dependents = next.get(depKey) ?? /* @__PURE__ */ new Set();
211
- dependents.add(slotKey);
212
- next.set(depKey, dependents);
213
- }
214
- }
215
- this.dependentsIndex = next;
216
- }
217
- getAffectedKeys(changedKeys) {
218
- const affected = /* @__PURE__ */ new Set();
219
- const visit = (key) => {
220
- if (affected.has(key)) return;
221
- affected.add(key);
222
- for (const dependent of this.dependentsIndex.get(key) ?? []) visit(dependent);
223
- };
224
- for (const key of changedKeys) visit(key);
225
- return [...affected].filter((key) => this.definitions.has(key));
226
- }
227
- listMissingDeps(ServiceClass) {
228
- const deps = ServiceClass.deps ?? {};
229
- const missing = [];
230
- for (const entry of Object.values(deps)) {
231
- const { key, optional: isOptional } = resolveDep(entry);
232
- if (isOptional) continue;
233
- const slot = this.resolveDepSlot(key);
234
- if (!slot || slot.status !== "ready" || !slot.instance) missing.push(key);
235
- }
236
- return missing;
237
- }
238
- ensureSlot(key, ServiceClass) {
239
- const existing = this.slots.get(key);
240
- if (existing) return existing;
241
- const slot = {
242
- error: null,
243
- instance: null,
244
- ServiceClass,
245
- status: "blocked"
246
- };
247
- this.slots.set(key, slot);
248
- return slot;
249
- }
250
- async teardownService(key, options = {}) {
251
- const slot = this.slots.get(key);
252
- if (!slot) return;
253
- const instance = slot.instance;
254
- slot.instance = null;
255
- slot.status = "blocked";
256
- slot.error = null;
257
- if (instance) await instance.__cleanupAllSetups(options.reason ?? "shutdown");
258
- if (options.removeSlot) this.slots.delete(key);
259
- }
260
- async unregister(key, token) {
261
- if (this.registrationTokens.get(key) !== token) return;
262
- this.registrationTokens.delete(key);
263
- this.definitions.delete(key);
264
- await this.teardownService(key, { removeSlot: true });
265
- this.rebuildDependentsIndex();
266
- await this.scheduleReconcile([key]);
267
- }
268
- async scheduleReconcile(keys) {
269
- for (const key of keys) this.dirtyKeys.add(key);
270
- if (this.draining) return this.draining;
271
- this.draining = (async () => {
272
- try {
273
- while (this.dirtyKeys.size > 0) {
274
- const batch = [...this.dirtyKeys];
275
- this.dirtyKeys.clear();
276
- await this.reconcileBatch(batch);
277
- }
278
- } catch (error) {
279
- this.drainError = error;
280
- console.error("[hot] runtime reconcile failed:", error);
281
- } finally {
282
- this.draining = null;
283
- if (this.dirtyKeys.size > 0) this.scheduleReconcile([]);
284
- }
285
- })();
286
- return this.draining;
287
- }
288
- async reconcileBatch(changedKeys) {
289
- const affectedKeys = this.getAffectedKeys(changedKeys);
290
- if (affectedKeys.length === 0) return;
291
- const affected = /* @__PURE__ */ new Map();
292
- for (const key of affectedKeys) {
293
- const ServiceClass = this.definitions.get(key);
294
- if (ServiceClass) affected.set(key, ServiceClass);
295
- }
296
- const levels = this.topologicalLevels(affected);
297
- for (const level of [...levels].reverse()) await Promise.all(level.map(async (key) => {
298
- const slot = this.slots.get(key);
299
- if (slot?.instance) await slot.instance.__cleanupAllSetups("reload");
300
- }));
301
- for (const level of levels) await Promise.all(level.map((key) => this.reconcileKey(key)));
302
- if (affectedKeys.length > 0) for (const cb of this.onReconciledCallbacks) try {
303
- cb(affectedKeys);
304
- } catch (e) {
305
- console.error("[hot] onReconciled callback failed:", e);
306
- }
307
- }
308
- async reconcileKey(key) {
309
- const ServiceClass = this.definitions.get(key);
310
- if (!ServiceClass) return;
311
- const slot = this.ensureSlot(key, ServiceClass);
312
- slot.ServiceClass = ServiceClass;
313
- const missingDeps = this.listMissingDeps(ServiceClass);
314
- if (missingDeps.length > 0) {
315
- const shouldLog = slot.instance !== null || slot.status !== "blocked";
316
- await this.teardownService(key, { reason: "reload" });
317
- if (shouldLog) console.log(`[hot] ${key} waiting on: ${missingDeps.join(", ")}`);
318
- return;
319
- }
320
- let instance = slot.instance;
321
- if (!instance) {
322
- instance = new ServiceClass();
323
- slot.instance = instance;
324
- } else Object.setPrototypeOf(instance, ServiceClass.prototype);
325
- slot.status = "evaluating";
326
- slot.error = null;
327
- try {
328
- await instance.__cleanupAllSetups("reload");
329
- this.injectCtx(instance, ServiceClass);
330
- await instance.evaluate();
331
- slot.status = "ready";
332
- } catch (e) {
333
- slot.status = "failed";
334
- slot.error = e;
335
- console.error(`[hot] ${key} failed to evaluate:`, e);
336
- }
337
- }
338
- topologicalLevels(services) {
339
- const keys = new Set(services.keys());
340
- const inDegree = /* @__PURE__ */ new Map();
341
- const dependents = /* @__PURE__ */ new Map();
342
- for (const key of keys) {
343
- inDegree.set(key, 0);
344
- dependents.set(key, []);
345
- }
346
- for (const [slotKey, ServiceClass] of services) {
347
- const deps = ServiceClass.deps ?? {};
348
- let degree = 0;
349
- for (const entry of Object.values(deps)) {
350
- const { key: depKey, optional: isOptional } = resolveDep(entry);
351
- if (keys.has(depKey)) {
352
- degree++;
353
- dependents.get(depKey).push(slotKey);
354
- } else if (isOptional) continue;
355
- }
356
- inDegree.set(slotKey, degree);
357
- }
358
- const levels = [];
359
- let queue = [...keys].filter((k) => inDegree.get(k) === 0);
360
- while (queue.length > 0) {
361
- levels.push(queue);
362
- const next = [];
363
- for (const key of queue) for (const dep of dependents.get(key)) {
364
- const d = inDegree.get(dep) - 1;
365
- inDegree.set(dep, d);
366
- if (d === 0) next.push(dep);
367
- }
368
- queue = next;
369
- }
370
- const resolved = levels.flat();
371
- if (resolved.length !== keys.size) {
372
- const missing = [...keys].filter((k) => !resolved.includes(k));
373
- throw new Error(`Circular dependency detected involving: ${missing.join(", ")}`);
374
- }
375
- return levels;
376
- }
377
- };
378
- /**
379
- * Devtools-only handles, attached to the global so they aren't part of the
380
- * public `ServiceRuntime` autocomplete surface. Same shape React DevTools
381
- * uses (`__REACT_DEVTOOLS_GLOBAL_HOOK__`): user code reading
382
- * `runtime.<...>` never lands on these methods; you only find them if you
383
- * specifically type `globalThis.__zenbu_dev__`. Kept here (next to the
384
- * runtime that owns the state) because the hook reaches into private
385
- * implementation details — `scheduleReconcile` stays `private` on the
386
- * class; the cast lives inside the encapsulation boundary.
387
- */
388
- function installDevHook(rt) {
389
- const internals = rt;
390
- globalThis.__zenbu_dev__ = { reloadService: async (key) => {
391
- if (!internals.definitions.has(key)) throw new Error(`No service registered for key "${key}"`);
392
- await internals.scheduleReconcile([key]);
393
- await rt.whenIdle();
394
- } };
395
- }
396
- const runtime = (() => {
397
- const existing = globalThis.__zenbu_service_runtime__;
398
- if (existing) {
399
- Object.setPrototypeOf(existing, ServiceRuntime.prototype);
400
- installDevHook(existing);
401
- return existing;
402
- }
403
- const fresh = new ServiceRuntime();
404
- globalThis.__zenbu_service_runtime__ = fresh;
405
- installDevHook(fresh);
406
- return fresh;
407
- })();
408
- //#endregion
409
- export { serviceWithDeps as a, runtime as i, ServiceRuntime as n, optional as r, Service as t };
@@ -1,28 +0,0 @@
1
- import { a as f, i as createSchema } from "./schema-CIg4GzHQ.mjs";
2
- import zod from "zod";
3
- //#region src/schema.ts
4
- const viewRegistryEntrySchema = zod.object({
5
- scope: zod.string(),
6
- url: zod.string(),
7
- port: zod.number(),
8
- icon: zod.string().optional(),
9
- meta: zod.object({
10
- kind: zod.string().optional(),
11
- sidebar: zod.boolean().optional(),
12
- bottomPanel: zod.boolean().optional(),
13
- label: zod.string().optional()
14
- }).optional()
15
- });
16
- const windowBoundsSchema = zod.object({
17
- x: zod.number(),
18
- y: zod.number(),
19
- width: zod.number(),
20
- height: zod.number()
21
- });
22
- const windowPrefsSchema = zod.object({ lastKnownBounds: windowBoundsSchema.optional() });
23
- const schema = createSchema({
24
- lastKnownViewRegistry: f.array(viewRegistryEntrySchema).default([]),
25
- windowPrefs: f.record(zod.string(), windowPrefsSchema).default({})
26
- });
27
- //#endregion
28
- export { schema as t };
@@ -1,2 +0,0 @@
1
- import "./server-BXwZEQ-n.mjs";
2
- export {};
@@ -1,110 +0,0 @@
1
- import { t as bootstrapEnv } from "./env-bootstrap-rj7I-59x.mjs";
2
- import { createRequire, register } from "node:module";
3
- import fs from "node:fs";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { pathToFileURL } from "node:url";
7
- import { register as register$1 } from "tsx/esm/api";
8
- //#region src/setup-gate.ts
9
- const verbose = process.env.ZENBU_VERBOSE === "1";
10
- function projectArg() {
11
- const arg = process.argv.find((item) => item.startsWith("--project="));
12
- return arg ? path.resolve(arg.slice(10)) : null;
13
- }
14
- function appDirName(name) {
15
- return name.replace(/^@/, "").replace(/[\\/]/g, "__");
16
- }
17
- function readPackageJson(packageDir) {
18
- const pkgPath = path.join(packageDir, "package.json");
19
- return JSON.parse(fs.readFileSync(pkgPath, "utf8"));
20
- }
21
- function findProjectRoot(projectDir) {
22
- let dir = path.resolve(projectDir);
23
- while (dir !== path.dirname(dir)) {
24
- if (fs.existsSync(path.join(dir, "package.json"))) return dir;
25
- dir = path.dirname(dir);
26
- }
27
- return path.resolve(projectDir);
28
- }
29
- function resolveConfigPath(projectRoot) {
30
- const configPath = path.join(projectRoot, "config.json");
31
- if (!fs.existsSync(configPath)) throw new Error(`config.json not found at ${configPath}`);
32
- return configPath;
33
- }
34
- function findTsconfig(projectRoot) {
35
- const candidate = path.join(projectRoot, "tsconfig.json");
36
- return fs.existsSync(candidate) ? candidate : false;
37
- }
38
- function loadElectronApp() {
39
- const electron = createRequire(import.meta.url)("electron");
40
- if (!electron.app) throw new Error("Electron app API is unavailable; setup-gate must run inside Electron");
41
- return electron.app;
42
- }
43
- async function closeRegisteredWatchers() {
44
- await (await import("@zenbujs/hmr/pause")).closeAllWatchers?.();
45
- }
46
- async function registerLoaders(tsconfig, projectRoot) {
47
- register(import.meta.resolve("@zenbujs/core/loaders/zenbu"));
48
- register$1({ tsconfig });
49
- process.env.ZENBU_ADVICE_ROOT = projectRoot;
50
- await import("./node-D4M19_mV.mjs");
51
- const dynohot = await import(pathToFileURL(createRequire(import.meta.url).resolve("@zenbujs/hmr/register")).href);
52
- if (typeof dynohot.register === "function") dynohot.register({ ignore: /[/\\](?:node_modules|dist)[/\\]/ });
53
- }
54
- async function setupGate() {
55
- const app = loadElectronApp();
56
- await app.whenReady();
57
- bootstrapEnv();
58
- const bundledAppPath = app.getAppPath();
59
- const appName = readPackageJson(bundledAppPath).name ?? path.basename(bundledAppPath);
60
- const resolvedProjectDir = projectArg() ?? path.join(process.env.ZENBU_APPS_DIR ?? path.join(os.homedir(), ".zenbu", "apps"), appDirName(appName));
61
- if (!fs.existsSync(resolvedProjectDir)) throw new Error(`setup-gate: project directory ${resolvedProjectDir} does not exist. In a shipped .app, the launcher provisions this dir before invoking setup-gate. In dev, point at an existing project with --project=.`);
62
- const projectRoot = findProjectRoot(resolvedProjectDir);
63
- const configPath = resolveConfigPath(projectRoot);
64
- const tsconfig = findTsconfig(projectRoot);
65
- process.chdir(projectRoot);
66
- process.env.ZENBU_CONFIG_PATH = configPath;
67
- if (!process.argv.some((arg) => arg.startsWith("--project="))) process.argv.push(`--project=${resolvedProjectDir}`);
68
- if (verbose) {
69
- console.log("[setup-gate] project:", resolvedProjectDir);
70
- console.log("[setup-gate] config:", configPath);
71
- }
72
- await registerLoaders(tsconfig, projectRoot);
73
- const { defaultServices } = await import("./services/default.mjs");
74
- await defaultServices();
75
- let shuttingDown = false;
76
- const shutdown = async (exitCode = 0) => {
77
- if (shuttingDown) return;
78
- shuttingDown = true;
79
- try {
80
- await globalThis.__zenbu_service_runtime__?.shutdown();
81
- } catch (err) {
82
- console.error("[setup-gate] shutdown failed:", err);
83
- }
84
- try {
85
- await closeRegisteredWatchers();
86
- } catch (err) {
87
- console.error("[setup-gate] closeAllWatchers failed:", err);
88
- }
89
- app.exit(exitCode);
90
- };
91
- app.on("before-quit", (event) => {
92
- if (shuttingDown) return;
93
- event.preventDefault();
94
- shutdown(0);
95
- });
96
- process.on("SIGINT", () => void shutdown(0));
97
- process.on("SIGTERM", () => void shutdown(0));
98
- const mod = await import(`zenbu:plugins?config=${encodeURIComponent(configPath)}`, { with: { hot: "import" } });
99
- if (typeof mod.default === "function") {
100
- const controller = mod.default();
101
- if (controller && typeof controller.main === "function") await controller.main();
102
- }
103
- await globalThis.__zenbu_service_runtime__?.whenIdle();
104
- }
105
- setupGate().catch((error) => {
106
- console.error(error);
107
- process.exit(1);
108
- });
109
- //#endregion
110
- export { setupGate as t };
@@ -1,2 +0,0 @@
1
- import "./renderer-host-Bg8QdeeH.mjs";
2
- export {};
@@ -1,2 +0,0 @@
1
- import "./window-CmmpCVX6.mjs";
2
- export {};
File without changes
File without changes
@@ -1,9 +1,9 @@
1
1
  import "node:fs";
2
2
  import os from "node:os";
3
3
  import path from "node:path";
4
+ import { execFile } from "node:child_process";
4
5
  import crypto from "node:crypto";
5
6
  import fsp from "node:fs/promises";
6
- import { execFile } from "node:child_process";
7
7
  import { promisify } from "node:util";
8
8
  //#region src/cli/lib/mirror-sync.ts
9
9
  const execFile$1 = promisify(execFile);
File without changes
File without changes
File without changes