@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.
- package/dist/{advice-config-CjgkEf2E.mjs → advice-config-QYB2qEd_.mjs} +32 -14
- package/dist/advice.mjs +1 -1
- package/dist/{base-window-BUt8pwbw.mjs → base-window-BbFRRhKP.mjs} +9 -4
- package/dist/{build-config-pbv0w4oN.mjs → build-config-C3a-o3_B.mjs} +8 -2
- package/dist/{build-electron-BzHa_hRi.mjs → build-electron-CNJ0dLND.mjs} +12 -6
- package/dist/{build-source-CnTfQBGK.mjs → build-source-C2puqEVr.mjs} +13 -8
- package/dist/chunk-DsiFFCwN.mjs +16 -0
- package/dist/cli/bin.mjs +12 -15
- package/dist/cli/build.d.mts +1 -52
- package/dist/cli/build.mjs +2 -47
- package/dist/cli/resolve-config.mjs +37 -0
- package/dist/{cli-BLbQQIVB.mjs → cli-C3R1LBMY.mjs} +5 -5
- package/dist/{config-CdVrW85P.mjs → config-DXRCDUxG.mjs} +1 -1
- package/dist/config.d.mts +3 -0
- package/dist/config.mjs +4 -0
- package/dist/{db-BXadETOb.mjs → db-xjvahRFJ.mjs} +47 -41
- package/dist/db.d.mts +1 -1
- package/dist/db.mjs +2 -2
- package/dist/env-bootstrap.d.mts +1 -1
- package/dist/env-bootstrap.mjs +52 -1
- package/dist/index-ClXLQ1fw.d.mts +1 -0
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +4 -4
- package/dist/{link-VOoGs-pY.mjs → link-c0_aLWQ3.mjs} +87 -120
- package/dist/load-config-xMf2wxH8.mjs +141 -0
- package/dist/loaders/zenbu.d.mts +17 -0
- package/dist/loaders/zenbu.mjs +144 -135
- package/dist/{monorepo-CQeQBIpa.mjs → monorepo-3avKJwzJ.mjs} +5 -2
- package/dist/node-loader.mjs +1 -1
- package/dist/{publish-source-BJdpDAFH.mjs → publish-source-Dill72NS.mjs} +12 -6
- package/dist/react.d.mts +3 -3
- package/dist/react.mjs +2 -2
- package/dist/{registry-Dh_e7HU1.d.mts → registry-eX6e2oql.d.mts} +1 -1
- package/dist/registry.d.mts +1 -1
- package/dist/{reloader-lLAJ3lqg.mjs → reloader-DzEO8kJr.mjs} +6 -4
- package/dist/{renderer-host-Bg8QdeeH.mjs → renderer-host-Cau9JK0v.mjs} +90 -212
- package/dist/{rpc-BwwQK6hD.mjs → rpc-JfGv-Wuw.mjs} +7 -5
- package/dist/rpc.d.mts +1 -1
- package/dist/rpc.mjs +1 -1
- package/dist/{runtime-CjqDr8Yf.d.mts → runtime-pCeVzj--.d.mts} +73 -1
- package/dist/runtime.d.mts +2 -2
- package/dist/runtime.mjs +522 -2
- package/dist/{schema-DMoSkwUx.d.mts → schema-Dl85YjXW.d.mts} +1 -1
- package/dist/schema.d.mts +1 -1
- package/dist/schema.mjs +27 -1
- package/dist/{server-BXwZEQ-n.mjs → server-y3PPbh3l.mjs} +5 -3
- package/dist/services/default.mjs +10 -10
- package/dist/services/index.d.mts +8 -4
- package/dist/services/index.mjs +6 -6
- package/dist/setup-gate.d.mts +1 -1
- package/dist/setup-gate.mjs +248 -1
- package/dist/{transform-DJH3vN4b.mjs → transform-CmFYPmt8.mjs} +1 -1
- package/dist/transforms-CuTODvDx.d.mts +145 -0
- package/dist/transforms-htxfTwsY.mjs +47 -0
- package/dist/{transport-BMSzG2-F.mjs → transport-F2hv_OEm.mjs} +1 -1
- package/dist/{vite-plugins-Bh3SCOw-.mjs → vite-plugins-Do7liKi_.mjs} +5 -19
- package/dist/vite.mjs +1 -1
- package/dist/{window-CmmpCVX6.mjs → window-o2NGUsIb.mjs} +10 -7
- package/dist/{write-9dRFczGJ.mjs → write-DgIRjo23.mjs} +1 -1
- package/package.json +11 -10
- package/dist/advice-config-Cy133IQP.mjs +0 -2
- package/dist/base-window-DEIAk618.mjs +0 -2
- package/dist/chunk-Dm34NbLt.mjs +0 -6
- package/dist/config-LK73dJmO.mjs +0 -2
- package/dist/db-ByKPbnP6.mjs +0 -2
- package/dist/env-bootstrap-rj7I-59x.mjs +0 -53
- package/dist/http-IBcLzbYu.mjs +0 -2
- package/dist/load-build-config-DozuRhAN.mjs +0 -40
- package/dist/reloader-BCkLjDhS.mjs +0 -2
- package/dist/renderer-host-DpvBPTHJ.mjs +0 -2
- package/dist/rpc-CqitnyR4.mjs +0 -2
- package/dist/runtime-DUFKDIe4.mjs +0 -409
- package/dist/schema-dGK6qkfR.mjs +0 -28
- package/dist/server-DjrZUbbu.mjs +0 -2
- package/dist/setup-gate-BcoqWu8S.mjs +0 -110
- package/dist/view-registry-BualWgAf.mjs +0 -2
- package/dist/window-CM2a9Kyc.mjs +0 -2
- package/dist/{index-FtE8MXJ_.d.mts → cli/resolve-config.d.mts} +0 -0
- package/dist/{dev-BU_llQh1.mjs → dev-Dazhu66l.mjs} +0 -0
- package/dist/{env-bootstrap-BtVME-CU.d.mts → env-bootstrap-DW2hVhSO.d.mts} +0 -0
- package/dist/{index-Bhlbyrn7.d.mts → index-C-ALz_SH.d.mts} +0 -0
- package/dist/{index-CPZ5d6Hl.d.mts → index-M_lSNBrq.d.mts} +0 -0
- package/dist/{log-CyKv8hQg.mjs → log-6rzaCV0I.mjs} +0 -0
- package/dist/{mirror-sync-BN59kMCG.mjs → mirror-sync-PDzxhf1w.mjs} +1 -1
- /package/dist/{node-D4M19_mV.mjs → node-_8xShqxr.mjs} +0 -0
- /package/dist/{schema-CIg4GzHQ.mjs → schema-Ca7SxXgS.mjs} +0 -0
- /package/dist/{setup-gate-BqOzm7zp.d.mts → setup-gate-Dcy8gGPJ.d.mts} +0 -0
- /package/dist/{src-pELM4_iH.mjs → src-Cven45mq.mjs} +0 -0
- /package/dist/{trace-DCB7qFzT.mjs → trace-BaVg0rnY.mjs} +0 -0
package/dist/setup-gate.mjs
CHANGED
|
@@ -1,2 +1,249 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { bootstrapEnv } from "./env-bootstrap.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
|
+
function registerLoader(specifier, opts) {
|
|
10
|
+
return register(specifier, void 0, opts);
|
|
11
|
+
}
|
|
12
|
+
const verbose = process.env.ZENBU_VERBOSE === "1";
|
|
13
|
+
function isPluginModule(value) {
|
|
14
|
+
return typeof value === "object" && value !== null && typeof value.default === "function";
|
|
15
|
+
}
|
|
16
|
+
function isPluginController(value) {
|
|
17
|
+
return typeof value === "object" && value !== null && typeof value.main === "function";
|
|
18
|
+
}
|
|
19
|
+
function envMs(name) {
|
|
20
|
+
const raw = process.env[name];
|
|
21
|
+
if (!raw) return null;
|
|
22
|
+
const value = Number(raw);
|
|
23
|
+
return Number.isFinite(value) && value >= 0 ? value : null;
|
|
24
|
+
}
|
|
25
|
+
function projectArg() {
|
|
26
|
+
const arg = process.argv.find((item) => item.startsWith("--project="));
|
|
27
|
+
return arg ? path.resolve(arg.slice(10)) : null;
|
|
28
|
+
}
|
|
29
|
+
function appDirName(name) {
|
|
30
|
+
return name.replace(/^@/, "").replace(/[\\/]/g, "__");
|
|
31
|
+
}
|
|
32
|
+
function readPackageJson(packageDir) {
|
|
33
|
+
const pkgPath = path.join(packageDir, "package.json");
|
|
34
|
+
return JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
35
|
+
}
|
|
36
|
+
function findProjectRoot(projectDir) {
|
|
37
|
+
let dir = path.resolve(projectDir);
|
|
38
|
+
while (dir !== path.dirname(dir)) {
|
|
39
|
+
if (fs.existsSync(path.join(dir, "package.json"))) return dir;
|
|
40
|
+
dir = path.dirname(dir);
|
|
41
|
+
}
|
|
42
|
+
return path.resolve(projectDir);
|
|
43
|
+
}
|
|
44
|
+
function resolveConfigPath(projectRoot) {
|
|
45
|
+
const candidates = [
|
|
46
|
+
"zenbu.config.ts",
|
|
47
|
+
"zenbu.config.mts",
|
|
48
|
+
"zenbu.config.js",
|
|
49
|
+
"zenbu.config.mjs"
|
|
50
|
+
];
|
|
51
|
+
for (const name of candidates) {
|
|
52
|
+
const candidate = path.join(projectRoot, name);
|
|
53
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
54
|
+
}
|
|
55
|
+
throw new Error(`No zenbu config found at ${projectRoot}. Expected one of: ${candidates.join(", ")}`);
|
|
56
|
+
}
|
|
57
|
+
function findTsconfig(projectRoot) {
|
|
58
|
+
const candidate = path.join(projectRoot, "tsconfig.json");
|
|
59
|
+
return fs.existsSync(candidate) ? candidate : false;
|
|
60
|
+
}
|
|
61
|
+
function loadElectronApp() {
|
|
62
|
+
const electron = createRequire(import.meta.url)("electron");
|
|
63
|
+
if (!electron.app) throw new Error("Electron app API is unavailable; setup-gate must run inside Electron");
|
|
64
|
+
return electron.app;
|
|
65
|
+
}
|
|
66
|
+
async function closeRegisteredWatchers() {
|
|
67
|
+
await (await import("@zenbujs/hmr/pause")).closeAllWatchers?.();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Extract the splash's intended background color from a
|
|
71
|
+
* `<meta name="zenbu-bg" content="#xxx">` tag. Used as the BaseWindow's
|
|
72
|
+
* `backgroundColor` so the OS doesn't paint a single white frame before
|
|
73
|
+
* the WebContentsView's pixels reach the screen. Convention only —
|
|
74
|
+
* defaults to `#F4F4F4` when unset.
|
|
75
|
+
*/
|
|
76
|
+
function readSplashBgColor(splashPath) {
|
|
77
|
+
try {
|
|
78
|
+
const match = fs.readFileSync(splashPath, "utf8").match(/<meta\s+name=["']zenbu-bg["']\s+content=["']([^"']+)["']/i);
|
|
79
|
+
if (match?.[1]) return match[1];
|
|
80
|
+
} catch {}
|
|
81
|
+
return "#F4F4F4";
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Spawn the splash window before any plugin service evaluates. The window
|
|
85
|
+
* is created HIDDEN, the splash HTML is loaded into a `WebContentsView`,
|
|
86
|
+
* we wait for `loadFile` to resolve (= did-finish-load), then `win.show()`
|
|
87
|
+
* — by the time the OS composites the window, the splash pixels are already
|
|
88
|
+
* there. No white-frame flash.
|
|
89
|
+
*
|
|
90
|
+
* `BaseWindowService.evaluate()` adopts this window from
|
|
91
|
+
* `globalThis.__zenbu_boot_windows__` instead of creating a new one, so
|
|
92
|
+
* `WindowService.openView` can swap the splash content view for the
|
|
93
|
+
* Vite-served renderer in-place when the renderer is ready.
|
|
94
|
+
*/
|
|
95
|
+
async function spawnSplashWindow() {
|
|
96
|
+
const slot = globalThis;
|
|
97
|
+
const splashPath = slot.__zenbu_main_resolved_config__?.payload?.splashPath;
|
|
98
|
+
if (!splashPath || !fs.existsSync(splashPath)) {
|
|
99
|
+
if (verbose) console.log("[setup-gate] no splash.html resolved; skipping splash window");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const electron = await import("electron");
|
|
103
|
+
const backgroundColor = readSplashBgColor(splashPath);
|
|
104
|
+
const win = new electron.BaseWindow({
|
|
105
|
+
width: 1100,
|
|
106
|
+
height: 750,
|
|
107
|
+
show: false,
|
|
108
|
+
titleBarStyle: "hidden",
|
|
109
|
+
trafficLightPosition: {
|
|
110
|
+
x: 14,
|
|
111
|
+
y: 10
|
|
112
|
+
},
|
|
113
|
+
backgroundColor
|
|
114
|
+
});
|
|
115
|
+
const splashView = new electron.WebContentsView({ webPreferences: { paintWhenInitiallyHidden: true } });
|
|
116
|
+
win.contentView.addChildView(splashView);
|
|
117
|
+
const bounds = win.getContentBounds();
|
|
118
|
+
splashView.setBounds({
|
|
119
|
+
x: 0,
|
|
120
|
+
y: 0,
|
|
121
|
+
width: bounds.width,
|
|
122
|
+
height: bounds.height
|
|
123
|
+
});
|
|
124
|
+
await Promise.race([splashView.webContents.loadFile(splashPath).catch(() => {}), new Promise((resolve) => setTimeout(resolve, 1500))]);
|
|
125
|
+
win.show();
|
|
126
|
+
const boot = {
|
|
127
|
+
windowId: "main",
|
|
128
|
+
win
|
|
129
|
+
};
|
|
130
|
+
slot.__zenbu_boot_windows__ = [...slot.__zenbu_boot_windows__ ?? [], boot];
|
|
131
|
+
if (verbose) console.log("[setup-gate] splash window shown with", splashPath, "bg=", backgroundColor);
|
|
132
|
+
}
|
|
133
|
+
async function registerLoaders(tsconfig, projectRoot) {
|
|
134
|
+
register$1({ tsconfig });
|
|
135
|
+
const { loadConfig } = await import("./load-config-xMf2wxH8.mjs").then((n) => n.n);
|
|
136
|
+
const { resolved, pluginSourceFiles } = await loadConfig(projectRoot);
|
|
137
|
+
const loaderData = {
|
|
138
|
+
payload: {
|
|
139
|
+
plugins: resolved.plugins.map((p) => ({
|
|
140
|
+
name: p.name,
|
|
141
|
+
dir: p.dir,
|
|
142
|
+
services: p.services,
|
|
143
|
+
schemaPath: p.schemaPath,
|
|
144
|
+
migrationsPath: p.migrationsPath,
|
|
145
|
+
preloadPath: p.preloadPath,
|
|
146
|
+
eventsPath: p.eventsPath,
|
|
147
|
+
icons: p.icons
|
|
148
|
+
})),
|
|
149
|
+
appEntrypoint: resolved.uiEntrypointPath,
|
|
150
|
+
splashPath: resolved.splashPath
|
|
151
|
+
},
|
|
152
|
+
pluginSourceFiles
|
|
153
|
+
};
|
|
154
|
+
globalThis.__zenbu_main_resolved_config__ = loaderData;
|
|
155
|
+
registerLoader(import.meta.resolve("@zenbujs/core/loaders/zenbu"), { data: loaderData });
|
|
156
|
+
process.env.ZENBU_ADVICE_ROOT = projectRoot;
|
|
157
|
+
await import("./node-_8xShqxr.mjs");
|
|
158
|
+
const dynohot = await import(pathToFileURL(createRequire(import.meta.url).resolve("@zenbujs/hmr/register")).href);
|
|
159
|
+
if (typeof dynohot.register === "function") dynohot.register({ ignore: /[/\\](?:node_modules|dist)[/\\]/ });
|
|
160
|
+
}
|
|
161
|
+
async function setupGate() {
|
|
162
|
+
const app = loadElectronApp();
|
|
163
|
+
await app.whenReady();
|
|
164
|
+
bootstrapEnv();
|
|
165
|
+
let shuttingDown = false;
|
|
166
|
+
const shutdown = async (exitCode = 0) => {
|
|
167
|
+
if (shuttingDown) return;
|
|
168
|
+
shuttingDown = true;
|
|
169
|
+
try {
|
|
170
|
+
await globalThis.__zenbu_service_runtime__?.shutdown();
|
|
171
|
+
} catch (err) {
|
|
172
|
+
console.error("[setup-gate] shutdown failed:", err);
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
await closeRegisteredWatchers();
|
|
176
|
+
} catch (err) {
|
|
177
|
+
console.error("[setup-gate] closeAllWatchers failed:", err);
|
|
178
|
+
}
|
|
179
|
+
process.exit(exitCode);
|
|
180
|
+
};
|
|
181
|
+
app.on("before-quit", (event) => {
|
|
182
|
+
event.preventDefault();
|
|
183
|
+
shutdown(0);
|
|
184
|
+
});
|
|
185
|
+
process.on("SIGINT", () => void shutdown(0));
|
|
186
|
+
process.on("SIGTERM", () => void shutdown(0));
|
|
187
|
+
const autoQuitReadyMs = envMs("ZENBU_AUTO_QUIT_AFTER_READY_MS");
|
|
188
|
+
if (autoQuitReadyMs != null) {
|
|
189
|
+
if (verbose) console.log("[setup-gate] auto-quit after ready scheduled:", autoQuitReadyMs);
|
|
190
|
+
setTimeout(() => app.quit(), autoQuitReadyMs).unref();
|
|
191
|
+
}
|
|
192
|
+
const bundledAppPath = app.getAppPath();
|
|
193
|
+
const appName = readPackageJson(bundledAppPath).name ?? path.basename(bundledAppPath);
|
|
194
|
+
const resolvedProjectDir = projectArg() ?? path.join(process.env.ZENBU_APPS_DIR ?? path.join(os.homedir(), ".zenbu", "apps"), appDirName(appName));
|
|
195
|
+
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=.`);
|
|
196
|
+
const projectRoot = findProjectRoot(resolvedProjectDir);
|
|
197
|
+
const configPath = resolveConfigPath(projectRoot);
|
|
198
|
+
const tsconfig = findTsconfig(projectRoot);
|
|
199
|
+
process.chdir(projectRoot);
|
|
200
|
+
process.env.ZENBU_CONFIG_PATH = configPath;
|
|
201
|
+
if (!process.argv.some((arg) => arg.startsWith("--project="))) process.argv.push(`--project=${resolvedProjectDir}`);
|
|
202
|
+
if (verbose) {
|
|
203
|
+
console.log("[setup-gate] project:", resolvedProjectDir);
|
|
204
|
+
console.log("[setup-gate] config:", configPath);
|
|
205
|
+
}
|
|
206
|
+
await registerLoaders(tsconfig, projectRoot);
|
|
207
|
+
if (shuttingDown) return;
|
|
208
|
+
try {
|
|
209
|
+
await spawnSplashWindow();
|
|
210
|
+
} catch (err) {
|
|
211
|
+
if (shuttingDown) return;
|
|
212
|
+
throw err;
|
|
213
|
+
}
|
|
214
|
+
if (shuttingDown) return;
|
|
215
|
+
try {
|
|
216
|
+
const { defaultServices } = await import("./services/default.mjs");
|
|
217
|
+
await defaultServices();
|
|
218
|
+
} catch (err) {
|
|
219
|
+
if (shuttingDown) return;
|
|
220
|
+
throw err;
|
|
221
|
+
}
|
|
222
|
+
if (shuttingDown) return;
|
|
223
|
+
const url = `zenbu:plugins?config=${encodeURIComponent(configPath)}`;
|
|
224
|
+
let mod;
|
|
225
|
+
try {
|
|
226
|
+
mod = await import(url, { with: { hot: "import" } });
|
|
227
|
+
} catch (err) {
|
|
228
|
+
if (shuttingDown) return;
|
|
229
|
+
throw err;
|
|
230
|
+
}
|
|
231
|
+
if (shuttingDown) return;
|
|
232
|
+
if (isPluginModule(mod)) {
|
|
233
|
+
const controller = mod.default();
|
|
234
|
+
if (isPluginController(controller)) await controller.main();
|
|
235
|
+
}
|
|
236
|
+
if (shuttingDown) return;
|
|
237
|
+
await globalThis.__zenbu_service_runtime__?.whenIdle();
|
|
238
|
+
const autoQuitMs = envMs("ZENBU_AUTO_QUIT_AFTER_IDLE_MS");
|
|
239
|
+
if (autoQuitMs != null) {
|
|
240
|
+
if (verbose) console.log("[setup-gate] auto-quit scheduled:", autoQuitMs);
|
|
241
|
+
setTimeout(() => app.quit(), autoQuitMs).unref();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
setupGate().catch((error) => {
|
|
245
|
+
console.error(error);
|
|
246
|
+
process.exit(1);
|
|
247
|
+
});
|
|
248
|
+
//#endregion
|
|
2
249
|
export { setupGate };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as __require, t as __commonJSMin } from "./chunk-DsiFFCwN.mjs";
|
|
2
2
|
//#region ../../node_modules/.pnpm/@babel+types@7.29.0/node_modules/@babel/types/lib/utils/shallowEqual.js
|
|
3
3
|
var require_shallowEqual = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
//#region src/cli/lib/build-config.d.ts
|
|
2
|
+
interface TransformInput {
|
|
3
|
+
path: string;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
interface TransformOutput {
|
|
7
|
+
code?: string;
|
|
8
|
+
drop?: boolean;
|
|
9
|
+
}
|
|
10
|
+
type Transform = (file: TransformInput) => TransformOutput | null | undefined | void;
|
|
11
|
+
interface MirrorConfig {
|
|
12
|
+
target: string;
|
|
13
|
+
branch?: string;
|
|
14
|
+
}
|
|
15
|
+
interface BundleConfig {
|
|
16
|
+
extraResources?: string[];
|
|
17
|
+
}
|
|
18
|
+
interface BuildConfig {
|
|
19
|
+
source?: string;
|
|
20
|
+
out?: string;
|
|
21
|
+
include: string[];
|
|
22
|
+
ignore?: string[];
|
|
23
|
+
transforms?: Transform[];
|
|
24
|
+
mirror?: MirrorConfig;
|
|
25
|
+
bundle?: BundleConfig;
|
|
26
|
+
}
|
|
27
|
+
declare function defineBuildConfig(config: BuildConfig): BuildConfig;
|
|
28
|
+
type ResolvedBuildConfig = Required<Omit<BuildConfig, "mirror" | "bundle">> & {
|
|
29
|
+
mirror?: MirrorConfig;
|
|
30
|
+
bundle?: BundleConfig;
|
|
31
|
+
};
|
|
32
|
+
declare function resolveBuildConfig(config: BuildConfig): ResolvedBuildConfig;
|
|
33
|
+
/**
|
|
34
|
+
* A Zenbu plugin's main-process surface. Plugins are pure main-process: they
|
|
35
|
+
* register services + side-effect modules (schema, preload, events). UI is
|
|
36
|
+
* handled exclusively at the outer config level via `uiEntrypoint` — there
|
|
37
|
+
* is exactly one HTML entrypoint per app.
|
|
38
|
+
*
|
|
39
|
+
* `services` is an array of glob patterns (relative to the plugin file's
|
|
40
|
+
* directory). `schema` / `preload` / `events` are optional file paths.
|
|
41
|
+
*/
|
|
42
|
+
interface Plugin {
|
|
43
|
+
name: string;
|
|
44
|
+
services: string[];
|
|
45
|
+
schema?: string;
|
|
46
|
+
migrations?: string;
|
|
47
|
+
preload?: string;
|
|
48
|
+
events?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Plugin-author-defined SVG icons keyed by view scope. Read by
|
|
51
|
+
* `view-registry` to decorate registered views. Optional.
|
|
52
|
+
*/
|
|
53
|
+
icons?: Record<string, string>;
|
|
54
|
+
}
|
|
55
|
+
declare function definePlugin(plugin: Plugin): Plugin;
|
|
56
|
+
/**
|
|
57
|
+
* A plugin manifest after path resolution. Every relative path has been made
|
|
58
|
+
* absolute against `dir` (the directory the manifest came from). Glob-form
|
|
59
|
+
* service entries stay as patterns (still anchored to `dir`).
|
|
60
|
+
*
|
|
61
|
+
* The runtime stores these in `runtime.getPlugins()`; consumers like
|
|
62
|
+
* `services/db.ts`, `services/advice-config.ts`, `vite-plugins.ts` read from
|
|
63
|
+
* there instead of walking the filesystem looking for `zenbu.plugin.json`.
|
|
64
|
+
*/
|
|
65
|
+
interface ResolvedPlugin {
|
|
66
|
+
name: string;
|
|
67
|
+
/** Absolute directory the plugin was loaded from. */
|
|
68
|
+
dir: string;
|
|
69
|
+
/** Glob patterns for service files. Anchored to `dir`. */
|
|
70
|
+
services: string[];
|
|
71
|
+
/** Absolute path to `schema.ts` (or undefined). */
|
|
72
|
+
schemaPath?: string;
|
|
73
|
+
/** Absolute path to migrations dir/file (or undefined). */
|
|
74
|
+
migrationsPath?: string;
|
|
75
|
+
/** Absolute path to `preload.ts` (or undefined). */
|
|
76
|
+
preloadPath?: string;
|
|
77
|
+
/** Absolute path to `events.ts` (or undefined). */
|
|
78
|
+
eventsPath?: string;
|
|
79
|
+
/** Plugin-author-defined SVG icons. */
|
|
80
|
+
icons?: Record<string, string>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The whole-app `zenbu.config.ts` shape. Authored by user code; imported
|
|
84
|
+
* (and re-imported on every change) by the loader and CLI.
|
|
85
|
+
*
|
|
86
|
+
* - `db`: directory the kyju database lives in (relative to the config file).
|
|
87
|
+
* - `uiEntrypoint`: path to the boot-window's HTML file. Exactly one — there
|
|
88
|
+
* is no per-plugin UI (today's per-plugin `uiEntrypoint` was effectively a
|
|
89
|
+
* bug that the new shape disallows at the type level).
|
|
90
|
+
* - `plugins`: flat list. Each entry is either an inline `definePlugin({...})`
|
|
91
|
+
* or a path to a `zenbu.plugin.ts` whose default export is a plugin. The
|
|
92
|
+
* "host plugin" is just `plugins[0]` by convention; nothing structurally
|
|
93
|
+
* distinguishes it.
|
|
94
|
+
* - `build`: shipped as `defineBuildConfig({...})`. Drives `zen build:source`
|
|
95
|
+
* and `zen build:electron`.
|
|
96
|
+
*/
|
|
97
|
+
interface Config {
|
|
98
|
+
db: string;
|
|
99
|
+
uiEntrypoint: string;
|
|
100
|
+
plugins: Array<Plugin | string>;
|
|
101
|
+
build?: BuildConfig;
|
|
102
|
+
}
|
|
103
|
+
declare function defineConfig(config: Config): Config;
|
|
104
|
+
interface ResolvedConfig {
|
|
105
|
+
/** Absolute path to the `zenbu.config.ts` this came from. */
|
|
106
|
+
configPath: string;
|
|
107
|
+
/** Directory containing `zenbu.config.ts`. */
|
|
108
|
+
projectDir: string;
|
|
109
|
+
/** Absolute path to the database directory. */
|
|
110
|
+
dbPath: string;
|
|
111
|
+
/**
|
|
112
|
+
* Absolute path to the renderer's entrypoint directory. Vite's `root`
|
|
113
|
+
* resolves here; `index.html` inside it is served through Vite.
|
|
114
|
+
*/
|
|
115
|
+
uiEntrypointPath: string;
|
|
116
|
+
/**
|
|
117
|
+
* Absolute path to `splash.html` inside the entrypoint directory. Loaded
|
|
118
|
+
* raw (no Vite) into a transient BrowserView during the brief window
|
|
119
|
+
* between Electron `whenReady` and the renderer's first paint.
|
|
120
|
+
*/
|
|
121
|
+
splashPath: string;
|
|
122
|
+
plugins: ResolvedPlugin[];
|
|
123
|
+
/** Resolved build config; defaults filled in even when user omits. */
|
|
124
|
+
build: ResolvedBuildConfig;
|
|
125
|
+
}
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region src/cli/lib/transforms.d.ts
|
|
128
|
+
/**
|
|
129
|
+
* Marker-based feature-flag stripping. Removes lines between
|
|
130
|
+
* // @zenbu:strip-if FLAG (strip when FLAG is truthy)
|
|
131
|
+
* // @zenbu:strip-if !FLAG (strip when FLAG is falsy)
|
|
132
|
+
* ...
|
|
133
|
+
* // @zenbu:end
|
|
134
|
+
*
|
|
135
|
+
* Pure string/line ops — no AST, no compiler dep.
|
|
136
|
+
*/
|
|
137
|
+
declare function stripIfDisabled(flags: Record<string, boolean>): Transform;
|
|
138
|
+
/**
|
|
139
|
+
* Drop files whose path matches the given pattern (relative path from the
|
|
140
|
+
* source root, posix slashes). Also covered by `ignore` globs in the config;
|
|
141
|
+
* use this when a regex is more convenient than a glob.
|
|
142
|
+
*/
|
|
143
|
+
declare function dropFiles(pattern: RegExp | ((path: string) => boolean)): Transform;
|
|
144
|
+
//#endregion
|
|
145
|
+
export { resolveBuildConfig as _, Config as a, ResolvedBuildConfig as c, Transform as d, TransformInput as f, definePlugin as g, defineConfig as h, BundleConfig as i, ResolvedConfig as l, defineBuildConfig as m, stripIfDisabled as n, MirrorConfig as o, TransformOutput as p, BuildConfig as r, Plugin as s, dropFiles as t, ResolvedPlugin as u };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/cli/lib/transforms.ts
|
|
2
|
+
const STRIP_START = /^\s*\/\/\s*@zenbu:strip-if\s+(!?)([A-Za-z_][A-Za-z0-9_]*)\s*$/;
|
|
3
|
+
const STRIP_END = /^\s*\/\/\s*@zenbu:end\s*$/;
|
|
4
|
+
/**
|
|
5
|
+
* Marker-based feature-flag stripping. Removes lines between
|
|
6
|
+
* // @zenbu:strip-if FLAG (strip when FLAG is truthy)
|
|
7
|
+
* // @zenbu:strip-if !FLAG (strip when FLAG is falsy)
|
|
8
|
+
* ...
|
|
9
|
+
* // @zenbu:end
|
|
10
|
+
*
|
|
11
|
+
* Pure string/line ops — no AST, no compiler dep.
|
|
12
|
+
*/
|
|
13
|
+
function stripIfDisabled(flags) {
|
|
14
|
+
return (file) => {
|
|
15
|
+
const lines = file.code.split("\n");
|
|
16
|
+
const out = [];
|
|
17
|
+
let stripDepth = 0;
|
|
18
|
+
for (const line of lines) {
|
|
19
|
+
const startMatch = STRIP_START.exec(line);
|
|
20
|
+
if (startMatch) {
|
|
21
|
+
const negated = startMatch[1] === "!";
|
|
22
|
+
const flagValue = flags[startMatch[2]] ?? false;
|
|
23
|
+
if ((negated ? !flagValue : flagValue) || stripDepth > 0) stripDepth += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (STRIP_END.test(line)) {
|
|
27
|
+
if (stripDepth > 0) stripDepth -= 1;
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (stripDepth === 0) out.push(line);
|
|
31
|
+
}
|
|
32
|
+
return { code: out.join("\n") };
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Drop files whose path matches the given pattern (relative path from the
|
|
37
|
+
* source root, posix slashes). Also covered by `ignore` globs in the config;
|
|
38
|
+
* use this when a regex is more convenient than a glob.
|
|
39
|
+
*/
|
|
40
|
+
function dropFiles(pattern) {
|
|
41
|
+
const test = typeof pattern === "function" ? pattern : (p) => pattern.test(p);
|
|
42
|
+
return (file) => {
|
|
43
|
+
if (test(file.path)) return { drop: true };
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { stripIfDisabled as n, dropFiles as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getPlugins } from "./runtime.mjs";
|
|
2
|
+
import { n as require_lib, t as zenbuAdviceTransform$1 } from "./transform-CmFYPmt8.mjs";
|
|
3
|
+
import { a as getAllScopes, i as getAllContentScriptPaths, n as getAdvice, o as getContentScripts } from "./advice-config-QYB2qEd_.mjs";
|
|
3
4
|
import path from "node:path";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import fsp from "node:fs/promises";
|
|
6
6
|
//#region ../advice/src/vite.ts
|
|
7
7
|
var import_lib = require_lib();
|
|
8
8
|
const defaultInclude = /\.[jt]sx?$/;
|
|
@@ -117,22 +117,8 @@ function zenbuFrameworkResolve() {
|
|
|
117
117
|
* proactively calls `server.restart()` on add/change/unlink of any
|
|
118
118
|
* `tsconfig.local.json`.
|
|
119
119
|
*/
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
if (!configPath) return;
|
|
123
|
-
const configDir = path.dirname(configPath);
|
|
124
|
-
let tsconfigPaths = [];
|
|
125
|
-
try {
|
|
126
|
-
const raw = await fsp.readFile(configPath, "utf8");
|
|
127
|
-
const config = JSON.parse(raw);
|
|
128
|
-
if (Array.isArray(config.plugins)) for (const entry of config.plugins) {
|
|
129
|
-
if (typeof entry !== "string") continue;
|
|
130
|
-
const manifestAbs = path.isAbsolute(entry) ? entry : path.resolve(configDir, entry);
|
|
131
|
-
tsconfigPaths.push(path.join(path.dirname(manifestAbs), "tsconfig.local.json"));
|
|
132
|
-
}
|
|
133
|
-
} catch {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
120
|
+
configureServer(server) {
|
|
121
|
+
const tsconfigPaths = getPlugins().map((p) => path.join(p.dir, "tsconfig.local.json"));
|
|
136
122
|
if (tsconfigPaths.length === 0) return;
|
|
137
123
|
server.watcher.add(tsconfigPaths);
|
|
138
124
|
let restarting = false;
|
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-
|
|
1
|
+
import { a as zenbuVitePlugins, i as zenbuFrameworkResolve, n as resolveAdviceRuntime, r as zenbuAdviceTransform, t as advicePreludePlugin } from "./vite-plugins-Do7liKi_.mjs";
|
|
2
2
|
export { advicePreludePlugin, resolveAdviceRuntime, zenbuAdviceTransform, zenbuFrameworkResolve, zenbuVitePlugins };
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { t as
|
|
1
|
+
import { n as __exportAll } from "./chunk-DsiFFCwN.mjs";
|
|
2
|
+
import { runtime, serviceWithDeps } 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-Cau9JK0v.mjs";
|
|
5
|
+
import { t as BaseWindowService } from "./base-window-BbFRRhKP.mjs";
|
|
5
6
|
import { URLSearchParams } from "node:url";
|
|
6
7
|
import { WebContentsView, 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 "";
|
|
@@ -62,9 +64,10 @@ var WindowService = class extends serviceWithDeps({
|
|
|
62
64
|
const view = new WebContentsView({ webPreferences: {
|
|
63
65
|
nodeIntegration: false,
|
|
64
66
|
contextIsolation: true,
|
|
65
|
-
sandbox: true
|
|
67
|
+
sandbox: true,
|
|
68
|
+
...args.view?.webPreferences
|
|
66
69
|
} });
|
|
67
|
-
view.setBackgroundColor("#F4F4F4");
|
|
70
|
+
view.setBackgroundColor(args.view?.backgroundColor ?? "#F4F4F4");
|
|
68
71
|
win.contentView.addChildView(view);
|
|
69
72
|
const disposeContextMenu = electronContextMenu({
|
|
70
73
|
window: view,
|
|
@@ -153,4 +156,4 @@ var WindowService = class extends serviceWithDeps({
|
|
|
153
156
|
};
|
|
154
157
|
runtime.register(WindowService, import.meta);
|
|
155
158
|
//#endregion
|
|
156
|
-
export { WindowService as t };
|
|
159
|
+
export { window_exports as n, WindowService as t };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenbujs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./dist/cli/build.d.mts",
|
|
23
23
|
"import": "./dist/cli/build.mjs"
|
|
24
24
|
},
|
|
25
|
+
"./config": {
|
|
26
|
+
"types": "./dist/config.d.mts",
|
|
27
|
+
"import": "./dist/config.mjs"
|
|
28
|
+
},
|
|
25
29
|
"./loaders/zenbu": {
|
|
26
30
|
"types": "./dist/loaders/zenbu.d.mts",
|
|
27
31
|
"import": "./dist/loaders/zenbu.mjs"
|
|
@@ -98,27 +102,24 @@
|
|
|
98
102
|
"vite": "^6.0.0",
|
|
99
103
|
"ws": "^8.18.0",
|
|
100
104
|
"zod": "^4.3.6",
|
|
101
|
-
"@zenbujs/hmr": "0.0.
|
|
105
|
+
"@zenbujs/hmr": "0.0.2"
|
|
102
106
|
},
|
|
103
107
|
"devDependencies": {
|
|
104
108
|
"@types/node": "^22.0.0",
|
|
105
109
|
"@types/react": "^19.0.0",
|
|
106
110
|
"@types/ws": "^8.18.0",
|
|
107
111
|
"electron": "^42.0.0",
|
|
108
|
-
"eslint": "^9.0.0",
|
|
109
112
|
"tsdown": "^0.21.10",
|
|
110
113
|
"typescript": "^5.4.5",
|
|
114
|
+
"@zenbu/zenrpc": "0.0.0",
|
|
111
115
|
"@zenbu/kyju": "0.0.0",
|
|
112
|
-
"@zenbu/
|
|
113
|
-
"@zenbu/advice": "0.0.0",
|
|
114
|
-
"@zenbu/zenrpc": "0.0.0"
|
|
116
|
+
"@zenbu/advice": "0.0.0"
|
|
115
117
|
},
|
|
116
118
|
"scripts": {
|
|
117
119
|
"build": "node --max-old-space-size=8192 ./node_modules/tsdown/dist/run.mjs",
|
|
118
120
|
"dev": "tsdown --watch",
|
|
119
|
-
"link:types": "node
|
|
120
|
-
"db:generate": "node
|
|
121
|
-
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
122
|
-
"lint": "eslint . --max-warnings=0"
|
|
121
|
+
"link:types": "node ./dist/cli/bin.mjs link --types-config ./zenbu-types.config.json --registry ./types",
|
|
122
|
+
"db:generate": "node ./dist/cli/bin.mjs db generate --schema src/schema.ts --migrations ./migrations",
|
|
123
|
+
"typecheck": "tsc --noEmit -p tsconfig.json"
|
|
123
124
|
}
|
|
124
125
|
}
|
package/dist/chunk-Dm34NbLt.mjs
DELETED
|
@@ -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 };
|
package/dist/config-LK73dJmO.mjs
DELETED
package/dist/db-ByKPbnP6.mjs
DELETED
|
@@ -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 };
|