@zenbujs/core 0.0.4 → 0.0.8

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 (106) hide show
  1. package/dist/{advice-config-BLXjqjGN.mjs → advice-config-DXSIo0sg.mjs} +49 -38
  2. package/dist/advice.d.mts +8 -8
  3. package/dist/advice.mjs +2 -2
  4. package/dist/base-window-BxBZ2md_.mjs +143 -0
  5. package/dist/build-config-Dzg2frpk.d.mts +215 -0
  6. package/dist/build-config-pWdmLnrk.mjs +53 -0
  7. package/dist/{build-electron-C3Beey84.mjs → build-electron-Dsbb1EMl.mjs} +308 -120
  8. package/dist/{build-source-BvC4bPqH.mjs → build-source-d1J3shV8.mjs} +62 -27
  9. package/dist/chunk-DsiFFCwN.mjs +16 -0
  10. package/dist/cli/bin.mjs +7 -7
  11. package/dist/cli/build.d.mts +2 -2
  12. package/dist/cli/build.mjs +2 -3
  13. package/dist/cli/resolve-config.mjs +3 -2
  14. package/dist/{cli-F0B4dvSg.mjs → cli-kL6mPgBE.mjs} +4 -4
  15. package/dist/{config-BlRXeUXx.mjs → config-BK78JDRI.mjs} +1 -1
  16. package/dist/config.d.mts +3 -2
  17. package/dist/config.mjs +3 -3
  18. package/dist/{db-Cd5ETuPG.mjs → db-Bc292RYo.mjs} +2 -2
  19. package/dist/db.d.mts +1 -1
  20. package/dist/db.mjs +2 -2
  21. package/dist/dev-B2emj0HZ.mjs +301 -0
  22. package/dist/env-bootstrap.d.mts +1 -1
  23. package/dist/env-bootstrap.mjs +52 -1
  24. package/dist/events.d.mts +19 -0
  25. package/dist/events.mjs +1 -0
  26. package/dist/host-version-BIrF8tX7.mjs +65 -0
  27. package/dist/index-w5QyDjuf.d.mts +780 -0
  28. package/dist/index.d.mts +5 -6
  29. package/dist/index.mjs +5 -5
  30. package/dist/installing-preload.cjs +60 -0
  31. package/dist/launcher.mjs +2615 -122
  32. package/dist/{link-BJmsKgPa.mjs → link-glX89NV5.mjs} +215 -89
  33. package/dist/{load-config-BG2tPIfF.mjs → load-config-C4Oe2qZO.mjs} +22 -3
  34. package/dist/loaders/zenbu.d.mts +1 -0
  35. package/dist/loaders/zenbu.mjs +108 -86
  36. package/dist/{monorepo-DCruz9Jx.mjs → monorepo-Dct-kkbQ.mjs} +3 -0
  37. package/dist/node-loader.mjs +1 -1
  38. package/dist/{publish-source-34Hn9zb0.mjs → publish-source-Dq2c0iOw.mjs} +2 -2
  39. package/dist/react.d.mts +56 -7
  40. package/dist/react.mjs +118 -7
  41. package/dist/registry-CMp8FYgS.d.mts +47 -0
  42. package/dist/registry-generated.d.mts +26 -0
  43. package/dist/registry-generated.mjs +1 -0
  44. package/dist/registry.d.mts +2 -2
  45. package/dist/{reloader-DJoCB0bC.mjs → reloader-B22UiNA2.mjs} +7 -7
  46. package/dist/{renderer-host-ztaSIOGx.mjs → renderer-host-DD16MXhI.mjs} +178 -57
  47. package/dist/{rpc-CsgWnlZx.mjs → rpc-C4_NQmpT.mjs} +11 -8
  48. package/dist/rpc.d.mts +1 -1
  49. package/dist/rpc.mjs +1 -1
  50. package/dist/runtime-BQWntcOb.d.mts +218 -0
  51. package/dist/runtime.d.mts +2 -2
  52. package/dist/runtime.mjs +578 -2
  53. package/dist/{schema-DvT61x2_.d.mts → schema-CjrMVk36.d.mts} +3 -3
  54. package/dist/schema.d.mts +1 -1
  55. package/dist/schema.mjs +27 -1
  56. package/dist/{server-DB3Eki_G.mjs → server-CZLMF8Dj.mjs} +6 -6
  57. package/dist/services/default.d.mts +3 -3
  58. package/dist/services/default.mjs +14 -13
  59. package/dist/services/index.d.mts +2 -276
  60. package/dist/services/index.mjs +8 -7
  61. package/dist/setup-gate.d.mts +1 -1
  62. package/dist/setup-gate.mjs +341 -1
  63. package/dist/{transform-DJH3vN4b.mjs → transform-BzrwkEdf.mjs} +23 -917
  64. package/dist/{transport-BMSzG2-F.mjs → transport-F2hv_OEm.mjs} +1 -1
  65. package/dist/updater-DCkz9M1c.mjs +1008 -0
  66. package/dist/{vite-plugins-t4MlFcz3.mjs → vite-plugins-tt6KAtyE.mjs} +27 -26
  67. package/dist/vite.d.mts +3 -3
  68. package/dist/vite.mjs +1 -1
  69. package/dist/{window-DUvMTons.mjs → window-YFKvAM0l.mjs} +36 -19
  70. package/dist/{write-9dRFczGJ.mjs → write-DgIRjo23.mjs} +1 -1
  71. package/package.json +18 -5
  72. package/dist/advice-config-D6K_a7e9.mjs +0 -2
  73. package/dist/base-window-D8CpxMU3.mjs +0 -94
  74. package/dist/base-window-OXg2KSyP.mjs +0 -2
  75. package/dist/build-config-BwnnfrN-.mjs +0 -23
  76. package/dist/chunk-Dm34NbLt.mjs +0 -6
  77. package/dist/config-Ch1FreWU.mjs +0 -2
  78. package/dist/db-Bz_CDIWg.mjs +0 -2
  79. package/dist/dev-DLutFPyo.mjs +0 -85
  80. package/dist/env-bootstrap-rj7I-59x.mjs +0 -53
  81. package/dist/http-B36qtsm0.mjs +0 -2
  82. package/dist/load-config-CQG4297M.mjs +0 -2
  83. package/dist/registry-CioEYLI5.d.mts +0 -61
  84. package/dist/reloader-FeHKV2jd.mjs +0 -2
  85. package/dist/renderer-host-BQpS0ZM2.mjs +0 -2
  86. package/dist/rpc-D_s7-WZe.mjs +0 -2
  87. package/dist/runtime-C95iyVn6.mjs +0 -461
  88. package/dist/runtime-CsiDppGF.d.mts +0 -149
  89. package/dist/schema-dGK6qkfR.mjs +0 -28
  90. package/dist/server-CgzQOPSW.mjs +0 -2
  91. package/dist/setup-gate-D8XfYY52.mjs +0 -140
  92. package/dist/transforms-DVoy8dCu.mjs +0 -47
  93. package/dist/transforms-EVd5Fgyk.d.mts +0 -136
  94. package/dist/view-registry-2zePxTEg.mjs +0 -2
  95. package/dist/window-S3TlTXlK.mjs +0 -2
  96. /package/dist/{env-bootstrap-uCKbw2q8.d.mts → env-bootstrap-rTs8KR3-.d.mts} +0 -0
  97. /package/dist/{index-CE0iPntP.d.mts → index-C-ALz_SH.d.mts} +0 -0
  98. /package/dist/{index-CKKoxA9V.d.mts → index-ClXLQ1fw.d.mts} +0 -0
  99. /package/dist/{index-UK58xuoR.d.mts → index-DeDxePAa.d.mts} +0 -0
  100. /package/dist/{log-CyKv8hQg.mjs → log-6rzaCV0I.mjs} +0 -0
  101. /package/dist/{mirror-sync-EiWvdzTJ.mjs → mirror-sync-pYU6f3-c.mjs} +0 -0
  102. /package/dist/{node-CvZnTx53.mjs → node-BhfLKYCi.mjs} +0 -0
  103. /package/dist/{schema-CIg4GzHQ.mjs → schema-Ca7SxXgS.mjs} +0 -0
  104. /package/dist/{setup-gate-D62nX5lk.d.mts → setup-gate-BQq0QgZH.d.mts} +0 -0
  105. /package/dist/{src-pELM4_iH.mjs → src-Cven45mq.mjs} +0 -0
  106. /package/dist/{trace-DCB7qFzT.mjs → trace-BaVg0rnY.mjs} +0 -0
