muon-ui 0.26.0 → 0.26.47
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/README.md +5 -0
- package/android.d.ts +4 -4
- package/dist/android/lib/index.cjs +13 -10
- package/dist/android/lib/index.cjs.map +1 -1
- package/dist/android/lib/index.mjs +14 -11
- package/dist/android/lib/index.mjs.map +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.aar +0 -0
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.aar.md5 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.aar.sha1 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.aar.sha256 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.aar.sha512 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.module +10 -10
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.module.md5 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.module.sha1 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.module.sha256 +1 -1
- package/dist/android/maven/dev/muon/runtime/0.1.0/runtime-0.1.0.module.sha512 +1 -1
- package/dist/android/maven/dev/muon/runtime/maven-metadata.xml +1 -1
- package/dist/android/maven/dev/muon/runtime/maven-metadata.xml.md5 +1 -1
- package/dist/android/maven/dev/muon/runtime/maven-metadata.xml.sha1 +1 -1
- package/dist/android/maven/dev/muon/runtime/maven-metadata.xml.sha256 +1 -1
- package/dist/android/maven/dev/muon/runtime/maven-metadata.xml.sha512 +1 -1
- package/dist/android/renderer/renderer.js +41 -14
- package/dist/android/renderer/renderer.js.map +1 -1
- package/dist/cli.cjs +82 -56
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/native/linux-amd64/muon-builder +0 -0
- package/dist/native/linux-amd64/muon-launcher +0 -0
- package/dist/native/linux-amd64/muon-runtime-helper +0 -0
- package/dist/native/linux-arm64/muon-builder +0 -0
- package/dist/native/linux-arm64/muon-launcher +0 -0
- package/dist/native/linux-arm64/muon-runtime-helper +0 -0
- package/dist/native/linux-armhf/muon-builder +0 -0
- package/dist/native/linux-armhf/muon-launcher +0 -0
- package/dist/native/linux-armhf/muon-runtime-helper +0 -0
- package/dist/native/windows-amd64/muon-builder.exe +0 -0
- package/dist/native/windows-amd64/muon-launcher.exe +0 -0
- package/dist/native/windows-amd64/muon-plugin-inspector.exe +0 -0
- package/dist/native/windows-i686/muon-builder.exe +0 -0
- package/dist/native/windows-i686/muon-launcher.exe +0 -0
- package/dist/native/windows-i686/muon-plugin-inspector.exe +0 -0
- package/dist/runtime/linux-amd64/libmuon-ui.so +0 -0
- package/dist/runtime/linux-amd64/muon-core +0 -0
- package/dist/runtime/linux-amd64/plugins/node-bridge.mjs +5 -5
- package/dist/runtime/linux-amd64/plugins/node.so +0 -0
- package/dist/runtime/linux-arm64/libmuon-ui.so +0 -0
- package/dist/runtime/linux-arm64/muon-core +0 -0
- package/dist/runtime/linux-arm64/plugins/node-bridge.mjs +5 -5
- package/dist/runtime/linux-arm64/plugins/node.so +0 -0
- package/dist/runtime/linux-armhf/libmuon-ui.so +0 -0
- package/dist/runtime/linux-armhf/muon-core +0 -0
- package/dist/runtime/linux-armhf/plugins/node-bridge.mjs +5 -5
- package/dist/runtime/linux-armhf/plugins/node.so +0 -0
- package/dist/runtime/windows-amd64/libcardio.dll +0 -0
- package/dist/runtime/windows-amd64/libmuon-ui.dll +0 -0
- package/dist/runtime/windows-amd64/muon-core.exe +0 -0
- package/dist/runtime/windows-amd64/plugins/node-bridge.mjs +5 -5
- package/dist/runtime/windows-amd64/plugins/node.dll +0 -0
- package/dist/runtime/windows-i686/libcardio.dll +0 -0
- package/dist/runtime/windows-i686/libmuon-ui.dll +0 -0
- package/dist/runtime/windows-i686/muon-core.exe +0 -0
- package/dist/runtime/windows-i686/plugins/node-bridge.mjs +5 -5
- package/dist/runtime/windows-i686/plugins/node.dll +0 -0
- package/dist/{vite-internals-DseKep-X.cjs → vite-internals-CueaxMaY.cjs} +4225 -1963
- package/dist/vite-internals-CueaxMaY.cjs.map +1 -0
- package/dist/vite.cjs +100 -1294
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +6102 -5128
- package/dist/vite.mjs.map +1 -1
- package/images/get-started-android.png +0 -0
- package/muon-virtual-modules.d.ts +53 -0
- package/package.json +13 -13
- package/vite.d.ts +8 -0
- package/dist/vite-internals-DseKep-X.cjs.map +0 -1
package/dist/vite.cjs
CHANGED
|
@@ -1,1302 +1,21 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: muon-ui
|
|
3
|
-
* version: 0.26.
|
|
3
|
+
* version: 0.26.47
|
|
4
4
|
* description: A multi-platform GUI application framework that uses CEF as its backend
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/muon-ui.git
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: 95dc2712686873c8a022483fd9abf18598019bd7
|
|
9
9
|
*/
|
|
10
|
-
const require_vite_internals = require("./vite-internals-
|
|
10
|
+
const require_vite_internals = require("./vite-internals-CueaxMaY.cjs");
|
|
11
11
|
let node_fs_promises = require("node:fs/promises");
|
|
12
12
|
let node_path = require("node:path");
|
|
13
|
+
let node_fs = require("node:fs");
|
|
13
14
|
let node_url = require("node:url");
|
|
14
15
|
let node_child_process = require("node:child_process");
|
|
15
|
-
let node_fs = require("node:fs");
|
|
16
16
|
let node_os = require("node:os");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//#region src/capability.ts
|
|
20
|
-
var virtualModulePrefix = "\0muon-capability:";
|
|
21
|
-
var capabilityIdByteLength = 16;
|
|
22
|
-
var moduleNamePattern = /^[A-Za-z_$][A-Za-z0-9_$]*:[A-Za-z_$][A-Za-z0-9_$]*(?:\.[A-Za-z_$][A-Za-z0-9_$]*)*$/u;
|
|
23
|
-
var jsIdentifierPattern = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
24
|
-
var defaultMuonCapabilityFunctionPaths = [
|
|
25
|
-
"muon.browser.reload",
|
|
26
|
-
"muon.browser.hardReload",
|
|
27
|
-
"muon.browser.toggleFullscreen",
|
|
28
|
-
"muon.browser.enterFullscreen",
|
|
29
|
-
"muon.browser.exitFullscreen",
|
|
30
|
-
"muon.browser.zoomIn",
|
|
31
|
-
"muon.browser.zoomOut",
|
|
32
|
-
"muon.browser.resetZoom",
|
|
33
|
-
"muon.browser.show",
|
|
34
|
-
"muon.browser.hide",
|
|
35
|
-
"muon.browser.focus",
|
|
36
|
-
"muon.browser.blur",
|
|
37
|
-
"muon.browser.minimize",
|
|
38
|
-
"muon.browser.maximize",
|
|
39
|
-
"muon.browser.restore",
|
|
40
|
-
"muon.browser.setTitleBarVisibility",
|
|
41
|
-
"muon.browser.setTitleBarIcon",
|
|
42
|
-
"muon.browser.getWindowBounds",
|
|
43
|
-
"muon.browser.setWindowBounds",
|
|
44
|
-
"muon.browser.setContextMenuItems",
|
|
45
|
-
"muon.browser.clearContextMenuItems",
|
|
46
|
-
"muon.browser.createTray",
|
|
47
|
-
"muon.browser.setTrayMenu",
|
|
48
|
-
"muon.browser.setTrayIcon",
|
|
49
|
-
"muon.browser.setTrayTooltip",
|
|
50
|
-
"muon.browser.removeTray",
|
|
51
|
-
"muon.browser.close",
|
|
52
|
-
"muon.browser.shutdown",
|
|
53
|
-
"muon.browser.recycle",
|
|
54
|
-
"muon.environments.getVariables",
|
|
55
|
-
"muon.environments.getConfigValues",
|
|
56
|
-
"muon.environments.getCommandLine",
|
|
57
|
-
"muon.environments.getProcessId",
|
|
58
|
-
"muon.environments.getRuntimeInfo",
|
|
59
|
-
"muon.environments.getAutostart",
|
|
60
|
-
"muon.environments.setAutostart",
|
|
61
|
-
"muon.executor.spawn",
|
|
62
|
-
"muon.executor.loadLibrary",
|
|
63
|
-
"muon.fs.readFile",
|
|
64
|
-
"muon.fs.writeFile",
|
|
65
|
-
"muon.fs.readTextFile",
|
|
66
|
-
"muon.fs.writeTextFile",
|
|
67
|
-
"muon.fs.stat",
|
|
68
|
-
"muon.fs.lstat",
|
|
69
|
-
"muon.fs.exists",
|
|
70
|
-
"muon.fs.access",
|
|
71
|
-
"muon.fs.readdir",
|
|
72
|
-
"muon.fs.mkdir",
|
|
73
|
-
"muon.fs.rm",
|
|
74
|
-
"muon.fs.unlink",
|
|
75
|
-
"muon.fs.rmdir",
|
|
76
|
-
"muon.fs.rename",
|
|
77
|
-
"muon.fs.copyFile",
|
|
78
|
-
"muon.fs.appendFile",
|
|
79
|
-
"muon.fs.appendTextFile",
|
|
80
|
-
"muon.fs.truncate",
|
|
81
|
-
"muon.fs.realpath",
|
|
82
|
-
"muon.fs.readlink",
|
|
83
|
-
"muon.fs.symlink",
|
|
84
|
-
"muon.fs.watch",
|
|
85
|
-
"muon.fs.dialogs.selectFile",
|
|
86
|
-
"muon.fs.dialogs.selectFiles",
|
|
87
|
-
"muon.fs.dialogs.selectDirectory",
|
|
88
|
-
"muon.fs.dialogs.selectDirectories",
|
|
89
|
-
"muon.fs.dialogs.selectSaveFile",
|
|
90
|
-
"muon.launcher.getSettings",
|
|
91
|
-
"muon.launcher.setSettings",
|
|
92
|
-
"muon.launcher.triggerUpdate"
|
|
93
|
-
];
|
|
94
|
-
var normalizePath = (path) => (path.split("?")[0] ?? "").replaceAll("\\", "/");
|
|
95
|
-
var createCapabilityId = (usedIds) => {
|
|
96
|
-
for (;;) {
|
|
97
|
-
const id = `cap-${(0, node_crypto.randomBytes)(capabilityIdByteLength).toString("hex")}`;
|
|
98
|
-
if (!usedIds.has(id)) {
|
|
99
|
-
usedIds.add(id);
|
|
100
|
-
return id;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
var parseCapabilitySpecifier = (source) => {
|
|
105
|
-
if (!moduleNamePattern.test(source)) return;
|
|
106
|
-
const separator = source.indexOf(":");
|
|
107
|
-
return {
|
|
108
|
-
moduleName: source,
|
|
109
|
-
namespace: `${source.slice(0, separator)}.${source.slice(separator + 1)}`
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
var escapeRegExp = (source) => source.replace(/[\\^$+?.()|[\]{}]/gu, "\\$&");
|
|
113
|
-
var globToRegExp = (glob, separator) => {
|
|
114
|
-
let source = "^";
|
|
115
|
-
for (let index = 0; index < glob.length; index += 1) {
|
|
116
|
-
const current = glob[index] ?? "";
|
|
117
|
-
const next = glob[index + 1];
|
|
118
|
-
if (current === "*" && next === "*") {
|
|
119
|
-
source += ".*";
|
|
120
|
-
index += 1;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (current === "*") {
|
|
124
|
-
source += `[^${escapeRegExp(separator)}]*`;
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
source += escapeRegExp(current);
|
|
128
|
-
}
|
|
129
|
-
source += "$";
|
|
130
|
-
return new RegExp(source, "u");
|
|
131
|
-
};
|
|
132
|
-
var isGlobMatch = (glob, value, separator) => globToRegExp(glob, separator).test(value);
|
|
133
|
-
var containsGlob = (value) => value.includes("*");
|
|
134
|
-
var toRootRelativeImporter = (root, importer) => normalizePath((0, node_path.relative)(root, importer));
|
|
135
|
-
var readPackageName = (packageJsonPath) => {
|
|
136
|
-
try {
|
|
137
|
-
const parsed = JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
|
|
138
|
-
return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed) && typeof parsed.name === "string" ? parsed.name : void 0;
|
|
139
|
-
} catch {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
var getImporterPackageName = (root, importer) => {
|
|
144
|
-
const normalizedRoot = normalizePath(root);
|
|
145
|
-
const rootPackageJsonPath = (0, node_path.join)(root, "package.json");
|
|
146
|
-
let directory = (0, node_path.dirname)(normalizePath(importer));
|
|
147
|
-
for (;;) {
|
|
148
|
-
const packageJsonPath = (0, node_path.join)(directory, "package.json");
|
|
149
|
-
if (packageJsonPath !== rootPackageJsonPath && (0, node_fs.existsSync)(packageJsonPath)) return readPackageName(packageJsonPath);
|
|
150
|
-
if (normalizePath(directory) === normalizedRoot) return;
|
|
151
|
-
const parent = (0, node_path.dirname)(directory);
|
|
152
|
-
if (parent === directory) return;
|
|
153
|
-
directory = parent;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
var matchesCapabilityRuleImporter = (rule, root, importer) => {
|
|
157
|
-
const relativeImporter = toRootRelativeImporter(root, importer);
|
|
158
|
-
if (rule.sources?.some((pattern) => isGlobMatch(normalizePath(pattern), relativeImporter, "/")) ?? false) return true;
|
|
159
|
-
const packageName = getImporterPackageName(root, importer);
|
|
160
|
-
return packageName === void 0 ? false : rule.packages?.includes(packageName) ?? false;
|
|
161
|
-
};
|
|
162
|
-
var hasNamespaceFunctionAllow = (namespace, allow) => allow.some((entry) => {
|
|
163
|
-
if (entry.startsWith(`${namespace}.`)) return true;
|
|
164
|
-
return isGlobMatch(entry, `${namespace}.placeholder`, ".");
|
|
165
|
-
});
|
|
166
|
-
var getExactExportName = (namespace, functionPath) => {
|
|
167
|
-
const prefix = `${namespace}.`;
|
|
168
|
-
if (!functionPath.startsWith(prefix)) return;
|
|
169
|
-
const name = functionPath.slice(prefix.length);
|
|
170
|
-
if (!jsIdentifierPattern.test(name)) return;
|
|
171
|
-
return name;
|
|
172
|
-
};
|
|
173
|
-
var getExportedFunctions = (namespace, allow, functionPaths) => {
|
|
174
|
-
const exportedFunctions = /* @__PURE__ */ new Map();
|
|
175
|
-
const addExport = (functionPath) => {
|
|
176
|
-
const exportName = getExactExportName(namespace, functionPath);
|
|
177
|
-
if (exportName !== void 0 && !exportedFunctions.has(exportName)) exportedFunctions.set(exportName, functionPath);
|
|
178
|
-
};
|
|
179
|
-
for (const entry of allow) {
|
|
180
|
-
if (!containsGlob(entry)) {
|
|
181
|
-
addExport(entry);
|
|
182
|
-
continue;
|
|
183
|
-
}
|
|
184
|
-
for (const functionPath of functionPaths) if (isGlobMatch(entry, functionPath, ".")) addExport(functionPath);
|
|
185
|
-
}
|
|
186
|
-
return Array.from(exportedFunctions.entries());
|
|
187
|
-
};
|
|
188
|
-
var createFunctionPathCatalog = (functionPaths) => {
|
|
189
|
-
const catalog = [];
|
|
190
|
-
const seen = /* @__PURE__ */ new Set();
|
|
191
|
-
for (const functionPath of [...defaultMuonCapabilityFunctionPaths, ...functionPaths ?? []]) if (!seen.has(functionPath)) {
|
|
192
|
-
seen.add(functionPath);
|
|
193
|
-
catalog.push(functionPath);
|
|
194
|
-
}
|
|
195
|
-
return catalog;
|
|
196
|
-
};
|
|
197
|
-
var createRuleRuntimeEntry = (rule, id) => ({
|
|
198
|
-
id,
|
|
199
|
-
allow: [...rule.allow]
|
|
200
|
-
});
|
|
201
|
-
var validateCapabilityRule = (rule) => {
|
|
202
|
-
if ((rule.sources === void 0 || rule.sources.length === 0) && (rule.packages === void 0 || rule.packages.length === 0)) throw new Error("muon capability import rule requires sources or packages.");
|
|
203
|
-
};
|
|
204
|
-
var createModuleVirtualId = (rule) => `${virtualModulePrefix}${rule.index}:${rule.moduleName}`;
|
|
205
|
-
var parseModuleVirtualId = (id) => {
|
|
206
|
-
if (!id.startsWith(virtualModulePrefix)) return;
|
|
207
|
-
const payload = id.slice(17);
|
|
208
|
-
const separator = payload.indexOf(":");
|
|
209
|
-
if (separator <= 0) return;
|
|
210
|
-
const index = Number.parseInt(payload.slice(0, separator), 10);
|
|
211
|
-
if (!Number.isInteger(index) || index < 0) return;
|
|
212
|
-
return {
|
|
213
|
-
index,
|
|
214
|
-
moduleName: payload.slice(separator + 1)
|
|
215
|
-
};
|
|
216
|
-
};
|
|
217
|
-
var createExecutorSpawnExport = (capabilityId, functionPath) => `const __muonExecutorActiveProcesses = new Set();
|
|
218
|
-
const __muonExecutorEmptyBytes = new Uint8Array(0);
|
|
219
|
-
const __muonExecutorOwnerCallback = () => {};
|
|
220
|
-
const __muonExecutorAsyncDispose =
|
|
221
|
-
typeof Symbol === "function" && typeof Symbol.asyncDispose === "symbol"
|
|
222
|
-
? Symbol.asyncDispose
|
|
223
|
-
: null;
|
|
224
|
-
const __muonExecutorToBytes = (data) => {
|
|
225
|
-
if (typeof data === "string") {
|
|
226
|
-
return new TextEncoder().encode(data);
|
|
227
|
-
}
|
|
228
|
-
if (data instanceof ArrayBuffer) {
|
|
229
|
-
return new Uint8Array(data);
|
|
230
|
-
}
|
|
231
|
-
if (ArrayBuffer.isView(data)) {
|
|
232
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
233
|
-
}
|
|
234
|
-
throw new TypeError("stdin data must be a string or BufferSource");
|
|
235
|
-
};
|
|
236
|
-
const __muonExecutorFromBase64 = (source) => {
|
|
237
|
-
const text = atob(source ?? "");
|
|
238
|
-
const bytes = new Uint8Array(text.length);
|
|
239
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
240
|
-
bytes[index] = text.charCodeAt(index);
|
|
241
|
-
}
|
|
242
|
-
return bytes;
|
|
243
|
-
};
|
|
244
|
-
const __muonExecutorRpc = async (
|
|
245
|
-
request,
|
|
246
|
-
data = __muonExecutorEmptyBytes,
|
|
247
|
-
onStdout = null,
|
|
248
|
-
onStderr = null,
|
|
249
|
-
) =>
|
|
250
|
-
JSON.parse(
|
|
251
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [
|
|
252
|
-
JSON.stringify(request),
|
|
253
|
-
data,
|
|
254
|
-
0,
|
|
255
|
-
__muonExecutorOwnerCallback,
|
|
256
|
-
onStdout,
|
|
257
|
-
onStderr,
|
|
258
|
-
]),
|
|
259
|
-
);
|
|
260
|
-
const __muonExecutorDecodeWaitResult = (raw) => {
|
|
261
|
-
const result = {
|
|
262
|
-
processId: raw.processId,
|
|
263
|
-
exitCode: raw.exitCode,
|
|
264
|
-
};
|
|
265
|
-
if (Object.prototype.hasOwnProperty.call(raw, "stdoutBase64")) {
|
|
266
|
-
result.stdout = __muonExecutorFromBase64(raw.stdoutBase64);
|
|
267
|
-
}
|
|
268
|
-
if (Object.prototype.hasOwnProperty.call(raw, "stderrBase64")) {
|
|
269
|
-
result.stderr = __muonExecutorFromBase64(raw.stderrBase64);
|
|
270
|
-
}
|
|
271
|
-
return result;
|
|
272
|
-
};
|
|
273
|
-
const __muonExecutorReleaseActiveProcesses = async () => {
|
|
274
|
-
if (__muonExecutorActiveProcesses.size === 0) {
|
|
275
|
-
return;
|
|
276
|
-
}
|
|
277
|
-
for (const handle of Array.from(__muonExecutorActiveProcesses)) {
|
|
278
|
-
try {
|
|
279
|
-
await handle.release();
|
|
280
|
-
} catch {}
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
if (typeof globalThis.addEventListener === "function") {
|
|
284
|
-
for (const eventName of ["beforeunload", "pagehide", "unload"]) {
|
|
285
|
-
globalThis.addEventListener(eventName, __muonExecutorReleaseActiveProcesses);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
export const spawn = async (options = {}) => {
|
|
289
|
-
const stdoutCallback =
|
|
290
|
-
typeof options.onStdout === "function"
|
|
291
|
-
? (chunk) => options.onStdout(new Uint8Array(chunk))
|
|
292
|
-
: null;
|
|
293
|
-
const stderrCallback =
|
|
294
|
-
typeof options.onStderr === "function"
|
|
295
|
-
? (chunk) => options.onStderr(new Uint8Array(chunk))
|
|
296
|
-
: null;
|
|
297
|
-
const start = await __muonExecutorRpc(
|
|
298
|
-
{
|
|
299
|
-
op: "start",
|
|
300
|
-
options: {
|
|
301
|
-
command: options.command,
|
|
302
|
-
args: options.args,
|
|
303
|
-
cwd: options.cwd,
|
|
304
|
-
env: options.env,
|
|
305
|
-
daemon: options.daemon,
|
|
306
|
-
},
|
|
307
|
-
captureStdout: stdoutCallback === null,
|
|
308
|
-
captureStderr: stderrCallback === null,
|
|
309
|
-
},
|
|
310
|
-
__muonExecutorEmptyBytes,
|
|
311
|
-
stdoutCallback,
|
|
312
|
-
stderrCallback,
|
|
313
|
-
);
|
|
314
|
-
const handleId = start.handleId;
|
|
315
|
-
let released = false;
|
|
316
|
-
let stdinClosing = false;
|
|
317
|
-
let waitPromise = null;
|
|
318
|
-
const release = async () => {
|
|
319
|
-
if (released) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
released = true;
|
|
323
|
-
__muonExecutorActiveProcesses.delete(handle);
|
|
324
|
-
await __muonExecutorRpc({ op: "dispose", handleId });
|
|
325
|
-
};
|
|
326
|
-
const handle = {
|
|
327
|
-
processId: start.processId,
|
|
328
|
-
writeStdin: async (data) => {
|
|
329
|
-
if (released) {
|
|
330
|
-
throw new Error("executor process is released");
|
|
331
|
-
}
|
|
332
|
-
if (stdinClosing) {
|
|
333
|
-
throw new Error("stdin is closed");
|
|
334
|
-
}
|
|
335
|
-
await __muonExecutorRpc(
|
|
336
|
-
{ op: "writeStdin", handleId },
|
|
337
|
-
__muonExecutorToBytes(data),
|
|
338
|
-
);
|
|
339
|
-
},
|
|
340
|
-
closeStdin: async () => {
|
|
341
|
-
if (released) {
|
|
342
|
-
throw new Error("executor process is released");
|
|
343
|
-
}
|
|
344
|
-
stdinClosing = true;
|
|
345
|
-
await __muonExecutorRpc({ op: "closeStdin", handleId });
|
|
346
|
-
},
|
|
347
|
-
wait: () => {
|
|
348
|
-
if (waitPromise !== null) {
|
|
349
|
-
return waitPromise;
|
|
350
|
-
}
|
|
351
|
-
waitPromise = (async () => {
|
|
352
|
-
try {
|
|
353
|
-
return __muonExecutorDecodeWaitResult(
|
|
354
|
-
await __muonExecutorRpc({ op: "wait", handleId }),
|
|
355
|
-
);
|
|
356
|
-
} finally {
|
|
357
|
-
if (!released) {
|
|
358
|
-
released = true;
|
|
359
|
-
__muonExecutorActiveProcesses.delete(handle);
|
|
360
|
-
try {
|
|
361
|
-
await __muonExecutorRpc({ op: "dispose", handleId });
|
|
362
|
-
} catch {}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
})();
|
|
366
|
-
return waitPromise;
|
|
367
|
-
},
|
|
368
|
-
kill: async () => {
|
|
369
|
-
if (released) {
|
|
370
|
-
throw new Error("executor process is released");
|
|
371
|
-
}
|
|
372
|
-
await __muonExecutorRpc({ op: "kill", handleId });
|
|
373
|
-
},
|
|
374
|
-
release,
|
|
375
|
-
};
|
|
376
|
-
if (__muonExecutorAsyncDispose !== null) {
|
|
377
|
-
Object.defineProperty(handle, __muonExecutorAsyncDispose, {
|
|
378
|
-
configurable: false,
|
|
379
|
-
enumerable: false,
|
|
380
|
-
value: release,
|
|
381
|
-
writable: false,
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
|
-
Object.freeze(handle);
|
|
385
|
-
__muonExecutorActiveProcesses.add(handle);
|
|
386
|
-
return handle;
|
|
387
|
-
};`;
|
|
388
|
-
var createExecutorLoadLibraryExport = (capabilityId, functionPath) => `const __muonAdhocActiveLibraries = new Set();
|
|
389
|
-
const __muonAdhocEmptyBytes = new Uint8Array(0);
|
|
390
|
-
const __muonAdhocAsyncDispose =
|
|
391
|
-
typeof Symbol === "function" && typeof Symbol.asyncDispose === "symbol"
|
|
392
|
-
? Symbol.asyncDispose
|
|
393
|
-
: null;
|
|
394
|
-
const __muonAdhocPointerBrand =
|
|
395
|
-
typeof Symbol === "function" ? Symbol.for("muon.nativePointer") : "__muonNativePointer";
|
|
396
|
-
const __muonAdhocType = (name) => Object.freeze({ name });
|
|
397
|
-
const __muonAdhocTypes = Object.freeze({
|
|
398
|
-
voidType: __muonAdhocType("void"),
|
|
399
|
-
boolType: __muonAdhocType("bool"),
|
|
400
|
-
int8Type: __muonAdhocType("int8"),
|
|
401
|
-
uint8Type: __muonAdhocType("uint8"),
|
|
402
|
-
int16Type: __muonAdhocType("int16"),
|
|
403
|
-
uint16Type: __muonAdhocType("uint16"),
|
|
404
|
-
int32Type: __muonAdhocType("int32"),
|
|
405
|
-
uint32Type: __muonAdhocType("uint32"),
|
|
406
|
-
int64Type: __muonAdhocType("int64"),
|
|
407
|
-
uint64Type: __muonAdhocType("uint64"),
|
|
408
|
-
float32Type: __muonAdhocType("float32"),
|
|
409
|
-
float64Type: __muonAdhocType("float64"),
|
|
410
|
-
stringType: __muonAdhocType("string"),
|
|
411
|
-
pointerType: __muonAdhocType("pointer"),
|
|
412
|
-
bufferViewType: __muonAdhocType("bufferView"),
|
|
413
|
-
usizeType: __muonAdhocType("usize"),
|
|
414
|
-
});
|
|
415
|
-
const __muonAdhocToBytes = (data) => {
|
|
416
|
-
if (typeof data === "string") {
|
|
417
|
-
return new TextEncoder().encode(data);
|
|
418
|
-
}
|
|
419
|
-
if (data instanceof ArrayBuffer) {
|
|
420
|
-
return new Uint8Array(data);
|
|
421
|
-
}
|
|
422
|
-
if (ArrayBuffer.isView(data)) {
|
|
423
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
424
|
-
}
|
|
425
|
-
throw new TypeError("bufferView argument must be a string or BufferSource");
|
|
426
|
-
};
|
|
427
|
-
const __muonAdhocFromBase64 = (source) => {
|
|
428
|
-
const text = atob(source ?? "");
|
|
429
|
-
const bytes = new Uint8Array(text.length);
|
|
430
|
-
for (let index = 0; index < text.length; index += 1) {
|
|
431
|
-
bytes[index] = text.charCodeAt(index);
|
|
432
|
-
}
|
|
433
|
-
return bytes;
|
|
434
|
-
};
|
|
435
|
-
const __muonAdhocCreatePointer = (value) => {
|
|
436
|
-
const text = String(value ?? "0");
|
|
437
|
-
const pointer = {
|
|
438
|
-
[__muonAdhocPointerBrand]: true,
|
|
439
|
-
value: text,
|
|
440
|
-
toString: () => text,
|
|
441
|
-
toJSON: () => text,
|
|
442
|
-
};
|
|
443
|
-
return Object.freeze(pointer);
|
|
444
|
-
};
|
|
445
|
-
const __muonAdhocNormalizeType = (type) => {
|
|
446
|
-
if (typeof type === "string") {
|
|
447
|
-
return { name: type };
|
|
448
|
-
}
|
|
449
|
-
if (type && typeof type.name === "string") {
|
|
450
|
-
return { name: type.name };
|
|
451
|
-
}
|
|
452
|
-
throw new TypeError("adhoc type descriptor is invalid");
|
|
453
|
-
};
|
|
454
|
-
const __muonAdhocNormalizeSignature = (signature) => {
|
|
455
|
-
if (!signature || !Array.isArray(signature.argTypes)) {
|
|
456
|
-
throw new TypeError("adhoc signature is invalid");
|
|
457
|
-
}
|
|
458
|
-
return {
|
|
459
|
-
argTypes: signature.argTypes.map(__muonAdhocNormalizeType),
|
|
460
|
-
returnType: __muonAdhocNormalizeType(signature.returnType),
|
|
461
|
-
};
|
|
462
|
-
};
|
|
463
|
-
const __muonAdhocEncodeInteger = (value) => {
|
|
464
|
-
if (typeof value === "bigint") {
|
|
465
|
-
return value.toString();
|
|
466
|
-
}
|
|
467
|
-
if (typeof value === "number") {
|
|
468
|
-
if (!Number.isFinite(value) || Math.trunc(value) !== value) {
|
|
469
|
-
throw new TypeError("integer argument must be finite");
|
|
470
|
-
}
|
|
471
|
-
return String(value);
|
|
472
|
-
}
|
|
473
|
-
if (typeof value === "string") {
|
|
474
|
-
return value;
|
|
475
|
-
}
|
|
476
|
-
throw new TypeError("integer argument must be a number, bigint, or string");
|
|
477
|
-
};
|
|
478
|
-
const __muonAdhocEncodePointer = (value) => {
|
|
479
|
-
if (value === null || value === undefined) {
|
|
480
|
-
return "0";
|
|
481
|
-
}
|
|
482
|
-
if (typeof value === "object" && value[__muonAdhocPointerBrand]) {
|
|
483
|
-
return value.value;
|
|
484
|
-
}
|
|
485
|
-
return __muonAdhocEncodeInteger(value);
|
|
486
|
-
};
|
|
487
|
-
const __muonAdhocEncodeCall = (signature, args) => {
|
|
488
|
-
if (args.length !== signature.argTypes.length) {
|
|
489
|
-
throw new TypeError("Invalid adhoc argument count");
|
|
490
|
-
}
|
|
491
|
-
const encoded = [];
|
|
492
|
-
const chunks = [];
|
|
493
|
-
const bufferViews = [];
|
|
494
|
-
let offset = 0;
|
|
495
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
496
|
-
const name = signature.argTypes[index].name;
|
|
497
|
-
const value = args[index];
|
|
498
|
-
if (name === "int64" || name === "uint64" || name === "usize") {
|
|
499
|
-
encoded.push(__muonAdhocEncodeInteger(value));
|
|
500
|
-
} else if (name === "pointer") {
|
|
501
|
-
encoded.push(__muonAdhocEncodePointer(value));
|
|
502
|
-
} else if (name === "bufferView") {
|
|
503
|
-
const bytes = __muonAdhocToBytes(value);
|
|
504
|
-
chunks.push(bytes);
|
|
505
|
-
bufferViews.push({ argIndex: index, offset, size: bytes.byteLength });
|
|
506
|
-
offset += bytes.byteLength;
|
|
507
|
-
encoded.push(null);
|
|
508
|
-
} else {
|
|
509
|
-
encoded.push(value);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
const data = new Uint8Array(offset);
|
|
513
|
-
let writeOffset = 0;
|
|
514
|
-
for (const chunk of chunks) {
|
|
515
|
-
data.set(chunk, writeOffset);
|
|
516
|
-
writeOffset += chunk.byteLength;
|
|
517
|
-
}
|
|
518
|
-
return { args: encoded, bufferViews, data };
|
|
519
|
-
};
|
|
520
|
-
const __muonAdhocDecodeResult = (signature, raw) => {
|
|
521
|
-
const name = signature.returnType.name;
|
|
522
|
-
if (name === "void") {
|
|
523
|
-
return undefined;
|
|
524
|
-
}
|
|
525
|
-
if (name === "pointer") {
|
|
526
|
-
return __muonAdhocCreatePointer(raw.pointer);
|
|
527
|
-
}
|
|
528
|
-
if (name === "int64" || name === "uint64" || name === "usize") {
|
|
529
|
-
return BigInt(raw.value);
|
|
530
|
-
}
|
|
531
|
-
if (name === "bufferView") {
|
|
532
|
-
return __muonAdhocFromBase64(raw.base64);
|
|
533
|
-
}
|
|
534
|
-
return raw.value;
|
|
535
|
-
};
|
|
536
|
-
const __muonAdhocRpc = async (request, data = __muonAdhocEmptyBytes) =>
|
|
537
|
-
JSON.parse(
|
|
538
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [
|
|
539
|
-
JSON.stringify(request),
|
|
540
|
-
data,
|
|
541
|
-
0,
|
|
542
|
-
]),
|
|
543
|
-
);
|
|
544
|
-
const __muonAdhocReleaseActiveLibraries = async () => {
|
|
545
|
-
if (__muonAdhocActiveLibraries.size === 0) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
for (const handle of Array.from(__muonAdhocActiveLibraries)) {
|
|
549
|
-
try {
|
|
550
|
-
await handle.release();
|
|
551
|
-
} catch {}
|
|
552
|
-
}
|
|
553
|
-
};
|
|
554
|
-
if (typeof globalThis.addEventListener === "function") {
|
|
555
|
-
for (const eventName of ["beforeunload", "pagehide", "unload"]) {
|
|
556
|
-
globalThis.addEventListener(eventName, __muonAdhocReleaseActiveLibraries);
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
export const voidType = __muonAdhocTypes.voidType;
|
|
560
|
-
export const boolType = __muonAdhocTypes.boolType;
|
|
561
|
-
export const int8Type = __muonAdhocTypes.int8Type;
|
|
562
|
-
export const uint8Type = __muonAdhocTypes.uint8Type;
|
|
563
|
-
export const int16Type = __muonAdhocTypes.int16Type;
|
|
564
|
-
export const uint16Type = __muonAdhocTypes.uint16Type;
|
|
565
|
-
export const int32Type = __muonAdhocTypes.int32Type;
|
|
566
|
-
export const uint32Type = __muonAdhocTypes.uint32Type;
|
|
567
|
-
export const int64Type = __muonAdhocTypes.int64Type;
|
|
568
|
-
export const uint64Type = __muonAdhocTypes.uint64Type;
|
|
569
|
-
export const float32Type = __muonAdhocTypes.float32Type;
|
|
570
|
-
export const float64Type = __muonAdhocTypes.float64Type;
|
|
571
|
-
export const stringType = __muonAdhocTypes.stringType;
|
|
572
|
-
export const pointerType = __muonAdhocTypes.pointerType;
|
|
573
|
-
export const bufferViewType = __muonAdhocTypes.bufferViewType;
|
|
574
|
-
export const usizeType = __muonAdhocTypes.usizeType;
|
|
575
|
-
export const loadLibrary = async (path) => {
|
|
576
|
-
const start = await __muonAdhocRpc({ op: "load", path });
|
|
577
|
-
const libraryId = start.libraryId;
|
|
578
|
-
let released = false;
|
|
579
|
-
const release = async () => {
|
|
580
|
-
if (released) {
|
|
581
|
-
return;
|
|
582
|
-
}
|
|
583
|
-
released = true;
|
|
584
|
-
__muonAdhocActiveLibraries.delete(handle);
|
|
585
|
-
await __muonAdhocRpc({ op: "release", libraryId });
|
|
586
|
-
};
|
|
587
|
-
const handle = {
|
|
588
|
-
getFunction: async (name, signature) => {
|
|
589
|
-
if (released) {
|
|
590
|
-
throw new Error("adhoc library is released");
|
|
591
|
-
}
|
|
592
|
-
const normalizedSignature = __muonAdhocNormalizeSignature(signature);
|
|
593
|
-
const loaded = await __muonAdhocRpc({
|
|
594
|
-
op: "getFunction",
|
|
595
|
-
libraryId,
|
|
596
|
-
name,
|
|
597
|
-
signature: normalizedSignature,
|
|
598
|
-
});
|
|
599
|
-
const functionId = loaded.functionId;
|
|
600
|
-
return async (...args) => {
|
|
601
|
-
if (released) {
|
|
602
|
-
throw new Error("adhoc library is released");
|
|
603
|
-
}
|
|
604
|
-
const encoded = __muonAdhocEncodeCall(normalizedSignature, args);
|
|
605
|
-
const raw = await __muonAdhocRpc(
|
|
606
|
-
{
|
|
607
|
-
op: "call",
|
|
608
|
-
libraryId,
|
|
609
|
-
functionId,
|
|
610
|
-
args: encoded.args,
|
|
611
|
-
bufferViews: encoded.bufferViews,
|
|
612
|
-
},
|
|
613
|
-
encoded.data,
|
|
614
|
-
);
|
|
615
|
-
return __muonAdhocDecodeResult(normalizedSignature, raw);
|
|
616
|
-
};
|
|
617
|
-
},
|
|
618
|
-
release,
|
|
619
|
-
};
|
|
620
|
-
if (__muonAdhocAsyncDispose !== null) {
|
|
621
|
-
Object.defineProperty(handle, __muonAdhocAsyncDispose, {
|
|
622
|
-
configurable: false,
|
|
623
|
-
enumerable: false,
|
|
624
|
-
value: release,
|
|
625
|
-
writable: false,
|
|
626
|
-
});
|
|
627
|
-
}
|
|
628
|
-
Object.freeze(handle);
|
|
629
|
-
__muonAdhocActiveLibraries.add(handle);
|
|
630
|
-
return handle;
|
|
631
|
-
};`;
|
|
632
|
-
var createBrowserContextMenuHelpers = () => `const __muonBrowserContextMenuEventName = "muon-browser-context-menu-command";
|
|
633
|
-
const __muonBrowserContextMenuWhenKeys = [
|
|
634
|
-
"editable",
|
|
635
|
-
"selection",
|
|
636
|
-
"link",
|
|
637
|
-
"image",
|
|
638
|
-
"canCopy",
|
|
639
|
-
"canPaste",
|
|
640
|
-
];
|
|
641
|
-
let __muonBrowserContextMenuToken = "";
|
|
642
|
-
let __muonBrowserContextMenuHandler = undefined;
|
|
643
|
-
let __muonBrowserContextMenuListening = false;
|
|
644
|
-
const __muonCreateBrowserContextMenuToken = () => {
|
|
645
|
-
const crypto = globalThis.crypto;
|
|
646
|
-
if (
|
|
647
|
-
crypto &&
|
|
648
|
-
typeof crypto.getRandomValues === "function" &&
|
|
649
|
-
typeof globalThis.Uint32Array === "function"
|
|
650
|
-
) {
|
|
651
|
-
const values = new globalThis.Uint32Array(4);
|
|
652
|
-
crypto.getRandomValues(values);
|
|
653
|
-
return Array.from(values, (value) => value.toString(16).padStart(8, "0")).join("");
|
|
654
|
-
}
|
|
655
|
-
return \`\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2)}\`;
|
|
656
|
-
};
|
|
657
|
-
const __muonEnsureBrowserContextMenuListener = () => {
|
|
658
|
-
if (
|
|
659
|
-
__muonBrowserContextMenuListening ||
|
|
660
|
-
typeof globalThis.addEventListener !== "function"
|
|
661
|
-
) {
|
|
662
|
-
return;
|
|
663
|
-
}
|
|
664
|
-
globalThis.addEventListener(__muonBrowserContextMenuEventName, (event) => {
|
|
665
|
-
const detail = event && event.detail;
|
|
666
|
-
if (
|
|
667
|
-
typeof detail !== "object" ||
|
|
668
|
-
detail === null ||
|
|
669
|
-
detail.token !== __muonBrowserContextMenuToken ||
|
|
670
|
-
typeof __muonBrowserContextMenuHandler !== "function"
|
|
671
|
-
) {
|
|
672
|
-
return;
|
|
673
|
-
}
|
|
674
|
-
__muonBrowserContextMenuHandler(detail);
|
|
675
|
-
});
|
|
676
|
-
__muonBrowserContextMenuListening = true;
|
|
677
|
-
};
|
|
678
|
-
const __muonNormalizeBrowserContextMenuPlacement = (placement) => {
|
|
679
|
-
if (placement === undefined) {
|
|
680
|
-
return undefined;
|
|
681
|
-
}
|
|
682
|
-
if (placement === "start" || placement === "afterEdit" || placement === "end") {
|
|
683
|
-
return placement;
|
|
684
|
-
}
|
|
685
|
-
throw new TypeError("Invalid context menu placement");
|
|
686
|
-
};
|
|
687
|
-
const __muonNormalizeBrowserContextMenuWhen = (when) => {
|
|
688
|
-
if (when === undefined) {
|
|
689
|
-
return undefined;
|
|
690
|
-
}
|
|
691
|
-
if (typeof when !== "object" || when === null || Array.isArray(when)) {
|
|
692
|
-
throw new TypeError("Invalid context menu condition");
|
|
693
|
-
}
|
|
694
|
-
const normalized = {};
|
|
695
|
-
for (const key of __muonBrowserContextMenuWhenKeys) {
|
|
696
|
-
const value = when[key];
|
|
697
|
-
if (value === undefined) {
|
|
698
|
-
continue;
|
|
699
|
-
}
|
|
700
|
-
if (typeof value !== "boolean") {
|
|
701
|
-
throw new TypeError("Invalid context menu condition");
|
|
702
|
-
}
|
|
703
|
-
normalized[key] = value;
|
|
704
|
-
}
|
|
705
|
-
return normalized;
|
|
706
|
-
};
|
|
707
|
-
const __muonNormalizeBrowserContextMenuCommandId = (id) => {
|
|
708
|
-
if (
|
|
709
|
-
typeof id !== "string" ||
|
|
710
|
-
id === "" ||
|
|
711
|
-
/[\\u0000-\\u001f]/u.test(id) ||
|
|
712
|
-
id.startsWith("muon.") ||
|
|
713
|
-
id.startsWith("standard.")
|
|
714
|
-
) {
|
|
715
|
-
throw new TypeError("Invalid context menu item id");
|
|
716
|
-
}
|
|
717
|
-
return id;
|
|
718
|
-
};
|
|
719
|
-
const __muonNormalizeBrowserContextMenuItem = (item) => {
|
|
720
|
-
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
721
|
-
throw new TypeError("Invalid context menu item");
|
|
722
|
-
}
|
|
723
|
-
const placement = __muonNormalizeBrowserContextMenuPlacement(item.placement);
|
|
724
|
-
const when = __muonNormalizeBrowserContextMenuWhen(item.when);
|
|
725
|
-
if (item.type === "separator") {
|
|
726
|
-
return {
|
|
727
|
-
type: "separator",
|
|
728
|
-
...(placement === undefined ? {} : { placement }),
|
|
729
|
-
...(when === undefined ? {} : { when }),
|
|
730
|
-
};
|
|
731
|
-
}
|
|
732
|
-
if (item.type !== undefined && item.type !== "item") {
|
|
733
|
-
throw new TypeError("Invalid context menu item type");
|
|
734
|
-
}
|
|
735
|
-
if (typeof item.label !== "string" || item.label === "") {
|
|
736
|
-
throw new TypeError("Invalid context menu item label");
|
|
737
|
-
}
|
|
738
|
-
if (item.enabled !== undefined && typeof item.enabled !== "boolean") {
|
|
739
|
-
throw new TypeError("Invalid context menu item enabled state");
|
|
740
|
-
}
|
|
741
|
-
return {
|
|
742
|
-
id: __muonNormalizeBrowserContextMenuCommandId(item.id),
|
|
743
|
-
label: item.label,
|
|
744
|
-
enabled: item.enabled === undefined ? true : item.enabled,
|
|
745
|
-
...(placement === undefined ? {} : { placement }),
|
|
746
|
-
...(when === undefined ? {} : { when }),
|
|
747
|
-
};
|
|
748
|
-
};
|
|
749
|
-
const __muonNormalizeBrowserContextMenuItems = (items) => {
|
|
750
|
-
if (!Array.isArray(items)) {
|
|
751
|
-
throw new TypeError("Invalid context menu items");
|
|
752
|
-
}
|
|
753
|
-
return items.map(__muonNormalizeBrowserContextMenuItem);
|
|
754
|
-
};`;
|
|
755
|
-
var createBrowserSetContextMenuItemsExport = (capabilityId, functionPath) => `export const setContextMenuItems = async (items, handler = undefined) => {
|
|
756
|
-
if (handler !== undefined && typeof handler !== "function") {
|
|
757
|
-
throw new TypeError("Invalid context menu handler");
|
|
758
|
-
}
|
|
759
|
-
const normalized = __muonNormalizeBrowserContextMenuItems(items);
|
|
760
|
-
const token = __muonCreateBrowserContextMenuToken();
|
|
761
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [JSON.stringify(normalized), token]);
|
|
762
|
-
__muonBrowserContextMenuToken = token;
|
|
763
|
-
__muonBrowserContextMenuHandler = handler;
|
|
764
|
-
__muonEnsureBrowserContextMenuListener();
|
|
765
|
-
};`;
|
|
766
|
-
var createBrowserClearContextMenuItemsExport = (capabilityId, functionPath) => `export const clearContextMenuItems = async () => {
|
|
767
|
-
__muonBrowserContextMenuToken = "";
|
|
768
|
-
__muonBrowserContextMenuHandler = undefined;
|
|
769
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, []);
|
|
770
|
-
};`;
|
|
771
|
-
var createBrowserTrayHelpers = () => `const __muonBrowserTrayEventName = "muon-browser-tray-event";
|
|
772
|
-
const __muonBrowserTrayHandlers = new Map();
|
|
773
|
-
let __muonBrowserTrayListening = false;
|
|
774
|
-
const __muonCreateBrowserTrayToken = () => {
|
|
775
|
-
const crypto = globalThis.crypto;
|
|
776
|
-
if (
|
|
777
|
-
crypto &&
|
|
778
|
-
typeof crypto.getRandomValues === "function" &&
|
|
779
|
-
typeof globalThis.Uint32Array === "function"
|
|
780
|
-
) {
|
|
781
|
-
const values = new globalThis.Uint32Array(4);
|
|
782
|
-
crypto.getRandomValues(values);
|
|
783
|
-
return Array.from(values, (value) => value.toString(16).padStart(8, "0")).join("");
|
|
784
|
-
}
|
|
785
|
-
return \`\${Date.now().toString(36)}-\${Math.random().toString(36).slice(2)}\`;
|
|
786
|
-
};
|
|
787
|
-
const __muonEnsureBrowserTrayListener = () => {
|
|
788
|
-
if (
|
|
789
|
-
__muonBrowserTrayListening ||
|
|
790
|
-
typeof globalThis.addEventListener !== "function"
|
|
791
|
-
) {
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
globalThis.addEventListener(__muonBrowserTrayEventName, (event) => {
|
|
795
|
-
const detail = event && event.detail;
|
|
796
|
-
if (
|
|
797
|
-
typeof detail !== "object" ||
|
|
798
|
-
detail === null ||
|
|
799
|
-
typeof detail.trayId !== "string"
|
|
800
|
-
) {
|
|
801
|
-
return;
|
|
802
|
-
}
|
|
803
|
-
const entry = __muonBrowserTrayHandlers.get(detail.trayId);
|
|
804
|
-
if (
|
|
805
|
-
entry === undefined ||
|
|
806
|
-
detail.token !== entry.token ||
|
|
807
|
-
typeof entry.handler !== "function"
|
|
808
|
-
) {
|
|
809
|
-
return;
|
|
810
|
-
}
|
|
811
|
-
entry.handler(detail);
|
|
812
|
-
});
|
|
813
|
-
__muonBrowserTrayListening = true;
|
|
814
|
-
};
|
|
815
|
-
const __muonNormalizeBrowserTrayId = (id) => {
|
|
816
|
-
if (
|
|
817
|
-
typeof id !== "string" ||
|
|
818
|
-
id === "" ||
|
|
819
|
-
/[\\u0000-\\u001f]/u.test(id) ||
|
|
820
|
-
id.startsWith("muon.") ||
|
|
821
|
-
id.startsWith("standard.")
|
|
822
|
-
) {
|
|
823
|
-
throw new TypeError("Invalid tray id");
|
|
824
|
-
}
|
|
825
|
-
return id;
|
|
826
|
-
};
|
|
827
|
-
const __muonNormalizeBrowserTrayMenuItem = (item) => {
|
|
828
|
-
if (typeof item !== "object" || item === null || Array.isArray(item)) {
|
|
829
|
-
throw new TypeError("Invalid tray menu item");
|
|
830
|
-
}
|
|
831
|
-
if (item.type === "separator") {
|
|
832
|
-
return { type: "separator" };
|
|
833
|
-
}
|
|
834
|
-
const type = item.type === undefined ? "item" : item.type;
|
|
835
|
-
if (type !== "item" && type !== "checkbox" && type !== "radio") {
|
|
836
|
-
throw new TypeError("Invalid tray menu item type");
|
|
837
|
-
}
|
|
838
|
-
if (typeof item.label !== "string" || item.label === "") {
|
|
839
|
-
throw new TypeError("Invalid tray menu item label");
|
|
840
|
-
}
|
|
841
|
-
if (item.enabled !== undefined && typeof item.enabled !== "boolean") {
|
|
842
|
-
throw new TypeError("Invalid tray menu item enabled state");
|
|
843
|
-
}
|
|
844
|
-
if (item.checked !== undefined && typeof item.checked !== "boolean") {
|
|
845
|
-
throw new TypeError("Invalid tray menu item checked state");
|
|
846
|
-
}
|
|
847
|
-
if (type === "item" && item.checked !== undefined) {
|
|
848
|
-
throw new TypeError("Invalid tray menu item checked state");
|
|
849
|
-
}
|
|
850
|
-
return {
|
|
851
|
-
...(type === "item" ? {} : { type }),
|
|
852
|
-
id: __muonNormalizeBrowserTrayId(item.id),
|
|
853
|
-
label: item.label,
|
|
854
|
-
enabled: item.enabled === undefined ? true : item.enabled,
|
|
855
|
-
...(item.checked === undefined ? {} : { checked: item.checked }),
|
|
856
|
-
};
|
|
857
|
-
};
|
|
858
|
-
const __muonNormalizeBrowserTrayMenuItems = (items) => {
|
|
859
|
-
if (!Array.isArray(items)) {
|
|
860
|
-
throw new TypeError("Invalid tray menu items");
|
|
861
|
-
}
|
|
862
|
-
return items.map(__muonNormalizeBrowserTrayMenuItem);
|
|
863
|
-
};
|
|
864
|
-
const __muonNormalizeBrowserTrayOptions = (options) => {
|
|
865
|
-
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
866
|
-
throw new TypeError("Invalid tray options");
|
|
867
|
-
}
|
|
868
|
-
const hasIcon = options.icon !== undefined;
|
|
869
|
-
if (hasIcon && (typeof options.icon !== "string" || options.icon === "")) {
|
|
870
|
-
throw new TypeError("Invalid tray icon");
|
|
871
|
-
}
|
|
872
|
-
if (options.tooltip !== undefined && options.tooltip !== null && typeof options.tooltip !== "string") {
|
|
873
|
-
throw new TypeError("Invalid tray tooltip");
|
|
874
|
-
}
|
|
875
|
-
return {
|
|
876
|
-
...(options.id === undefined ? {} : { id: __muonNormalizeBrowserTrayId(options.id) }),
|
|
877
|
-
...(hasIcon ? { icon: options.icon } : {}),
|
|
878
|
-
...(options.tooltip === undefined || options.tooltip === null ? {} : { tooltip: options.tooltip }),
|
|
879
|
-
...(options.menu === undefined ? {} : { menu: __muonNormalizeBrowserTrayMenuItems(options.menu) }),
|
|
880
|
-
};
|
|
881
|
-
};`;
|
|
882
|
-
var createBrowserCreateTrayExport = (capabilityId, functionPath) => `export const createTray = async (options, handler = undefined) => {
|
|
883
|
-
if (handler !== undefined && typeof handler !== "function") {
|
|
884
|
-
throw new TypeError("Invalid tray handler");
|
|
885
|
-
}
|
|
886
|
-
const normalized = __muonNormalizeBrowserTrayOptions(options);
|
|
887
|
-
const token = __muonCreateBrowserTrayToken();
|
|
888
|
-
const trayId = await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [JSON.stringify(normalized), token]);
|
|
889
|
-
__muonBrowserTrayHandlers.set(trayId, { token, handler });
|
|
890
|
-
__muonEnsureBrowserTrayListener();
|
|
891
|
-
return trayId;
|
|
892
|
-
};`;
|
|
893
|
-
var createBrowserSetTrayMenuExport = (capabilityId, functionPath) => `export const setTrayMenu = async (id, items, handler = undefined) => {
|
|
894
|
-
if (handler !== undefined && typeof handler !== "function") {
|
|
895
|
-
throw new TypeError("Invalid tray handler");
|
|
896
|
-
}
|
|
897
|
-
const trayId = __muonNormalizeBrowserTrayId(id);
|
|
898
|
-
const normalized = __muonNormalizeBrowserTrayMenuItems(items);
|
|
899
|
-
const token = __muonCreateBrowserTrayToken();
|
|
900
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [trayId, JSON.stringify(normalized), token]);
|
|
901
|
-
__muonBrowserTrayHandlers.set(trayId, { token, handler });
|
|
902
|
-
__muonEnsureBrowserTrayListener();
|
|
903
|
-
};`;
|
|
904
|
-
var createBrowserSetTrayIconExport = (capabilityId, functionPath) => `export const setTrayIcon = async (id, iconPath) => {
|
|
905
|
-
const trayId = __muonNormalizeBrowserTrayId(id);
|
|
906
|
-
if (typeof iconPath !== "string" || iconPath === "") {
|
|
907
|
-
throw new TypeError("Invalid tray icon");
|
|
908
|
-
}
|
|
909
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [trayId, iconPath]);
|
|
910
|
-
};`;
|
|
911
|
-
var createBrowserSetTrayTooltipExport = (capabilityId, functionPath) => `export const setTrayTooltip = async (id, tooltip) => {
|
|
912
|
-
const trayId = __muonNormalizeBrowserTrayId(id);
|
|
913
|
-
if (tooltip !== null && typeof tooltip !== "string") {
|
|
914
|
-
throw new TypeError("Invalid tray tooltip");
|
|
915
|
-
}
|
|
916
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [trayId, tooltip === null ? "" : tooltip]);
|
|
917
|
-
};`;
|
|
918
|
-
var createBrowserRemoveTrayExport = (capabilityId, functionPath) => `export const removeTray = async (id) => {
|
|
919
|
-
const trayId = __muonNormalizeBrowserTrayId(id);
|
|
920
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, [trayId]);
|
|
921
|
-
__muonBrowserTrayHandlers.delete(trayId);
|
|
922
|
-
};`;
|
|
923
|
-
var createGenericFunctionExport = (exportName, capabilityId, functionPath) => `export const ${exportName} = async (...args) =>
|
|
924
|
-
await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, args);`;
|
|
925
|
-
var createEnvironmentsGetConfigValuesExport = (capabilityId, functionPath) => `export const getConfigValues = async () => JSON.parse(await __muonCall(${JSON.stringify(capabilityId)}, ${JSON.stringify(functionPath)}, []));`;
|
|
926
|
-
var createModuleSource = (rule) => {
|
|
927
|
-
const exportedFunctions = getExportedFunctions(rule.namespace, rule.rule.allow, rule.functionPaths);
|
|
928
|
-
if (exportedFunctions.length === 0) {
|
|
929
|
-
const hasWildcardAllow = rule.rule.allow.some(containsGlob);
|
|
930
|
-
throw new Error(hasWildcardAllow ? `muon capability import has no matching function exports: ${rule.moduleName}` : `muon capability import has no exact function exports: ${rule.moduleName}`);
|
|
931
|
-
}
|
|
932
|
-
const usesBrowserContextMenuHelpers = exportedFunctions.some(([exportName]) => rule.namespace === "muon.browser" && (exportName === "setContextMenuItems" || exportName === "clearContextMenuItems"));
|
|
933
|
-
const usesBrowserTrayHelpers = exportedFunctions.some(([exportName]) => rule.namespace === "muon.browser" && (exportName === "createTray" || exportName === "setTrayMenu" || exportName === "setTrayIcon" || exportName === "setTrayTooltip" || exportName === "removeTray"));
|
|
934
|
-
const exports = exportedFunctions.map(([exportName, functionPath]) => {
|
|
935
|
-
if (rule.namespace === "muon.environments" && exportName === "getConfigValues") return createEnvironmentsGetConfigValuesExport(rule.id, functionPath);
|
|
936
|
-
if (rule.namespace === "muon.executor" && exportName === "spawn") return createExecutorSpawnExport(rule.id, functionPath);
|
|
937
|
-
if (rule.namespace === "muon.executor" && exportName === "loadLibrary") return createExecutorLoadLibraryExport(rule.id, functionPath);
|
|
938
|
-
if (rule.namespace === "muon.browser" && exportName === "setContextMenuItems") return createBrowserSetContextMenuItemsExport(rule.id, functionPath);
|
|
939
|
-
if (rule.namespace === "muon.browser" && exportName === "clearContextMenuItems") return createBrowserClearContextMenuItemsExport(rule.id, functionPath);
|
|
940
|
-
if (rule.namespace === "muon.browser" && exportName === "createTray") return createBrowserCreateTrayExport(rule.id, functionPath);
|
|
941
|
-
if (rule.namespace === "muon.browser" && exportName === "setTrayMenu") return createBrowserSetTrayMenuExport(rule.id, functionPath);
|
|
942
|
-
if (rule.namespace === "muon.browser" && exportName === "setTrayIcon") return createBrowserSetTrayIconExport(rule.id, functionPath);
|
|
943
|
-
if (rule.namespace === "muon.browser" && exportName === "setTrayTooltip") return createBrowserSetTrayTooltipExport(rule.id, functionPath);
|
|
944
|
-
if (rule.namespace === "muon.browser" && exportName === "removeTray") return createBrowserRemoveTrayExport(rule.id, functionPath);
|
|
945
|
-
return createGenericFunctionExport(exportName, rule.id, functionPath);
|
|
946
|
-
});
|
|
947
|
-
return `const __muonCall = globalThis.__muon_plugin_call;
|
|
948
|
-
if (typeof __muonCall !== "function") {
|
|
949
|
-
throw new Error("muon plugin capability bridge is not available.");
|
|
950
|
-
}
|
|
951
|
-
|
|
952
|
-
${usesBrowserContextMenuHelpers ? `${createBrowserContextMenuHelpers()}\n\n` : ""}
|
|
953
|
-
${usesBrowserTrayHelpers ? `${createBrowserTrayHelpers()}\n\n` : ""}
|
|
954
|
-
${exports.join("\n\n")}
|
|
955
|
-
`;
|
|
956
|
-
};
|
|
957
|
-
/**
|
|
958
|
-
* Creates a capability virtual module resolver for a bundler adapter.
|
|
959
|
-
*
|
|
960
|
-
* @param root Bundler project root.
|
|
961
|
-
* @param options Capability import options.
|
|
962
|
-
*/
|
|
963
|
-
var createMuonCapabilityModuleResolver = (root, options) => {
|
|
964
|
-
const rules = [...options?.imports ?? []];
|
|
965
|
-
const functionPaths = createFunctionPathCatalog(options?.functionPaths);
|
|
966
|
-
for (const rule of rules) validateCapabilityRule(rule);
|
|
967
|
-
const usedCapabilityIds = /* @__PURE__ */ new Set();
|
|
968
|
-
const runtimeEntries = rules.map((rule) => createRuleRuntimeEntry(rule, createCapabilityId(usedCapabilityIds)));
|
|
969
|
-
const resolveRule = (source, importer) => {
|
|
970
|
-
const parsed = parseCapabilitySpecifier(source);
|
|
971
|
-
if (parsed === void 0) return;
|
|
972
|
-
if (!rules.some((rule) => hasNamespaceFunctionAllow(parsed.namespace, rule.allow))) return;
|
|
973
|
-
if (importer === void 0) throw new Error(`muon capability import is not allowed without an importer: ${source}`);
|
|
974
|
-
const relativeImporter = toRootRelativeImporter(root, importer);
|
|
975
|
-
for (let index = 0; index < rules.length; index += 1) {
|
|
976
|
-
const rule = rules[index];
|
|
977
|
-
const runtimeEntry = runtimeEntries[index];
|
|
978
|
-
if (rule === void 0 || runtimeEntry === void 0 || !matchesCapabilityRuleImporter(rule, root, importer) || !hasNamespaceFunctionAllow(parsed.namespace, rule.allow)) continue;
|
|
979
|
-
return {
|
|
980
|
-
index,
|
|
981
|
-
id: runtimeEntry.id,
|
|
982
|
-
rule,
|
|
983
|
-
namespace: parsed.namespace,
|
|
984
|
-
moduleName: parsed.moduleName,
|
|
985
|
-
functionPaths
|
|
986
|
-
};
|
|
987
|
-
}
|
|
988
|
-
throw new Error(`muon capability import is not allowed: ${source} from ${relativeImporter}`);
|
|
989
|
-
};
|
|
990
|
-
return {
|
|
991
|
-
resolveId: (source, importer) => {
|
|
992
|
-
const rule = resolveRule(source, importer);
|
|
993
|
-
return rule === void 0 ? void 0 : { id: createModuleVirtualId(rule) };
|
|
994
|
-
},
|
|
995
|
-
load: (id) => {
|
|
996
|
-
const parsed = parseModuleVirtualId(id);
|
|
997
|
-
if (parsed === void 0) return;
|
|
998
|
-
const source = parseCapabilitySpecifier(parsed.moduleName);
|
|
999
|
-
const rule = rules[parsed.index];
|
|
1000
|
-
const runtimeEntry = runtimeEntries[parsed.index];
|
|
1001
|
-
if (source === void 0 || rule === void 0 || runtimeEntry === void 0) return;
|
|
1002
|
-
return createModuleSource({
|
|
1003
|
-
index: parsed.index,
|
|
1004
|
-
id: runtimeEntry.id,
|
|
1005
|
-
rule,
|
|
1006
|
-
namespace: source.namespace,
|
|
1007
|
-
moduleName: source.moduleName,
|
|
1008
|
-
functionPaths
|
|
1009
|
-
});
|
|
1010
|
-
},
|
|
1011
|
-
getRuntimePluginConfig: () => ({
|
|
1012
|
-
mode: "validate",
|
|
1013
|
-
capabilities: runtimeEntries
|
|
1014
|
-
})
|
|
1015
|
-
};
|
|
1016
|
-
};
|
|
1017
|
-
//#endregion
|
|
1018
|
-
//#region src/plugin-access.ts
|
|
1019
|
-
var import_dist = require_vite_internals.require_dist();
|
|
1020
|
-
var defaultConfigFileNames = [
|
|
1021
|
-
"muon.json5",
|
|
1022
|
-
"muon.jsonc",
|
|
1023
|
-
"muon.json"
|
|
1024
|
-
];
|
|
1025
|
-
var defaultPluginPages = ["asset://main/**"];
|
|
1026
|
-
var isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1027
|
-
var isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
1028
|
-
var isSha256HexString = (value) => value.length === 64 && /^[0-9a-fA-F]+$/.test(value);
|
|
1029
|
-
var isHexByteString = (value) => value.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(value);
|
|
1030
|
-
var containsNul = (value) => value.includes("\0");
|
|
1031
|
-
var getErrorMessage$1 = (error) => error instanceof Error ? error.message : String(error);
|
|
1032
|
-
var fileExists = async (path) => {
|
|
1033
|
-
try {
|
|
1034
|
-
await (0, node_fs_promises.access)(path, node_fs.constants.F_OK);
|
|
1035
|
-
return true;
|
|
1036
|
-
} catch {
|
|
1037
|
-
return false;
|
|
1038
|
-
}
|
|
1039
|
-
};
|
|
1040
|
-
var resolveMuonConfigPath = async (root, configPath) => {
|
|
1041
|
-
if (configPath !== void 0) {
|
|
1042
|
-
const resolvedPath = (0, node_path.resolve)(root, configPath);
|
|
1043
|
-
if (await fileExists(resolvedPath)) return resolvedPath;
|
|
1044
|
-
throw new Error(`muon config file does not exist: ${resolvedPath}`);
|
|
1045
|
-
}
|
|
1046
|
-
for (const fileName of defaultConfigFileNames) {
|
|
1047
|
-
const candidatePath = (0, node_path.join)(root, fileName);
|
|
1048
|
-
if (await fileExists(candidatePath)) return candidatePath;
|
|
1049
|
-
}
|
|
1050
|
-
};
|
|
1051
|
-
var readJsonObjectFile = async (path, label) => {
|
|
1052
|
-
let content;
|
|
1053
|
-
try {
|
|
1054
|
-
content = await (0, node_fs_promises.readFile)(path, "utf8");
|
|
1055
|
-
} catch (error) {
|
|
1056
|
-
throw new Error(`${label} could not be read: ${path}: ${getErrorMessage$1(error)}`);
|
|
1057
|
-
}
|
|
1058
|
-
let parsed;
|
|
1059
|
-
try {
|
|
1060
|
-
parsed = (0, import_dist.parse)(content);
|
|
1061
|
-
} catch (error) {
|
|
1062
|
-
throw new Error(`${label} could not be parsed: ${path}: ${getErrorMessage$1(error)}`);
|
|
1063
|
-
}
|
|
1064
|
-
if (!isJsonObject(parsed)) throw new Error(`${label} must contain a JSON object: ${path}`);
|
|
1065
|
-
return parsed;
|
|
1066
|
-
};
|
|
1067
|
-
var readOptionalStringArray = (object, key, configPath) => {
|
|
1068
|
-
const value = object[key];
|
|
1069
|
-
if (value === void 0) return;
|
|
1070
|
-
if (!isStringArray(value)) throw new Error(`muon.json ${configPath} must be an array of strings.`);
|
|
1071
|
-
return value;
|
|
1072
|
-
};
|
|
1073
|
-
var readPluginAccessImportOptions = (value, configPath) => {
|
|
1074
|
-
if (!isJsonObject(value)) throw new Error(`muon.json ${configPath} must be an object.`);
|
|
1075
|
-
const sources = readOptionalStringArray(value, "sources", `${configPath}.sources`);
|
|
1076
|
-
const packages = readOptionalStringArray(value, "packages", `${configPath}.packages`);
|
|
1077
|
-
const allow = readOptionalStringArray(value, "allow", `${configPath}.allow`);
|
|
1078
|
-
const options = {};
|
|
1079
|
-
if (sources !== void 0) options.sources = sources;
|
|
1080
|
-
if (packages !== void 0) options.packages = packages;
|
|
1081
|
-
if (allow !== void 0) options.allow = allow;
|
|
1082
|
-
return options;
|
|
1083
|
-
};
|
|
1084
|
-
var readOptionalStringRecord = (object, key, configPath) => {
|
|
1085
|
-
const value = object[key];
|
|
1086
|
-
if (value === void 0) return;
|
|
1087
|
-
if (!isJsonObject(value)) throw new Error(`muon.json ${configPath} must be an object.`);
|
|
1088
|
-
const config = {};
|
|
1089
|
-
for (const [entryKey, entryValue] of Object.entries(value)) {
|
|
1090
|
-
if (entryKey.length === 0) throw new Error(`muon.json ${configPath} key must not be empty.`);
|
|
1091
|
-
if (containsNul(entryKey)) throw new Error(`muon.json ${configPath} key must not contain NUL.`);
|
|
1092
|
-
const valuePath = `${configPath}.${entryKey}`;
|
|
1093
|
-
if (typeof entryValue !== "string") throw new Error(`muon.json ${valuePath} must be a string.`);
|
|
1094
|
-
if (containsNul(entryValue)) throw new Error(`muon.json ${valuePath} must not contain NUL.`);
|
|
1095
|
-
config[entryKey] = entryValue;
|
|
1096
|
-
}
|
|
1097
|
-
return config;
|
|
1098
|
-
};
|
|
1099
|
-
var readPluginAccessEntryOptions = (value, index) => {
|
|
1100
|
-
const configPath = `plugin.plugins[${index}]`;
|
|
1101
|
-
if (!isJsonObject(value)) throw new Error(`muon.json ${configPath} must be an object.`);
|
|
1102
|
-
if (typeof value.name !== "string") throw new Error(`muon.json ${configPath}.name must be a string.`);
|
|
1103
|
-
if (value.signature !== void 0) {
|
|
1104
|
-
if (typeof value.signature !== "string") throw new Error(`muon.json ${configPath}.signature must be a string.`);
|
|
1105
|
-
if (!isSha256HexString(value.signature)) throw new Error(`muon.json ${configPath}.signature must be a 64-character SHA-256 hex string.`);
|
|
1106
|
-
}
|
|
1107
|
-
if (value.salt !== void 0) {
|
|
1108
|
-
if (typeof value.salt !== "string") throw new Error(`muon.json ${configPath}.salt must be a string.`);
|
|
1109
|
-
if (!isHexByteString(value.salt)) throw new Error(`muon.json ${configPath}.salt must be a hexadecimal byte string.`);
|
|
1110
|
-
}
|
|
1111
|
-
const allow = readOptionalStringArray(value, "allow", `${configPath}.allow`);
|
|
1112
|
-
const config = readOptionalStringRecord(value, "config", `${configPath}.config`);
|
|
1113
|
-
const rawImports = value.imports;
|
|
1114
|
-
if (rawImports !== void 0 && !Array.isArray(rawImports)) throw new Error(`muon.json ${configPath}.imports must be an array.`);
|
|
1115
|
-
const imports = rawImports === void 0 ? void 0 : rawImports.map((entry, importIndex) => readPluginAccessImportOptions(entry, `${configPath}.imports[${importIndex}]`));
|
|
1116
|
-
const options = { name: value.name };
|
|
1117
|
-
if (value.signature !== void 0) options.signature = value.signature;
|
|
1118
|
-
if (value.salt !== void 0) options.salt = value.salt;
|
|
1119
|
-
if (config !== void 0) options.config = config;
|
|
1120
|
-
if (allow !== void 0) options.allow = allow;
|
|
1121
|
-
if (imports !== void 0) options.imports = imports;
|
|
1122
|
-
return options;
|
|
1123
|
-
};
|
|
1124
|
-
var readPluginAccessOptions = (config) => {
|
|
1125
|
-
const browser = config.browser;
|
|
1126
|
-
if (isJsonObject(browser) && browser.plugin !== void 0) throw new Error("muon.json browser.plugin is no longer supported; use plugin.mode and plugin.pages instead.");
|
|
1127
|
-
const plugin = config.plugin;
|
|
1128
|
-
if (plugin === void 0) return {};
|
|
1129
|
-
if (!isJsonObject(plugin)) throw new Error("muon.json plugin must be an object.");
|
|
1130
|
-
const options = {};
|
|
1131
|
-
if (plugin.path !== void 0) {
|
|
1132
|
-
if (typeof plugin.path !== "string") throw new Error("muon.json plugin.path must be a string.");
|
|
1133
|
-
if (plugin.path.length === 0) throw new Error("muon.json plugin.path must not be empty.");
|
|
1134
|
-
options.path = plugin.path;
|
|
1135
|
-
}
|
|
1136
|
-
if (plugin.mode !== void 0) {
|
|
1137
|
-
if (typeof plugin.mode !== "string") throw new Error("muon.json plugin.mode must be a string.");
|
|
1138
|
-
if (plugin.mode.length === 0) throw new Error("muon.json plugin.mode must not be empty.");
|
|
1139
|
-
if (plugin.mode !== "simple" && plugin.mode !== "validate") throw new Error("muon.json plugin.mode has unknown value.");
|
|
1140
|
-
options.mode = plugin.mode;
|
|
1141
|
-
}
|
|
1142
|
-
const pages = readOptionalStringArray(plugin, "pages", "plugin.pages");
|
|
1143
|
-
if (pages !== void 0) options.pages = pages;
|
|
1144
|
-
const rawPlugins = plugin.plugins;
|
|
1145
|
-
if (rawPlugins !== void 0) {
|
|
1146
|
-
if (!Array.isArray(rawPlugins)) throw new Error("muon.json plugin.plugins must be an array.");
|
|
1147
|
-
options.plugins = rawPlugins.map((entry, index) => readPluginAccessEntryOptions(entry, index));
|
|
1148
|
-
}
|
|
1149
|
-
return options;
|
|
1150
|
-
};
|
|
1151
|
-
var hasImportSourceSelector = (entry) => entry.sources !== void 0 && entry.sources.length > 0 || entry.packages !== void 0 && entry.packages.length > 0;
|
|
1152
|
-
var validatePluginConfig = (rawConfig, configPath) => {
|
|
1153
|
-
if (rawConfig === void 0) return;
|
|
1154
|
-
if (!isJsonObject(rawConfig)) throw new Error(`muon.json ${configPath} must be an object.`);
|
|
1155
|
-
for (const [entryKey, entryValue] of Object.entries(rawConfig)) {
|
|
1156
|
-
if (entryKey.length === 0) throw new Error(`muon.json ${configPath} key must not be empty.`);
|
|
1157
|
-
if (containsNul(entryKey)) throw new Error(`muon.json ${configPath} key must not contain NUL.`);
|
|
1158
|
-
const valuePath = `${configPath}.${entryKey}`;
|
|
1159
|
-
if (typeof entryValue !== "string") throw new Error(`muon.json ${valuePath} must be a string.`);
|
|
1160
|
-
if (containsNul(entryValue)) throw new Error(`muon.json ${valuePath} must not contain NUL.`);
|
|
1161
|
-
}
|
|
1162
|
-
};
|
|
1163
|
-
var validatePluginAccessOptions = (resolved) => {
|
|
1164
|
-
for (const [pluginIndex, plugin] of resolved.plugins.entries()) {
|
|
1165
|
-
const pluginPath = `plugin.plugins[${pluginIndex}]`;
|
|
1166
|
-
const signature = plugin.signature;
|
|
1167
|
-
if (signature !== void 0) {
|
|
1168
|
-
if (typeof signature !== "string") throw new Error(`muon.json ${pluginPath}.signature must be a string.`);
|
|
1169
|
-
if (!isSha256HexString(signature)) throw new Error(`muon.json ${pluginPath}.signature must be a 64-character SHA-256 hex string.`);
|
|
1170
|
-
}
|
|
1171
|
-
const salt = plugin.salt;
|
|
1172
|
-
if (salt !== void 0) {
|
|
1173
|
-
if (typeof salt !== "string") throw new Error(`muon.json ${pluginPath}.salt must be a string.`);
|
|
1174
|
-
if (!isHexByteString(salt)) throw new Error(`muon.json ${pluginPath}.salt must be a hexadecimal byte string.`);
|
|
1175
|
-
}
|
|
1176
|
-
validatePluginConfig(plugin.config, `${pluginPath}.config`);
|
|
1177
|
-
if (plugin.name === "internal" && plugin.signature !== void 0) throw new Error(`muon.json ${pluginPath}.signature is not supported for internal plugins.`);
|
|
1178
|
-
if (plugin.name === "internal" && plugin.salt !== void 0) throw new Error(`muon.json ${pluginPath}.salt is not supported for internal plugins.`);
|
|
1179
|
-
if (plugin.signature !== void 0 && plugin.salt === void 0) throw new Error(`muon.json ${pluginPath}.signature requires ${pluginPath}.salt.`);
|
|
1180
|
-
if (resolved.mode === "validate") {
|
|
1181
|
-
if (plugin.allow !== void 0) throw new Error(`muon.json ${pluginPath}.allow is only supported in simple mode; use ${pluginPath}.imports[].allow in validate mode.`);
|
|
1182
|
-
if (plugin.imports === void 0) throw new Error(`muon.json ${pluginPath}.imports is required in validate mode.`);
|
|
1183
|
-
if (plugin.imports.length === 0) throw new Error(`muon.json ${pluginPath}.imports must not be empty in validate mode.`);
|
|
1184
|
-
for (const [importIndex, entry] of plugin.imports.entries()) {
|
|
1185
|
-
const importPath = `${pluginPath}.imports[${importIndex}]`;
|
|
1186
|
-
if (!hasImportSourceSelector(entry)) throw new Error(`muon.json ${importPath} requires sources or packages.`);
|
|
1187
|
-
if (entry.allow === void 0) throw new Error(`muon.json ${importPath}.allow is required in validate mode.`);
|
|
1188
|
-
if (entry.allow.length === 0) throw new Error(`muon.json ${importPath}.allow must not be empty in validate mode.`);
|
|
1189
|
-
}
|
|
1190
|
-
continue;
|
|
1191
|
-
}
|
|
1192
|
-
if (plugin.allow === void 0) throw new Error(`muon.json ${pluginPath}.allow is required in simple mode.`);
|
|
1193
|
-
if (plugin.imports !== void 0) throw new Error(`muon.json ${pluginPath}.imports is only supported in validate mode.`);
|
|
1194
|
-
}
|
|
1195
|
-
return resolved;
|
|
1196
|
-
};
|
|
1197
|
-
var getValidateImportAllow = (entry, pluginIndex, importIndex) => {
|
|
1198
|
-
if (entry.allow === void 0 || entry.allow.length === 0) throw new Error(`muon.json plugin.plugins[${pluginIndex}].imports[${importIndex}].allow is required in validate mode.`);
|
|
1199
|
-
return entry.allow;
|
|
1200
|
-
};
|
|
1201
|
-
var getSimplePluginAllow = (plugin, pluginIndex) => {
|
|
1202
|
-
if (plugin.allow === void 0) throw new Error(`muon.json plugin.plugins[${pluginIndex}].allow is required in simple mode.`);
|
|
1203
|
-
return plugin.allow;
|
|
1204
|
-
};
|
|
1205
|
-
var toCapabilityImports = (plugins) => plugins.flatMap((plugin, pluginIndex) => (plugin.imports ?? []).map((entry, importIndex) => {
|
|
1206
|
-
if (!hasImportSourceSelector(entry)) throw new Error(`muon.json plugin.plugins[${pluginIndex}].imports[${importIndex}] requires sources or packages.`);
|
|
1207
|
-
const rule = {
|
|
1208
|
-
allow: getValidateImportAllow(entry, pluginIndex, importIndex),
|
|
1209
|
-
pluginName: plugin.name
|
|
1210
|
-
};
|
|
1211
|
-
if (entry.sources !== void 0) rule.sources = entry.sources;
|
|
1212
|
-
if (entry.packages !== void 0) rule.packages = entry.packages;
|
|
1213
|
-
return rule;
|
|
1214
|
-
}));
|
|
1215
|
-
var toValidateRuntimePluginEntries = (plugins) => plugins.map((plugin, pluginIndex) => {
|
|
1216
|
-
const allow = [];
|
|
1217
|
-
const seenAllow = /* @__PURE__ */ new Set();
|
|
1218
|
-
for (const [importIndex, entry] of (plugin.imports ?? []).entries()) for (const functionPath of getValidateImportAllow(entry, pluginIndex, importIndex)) if (!seenAllow.has(functionPath)) {
|
|
1219
|
-
seenAllow.add(functionPath);
|
|
1220
|
-
allow.push(functionPath);
|
|
1221
|
-
}
|
|
1222
|
-
return {
|
|
1223
|
-
name: plugin.name,
|
|
1224
|
-
...plugin.signature === void 0 ? {} : { signature: plugin.signature },
|
|
1225
|
-
...plugin.salt === void 0 ? {} : { salt: plugin.salt },
|
|
1226
|
-
...plugin.config === void 0 ? {} : { config: plugin.config },
|
|
1227
|
-
allow
|
|
1228
|
-
};
|
|
1229
|
-
});
|
|
1230
|
-
var toSimpleRuntimePluginEntries = (plugins) => plugins.map((plugin, pluginIndex) => ({
|
|
1231
|
-
name: plugin.name,
|
|
1232
|
-
...plugin.signature === void 0 ? {} : { signature: plugin.signature },
|
|
1233
|
-
...plugin.salt === void 0 ? {} : { salt: plugin.salt },
|
|
1234
|
-
...plugin.config === void 0 ? {} : { config: plugin.config },
|
|
1235
|
-
allow: [...getSimplePluginAllow(plugin, pluginIndex)]
|
|
1236
|
-
}));
|
|
1237
|
-
var shouldOverlayRuntimePlugins = (resolved, override) => override !== false && (override?.plugins !== void 0 || resolved.mode === "validate" && resolved.plugins.length > 0);
|
|
1238
|
-
var toRuntimePluginEntries = (resolved) => resolved.mode === "validate" ? toValidateRuntimePluginEntries(resolved.plugins) : toSimpleRuntimePluginEntries(resolved.plugins);
|
|
1239
|
-
var mergePluginAccessOptions = (base, override) => ({
|
|
1240
|
-
...(override?.path ?? base.path) === void 0 ? {} : { path: override?.path ?? base.path },
|
|
1241
|
-
mode: override?.mode ?? base.mode ?? "validate",
|
|
1242
|
-
pages: override?.pages ?? base.pages ?? defaultPluginPages,
|
|
1243
|
-
plugins: override?.plugins ?? base.plugins ?? []
|
|
1244
|
-
});
|
|
1245
|
-
var createRuntimeOverlay = (root, resolved, override) => {
|
|
1246
|
-
if (override === false) return {};
|
|
1247
|
-
const path = override?.path !== void 0 ? (0, node_path.resolve)(root, override.path) : void 0;
|
|
1248
|
-
const plugins = shouldOverlayRuntimePlugins(resolved, override) ? toRuntimePluginEntries(resolved) : void 0;
|
|
1249
|
-
return {
|
|
1250
|
-
pages: resolved.pages,
|
|
1251
|
-
...path === void 0 ? {} : { path },
|
|
1252
|
-
...plugins === void 0 ? {} : { plugins }
|
|
1253
|
-
};
|
|
1254
|
-
};
|
|
1255
|
-
var resolveInspectorPluginPath = (root, configPath, resolved, override) => {
|
|
1256
|
-
if (override !== false && override?.path !== void 0) return (0, node_path.resolve)(root, override.path);
|
|
1257
|
-
const basePath = configPath === void 0 ? root : (0, node_path.resolve)(configPath, "..");
|
|
1258
|
-
return (0, node_path.resolve)(basePath, resolved.path ?? "./plugins");
|
|
1259
|
-
};
|
|
1260
|
-
/**
|
|
1261
|
-
* Resolves public plugin access config from muon.json and Vite overrides.
|
|
1262
|
-
*
|
|
1263
|
-
* @param input Resolution inputs.
|
|
1264
|
-
* @returns Effective plugin access config for bundler integrations.
|
|
1265
|
-
*/
|
|
1266
|
-
var resolveMuonPluginAccessOptions = async ({ root, configPath, pluginAccess, onConfigReadError }) => {
|
|
1267
|
-
const resolvedConfigPath = await resolveMuonConfigPath(root, configPath);
|
|
1268
|
-
let base = {};
|
|
1269
|
-
if (resolvedConfigPath !== void 0) try {
|
|
1270
|
-
base = readPluginAccessOptions(await readJsonObjectFile(resolvedConfigPath, "muon config file"));
|
|
1271
|
-
} catch (error) {
|
|
1272
|
-
if (onConfigReadError === void 0) throw error;
|
|
1273
|
-
onConfigReadError(error);
|
|
1274
|
-
}
|
|
1275
|
-
if (pluginAccess === false) {
|
|
1276
|
-
const resolved = validatePluginAccessOptions(mergePluginAccessOptions(base, { mode: "simple" }));
|
|
1277
|
-
return {
|
|
1278
|
-
mode: "simple",
|
|
1279
|
-
pages: resolved.pages,
|
|
1280
|
-
capabilityOptions: { imports: [] },
|
|
1281
|
-
runtimeOverlay: createRuntimeOverlay(root, resolved, pluginAccess),
|
|
1282
|
-
pluginPath: resolveInspectorPluginPath(root, resolvedConfigPath, resolved, pluginAccess),
|
|
1283
|
-
plugins: resolved.plugins
|
|
1284
|
-
};
|
|
1285
|
-
}
|
|
1286
|
-
const resolved = validatePluginAccessOptions(mergePluginAccessOptions(base, pluginAccess));
|
|
1287
|
-
const capabilityOptions = { imports: resolved.mode === "validate" ? toCapabilityImports(resolved.plugins) : [] };
|
|
1288
|
-
return {
|
|
1289
|
-
mode: resolved.mode,
|
|
1290
|
-
pages: resolved.pages,
|
|
1291
|
-
capabilityOptions,
|
|
1292
|
-
runtimeOverlay: createRuntimeOverlay(root, resolved, pluginAccess),
|
|
1293
|
-
pluginPath: resolveInspectorPluginPath(root, resolvedConfigPath, resolved, pluginAccess),
|
|
1294
|
-
plugins: resolved.plugins
|
|
1295
|
-
};
|
|
1296
|
-
};
|
|
1297
|
-
//#endregion
|
|
1298
|
-
//#region src/plugin-inspector.ts
|
|
1299
|
-
var execFileAsync = (0, node_util.promisify)(node_child_process.execFile);
|
|
17
|
+
//#region cef/plugin-inspector.ts
|
|
18
|
+
var execFileAsync = (0, require("node:util").promisify)(node_child_process.execFile);
|
|
1300
19
|
var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
|
|
1301
20
|
var getInspectorExecutableName = (platform) => platform === "win32" ? "muon-plugin-inspector.exe" : "muon-plugin-inspector";
|
|
1302
21
|
var canExecute = async (path) => {
|
|
@@ -1393,14 +112,51 @@ var collectMuonPluginFunctionPathsForAccess = async (pluginAccess, environment =
|
|
|
1393
112
|
const wildcardPluginNames = new Set((pluginAccess.capabilityOptions.imports ?? []).filter((rule) => rule.pluginName !== void 0 && rule.pluginName !== "internal" && hasWildcardAllow(rule)).map((rule) => rule.pluginName));
|
|
1394
113
|
if (wildcardPluginNames.size === 0) return [];
|
|
1395
114
|
const plugins = pluginAccess.plugins.filter((plugin) => wildcardPluginNames.has(plugin.name));
|
|
1396
|
-
|
|
115
|
+
const catalogs = pluginAccess.nativeArtifacts ?? /* @__PURE__ */ new Map();
|
|
116
|
+
const producerPaths = plugins.flatMap((plugin) => catalogs.get(plugin.name)?.manifest.functions ?? []);
|
|
117
|
+
const inspected = await collectMuonPluginFunctionPaths({
|
|
1397
118
|
pluginPath: pluginAccess.pluginPath,
|
|
1398
|
-
plugins,
|
|
119
|
+
plugins: plugins.filter((plugin) => !catalogs.has(plugin.name)),
|
|
1399
120
|
environment
|
|
1400
121
|
});
|
|
122
|
+
return [...producerPaths, ...inspected];
|
|
1401
123
|
};
|
|
1402
124
|
//#endregion
|
|
1403
|
-
//#region
|
|
125
|
+
//#region android/plugin-catalog.ts
|
|
126
|
+
/**
|
|
127
|
+
* Resolves import permissions against producer catalogs for an Android Vite build.
|
|
128
|
+
* @param root - Vite project root.
|
|
129
|
+
* @param configPath - Application configuration override.
|
|
130
|
+
* @param options - Android build options supplied by Vite.
|
|
131
|
+
* @param access - Validated common plugin configuration.
|
|
132
|
+
* @returns Concrete per-plugin import rules and their public function catalog.
|
|
133
|
+
*/
|
|
134
|
+
var collectMuonAndroidPluginAccess = async (root, configPath, options, access) => {
|
|
135
|
+
const path = await require_vite_internals.resolveMuonConfigPath(root, configPath);
|
|
136
|
+
const android = (path === void 0 ? {} : await require_vite_internals.readJsonObjectFile(path, "muon config file")).android ?? {};
|
|
137
|
+
const abis = options?.abis ?? android.abis ?? ["arm64-v8a", "x86_64"];
|
|
138
|
+
if (abis.length === 0 || abis.some((abi) => abi !== "arm64-v8a" && abi !== "x86_64")) throw new Error("android.abis must select arm64-v8a or x86_64.");
|
|
139
|
+
const libraries = options?.plugins ?? android.plugins ?? [];
|
|
140
|
+
const catalogs = await require_vite_internals.readAndroidPluginMetadata(libraries, abis, options?.plugins === void 0 && path !== void 0 ? (0, node_path.dirname)(path) : root, true);
|
|
141
|
+
const allCatalogs = new Map(catalogs);
|
|
142
|
+
for (const [name, artifact] of access.nativeArtifacts ?? []) {
|
|
143
|
+
if (allCatalogs.has(name)) throw new Error(`Duplicate Android plugin definition: ${name}`);
|
|
144
|
+
allCatalogs.set(name, artifact.manifest.functions);
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
imports: access.plugins.flatMap((plugin) => {
|
|
148
|
+
const catalog = plugin.name === "internal" ? require_vite_internals.muonAndroidBuiltinFunctionPaths : allCatalogs.get(plugin.name);
|
|
149
|
+
if (catalog === void 0) throw new Error(`Android plugin ${plugin.name} requires a matching android.plugins metadata entry.`);
|
|
150
|
+
return (plugin.imports ?? []).map((rule) => ({
|
|
151
|
+
...rule,
|
|
152
|
+
allow: require_vite_internals.expandMuonAndroidFunctionAllows(rule.allow ?? [], catalog)
|
|
153
|
+
}));
|
|
154
|
+
}),
|
|
155
|
+
functionPaths: [...allCatalogs.values()].flat()
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region common/vite.ts
|
|
1404
160
|
var getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
1405
161
|
var muonViteDisableArgument = "--no-muon";
|
|
1406
162
|
var muonNodeModuleSpecifier = "muon:node";
|
|
@@ -1429,9 +185,18 @@ var muon = (options = {}) => {
|
|
|
1429
185
|
let resolvedPluginAccess = void 0;
|
|
1430
186
|
let loadedCapabilityRuntimePluginConfig = void 0;
|
|
1431
187
|
let nodeVirtualModuleEnabled = false;
|
|
1432
|
-
|
|
188
|
+
let developmentNativeTarget;
|
|
189
|
+
const getRuntimePluginConfig = () => {
|
|
190
|
+
const policy = resolveMuonRuntimePluginConfig(capabilityResolver, resolvedPluginAccess);
|
|
191
|
+
const artifacts = resolvedPluginAccess?.nativeArtifacts;
|
|
192
|
+
return developmentNativeTarget === void 0 || artifacts === void 0 || artifacts.size === 0 ? policy : require_vite_internals.applyMuonNativePluginCatalogs(policy, artifacts, developmentNativeTarget, resolvedPluginAccess.runtimeOverlay.path);
|
|
193
|
+
};
|
|
1433
194
|
const refreshPluginAccess = async (config) => {
|
|
1434
|
-
|
|
195
|
+
const targetOverride = process.env[require_vite_internals.muonBuildSequenceTargetsEnvironmentKey];
|
|
196
|
+
const normalizedTargets = (targetOverride === void 0 ? typeof options.build === "object" ? options.build.targets ?? [] : [] : JSON.parse(targetOverride)).flatMap((target) => target.split(",").map((part) => part.trim().toLowerCase()));
|
|
197
|
+
const backend = normalizedTargets.includes("android") ? "android" : "cef";
|
|
198
|
+
if (backend === "android" && normalizedTargets.some((target) => target !== "android")) throw new Error("Build Android and desktop Vite bundles separately.");
|
|
199
|
+
resolvedPluginAccess = await require_vite_internals.resolveMuonPluginAccessOptions({
|
|
1435
200
|
root: config.root,
|
|
1436
201
|
configPath: resolveMuonConfigPathForViteCommand(config, options),
|
|
1437
202
|
pluginAccess: options.pluginAccess,
|
|
@@ -1439,9 +204,48 @@ var muon = (options = {}) => {
|
|
|
1439
204
|
config.logger.warn(`muon project config will be ignored because it could not be read or parsed: ${getErrorMessage(error)}`);
|
|
1440
205
|
} } : {}
|
|
1441
206
|
});
|
|
1442
|
-
|
|
1443
|
-
|
|
207
|
+
if (resolvedPluginAccess.plugins.some((plugin) => plugin.native !== void 0)) {
|
|
208
|
+
const build = typeof options.build === "object" ? options.build : {};
|
|
209
|
+
const sourceConfig = await require_vite_internals.readBuildConfig(config.root, resolveMuonConfigPathForViteCommand(config, options));
|
|
210
|
+
const android = {
|
|
211
|
+
...sourceConfig.config.android,
|
|
212
|
+
...build.android
|
|
213
|
+
};
|
|
214
|
+
const nativeTargets = backend === "android" ? (android.abis ?? ["arm64-v8a", "x86_64"]).map((abi) => `android-${abi}`) : config.command === "serve" ? [require_vite_internals.getDefaultMuonBuildTarget()] : require_vite_internals.resolveBuildTargets({
|
|
215
|
+
...build,
|
|
216
|
+
...normalizedTargets.length ? { targets: normalizedTargets } : {}
|
|
217
|
+
}).map((target) => target);
|
|
218
|
+
const sdkPath = android.sdkPath === void 0 ? void 0 : (0, node_path.resolve)(build.android?.sdkPath === void 0 ? sourceConfig.directory : config.root, android.sdkPath);
|
|
219
|
+
const artifacts = await require_vite_internals.resolveMuonNativePlugins({
|
|
220
|
+
root: config.root,
|
|
221
|
+
directory: resolvedPluginAccess.nativeDirectory ?? config.root,
|
|
222
|
+
plugins: resolvedPluginAccess.plugins,
|
|
223
|
+
targets: nativeTargets,
|
|
224
|
+
environment: process.env,
|
|
225
|
+
...sdkPath === void 0 ? {} : { androidSdkPath: sdkPath }
|
|
226
|
+
});
|
|
227
|
+
resolvedPluginAccess.nativeArtifacts = artifacts;
|
|
228
|
+
if (config.command === "serve" && backend === "cef") {
|
|
229
|
+
const target = nativeTargets[0];
|
|
230
|
+
developmentNativeTarget = target;
|
|
231
|
+
const directory = (0, node_path.join)(config.root, ".muon/plugins/runtime", target);
|
|
232
|
+
await require_vite_internals.stageMuonNativePlugins(artifacts, target, directory);
|
|
233
|
+
resolvedPluginAccess.runtimeOverlay = {
|
|
234
|
+
...resolvedPluginAccess.runtimeOverlay,
|
|
235
|
+
path: directory,
|
|
236
|
+
plugins: resolvedPluginAccess.runtimeOverlay.plugins ?? resolvedPluginAccess.plugins.map(({ native: _native, imports: _imports, ...entry }) => ({
|
|
237
|
+
...entry,
|
|
238
|
+
allow: entry.allow ?? []
|
|
239
|
+
}))
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const androidAccess = backend === "android" && resolvedPluginAccess.mode === "validate" ? await collectMuonAndroidPluginAccess(config.root, resolveMuonConfigPathForViteCommand(config, options), typeof options.build === "object" ? options.build.android : void 0, resolvedPluginAccess) : void 0;
|
|
244
|
+
const pluginFunctionPaths = backend === "android" ? androidAccess?.functionPaths ?? [] : await collectMuonPluginFunctionPathsForAccess(resolvedPluginAccess);
|
|
245
|
+
capabilityResolver = resolvedPluginAccess.mode === "validate" ? require_vite_internals.createMuonCapabilityModuleResolver(config.root, {
|
|
1444
246
|
...resolvedPluginAccess.capabilityOptions,
|
|
247
|
+
...androidAccess === void 0 ? {} : { imports: androidAccess.imports },
|
|
248
|
+
backend,
|
|
1445
249
|
functionPaths: pluginFunctionPaths
|
|
1446
250
|
}) : void 0;
|
|
1447
251
|
loadedCapabilityRuntimePluginConfig = void 0;
|
|
@@ -1511,6 +315,7 @@ var muon = (options = {}) => {
|
|
|
1511
315
|
const muonBuildOptions = createMuonBuildOptions(resolvedConfig, buildOptions, getRuntimePluginConfig());
|
|
1512
316
|
const progressRenderer = require_vite_internals.createMuonProgressRenderer();
|
|
1513
317
|
muonBuildOptions.progress = progressRenderer.report;
|
|
318
|
+
if (resolvedPluginAccess !== void 0) muonBuildOptions.nativePluginAccess = resolvedPluginAccess;
|
|
1514
319
|
try {
|
|
1515
320
|
await require_vite_internals.buildMuonApp(muonBuildOptions);
|
|
1516
321
|
} finally {
|
|
@@ -1519,6 +324,7 @@ var muon = (options = {}) => {
|
|
|
1519
324
|
}
|
|
1520
325
|
}, options), {
|
|
1521
326
|
getResolvedConfig: () => resolvedConfig,
|
|
327
|
+
getNativePluginAccess: () => resolvedPluginAccess,
|
|
1522
328
|
getRuntimePluginConfig: () => resolvedConfig === void 0 ? void 0 : loadedCapabilityRuntimePluginConfig ?? getRuntimePluginConfig()
|
|
1523
329
|
});
|
|
1524
330
|
};
|