@zenbujs/core 0.0.1
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/LICENSE +11 -0
- package/dist/advice-config-CjgkEf2E.mjs +135 -0
- package/dist/advice-config-Cy133IQP.mjs +2 -0
- package/dist/advice-runtime.d.mts +35 -0
- package/dist/advice-runtime.mjs +131 -0
- package/dist/advice.d.mts +36 -0
- package/dist/advice.mjs +2 -0
- package/dist/base-window-BUt8pwbw.mjs +94 -0
- package/dist/base-window-DEIAk618.mjs +2 -0
- package/dist/build-config-pbv0w4oN.mjs +17 -0
- package/dist/build-electron-B4Gd0Gi4.mjs +516 -0
- package/dist/build-source-_q1n1zTV.mjs +162 -0
- package/dist/chunk-Dm34NbLt.mjs +6 -0
- package/dist/cli/bin.d.mts +1 -0
- package/dist/cli/bin.mjs +88 -0
- package/dist/cli/build.d.mts +53 -0
- package/dist/cli/build.mjs +48 -0
- package/dist/cli-BLbQQIVB.mjs +8054 -0
- package/dist/config-CdVrW85P.mjs +59 -0
- package/dist/config-LK73dJmO.mjs +2 -0
- package/dist/db-ByKPbnP6.mjs +2 -0
- package/dist/db-DhuAJrye.mjs +531 -0
- package/dist/db.d.mts +16 -0
- package/dist/db.mjs +16 -0
- package/dist/dev-BuqklM0k.mjs +85 -0
- package/dist/env-bootstrap-BtVME-CU.d.mts +16 -0
- package/dist/env-bootstrap-rj7I-59x.mjs +53 -0
- package/dist/env-bootstrap.d.mts +2 -0
- package/dist/env-bootstrap.mjs +2 -0
- package/dist/http-IBcLzbYu.mjs +2 -0
- package/dist/index-Bhlbyrn7.d.mts +63 -0
- package/dist/index-CPZ5d6Hl.d.mts +442 -0
- package/dist/index-FtE8MXJ_.d.mts +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.mjs +5 -0
- package/dist/launcher.mjs +173 -0
- package/dist/link-6roQ7Cn6.mjs +580 -0
- package/dist/loaders/zenbu.d.mts +22 -0
- package/dist/loaders/zenbu.mjs +267 -0
- package/dist/log-CyKv8hQg.mjs +20 -0
- package/dist/mirror-sync-CodOnwkD.mjs +332 -0
- package/dist/monorepo-CmGPHsVm.mjs +119 -0
- package/dist/node-D4M19_mV.mjs +5 -0
- package/dist/node-loader.d.mts +17 -0
- package/dist/node-loader.mjs +33 -0
- package/dist/pause-DvAUNmKn.mjs +52 -0
- package/dist/publish-source-BVgB62Zj.mjs +131 -0
- package/dist/react.d.mts +76 -0
- package/dist/react.mjs +291 -0
- package/dist/registry-Dh_e7HU1.d.mts +61 -0
- package/dist/registry.d.mts +2 -0
- package/dist/registry.mjs +1 -0
- package/dist/reloader-BCkLjDhS.mjs +2 -0
- package/dist/reloader-lLAJ3lqg.mjs +164 -0
- package/dist/renderer-host-Bg8QdeeH.mjs +1508 -0
- package/dist/renderer-host-DpvBPTHJ.mjs +2 -0
- package/dist/rpc-BwwQK6hD.mjs +71 -0
- package/dist/rpc-CqitnyR4.mjs +2 -0
- package/dist/rpc.d.mts +2 -0
- package/dist/rpc.mjs +2 -0
- package/dist/runtime-CjqDr8Yf.d.mts +109 -0
- package/dist/runtime-DUFKDIe4.mjs +409 -0
- package/dist/runtime.d.mts +2 -0
- package/dist/runtime.mjs +2 -0
- package/dist/schema-CIg4GzHQ.mjs +100 -0
- package/dist/schema-DMoSkwUx.d.mts +62 -0
- package/dist/schema-dGK6qkfR.mjs +28 -0
- package/dist/schema.d.mts +2 -0
- package/dist/schema.mjs +2 -0
- package/dist/server-BXwZEQ-n.mjs +66 -0
- package/dist/server-DjrZUbbu.mjs +2 -0
- package/dist/services/default.d.mts +11 -0
- package/dist/services/default.mjs +22 -0
- package/dist/services/index.d.mts +276 -0
- package/dist/services/index.mjs +7 -0
- package/dist/setup-gate-BeD6WS6d.mjs +110 -0
- package/dist/setup-gate-BqOzm7zp.d.mts +4 -0
- package/dist/setup-gate.d.mts +2 -0
- package/dist/setup-gate.mjs +2 -0
- package/dist/src-pELM4_iH.mjs +376 -0
- package/dist/trace-DCB7qFzT.mjs +10 -0
- package/dist/transform-DJH3vN4b.mjs +84041 -0
- package/dist/transport-BMSzG2-F.mjs +1045 -0
- package/dist/view-registry-BualWgAf.mjs +2 -0
- package/dist/vite-plugins-Bh3SCOw-.mjs +331 -0
- package/dist/vite.d.mts +68 -0
- package/dist/vite.mjs +2 -0
- package/dist/window-CM2a9Kyc.mjs +2 -0
- package/dist/window-CmmpCVX6.mjs +156 -0
- package/dist/write-9dRFczGJ.mjs +1248 -0
- package/migrations/0000_migration.ts +34 -0
- package/migrations/meta/0000_snapshot.json +18 -0
- package/migrations/meta/_journal.json +10 -0
- package/package.json +124 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
All Rights Reserved
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Zenbu Labs Inc.
|
|
4
|
+
|
|
5
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
6
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
7
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
8
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
9
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
10
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
11
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { i as runtime } from "./runtime-DUFKDIe4.mjs";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
//#region src/services/advice-config.ts
|
|
6
|
+
/**
|
|
7
|
+
* Walk up from the given file URL until we find a `zenbu.plugin.json`. The
|
|
8
|
+
* folder containing it is the plugin root and the anchor that
|
|
9
|
+
* `registerContentScript` / `registerAdvice` resolve relative paths against.
|
|
10
|
+
*
|
|
11
|
+
* Throws (with the URL in the message) if no manifest is found, because a
|
|
12
|
+
* silent fallback to `process.cwd()` would attach a content script to a
|
|
13
|
+
* nonsensical location and you'd debug it by staring at empty iframes.
|
|
14
|
+
*/
|
|
15
|
+
function findPluginRoot(metaUrl) {
|
|
16
|
+
let dir = path.dirname(fileURLToPath(metaUrl));
|
|
17
|
+
while (dir !== path.dirname(dir)) {
|
|
18
|
+
if (fs.existsSync(path.join(dir, "zenbu.plugin.json"))) return dir;
|
|
19
|
+
dir = path.dirname(dir);
|
|
20
|
+
}
|
|
21
|
+
throw new Error(`Could not find zenbu.plugin.json walking up from ${metaUrl}. Pass an absolute path, or call this from a file inside a Zenbu plugin.`);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Accepts either an absolute path (used as-is) or a path relative to the
|
|
25
|
+
* caller's plugin root. The `meta` argument is `import.meta` from the calling
|
|
26
|
+
* module; without it we can't compute the plugin root, so relative paths
|
|
27
|
+
* require it.
|
|
28
|
+
*/
|
|
29
|
+
function resolvePluginPath(modulePath, meta) {
|
|
30
|
+
if (path.isAbsolute(modulePath)) return modulePath;
|
|
31
|
+
if (!meta?.url) throw new Error(`registerContentScript/registerAdvice: relative path "${modulePath}" requires import.meta as the second argument so we can find the plugin root.`);
|
|
32
|
+
return path.resolve(findPluginRoot(meta.url), modulePath);
|
|
33
|
+
}
|
|
34
|
+
const RESOLVED_PREFIX = "\0@advice-prelude/";
|
|
35
|
+
const APP_RENDERER_RELOADER_ID = "app";
|
|
36
|
+
const adviceEntries = /* @__PURE__ */ new Map();
|
|
37
|
+
const contentScripts = /* @__PURE__ */ new Map();
|
|
38
|
+
function invalidatePrelude(scope) {
|
|
39
|
+
try {
|
|
40
|
+
const reloader = runtime.getSlot("reloader")?.instance;
|
|
41
|
+
if (!reloader) return;
|
|
42
|
+
const coreEntry = reloader.get(APP_RENDERER_RELOADER_ID);
|
|
43
|
+
if (!coreEntry?.viteServer) return;
|
|
44
|
+
const graph = coreEntry.viteServer.moduleGraph;
|
|
45
|
+
const invalidateScope = (s) => {
|
|
46
|
+
const prefix = RESOLVED_PREFIX + s;
|
|
47
|
+
const ids = [];
|
|
48
|
+
for (const id of graph.idToModuleMap.keys()) {
|
|
49
|
+
if (typeof id !== "string") continue;
|
|
50
|
+
if (id === prefix || id.startsWith(prefix + "?")) ids.push(id);
|
|
51
|
+
}
|
|
52
|
+
for (const id of ids) {
|
|
53
|
+
const mod = graph.getModuleById(id);
|
|
54
|
+
if (mod) graph.invalidateModule(mod);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
if (scope === "*") for (const s of getAllScopes()) invalidateScope(s);
|
|
58
|
+
else invalidateScope(scope);
|
|
59
|
+
} catch {}
|
|
60
|
+
}
|
|
61
|
+
function emitReload(scope) {
|
|
62
|
+
invalidatePrelude(scope);
|
|
63
|
+
try {
|
|
64
|
+
const rpc = runtime.getSlot("rpc")?.instance;
|
|
65
|
+
if (!rpc) return;
|
|
66
|
+
if (scope === "*") for (const s of getAllScopes()) rpc.emit.advice.reload({ scope: s });
|
|
67
|
+
else rpc.emit.advice.reload({ scope });
|
|
68
|
+
} catch {}
|
|
69
|
+
}
|
|
70
|
+
function registerAdvice(scope, entry, meta) {
|
|
71
|
+
const resolvedEntry = {
|
|
72
|
+
...entry,
|
|
73
|
+
modulePath: resolvePluginPath(entry.modulePath, meta)
|
|
74
|
+
};
|
|
75
|
+
const list = adviceEntries.get(scope) ?? [];
|
|
76
|
+
list.push(resolvedEntry);
|
|
77
|
+
adviceEntries.set(scope, list);
|
|
78
|
+
emitReload(scope);
|
|
79
|
+
return () => {
|
|
80
|
+
const current = adviceEntries.get(scope);
|
|
81
|
+
if (!current) return;
|
|
82
|
+
const idx = current.indexOf(resolvedEntry);
|
|
83
|
+
if (idx >= 0) current.splice(idx, 1);
|
|
84
|
+
if (current.length === 0) adviceEntries.delete(scope);
|
|
85
|
+
emitReload(scope);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
function getAdvice(scope) {
|
|
89
|
+
return adviceEntries.get(scope) ?? [];
|
|
90
|
+
}
|
|
91
|
+
function getAllAdviceScopes() {
|
|
92
|
+
return [...adviceEntries.keys()];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Register a content script for the given scope. `modulePath` is normally
|
|
96
|
+
* a path relative to the plugin root (the folder with `zenbu.plugin.json`);
|
|
97
|
+
* pass `import.meta` so we can resolve it. Absolute paths are accepted as
|
|
98
|
+
* an escape hatch.
|
|
99
|
+
*
|
|
100
|
+
* this.setup("inject", () =>
|
|
101
|
+
* registerContentScript("app", "src/content/clock.tsx", import.meta),
|
|
102
|
+
* )
|
|
103
|
+
*/
|
|
104
|
+
function registerContentScript(scope, modulePath, meta) {
|
|
105
|
+
const entry = { path: resolvePluginPath(modulePath, meta) };
|
|
106
|
+
const list = contentScripts.get(scope) ?? [];
|
|
107
|
+
list.push(entry);
|
|
108
|
+
contentScripts.set(scope, list);
|
|
109
|
+
emitReload(scope === "*" ? "*" : scope);
|
|
110
|
+
return () => {
|
|
111
|
+
const current = contentScripts.get(scope);
|
|
112
|
+
if (!current) return;
|
|
113
|
+
const idx = current.indexOf(entry);
|
|
114
|
+
if (idx >= 0) current.splice(idx, 1);
|
|
115
|
+
if (current.length === 0) contentScripts.delete(scope);
|
|
116
|
+
emitReload(scope === "*" ? "*" : scope);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function getContentScripts(scope) {
|
|
120
|
+
const scoped = (contentScripts.get(scope) ?? []).map((e) => e.path);
|
|
121
|
+
return [...scope !== "*" ? (contentScripts.get("*") ?? []).map((e) => e.path) : [], ...scoped];
|
|
122
|
+
}
|
|
123
|
+
function getAllContentScriptPaths() {
|
|
124
|
+
const paths = [];
|
|
125
|
+
for (const list of contentScripts.values()) for (const entry of list) paths.push(entry.path);
|
|
126
|
+
return paths;
|
|
127
|
+
}
|
|
128
|
+
function getAllScopes() {
|
|
129
|
+
const scopes = /* @__PURE__ */ new Set();
|
|
130
|
+
for (const k of adviceEntries.keys()) scopes.add(k);
|
|
131
|
+
for (const k of contentScripts.keys()) if (k !== "*") scopes.add(k);
|
|
132
|
+
return [...scopes];
|
|
133
|
+
}
|
|
134
|
+
//#endregion
|
|
135
|
+
export { getContentScripts as a, getAllScopes as i, getAllAdviceScopes as n, registerAdvice as o, getAllContentScriptPaths as r, registerContentScript as s, getAdvice as t };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region ../advice/src/runtime/registry.d.ts
|
|
2
|
+
type AdviceType = "before" | "after" | "around";
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region ../advice/src/runtime/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Register a function implementation. Called by transformed code.
|
|
7
|
+
* Sets entry.impl only -- does not touch entry.replacement, so plugin
|
|
8
|
+
* overrides survive HMR re-evaluation of the original module.
|
|
9
|
+
*/
|
|
10
|
+
declare function __def(moduleId: string, name: string, fn: Function): void;
|
|
11
|
+
/**
|
|
12
|
+
* Returns a stable wrapper function that dispatches through the advice chain.
|
|
13
|
+
* Returns the same function reference for the same moduleId+name across calls,
|
|
14
|
+
* which is critical for React Refresh component identity.
|
|
15
|
+
*/
|
|
16
|
+
declare function __ref(moduleId: string, name: string): Function;
|
|
17
|
+
/**
|
|
18
|
+
* Override a function with a plugin-provided replacement.
|
|
19
|
+
* Unlike __def(), this sets entry.replacement which takes precedence
|
|
20
|
+
* over entry.impl and is NOT cleared by subsequent __def() calls.
|
|
21
|
+
* This allows a prelude script to call replace() before modules load,
|
|
22
|
+
* and have the replacement survive module evaluation.
|
|
23
|
+
*/
|
|
24
|
+
declare function replace(moduleId: string, name: string, newFn: Function): void;
|
|
25
|
+
/**
|
|
26
|
+
* Remove a previously set replacement, restoring the original implementation.
|
|
27
|
+
*/
|
|
28
|
+
declare function unreplace(moduleId: string, name: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Add before/after/around advice to a function.
|
|
31
|
+
* Returns a removal function.
|
|
32
|
+
*/
|
|
33
|
+
declare function advise(moduleId: string, name: string, type: AdviceType, fn: Function): () => void;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { type AdviceType, __def, __ref, advise, replace, unreplace };
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
//#region ../advice/src/runtime/registry.ts
|
|
2
|
+
const registry = /* @__PURE__ */ new Map();
|
|
3
|
+
function getEntry(moduleId, name) {
|
|
4
|
+
return registry.get(moduleId)?.get(name);
|
|
5
|
+
}
|
|
6
|
+
function getOrCreateEntry(moduleId, name) {
|
|
7
|
+
let moduleMap = registry.get(moduleId);
|
|
8
|
+
if (!moduleMap) {
|
|
9
|
+
moduleMap = /* @__PURE__ */ new Map();
|
|
10
|
+
registry.set(moduleId, moduleMap);
|
|
11
|
+
}
|
|
12
|
+
let entry = moduleMap.get(name);
|
|
13
|
+
if (!entry) {
|
|
14
|
+
entry = {
|
|
15
|
+
impl: () => {
|
|
16
|
+
throw new Error(`${moduleId}:${name} not yet defined`);
|
|
17
|
+
},
|
|
18
|
+
replacement: null,
|
|
19
|
+
advice: []
|
|
20
|
+
};
|
|
21
|
+
moduleMap.set(name, entry);
|
|
22
|
+
}
|
|
23
|
+
return entry;
|
|
24
|
+
}
|
|
25
|
+
function setImpl(moduleId, name, fn) {
|
|
26
|
+
const entry = getOrCreateEntry(moduleId, name);
|
|
27
|
+
entry.impl = fn;
|
|
28
|
+
entry.wrapper = void 0;
|
|
29
|
+
}
|
|
30
|
+
function setReplacement(moduleId, name, fn) {
|
|
31
|
+
const entry = getOrCreateEntry(moduleId, name);
|
|
32
|
+
entry.replacement = fn;
|
|
33
|
+
}
|
|
34
|
+
function clearReplacement(moduleId, name) {
|
|
35
|
+
const entry = getEntry(moduleId, name);
|
|
36
|
+
if (entry) entry.replacement = null;
|
|
37
|
+
}
|
|
38
|
+
function addAdvice(moduleId, name, type, fn) {
|
|
39
|
+
const entry = getOrCreateEntry(moduleId, name);
|
|
40
|
+
const adviceEntry = {
|
|
41
|
+
type,
|
|
42
|
+
fn
|
|
43
|
+
};
|
|
44
|
+
entry.advice.push(adviceEntry);
|
|
45
|
+
return () => {
|
|
46
|
+
const idx = entry.advice.indexOf(adviceEntry);
|
|
47
|
+
if (idx >= 0) entry.advice.splice(idx, 1);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region ../advice/src/runtime/chain.ts
|
|
52
|
+
function applyAdviceChain(entry, args, thisArg) {
|
|
53
|
+
const befores = [];
|
|
54
|
+
const afters = [];
|
|
55
|
+
const arounds = [];
|
|
56
|
+
for (const a of entry.advice) switch (a.type) {
|
|
57
|
+
case "before":
|
|
58
|
+
befores.push(a);
|
|
59
|
+
break;
|
|
60
|
+
case "after":
|
|
61
|
+
afters.push(a);
|
|
62
|
+
break;
|
|
63
|
+
case "around":
|
|
64
|
+
arounds.push(a);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
const coreWithBeforesAfters = (...callArgs) => {
|
|
68
|
+
for (const b of befores) b.fn.apply(thisArg, callArgs);
|
|
69
|
+
let result = (entry.replacement ?? entry.impl).apply(thisArg, callArgs);
|
|
70
|
+
for (let i = afters.length - 1; i >= 0; i--) {
|
|
71
|
+
const afterResult = afters[i].fn.call(thisArg, result, ...callArgs);
|
|
72
|
+
if (afterResult !== void 0) result = afterResult;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
let composed = coreWithBeforesAfters;
|
|
77
|
+
for (let i = arounds.length - 1; i >= 0; i--) {
|
|
78
|
+
const aroundFn = arounds[i].fn;
|
|
79
|
+
const next = composed;
|
|
80
|
+
composed = (...callArgs) => aroundFn.call(thisArg, next, ...callArgs);
|
|
81
|
+
}
|
|
82
|
+
return composed(...args);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region ../advice/src/runtime/index.ts
|
|
86
|
+
globalThis.__zenbu_advice_registry__ = registry;
|
|
87
|
+
/**
|
|
88
|
+
* Register a function implementation. Called by transformed code.
|
|
89
|
+
* Sets entry.impl only -- does not touch entry.replacement, so plugin
|
|
90
|
+
* overrides survive HMR re-evaluation of the original module.
|
|
91
|
+
*/
|
|
92
|
+
function __def(moduleId, name, fn) {
|
|
93
|
+
setImpl(moduleId, name, fn);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns a stable wrapper function that dispatches through the advice chain.
|
|
97
|
+
* Returns the same function reference for the same moduleId+name across calls,
|
|
98
|
+
* which is critical for React Refresh component identity.
|
|
99
|
+
*/
|
|
100
|
+
function __ref(moduleId, name) {
|
|
101
|
+
const entry = getOrCreateEntry(moduleId, name);
|
|
102
|
+
if (!entry.wrapper) entry.wrapper = function wrapper(...args) {
|
|
103
|
+
return applyAdviceChain(entry, args, this);
|
|
104
|
+
};
|
|
105
|
+
return entry.wrapper;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Override a function with a plugin-provided replacement.
|
|
109
|
+
* Unlike __def(), this sets entry.replacement which takes precedence
|
|
110
|
+
* over entry.impl and is NOT cleared by subsequent __def() calls.
|
|
111
|
+
* This allows a prelude script to call replace() before modules load,
|
|
112
|
+
* and have the replacement survive module evaluation.
|
|
113
|
+
*/
|
|
114
|
+
function replace(moduleId, name, newFn) {
|
|
115
|
+
setReplacement(moduleId, name, newFn);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Remove a previously set replacement, restoring the original implementation.
|
|
119
|
+
*/
|
|
120
|
+
function unreplace(moduleId, name) {
|
|
121
|
+
clearReplacement(moduleId, name);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Add before/after/around advice to a function.
|
|
125
|
+
* Returns a removal function.
|
|
126
|
+
*/
|
|
127
|
+
function advise(moduleId, name, type, fn) {
|
|
128
|
+
return addAdvice(moduleId, name, type, fn);
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { __def, __ref, advise, replace, unreplace };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
//#region src/services/advice-config.d.ts
|
|
2
|
+
interface ViewAdviceEntry {
|
|
3
|
+
moduleId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
type: "replace" | "before" | "after" | "around";
|
|
6
|
+
modulePath: string;
|
|
7
|
+
exportName: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Public-facing advice spec. `modulePath` is normally a path relative to
|
|
11
|
+
* the plugin root (the folder containing `zenbu.plugin.json`); pass
|
|
12
|
+
* `import.meta` as the second argument so we can resolve it. Absolute
|
|
13
|
+
* paths are also accepted as an escape hatch.
|
|
14
|
+
*/
|
|
15
|
+
type AdviceSpec = Omit<ViewAdviceEntry, "modulePath"> & {
|
|
16
|
+
modulePath: string;
|
|
17
|
+
};
|
|
18
|
+
declare function registerAdvice(scope: string, entry: AdviceSpec, meta?: ImportMeta): () => void;
|
|
19
|
+
declare function getAdvice(scope: string): ViewAdviceEntry[];
|
|
20
|
+
declare function getAllAdviceScopes(): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Register a content script for the given scope. `modulePath` is normally
|
|
23
|
+
* a path relative to the plugin root (the folder with `zenbu.plugin.json`);
|
|
24
|
+
* pass `import.meta` so we can resolve it. Absolute paths are accepted as
|
|
25
|
+
* an escape hatch.
|
|
26
|
+
*
|
|
27
|
+
* this.setup("inject", () =>
|
|
28
|
+
* registerContentScript("app", "src/content/clock.tsx", import.meta),
|
|
29
|
+
* )
|
|
30
|
+
*/
|
|
31
|
+
declare function registerContentScript(scope: string, modulePath: string, meta?: ImportMeta): () => void;
|
|
32
|
+
declare function getContentScripts(scope: string): string[];
|
|
33
|
+
declare function getAllContentScriptPaths(): string[];
|
|
34
|
+
declare function getAllScopes(): string[];
|
|
35
|
+
//#endregion
|
|
36
|
+
export { type AdviceSpec, type ViewAdviceEntry, getAdvice, getAllAdviceScopes, getAllContentScriptPaths, getAllScopes, getContentScripts, registerAdvice, registerContentScript };
|
package/dist/advice.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as getContentScripts, i as getAllScopes, n as getAllAdviceScopes, o as registerAdvice, r as getAllContentScriptPaths, s as registerContentScript, t as getAdvice } from "./advice-config-CjgkEf2E.mjs";
|
|
2
|
+
export { getAdvice, getAllAdviceScopes, getAllContentScriptPaths, getAllScopes, getContentScripts, registerAdvice, registerContentScript };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { i as runtime, t as Service } from "./runtime-DUFKDIe4.mjs";
|
|
2
|
+
import { t as createLogger } from "./log-CyKv8hQg.mjs";
|
|
3
|
+
import { r as DbService } from "./renderer-host-Bg8QdeeH.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 };
|
|
@@ -0,0 +1,17 @@
|
|
|
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/seed",
|
|
9
|
+
include: config.include,
|
|
10
|
+
ignore: config.ignore ?? [],
|
|
11
|
+
transforms: config.transforms ?? [],
|
|
12
|
+
mirror: config.mirror,
|
|
13
|
+
bundle: config.bundle
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { resolveBuildConfig as n, defineBuildConfig as t };
|