@@ -1,12 +1,12 @@
1
- import { a as getPlugins } from "./runtime-C95iyVn6.mjs";
2
- import { n as require_lib, t as zenbuAdviceTransform$1 } from "./transform-DJH3vN4b.mjs";
3
- import { a as getContentScripts, i as getAllScopes, r as getAllContentScriptPaths, t as getAdvice } from "./advice-config-BLXjqjGN.mjs";
1
+ import { getPlugins } from "./runtime.mjs";
2
+ import { n as require_lib, t as zenbuAdviceTransform$1 } from "./transform-BzrwkEdf.mjs";
3
+ import { a as getAllTypes, i as getAllContentScriptPaths, n as getAdvice, o as getContentScripts } from "./advice-config-DXSIo0sg.mjs";
4
4
  import path from "node:path";
5
5
  import { fileURLToPath } from "node:url";
6
6
  //#region ../advice/src/vite.ts
7
7
  var import_lib = require_lib();
8
8
  const defaultInclude = /\.[jt]sx?$/;
9
- const defaultExclude = /node_modules/;
9
+ const defaultExclude = /node_modules|[/\\]\.vite[/\\]deps[/\\]|[/\\]vite-cache[/\\][^/\\]+[/\\]deps[/\\]/;
10
10
  function zenbuAdvicePlugin(options = {}) {
11
11
  let resolvedRoot;
12
12
  return {
@@ -29,7 +29,8 @@ function zenbuAdvicePlugin(options = {}) {
29
29
  parserOpts: { plugins: parserPlugins },
30
30
  sourceMaps: true,
31
31
  configFile: false,
32
- babelrc: false
32
+ babelrc: false,
33
+ compact: false
33
34
  });
34
35
  if (!result?.code) return null;
35
36
  return {
@@ -142,29 +143,29 @@ function zenbuFrameworkResolve() {
142
143
  }
143
144
  };
144
145
  }
145
- function getScopeFromPath(urlPath) {
146
+ function getTypeFromPath(urlPath) {
146
147
  const m = urlPath.match(/^\/views\/([^/]+)\//);
147
148
  return m ? m[1] : null;
148
149
  }
149
150
  /**
150
- * Resolve the view scope for a request. The kernel passes `?scope=<name>`
151
+ * Resolve the view type for a request. The kernel passes `?type=<name>`
151
152
  * in the iframe URL when opening a view (see `WindowService.openView`); we
152
- * also support `/views/<scope>/...` paths for plugins that register their
153
+ * also support `/views/<type>/...` paths for plugins that register their
153
154
  * own multi-page Vite layouts.
154
155
  */
155
- function resolveScope(urlPath, originalUrl) {
156
- const fromPath = getScopeFromPath(urlPath);
156
+ function resolveType(urlPath, originalUrl) {
157
+ const fromPath = getTypeFromPath(urlPath);
157
158
  if (fromPath) return fromPath;
158
159
  if (!originalUrl) return null;
159
160
  const queryIdx = originalUrl.indexOf("?");
160
161
  if (queryIdx < 0) return null;
161
- return new URLSearchParams(originalUrl.slice(queryIdx + 1)).get("scope");
162
+ return new URLSearchParams(originalUrl.slice(queryIdx + 1)).get("type");
162
163
  }
163
164
  function parsePreludeId(id) {
164
165
  const rest = id.slice(17);
165
166
  const queryIdx = rest.indexOf("?");
166
- if (queryIdx < 0) return { scope: rest };
167
- return { scope: rest.slice(0, queryIdx) };
167
+ if (queryIdx < 0) return { type: rest };
168
+ return { type: rest.slice(0, queryIdx) };
168
169
  }
169
170
  function generateAdvicePreludeCode(entries) {
170
171
  if (entries.length === 0) return "";
@@ -195,9 +196,9 @@ function resolveAdviceRuntime() {
195
196
  }
196
197
  /**
197
198
  * Per-iframe prelude that registers all advice + content scripts for the
198
- * iframe's scope. The prelude is loaded via a `<script type="module">` tag
199
- * injected into the iframe's HTML; loading it before the app's own entry
200
- * lets advice register before the modules it patches evaluate.
199
+ * iframe's view type. The prelude is loaded via a `<script type="module">`
200
+ * tag injected into the iframe's HTML; loading it before the app's own
201
+ * entry lets advice register before the modules it patches evaluate.
201
202
  */
202
203
  function advicePreludePlugin() {
203
204
  return {
@@ -209,15 +210,15 @@ function advicePreludePlugin() {
209
210
  },
210
211
  load(id) {
211
212
  if (!id.startsWith(RESOLVED_PREFIX)) return null;
212
- const { scope } = parsePreludeId(id);
213
- let code = generateAdvicePreludeCode(getAdvice(scope));
214
- for (const scriptPath of getContentScripts(scope)) code += `import ${JSON.stringify(scriptPath)}\n`;
213
+ const { type } = parsePreludeId(id);
214
+ let code = generateAdvicePreludeCode(getAdvice(type));
215
+ for (const scriptPath of getContentScripts(type)) code += `import ${JSON.stringify(scriptPath)}\n`;
215
216
  return code || "// no advice or content scripts\n";
216
217
  },
217
218
  handleHotUpdate({ file, server }) {
218
219
  let matched = false;
219
- for (const scope of getAllScopes()) {
220
- for (const entry of getAdvice(scope)) if (file === entry.modulePath) {
220
+ for (const type of getAllTypes()) {
221
+ for (const entry of getAdvice(type)) if (file === entry.modulePath) {
221
222
  matched = true;
222
223
  break;
223
224
  }
@@ -249,16 +250,16 @@ function advicePreludePlugin() {
249
250
  });
250
251
  },
251
252
  transformIndexHtml(html, ctx) {
252
- const scope = resolveScope(ctx.path ?? "", ctx.originalUrl);
253
- if (!scope) return html;
254
- const hasAdvice = getAdvice(scope).length > 0;
255
- const hasScripts = getContentScripts(scope).length > 0;
253
+ const type = resolveType(ctx.path ?? "", ctx.originalUrl);
254
+ if (!type) return html;
255
+ const hasAdvice = getAdvice(type).length > 0;
256
+ const hasScripts = getContentScripts(type).length > 0;
256
257
  if (!hasAdvice && !hasScripts) return html;
257
258
  return [{
258
259
  tag: "script",
259
260
  attrs: {
260
261
  type: "module",
261
- src: `${PRELUDE_PREFIX}${scope}`
262
+ src: `${PRELUDE_PREFIX}${type}`
262
263
  },
263
264
  injectTo: "head"
264
265
  }];
package/dist/vite.d.mts CHANGED
@@ -38,9 +38,9 @@ declare function zenbuFrameworkResolve(): Plugin;
38
38
  declare function resolveAdviceRuntime(): Plugin;
39
39
  /**
40
40
  * Per-iframe prelude that registers all advice + content scripts for the
41
- * iframe's scope. The prelude is loaded via a `<script type="module">` tag
42
- * injected into the iframe's HTML; loading it before the app's own entry
43
- * lets advice register before the modules it patches evaluate.
41
+ * iframe's view type. The prelude is loaded via a `<script type="module">`
42
+ * tag injected into the iframe's HTML; loading it before the app's own
43
+ * entry lets advice register before the modules it patches evaluate.
44
44
  */
45
45
  declare function advicePreludePlugin(): Plugin;
46
46
  /**
package/dist/vite.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as zenbuVitePlugins, i as zenbuFrameworkResolve, n as resolveAdviceRuntime, r as zenbuAdviceTransform, t as advicePreludePlugin } from "./vite-plugins-t4MlFcz3.mjs";
1
+ import { a as zenbuVitePlugins, i as zenbuFrameworkResolve, n as resolveAdviceRuntime, r as zenbuAdviceTransform, t as advicePreludePlugin } from "./vite-plugins-tt6KAtyE.mjs";
2
2
  export { advicePreludePlugin, resolveAdviceRuntime, zenbuAdviceTransform, zenbuFrameworkResolve, zenbuVitePlugins };
@@ -1,11 +1,13 @@
1
- import { d as serviceWithDeps, u as runtime } from "./runtime-C95iyVn6.mjs";
2
- import { t as createLogger } from "./log-CyKv8hQg.mjs";
3
- import { n as ViewRegistryService, o as HttpService, t as RendererHostService } from "./renderer-host-ztaSIOGx.mjs";
4
- import { t as BaseWindowService } from "./base-window-D8CpxMU3.mjs";
1
+ import { n as __exportAll } from "./chunk-DsiFFCwN.mjs";
2
+ import { Service, runtime } from "./runtime.mjs";
3
+ import { t as createLogger } from "./log-6rzaCV0I.mjs";
4
+ import { r as ViewRegistryService, s as HttpService, t as RendererHostService } from "./renderer-host-DD16MXhI.mjs";
5
+ import { i as entrypointBgColor, t as BaseWindowService } from "./base-window-BxBZ2md_.mjs";
5
6
  import { URLSearchParams } from "node:url";
6
- import { WebContentsView, clipboard, dialog, shell } from "electron";
7
+ import { WebContentsView, app, clipboard, dialog, shell } from "electron";
7
8
  import electronContextMenu from "electron-context-menu";
8
9
  //#region src/services/window.ts
10
+ var window_exports = /* @__PURE__ */ __exportAll({ WindowService: () => WindowService });
9
11
  const log = createLogger("window");
10
12
  function queryString(query) {
11
13
  if (!query) return "";
@@ -17,13 +19,15 @@ function queryString(query) {
17
19
  const encoded = params.toString();
18
20
  return encoded ? `?${encoded}` : "";
19
21
  }
20
- var WindowService = class extends serviceWithDeps({
21
- baseWindow: BaseWindowService,
22
- viewRegistry: ViewRegistryService,
23
- http: HttpService,
24
- rendererHost: RendererHostService
22
+ var WindowService = class extends Service.create({
23
+ key: "window",
24
+ deps: {
25
+ baseWindow: BaseWindowService,
26
+ viewRegistry: ViewRegistryService,
27
+ http: HttpService,
28
+ rendererHost: RendererHostService
29
+ }
25
30
  }) {
26
- static key = "window";
27
31
  mounted = /* @__PURE__ */ new Map();
28
32
  evaluate() {
29
33
  this.setup("window-view-cleanup", () => {
@@ -41,10 +45,22 @@ var WindowService = class extends serviceWithDeps({
41
45
  this.mounted.clear();
42
46
  };
43
47
  });
48
+ this.setup("activate-reopens-entrypoint", () => {
49
+ const onActivate = () => {
50
+ if (this.ctx.baseWindow.windows.size > 0) return;
51
+ this.openView({ type: "app" }).catch((err) => {
52
+ log.error("activate-reopens-entrypoint: openView failed:", err);
53
+ });
54
+ };
55
+ app.on("activate", onActivate);
56
+ return () => {
57
+ app.removeListener("activate", onActivate);
58
+ };
59
+ });
44
60
  }
45
61
  async openView(args) {
46
- const entry = this.ctx.viewRegistry.get(args.scope);
47
- if (!entry) throw new Error(`No registered view for scope "${args.scope}"`);
62
+ const entry = this.ctx.viewRegistry.get(args.type);
63
+ if (!entry) throw new Error(`No registered view for type "${args.type}"`);
48
64
  const windowId = args.windowId ?? "main";
49
65
  let win = this.ctx.baseWindow.windows.get(windowId);
50
66
  if (!win) win = this.ctx.baseWindow.createWindow({ windowId }).win;
@@ -62,9 +78,10 @@ var WindowService = class extends serviceWithDeps({
62
78
  const view = new WebContentsView({ webPreferences: {
63
79
  nodeIntegration: false,
64
80
  contextIsolation: true,
65
- sandbox: true
81
+ sandbox: true,
82
+ ...args.view?.webPreferences
66
83
  } });
67
- view.setBackgroundColor("#F4F4F4");
84
+ view.setBackgroundColor(args.view?.backgroundColor ?? entrypointBgColor());
68
85
  win.contentView.addChildView(view);
69
86
  const disposeContextMenu = electronContextMenu({
70
87
  window: view,
@@ -99,18 +116,18 @@ var WindowService = class extends serviceWithDeps({
99
116
  wsPort: this.ctx.http.port,
100
117
  wsToken: this.ctx.http.authToken,
101
118
  windowId,
102
- scope: args.scope
119
+ type: args.type
103
120
  })}`;
104
121
  await view.webContents.loadURL(url);
105
122
  this.mounted.set(windowId, {
106
123
  windowId,
107
- scope: args.scope,
124
+ type: args.type,
108
125
  view,
109
126
  disposeContextMenu
110
127
  });
111
128
  if (!win.isVisible()) win.show();
112
129
  win.focus();
113
- log.verbose(`mounted "${args.scope}" in window "${windowId}"`);
130
+ log.verbose(`mounted "${args.type}" in window "${windowId}"`);
114
131
  return { windowId };
115
132
  }
116
133
  async focusWindow(windowId) {
@@ -153,4 +170,4 @@ var WindowService = class extends serviceWithDeps({
153
170
  };
154
171
  runtime.register(WindowService, import.meta);
155
172
  //#endregion
156
- export { WindowService as t };
173
+ export { window_exports as n, WindowService as t };
@@ -1,4 +1,4 @@
1
- import { n as traceKyjuSync, t as traceKyju } from "./trace-DCB7qFzT.mjs";
1
+ import { n as traceKyjuSync, t as traceKyju } from "./trace-BaVg0rnY.mjs";
2
2
  import * as NFS from "node:fs";
3
3
  import * as OS from "node:os";
4
4
  import * as Path from "node:path";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenbujs/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -42,6 +42,14 @@
42
42
  "types": "./dist/registry.d.mts",
43
43
  "import": "./dist/registry.mjs"
44
44
  },
45
+ "./registry-generated": {
46
+ "types": "./dist/registry-generated.d.mts",
47
+ "import": "./dist/registry-generated.mjs"
48
+ },
49
+ "./events": {
50
+ "types": "./dist/events.d.mts",
51
+ "import": "./dist/events.mjs"
52
+ },
45
53
  "./schema": {
46
54
  "types": "./dist/schema.d.mts",
47
55
  "import": "./dist/schema.mjs"
@@ -98,28 +106,33 @@
98
106
  "electron-context-menu": "^4.1.2",
99
107
  "isomorphic-git": "^1.37.6",
100
108
  "nanoid": "^5.1.6",
109
+ "semver": "^7.8.0",
101
110
  "tsx": "^4.21.0",
102
111
  "vite": "^6.0.0",
103
112
  "ws": "^8.18.0",
104
113
  "zod": "^4.3.6",
105
- "@zenbujs/hmr": "0.0.1"
114
+ "@zenbujs/hmr": "0.0.2"
106
115
  },
107
116
  "devDependencies": {
108
117
  "@types/node": "^22.0.0",
109
118
  "@types/react": "^19.0.0",
119
+ "@types/semver": "^7.7.1",
110
120
  "@types/ws": "^8.18.0",
111
121
  "electron": "^42.0.0",
112
122
  "tsdown": "^0.21.10",
113
123
  "typescript": "^5.4.5",
114
- "@zenbu/advice": "0.0.0",
124
+ "vitest": "^3.2.4",
125
+ "@zenbu/zenrpc": "0.0.0",
115
126
  "@zenbu/kyju": "0.0.0",
116
- "@zenbu/zenrpc": "0.0.0"
127
+ "@zenbu/advice": "0.0.0"
117
128
  },
118
129
  "scripts": {
119
130
  "build": "node --max-old-space-size=8192 ./node_modules/tsdown/dist/run.mjs",
131
+ "prebuild": "pnpm link:types",
120
132
  "dev": "tsdown --watch",
121
- "link:types": "node ./dist/cli/bin.mjs link --types-config ./zenbu-types.config.json --registry ./types",
133
+ "link:types": "tsx ./src/cli/bin.ts link --types-config ./zenbu-types.config.json --out ./src/registry-generated.ts --augment-out ./types/zenbu-register.ts",
122
134
  "db:generate": "node ./dist/cli/bin.mjs db generate --schema src/schema.ts --migrations ./migrations",
135
+ "test": "vitest run",
123
136
  "typecheck": "tsc --noEmit -p tsconfig.json"
124
137
  }
125
138
  }
@@ -1,2 +0,0 @@
1
- import "./advice-config-BLXjqjGN.mjs";
2
- export {};
@@ -1,94 +0,0 @@
1
- import { t as Service, u as runtime } from "./runtime-C95iyVn6.mjs";
2
- import { t as createLogger } from "./log-CyKv8hQg.mjs";
3
- import { r as DbService } from "./renderer-host-ztaSIOGx.mjs";
4
- import { nanoid } from "nanoid";
5
- import { BaseWindow } from "electron";
6
- //#region src/services/base-window.ts
7
- const log = createLogger("base-window");
8
- const MAIN_WINDOW_ID = "main";
9
- var BaseWindowService = class extends Service {
10
- static key = "base-window";
11
- static deps = { db: DbService };
12
- windows = /* @__PURE__ */ new Map();
13
- get bootWindows() {
14
- return globalThis.__zenbu_boot_windows__ ?? [];
15
- }
16
- set bootWindows(v) {
17
- globalThis.__zenbu_boot_windows__ = v;
18
- }
19
- getZenWidth() {
20
- const flag = process.argv.find((a) => a.startsWith("--zen-width="));
21
- if (!flag) return void 0;
22
- const n = parseInt(flag.slice(12), 10);
23
- return isNaN(n) ? void 0 : n;
24
- }
25
- getWindowId(win) {
26
- for (const [id, w] of this.windows) if (w === win) return id;
27
- }
28
- createWindow(opts) {
29
- const windowId = opts?.windowId ?? nanoid();
30
- const zenWidth = this.getZenWidth();
31
- const win = new BaseWindow({
32
- width: opts?.width ?? zenWidth ?? 1100,
33
- height: opts?.height ?? 750,
34
- ...opts?.x != null && opts?.y != null ? {
35
- x: opts.x,
36
- y: opts.y
37
- } : {},
38
- show: opts?.show ?? true,
39
- titleBarStyle: "hidden",
40
- trafficLightPosition: {
41
- x: 14,
42
- y: 10
43
- },
44
- backgroundColor: "#F4F4F4"
45
- });
46
- this.windows.set(windowId, win);
47
- win.on("closed", () => this.windows.delete(windowId));
48
- return {
49
- win,
50
- windowId
51
- };
52
- }
53
- evaluate() {
54
- if (this.windows.size === 0) if (this.bootWindows.length > 0) {
55
- for (const boot of this.bootWindows) {
56
- this.windows.set(boot.windowId, boot.win);
57
- boot.win.on("closed", () => this.windows.delete(boot.windowId));
58
- }
59
- this.bootWindows = [];
60
- } else {
61
- const prefs = this.ctx.db.client.readRoot().plugin.core.windowPrefs;
62
- this.createWindow({
63
- windowId: MAIN_WINDOW_ID,
64
- ...prefs[MAIN_WINDOW_ID]?.lastKnownBounds
65
- });
66
- }
67
- this.setup("window-cleanup", () => {
68
- return () => {
69
- const snapshot = [...this.windows.entries()].map(([windowId, win]) => ({
70
- windowId,
71
- bounds: win.getBounds()
72
- }));
73
- this.ctx.db.client.update((root) => {
74
- const next = { ...root.plugin.core.windowPrefs };
75
- for (const { windowId, bounds } of snapshot) next[windowId] = {
76
- ...next[windowId],
77
- lastKnownBounds: bounds
78
- };
79
- root.plugin.core.windowPrefs = next;
80
- });
81
- for (const win of this.windows.values()) {
82
- win.__zenbu_on_close = null;
83
- win.__zenbu_on_closed = null;
84
- win.close();
85
- }
86
- this.windows.clear();
87
- };
88
- });
89
- log.verbose(`ready (${this.windows.size} windows)`);
90
- }
91
- };
92
- runtime.register(BaseWindowService, import.meta);
93
- //#endregion
94
- export { MAIN_WINDOW_ID as n, BaseWindowService as t };
@@ -1,2 +0,0 @@
1
- import "./base-window-D8CpxMU3.mjs";
2
- export {};
@@ -1,23 +0,0 @@
1
- //#region src/cli/lib/build-config.ts
2
- function defineBuildConfig(config) {
3
- return config;
4
- }
5
- function resolveBuildConfig(config) {
6
- return {
7
- source: config.source ?? ".",
8
- out: config.out ?? ".zenbu/build/source",
9
- include: config.include,
10
- ignore: config.ignore ?? [],
11
- transforms: config.transforms ?? [],
12
- mirror: config.mirror,
13
- bundle: config.bundle
14
- };
15
- }
16
- function definePlugin(plugin) {
17
- return plugin;
18
- }
19
- function defineConfig(config) {
20
- return config;
21
- }
22
- //#endregion
23
- export { resolveBuildConfig as i, defineConfig as n, definePlugin as r, defineBuildConfig as t };
@@ -1,6 +0,0 @@
1
- import { createRequire } from "node:module";
2
- //#region \0rolldown/runtime.js
3
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
4
- var __require = /* @__PURE__ */ createRequire(import.meta.url);
5
- //#endregion
6
- export { __require as n, __commonJSMin as t };
@@ -1,2 +0,0 @@
1
- import { n as loadConfig, t as findConfigFile } from "./config-BlRXeUXx.mjs";
2
- export { findConfigFile, loadConfig };
@@ -1,2 +0,0 @@
1
- import "./renderer-host-ztaSIOGx.mjs";
2
- export {};
@@ -1,85 +0,0 @@
1
- import { existsSync, statSync } from "node:fs";
2
- import path, { resolve } from "node:path";
3
- import { spawn } from "node:child_process";
4
- //#region src/cli/commands/dev.ts
5
- /**
6
- * `zen dev` — launch the local app under Electron with the setup-gate as the
7
- * main entry. This is the entrypoint of `pnpm dev` in scaffolded apps. The
8
- * command is intentionally hookable: future versions can layer doctor checks,
9
- * environment validation, or a managed dev-server here without touching the
10
- * user's `package.json` scripts.
11
- *
12
- * Defaults to a foreground/blocking child so Ctrl+C in the terminal kills the
13
- * Electron process and `pnpm dev` exits cleanly. Pass `--detach` to spawn it
14
- * in the background instead (returns immediately, Electron lives until quit).
15
- */
16
- function parseArgs(argv) {
17
- let pathArg;
18
- let detach = false;
19
- let verbose = false;
20
- for (let i = 0; i < argv.length; i++) {
21
- const arg = argv[i];
22
- if (arg === "--detach") detach = true;
23
- else if (arg === "--verbose" || arg === "-v") verbose = true;
24
- else if (!arg.startsWith("-") && pathArg == null) pathArg = arg;
25
- else {
26
- console.error(`zen dev: unknown flag "${arg}"`);
27
- console.error(`valid: zen dev [path] [--detach] [--verbose]`);
28
- process.exit(1);
29
- }
30
- }
31
- const projectDir = pathArg ? resolve(process.cwd(), pathArg) : process.cwd();
32
- if (!existsSync(projectDir)) {
33
- console.error(`zen dev: path "${pathArg}" does not exist`);
34
- process.exit(1);
35
- }
36
- try {
37
- if (!statSync(projectDir).isDirectory()) {
38
- console.error(`zen dev: path "${pathArg}" is not a directory`);
39
- process.exit(1);
40
- }
41
- } catch {
42
- console.error(`zen dev: cannot stat "${pathArg}"`);
43
- process.exit(1);
44
- }
45
- return {
46
- projectDir,
47
- detach,
48
- verbose
49
- };
50
- }
51
- function resolveLocalElectron(projectDir) {
52
- const candidates = [path.join(projectDir, "node_modules", "electron", "dist", "Electron.app", "Contents", "MacOS", "Electron"), path.join(projectDir, "node_modules", ".bin", "electron")];
53
- for (const candidate of candidates) if (existsSync(candidate)) return candidate;
54
- throw new Error(`Electron is not installed in ${projectDir}. Run \`pnpm install\` in the app.`);
55
- }
56
- function ensureSetupGate(projectDir) {
57
- const setupGate = path.join(projectDir, "node_modules", "@zenbujs", "core", "dist", "setup-gate.mjs");
58
- if (!existsSync(setupGate)) throw new Error(`@zenbujs/core setup-gate not found at ${setupGate}. Run \`pnpm install\` in the app.`);
59
- }
60
- async function runDev(argv) {
61
- const { projectDir, detach, verbose } = parseArgs(argv);
62
- if (verbose) console.error("[zen dev] launching:", projectDir);
63
- const electron = resolveLocalElectron(projectDir);
64
- ensureSetupGate(projectDir);
65
- const electronArgs = [projectDir, `--project=${projectDir}`];
66
- if (detach) {
67
- spawn(electron, electronArgs, {
68
- cwd: projectDir,
69
- detached: true,
70
- stdio: "ignore"
71
- }).unref();
72
- return;
73
- }
74
- const child = spawn(electron, electronArgs, {
75
- cwd: projectDir,
76
- stdio: "inherit"
77
- });
78
- process.on("SIGINT", () => child.kill("SIGINT"));
79
- process.on("SIGTERM", () => child.kill("SIGTERM"));
80
- child.on("exit", (code, signal) => {
81
- process.exit(code ?? (signal ? 1 : 0));
82
- });
83
- }
84
- //#endregion
85
- export { runDev };
@@ -1,53 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- //#region src/env-bootstrap.ts
5
- const internalDir = path.join(os.homedir(), ".zenbu", ".internal");
6
- const pathsJson = path.join(internalDir, "paths.json");
7
- function userCacheRoot() {
8
- if (process.platform === "darwin") return path.join(os.homedir(), "Library", "Caches");
9
- if (process.platform === "win32") return process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local");
10
- return process.env.XDG_CACHE_HOME ?? path.join(os.homedir(), ".cache");
11
- }
12
- function computePaths() {
13
- const cacheRoot = path.join(userCacheRoot(), "Zenbu");
14
- const binDir = path.join(cacheRoot, "bin");
15
- return {
16
- cacheRoot,
17
- binDir,
18
- bunInstall: path.join(cacheRoot, "bun"),
19
- bunPath: path.join(binDir, "bun"),
20
- pnpmHome: path.join(cacheRoot, "pnpm"),
21
- pnpmPath: path.join(binDir, "pnpm"),
22
- gitPath: path.join(binDir, "git"),
23
- writtenAt: Date.now()
24
- };
25
- }
26
- function bootstrapEnv() {
27
- const paths = computePaths();
28
- try {
29
- fs.mkdirSync(paths.binDir, { recursive: true });
30
- } catch {}
31
- const toolchainReady = fs.existsSync(paths.bunPath) && fs.existsSync(paths.pnpmPath);
32
- if (toolchainReady) {
33
- process.env.BUN_INSTALL ??= paths.bunInstall;
34
- process.env.PNPM_HOME ??= paths.pnpmHome;
35
- }
36
- const pathParts = toolchainReady ? [paths.binDir, process.env.PATH ?? ""] : [process.env.PATH ?? ""];
37
- const seen = /* @__PURE__ */ new Set();
38
- process.env.PATH = pathParts.flatMap((part) => part.split(path.delimiter)).filter((part) => {
39
- if (!part || seen.has(part)) return false;
40
- seen.add(part);
41
- return true;
42
- }).join(path.delimiter);
43
- try {
44
- fs.mkdirSync(internalDir, { recursive: true });
45
- fs.writeFileSync(pathsJson, JSON.stringify(paths, null, 2));
46
- } catch {}
47
- return {
48
- paths,
49
- needsToolchainDownload: !toolchainReady
50
- };
51
- }
52
- //#endregion
53
- export { bootstrapEnv as t };
@@ -1,2 +0,0 @@
1
- import "./renderer-host-ztaSIOGx.mjs";
2
- export {};
@@ -1,2 +0,0 @@
1
- import { n as loadConfig } from "./load-config-BG2tPIfF.mjs";
2
- export { loadConfig };
@@ -1,61 +0,0 @@
1
- import { n as SchemaRoot } from "./schema-DvT61x2_.mjs";
2
-
3
- //#region src/registry.d.ts
4
- type CoreEvents = {
5
- advice: {
6
- reload: {
7
- scope: string;
8
- };
9
- };
10
- };
11
- type Events = CoreEvents;
12
- type CoreDbSections = {
13
- core: SchemaRoot;
14
- };
15
- type CorePreloads = {};
16
- type CoreServiceRouter = {};
17
- /**
18
- * Module-augmentation point for plugin authors. `zen link` generates
19
- * `<app>/types/zenbu-register.ts` which declares:
20
- *
21
- * declare module "@zenbujs/core/registry" {
22
- * interface ZenbuRegister {
23
- * db: DbRoot
24
- * rpc: ServiceRouter
25
- * events: PluginEvents
26
- * }
27
- * }
28
- *
29
- * Server services (`DbService.client`, `RpcService.emit`) and renderer hooks
30
- * (`useDb`, `useRpc`, `useEvents`) all read their types from this single
31
- * registry, so the user's plugin types flow everywhere automatically.
32
- *
33
- * Mirrors the pattern TanStack Router uses for `Register`.
34
- */
35
- interface ZenbuRegister {}
36
- /**
37
- * Resolve the DB-root type from `ZenbuRegister["db"]`, falling back to a
38
- * core-only root when no augmentation has been declared (e.g. a plugin that
39
- * only emits events / RPC and doesn't define its own DB sections).
40
- */
41
- type ResolvedDbRoot = ZenbuRegister extends {
42
- db: infer T;
43
- } ? T : {
44
- plugin: CoreDbSections;
45
- };
46
- /**
47
- * Resolve the RPC router type from `ZenbuRegister["rpc"]`, falling back to
48
- * the core router when no augmentation has been declared.
49
- */
50
- type ResolvedServiceRouter = ZenbuRegister extends {
51
- rpc: infer T;
52
- } ? T : CoreServiceRouter;
53
- /**
54
- * Resolve the events tree from `ZenbuRegister["events"]`, falling back to
55
- * `CoreEvents` when no augmentation has been declared.
56
- */
57
- type ResolvedEvents = ZenbuRegister extends {
58
- events: infer T;
59
- } ? T : CoreEvents;
60
- //#endregion
61
- export { Events as a, ResolvedServiceRouter as c, CoreServiceRouter as i, ZenbuRegister as l, CoreEvents as n, ResolvedDbRoot as o, CorePreloads as r, ResolvedEvents as s, CoreDbSections as t };
@@ -1,2 +0,0 @@
1
- import "./reloader-DJoCB0bC.mjs";
2
- export {};