muon-ui 0.1.0
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 +21 -0
- package/README.md +84 -0
- package/dist/build-CCuZpajl.cjs +2083 -0
- package/dist/build-CCuZpajl.cjs.map +1 -0
- package/dist/cli.cjs +122 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/index.cjs +9 -0
- package/dist/index.mjs +9 -0
- package/dist/native/linux64/muon-bootstrap +0 -0
- package/dist/native/linux64/muon-prepare +0 -0
- package/dist/native/linuxarm/muon-bootstrap +0 -0
- package/dist/native/linuxarm/muon-prepare +0 -0
- package/dist/native/linuxarm64/muon-bootstrap +0 -0
- package/dist/native/linuxarm64/muon-prepare +0 -0
- package/dist/native/windows32/muon-bootstrap.exe +0 -0
- package/dist/native/windows32/muon-prepare.exe +0 -0
- package/dist/native/windows64/muon-bootstrap.exe +0 -0
- package/dist/native/windows64/muon-prepare.exe +0 -0
- package/dist/runtime/linux64/THIRD_PARTY_NOTICES.md +223 -0
- package/dist/runtime/linux64/libcardio.so +0 -0
- package/dist/runtime/linux64/libmuon-ui.so +0 -0
- package/dist/runtime/linux64/muon-core +0 -0
- package/dist/runtime/linuxarm/THIRD_PARTY_NOTICES.md +223 -0
- package/dist/runtime/linuxarm/libcardio.so +0 -0
- package/dist/runtime/linuxarm/libmuon-ui.so +0 -0
- package/dist/runtime/linuxarm/muon-core +0 -0
- package/dist/runtime/linuxarm64/THIRD_PARTY_NOTICES.md +223 -0
- package/dist/runtime/linuxarm64/libcardio.so +0 -0
- package/dist/runtime/linuxarm64/libmuon-ui.so +0 -0
- package/dist/runtime/linuxarm64/muon-core +0 -0
- package/dist/runtime/windows32/THIRD_PARTY_NOTICES.md +223 -0
- package/dist/runtime/windows32/libcardio.dll +0 -0
- package/dist/runtime/windows32/libmuon-ui.dll +0 -0
- package/dist/runtime/windows32/muon-core.exe +0 -0
- package/dist/runtime/windows64/THIRD_PARTY_NOTICES.md +223 -0
- package/dist/runtime/windows64/libcardio.dll +0 -0
- package/dist/runtime/windows64/libmuon-ui.dll +0 -0
- package/dist/runtime/windows64/muon-core.exe +0 -0
- package/dist/vite.cjs +242 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.mjs +2251 -0
- package/dist/vite.mjs.map +1 -0
- package/images/muon-120.png +0 -0
- package/images/vscode.png +0 -0
- package/muon.d.ts +1039 -0
- package/package.json +91 -0
- package/vite.d.ts +98 -0
package/dist/vite.cjs
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* name: muon-ui
|
|
3
|
+
* version: 0.1.0
|
|
4
|
+
* description: A multi-platform GUI application framework that uses CEF as its backend
|
|
5
|
+
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
|
+
* license: MIT
|
|
7
|
+
* repository.url: https://github.com/kekyo/muon-ui.git
|
|
8
|
+
* git.commit.hash: 35f9658786642562593735d3b589c1d7ab270ecf
|
|
9
|
+
*/
|
|
10
|
+
const require_build = require("./build-CCuZpajl.cjs");
|
|
11
|
+
let node_fs = require("node:fs");
|
|
12
|
+
let node_fs_promises = require("node:fs/promises");
|
|
13
|
+
let node_url = require("node:url");
|
|
14
|
+
let node_path = require("node:path");
|
|
15
|
+
let node_os = require("node:os");
|
|
16
|
+
//#region src/vite-internals.ts
|
|
17
|
+
var getServerOpenValue = (server) => {
|
|
18
|
+
const open = server.config.server.open;
|
|
19
|
+
return open === true || typeof open === "string" ? open : false;
|
|
20
|
+
};
|
|
21
|
+
var resolveFromRoot = (root, path) => (0, node_path.isAbsolute)(path) ? path : (0, node_path.resolve)(root, path);
|
|
22
|
+
var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
|
|
23
|
+
/**
|
|
24
|
+
* Resolves the muon-core runtime directory used by the Vite plugin.
|
|
25
|
+
*
|
|
26
|
+
* @param options Runtime path resolution inputs.
|
|
27
|
+
* @returns Absolute or package-relative runtime directory path.
|
|
28
|
+
*/
|
|
29
|
+
var resolveMuonRuntimePath = ({ root, target, muonPath, packageDirectory = moduleDirectory }) => muonPath === void 0 ? (0, node_path.join)(packageDirectory, "runtime", target) : resolveFromRoot(root, muonPath);
|
|
30
|
+
var getMuonExecutablePath = (runtimePath, platform) => (0, node_path.join)(runtimePath, platform === "win32" ? "muon-core.exe" : "muon-core");
|
|
31
|
+
var getLaunchScriptFileName = (platform) => platform === "win32" ? "open-muon.cmd" : "open-muon.sh";
|
|
32
|
+
var quotePosix = (value) => `'${value.replaceAll("'", "'\\''")}'`;
|
|
33
|
+
var getPlatformDirectoryName = (path, platform) => platform === "win32" ? node_path.win32.dirname(path) : (0, node_path.dirname)(path);
|
|
34
|
+
var createPosixMuonLaunchScript = ({ muonExecutablePath, projectConfigPath, overrideConfigPath }) => `#!/usr/bin/env bash
|
|
35
|
+
set -euo pipefail
|
|
36
|
+
MUON_EXECUTABLE=${quotePosix(muonExecutablePath)}
|
|
37
|
+
MUON_EXECUTABLE_DIRECTORY=${quotePosix(getPlatformDirectoryName(muonExecutablePath, "linux"))}
|
|
38
|
+
MUON_PROJECT_CONFIG=${quotePosix(projectConfigPath)}
|
|
39
|
+
MUON_OVERRIDE_CONFIG=${quotePosix(overrideConfigPath)}
|
|
40
|
+
|
|
41
|
+
if [[ ! -f "$MUON_PROJECT_CONFIG" ]]; then
|
|
42
|
+
echo "Muon startup failed: project config does not exist: $MUON_PROJECT_CONFIG" >&2
|
|
43
|
+
exit 1
|
|
44
|
+
fi
|
|
45
|
+
|
|
46
|
+
if [[ ! -x "$MUON_EXECUTABLE" ]]; then
|
|
47
|
+
echo "Muon startup failed: executable does not exist or is not executable: $MUON_EXECUTABLE" >&2
|
|
48
|
+
exit 1
|
|
49
|
+
fi
|
|
50
|
+
|
|
51
|
+
if [[ ! -f "$MUON_OVERRIDE_CONFIG" ]]; then
|
|
52
|
+
echo "Muon startup failed: generated override config does not exist: $MUON_OVERRIDE_CONFIG" >&2
|
|
53
|
+
exit 1
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
cd "$MUON_EXECUTABLE_DIRECTORY"
|
|
57
|
+
exec "$MUON_EXECUTABLE" -c "$MUON_PROJECT_CONFIG" -c "$MUON_OVERRIDE_CONFIG"
|
|
58
|
+
`;
|
|
59
|
+
var escapeWindowsCmdValue = (value) => value.replaceAll("%", "%%").replaceAll("\r", "").replaceAll("\n", "");
|
|
60
|
+
var createWindowsMuonLaunchScript = ({ muonExecutablePath, projectConfigPath, overrideConfigPath }) => `@echo off
|
|
61
|
+
setlocal
|
|
62
|
+
set "MUON_EXECUTABLE=${escapeWindowsCmdValue(muonExecutablePath)}"
|
|
63
|
+
set "MUON_EXECUTABLE_DIRECTORY=${escapeWindowsCmdValue(getPlatformDirectoryName(muonExecutablePath, "win32"))}"
|
|
64
|
+
set "MUON_PROJECT_CONFIG=${escapeWindowsCmdValue(projectConfigPath)}"
|
|
65
|
+
set "MUON_OVERRIDE_CONFIG=${escapeWindowsCmdValue(overrideConfigPath)}"
|
|
66
|
+
|
|
67
|
+
if not exist "%MUON_PROJECT_CONFIG%" (
|
|
68
|
+
echo Muon startup failed: project config does not exist: %MUON_PROJECT_CONFIG% 1>&2
|
|
69
|
+
exit /b 1
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
if not exist "%MUON_EXECUTABLE%" (
|
|
73
|
+
echo Muon startup failed: executable does not exist: %MUON_EXECUTABLE% 1>&2
|
|
74
|
+
exit /b 1
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
if not exist "%MUON_OVERRIDE_CONFIG%" (
|
|
78
|
+
echo Muon startup failed: generated override config does not exist: %MUON_OVERRIDE_CONFIG% 1>&2
|
|
79
|
+
exit /b 1
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
pushd "%MUON_EXECUTABLE_DIRECTORY%"
|
|
83
|
+
"%MUON_EXECUTABLE%" -c "%MUON_PROJECT_CONFIG%" -c "%MUON_OVERRIDE_CONFIG%"
|
|
84
|
+
set "MUON_EXIT_CODE=%ERRORLEVEL%"
|
|
85
|
+
popd
|
|
86
|
+
exit /b %MUON_EXIT_CODE%
|
|
87
|
+
`;
|
|
88
|
+
var createMuonLaunchScript = (options) => options.platform === "win32" ? createWindowsMuonLaunchScript(options) : createPosixMuonLaunchScript(options);
|
|
89
|
+
var getBaseUrl = (server) => server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0];
|
|
90
|
+
var getStartUrl = (server, openValue) => {
|
|
91
|
+
const baseUrl = getBaseUrl(server);
|
|
92
|
+
if (baseUrl === void 0) return;
|
|
93
|
+
return typeof openValue === "string" ? new URL(openValue, baseUrl).href : baseUrl;
|
|
94
|
+
};
|
|
95
|
+
var getWebSocketOrigin = (startUrl) => {
|
|
96
|
+
const url = new URL(startUrl);
|
|
97
|
+
if (url.protocol === "https:") url.protocol = "wss:";
|
|
98
|
+
else if (url.protocol === "http:") url.protocol = "ws:";
|
|
99
|
+
return url.origin;
|
|
100
|
+
};
|
|
101
|
+
var createMuonOverrideConfig = (startUrl) => {
|
|
102
|
+
const origin = new URL(startUrl).origin;
|
|
103
|
+
return {
|
|
104
|
+
browser: {
|
|
105
|
+
startPage: startUrl,
|
|
106
|
+
plugin: { allow: [`${origin}/**`] }
|
|
107
|
+
},
|
|
108
|
+
network: { allow: [`${origin}/**`, `${getWebSocketOrigin(startUrl)}/**`] }
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
var writeMuonOverrideConfig = (server, openValue, overrideConfigPath) => {
|
|
112
|
+
const startUrl = getStartUrl(server, openValue);
|
|
113
|
+
if (startUrl === void 0) {
|
|
114
|
+
server.config.logger.warn("Muon Vite plugin could not resolve a Vite URL.");
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
(0, node_fs.writeFileSync)(overrideConfigPath, `${JSON.stringify(createMuonOverrideConfig(startUrl), null, 2)}\n`);
|
|
118
|
+
};
|
|
119
|
+
var createRuntimePaths = async (server, stagePath, platform) => {
|
|
120
|
+
const temporaryDirectory = await (0, node_fs_promises.mkdtemp)((0, node_path.join)((0, node_os.tmpdir)(), "muon-vite-"));
|
|
121
|
+
return {
|
|
122
|
+
temporaryDirectory,
|
|
123
|
+
launchScriptPath: (0, node_path.join)(temporaryDirectory, getLaunchScriptFileName(platform)),
|
|
124
|
+
overrideConfigPath: (0, node_path.join)(temporaryDirectory, "muon.vite.json"),
|
|
125
|
+
projectConfigPath: (0, node_path.join)(server.config.root, "muon.json"),
|
|
126
|
+
muonExecutablePath: getMuonExecutablePath(stagePath, platform)
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
var writeLaunchScript = async (paths, platform) => {
|
|
130
|
+
await (0, node_fs_promises.writeFile)(paths.launchScriptPath, createMuonLaunchScript({
|
|
131
|
+
muonExecutablePath: paths.muonExecutablePath,
|
|
132
|
+
projectConfigPath: paths.projectConfigPath,
|
|
133
|
+
overrideConfigPath: paths.overrideConfigPath,
|
|
134
|
+
platform
|
|
135
|
+
}));
|
|
136
|
+
if (platform !== "win32") await (0, node_fs_promises.chmod)(paths.launchScriptPath, 448);
|
|
137
|
+
};
|
|
138
|
+
var startMuonViteBrowserBridge = async ({ server, pluginOptions, platform, architecture, environment }) => {
|
|
139
|
+
const openValue = getServerOpenValue(server);
|
|
140
|
+
if (openValue === false || server.httpServer === null) return;
|
|
141
|
+
const target = require_build.getDefaultMuonPrepareTarget(platform, architecture);
|
|
142
|
+
const preparedRuntime = await require_build.runMuonPrepare({
|
|
143
|
+
muonPath: resolveMuonRuntimePath({
|
|
144
|
+
root: server.config.root,
|
|
145
|
+
target,
|
|
146
|
+
muonPath: pluginOptions.muonPath
|
|
147
|
+
}),
|
|
148
|
+
cefPath: pluginOptions.cefPath === void 0 ? void 0 : resolveFromRoot(server.config.root, pluginOptions.cefPath),
|
|
149
|
+
stageDir: pluginOptions.stagePath === void 0 ? (0, node_path.resolve)(server.config.root, ".muon", target) : resolveFromRoot(server.config.root, pluginOptions.stagePath),
|
|
150
|
+
target,
|
|
151
|
+
cacheDir: environment.MUON_CACHE_DIR,
|
|
152
|
+
force: false,
|
|
153
|
+
quiet: false,
|
|
154
|
+
prepareExecutablePath: void 0,
|
|
155
|
+
environment,
|
|
156
|
+
cwd: server.config.root
|
|
157
|
+
});
|
|
158
|
+
if (preparedRuntime.stagePath === void 0) throw new Error("muon-prepare did not return a staged runtime path.");
|
|
159
|
+
const paths = await createRuntimePaths(server, preparedRuntime.stagePath, platform);
|
|
160
|
+
await writeLaunchScript(paths, platform);
|
|
161
|
+
const previousBrowser = environment.BROWSER;
|
|
162
|
+
environment.BROWSER = paths.launchScriptPath;
|
|
163
|
+
let cleanupPromise = void 0;
|
|
164
|
+
const cleanup = async () => {
|
|
165
|
+
if (cleanupPromise !== void 0) return cleanupPromise;
|
|
166
|
+
cleanupPromise = (async () => {
|
|
167
|
+
if (previousBrowser === void 0) delete environment.BROWSER;
|
|
168
|
+
else environment.BROWSER = previousBrowser;
|
|
169
|
+
await (0, node_fs_promises.rm)(paths.temporaryDirectory, {
|
|
170
|
+
recursive: true,
|
|
171
|
+
force: true
|
|
172
|
+
});
|
|
173
|
+
})();
|
|
174
|
+
return cleanupPromise;
|
|
175
|
+
};
|
|
176
|
+
const originalClose = server.close.bind(server);
|
|
177
|
+
server.close = async () => {
|
|
178
|
+
try {
|
|
179
|
+
await originalClose();
|
|
180
|
+
} finally {
|
|
181
|
+
await cleanup();
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
server.httpServer.once("close", () => {
|
|
185
|
+
cleanup();
|
|
186
|
+
});
|
|
187
|
+
server.httpServer.once("listening", () => {
|
|
188
|
+
writeMuonOverrideConfig(server, openValue, paths.overrideConfigPath);
|
|
189
|
+
});
|
|
190
|
+
};
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/vite.ts
|
|
193
|
+
/**
|
|
194
|
+
* Creates a Vite plugin that launches Muon through Vite's server.open flow.
|
|
195
|
+
*
|
|
196
|
+
* @param options Muon runtime location used for development startup.
|
|
197
|
+
* @returns Vite plugin instance.
|
|
198
|
+
*/
|
|
199
|
+
var muon = (options = {}) => {
|
|
200
|
+
let resolvedConfig = void 0;
|
|
201
|
+
return {
|
|
202
|
+
name: "muon",
|
|
203
|
+
configResolved: (config) => {
|
|
204
|
+
resolvedConfig = config;
|
|
205
|
+
},
|
|
206
|
+
configureServer: async (server) => {
|
|
207
|
+
await startMuonViteBrowserBridge({
|
|
208
|
+
server,
|
|
209
|
+
pluginOptions: options,
|
|
210
|
+
platform: process.platform,
|
|
211
|
+
architecture: process.arch,
|
|
212
|
+
environment: process.env
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
closeBundle: async () => {
|
|
216
|
+
if (resolvedConfig === void 0 || resolvedConfig.command !== "build") return;
|
|
217
|
+
if (options.build === false) return;
|
|
218
|
+
const buildOptions = typeof options.build === "object" ? options.build : {};
|
|
219
|
+
await require_build.buildMuonApp(createMuonBuildOptions(resolvedConfig, buildOptions));
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
var createMuonBuildOptions = (config, buildOptions) => {
|
|
224
|
+
const outDir = (0, node_path.isAbsolute)(config.build.outDir) ? config.build.outDir : (0, node_path.resolve)(config.root, config.build.outDir);
|
|
225
|
+
const options = {
|
|
226
|
+
root: config.root,
|
|
227
|
+
assetSourcePath: outDir,
|
|
228
|
+
assetPrefix: "main"
|
|
229
|
+
};
|
|
230
|
+
if (buildOptions.allTargets !== void 0) options.allTargets = buildOptions.allTargets;
|
|
231
|
+
if (buildOptions.targets !== void 0) options.targets = buildOptions.targets;
|
|
232
|
+
if (buildOptions.appName !== void 0) options.appName = buildOptions.appName;
|
|
233
|
+
if (buildOptions.outputRoot !== void 0) options.outputRoot = buildOptions.outputRoot;
|
|
234
|
+
if (buildOptions.configPath !== void 0) options.configPath = buildOptions.configPath;
|
|
235
|
+
if (buildOptions.packageDirectory !== void 0) options.packageDirectory = buildOptions.packageDirectory;
|
|
236
|
+
if (buildOptions.assetSalt !== void 0) options.assetSalt = buildOptions.assetSalt;
|
|
237
|
+
return options;
|
|
238
|
+
};
|
|
239
|
+
//#endregion
|
|
240
|
+
module.exports = muon;
|
|
241
|
+
|
|
242
|
+
//# sourceMappingURL=vite.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.cjs","names":[],"sources":["../src/vite-internals.ts","../src/vite.ts"],"sourcesContent":["// muon - Multi-platform GUI application framework that uses CEF as its backend\n// Copyright (c) Kouji Matsui. (@kekyo@mi.kekyo.net)\n// Under MIT.\n// https://github.com/kekyo/muon\n\nimport { chmod, mkdtemp, rm, writeFile } from \"node:fs/promises\";\nimport { writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { dirname, isAbsolute, join, resolve, win32 } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { ViteDevServer } from \"vite\";\n\nimport { getDefaultMuonPrepareTarget, runMuonPrepare } from \"./prepare.js\";\nimport type { MuonVitePluginOptions } from \"./vite.js\";\n\nexport interface MuonLaunchScriptOptions {\n muonExecutablePath: string;\n projectConfigPath: string;\n overrideConfigPath: string;\n platform: NodeJS.Platform;\n}\n\ninterface MuonViteSessionOptions {\n server: ViteDevServer;\n pluginOptions: MuonVitePluginOptions;\n platform: NodeJS.Platform;\n architecture: NodeJS.Architecture;\n environment: NodeJS.ProcessEnv;\n}\n\ninterface MuonRuntimePaths {\n temporaryDirectory: string;\n launchScriptPath: string;\n overrideConfigPath: string;\n projectConfigPath: string;\n muonExecutablePath: string;\n}\n\ninterface MuonOverrideConfig {\n browser: {\n startPage: string;\n plugin: {\n allow: string[];\n };\n };\n network: {\n allow: string[];\n };\n}\n\n/**\n * Options for resolving a Muon runtime directory used by the Vite plugin.\n */\nexport interface MuonRuntimePathOptions {\n /**\n * Vite project root used to resolve explicit relative paths.\n */\n root: string;\n\n /**\n * Muon runtime target such as linux64, linuxarm, linuxarm64, windows32, or windows64.\n */\n target: string;\n\n /**\n * Explicit custom muon-core runtime path.\n */\n muonPath: string | undefined;\n\n /**\n * Directory containing the packaged Muon JavaScript files.\n *\n * @remarks This is injectable for tests. Production code uses the module directory.\n */\n packageDirectory?: string;\n}\n\nconst getServerOpenValue = (\n server: ViteDevServer,\n): boolean | string | false => {\n const open = server.config.server.open;\n return open === true || typeof open === \"string\" ? open : false;\n};\n\nconst resolveFromRoot = (root: string, path: string): string =>\n isAbsolute(path) ? path : resolve(root, path);\n\nconst moduleDirectory =\n typeof __dirname === \"string\"\n ? __dirname\n : dirname(fileURLToPath(import.meta.url));\n\n/**\n * Resolves the muon-core runtime directory used by the Vite plugin.\n *\n * @param options Runtime path resolution inputs.\n * @returns Absolute or package-relative runtime directory path.\n */\nexport const resolveMuonRuntimePath = ({\n root,\n target,\n muonPath,\n packageDirectory = moduleDirectory,\n}: MuonRuntimePathOptions): string =>\n muonPath === undefined\n ? join(packageDirectory, \"runtime\", target)\n : resolveFromRoot(root, muonPath);\n\nexport const getMuonExecutablePath = (\n runtimePath: string,\n platform: NodeJS.Platform,\n): string =>\n join(runtimePath, platform === \"win32\" ? \"muon-core.exe\" : \"muon-core\");\n\nconst getLaunchScriptFileName = (platform: NodeJS.Platform): string =>\n platform === \"win32\" ? \"open-muon.cmd\" : \"open-muon.sh\";\n\nconst quotePosix = (value: string): string =>\n `'${value.replaceAll(\"'\", \"'\\\\''\")}'`;\n\nconst getPlatformDirectoryName = (\n path: string,\n platform: NodeJS.Platform,\n): string => (platform === \"win32\" ? win32.dirname(path) : dirname(path));\n\nconst createPosixMuonLaunchScript = ({\n muonExecutablePath,\n projectConfigPath,\n overrideConfigPath,\n}: MuonLaunchScriptOptions): string => `#!/usr/bin/env bash\nset -euo pipefail\nMUON_EXECUTABLE=${quotePosix(muonExecutablePath)}\nMUON_EXECUTABLE_DIRECTORY=${quotePosix(getPlatformDirectoryName(muonExecutablePath, \"linux\"))}\nMUON_PROJECT_CONFIG=${quotePosix(projectConfigPath)}\nMUON_OVERRIDE_CONFIG=${quotePosix(overrideConfigPath)}\n\nif [[ ! -f \"$MUON_PROJECT_CONFIG\" ]]; then\n echo \"Muon startup failed: project config does not exist: $MUON_PROJECT_CONFIG\" >&2\n exit 1\nfi\n\nif [[ ! -x \"$MUON_EXECUTABLE\" ]]; then\n echo \"Muon startup failed: executable does not exist or is not executable: $MUON_EXECUTABLE\" >&2\n exit 1\nfi\n\nif [[ ! -f \"$MUON_OVERRIDE_CONFIG\" ]]; then\n echo \"Muon startup failed: generated override config does not exist: $MUON_OVERRIDE_CONFIG\" >&2\n exit 1\nfi\n\ncd \"$MUON_EXECUTABLE_DIRECTORY\"\nexec \"$MUON_EXECUTABLE\" -c \"$MUON_PROJECT_CONFIG\" -c \"$MUON_OVERRIDE_CONFIG\"\n`;\n\nconst escapeWindowsCmdValue = (value: string): string =>\n value.replaceAll(\"%\", \"%%\").replaceAll(\"\\r\", \"\").replaceAll(\"\\n\", \"\");\n\nconst createWindowsMuonLaunchScript = ({\n muonExecutablePath,\n projectConfigPath,\n overrideConfigPath,\n}: MuonLaunchScriptOptions): string => `@echo off\nsetlocal\nset \"MUON_EXECUTABLE=${escapeWindowsCmdValue(muonExecutablePath)}\"\nset \"MUON_EXECUTABLE_DIRECTORY=${escapeWindowsCmdValue(getPlatformDirectoryName(muonExecutablePath, \"win32\"))}\"\nset \"MUON_PROJECT_CONFIG=${escapeWindowsCmdValue(projectConfigPath)}\"\nset \"MUON_OVERRIDE_CONFIG=${escapeWindowsCmdValue(overrideConfigPath)}\"\n\nif not exist \"%MUON_PROJECT_CONFIG%\" (\n echo Muon startup failed: project config does not exist: %MUON_PROJECT_CONFIG% 1>&2\n exit /b 1\n)\n\nif not exist \"%MUON_EXECUTABLE%\" (\n echo Muon startup failed: executable does not exist: %MUON_EXECUTABLE% 1>&2\n exit /b 1\n)\n\nif not exist \"%MUON_OVERRIDE_CONFIG%\" (\n echo Muon startup failed: generated override config does not exist: %MUON_OVERRIDE_CONFIG% 1>&2\n exit /b 1\n)\n\npushd \"%MUON_EXECUTABLE_DIRECTORY%\"\n\"%MUON_EXECUTABLE%\" -c \"%MUON_PROJECT_CONFIG%\" -c \"%MUON_OVERRIDE_CONFIG%\"\nset \"MUON_EXIT_CODE=%ERRORLEVEL%\"\npopd\nexit /b %MUON_EXIT_CODE%\n`;\n\nexport const createMuonLaunchScript = (\n options: MuonLaunchScriptOptions,\n): string =>\n options.platform === \"win32\"\n ? createWindowsMuonLaunchScript(options)\n : createPosixMuonLaunchScript(options);\n\nconst getBaseUrl = (server: ViteDevServer): string | undefined =>\n server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0];\n\nconst getStartUrl = (\n server: ViteDevServer,\n openValue: boolean | string,\n): string | undefined => {\n const baseUrl = getBaseUrl(server);\n if (baseUrl === undefined) {\n return undefined;\n }\n return typeof openValue === \"string\"\n ? new URL(openValue, baseUrl).href\n : baseUrl;\n};\n\nconst getWebSocketOrigin = (startUrl: string): string => {\n const url = new URL(startUrl);\n if (url.protocol === \"https:\") {\n url.protocol = \"wss:\";\n } else if (url.protocol === \"http:\") {\n url.protocol = \"ws:\";\n }\n return url.origin;\n};\n\nconst createMuonOverrideConfig = (startUrl: string): MuonOverrideConfig => {\n const origin = new URL(startUrl).origin;\n return {\n browser: {\n startPage: startUrl,\n plugin: {\n allow: [`${origin}/**`],\n },\n },\n network: {\n allow: [`${origin}/**`, `${getWebSocketOrigin(startUrl)}/**`],\n },\n };\n};\n\nconst writeMuonOverrideConfig = (\n server: ViteDevServer,\n openValue: boolean | string,\n overrideConfigPath: string,\n): void => {\n const startUrl = getStartUrl(server, openValue);\n if (startUrl === undefined) {\n server.config.logger.warn(\"Muon Vite plugin could not resolve a Vite URL.\");\n return;\n }\n writeFileSync(\n overrideConfigPath,\n `${JSON.stringify(createMuonOverrideConfig(startUrl), null, 2)}\\n`,\n );\n};\n\nconst createRuntimePaths = async (\n server: ViteDevServer,\n stagePath: string,\n platform: NodeJS.Platform,\n): Promise<MuonRuntimePaths> => {\n const temporaryDirectory = await mkdtemp(join(tmpdir(), \"muon-vite-\"));\n return {\n temporaryDirectory,\n launchScriptPath: join(\n temporaryDirectory,\n getLaunchScriptFileName(platform),\n ),\n overrideConfigPath: join(temporaryDirectory, \"muon.vite.json\"),\n projectConfigPath: join(server.config.root, \"muon.json\"),\n muonExecutablePath: getMuonExecutablePath(stagePath, platform),\n };\n};\n\nconst writeLaunchScript = async (\n paths: MuonRuntimePaths,\n platform: NodeJS.Platform,\n): Promise<void> => {\n await writeFile(\n paths.launchScriptPath,\n createMuonLaunchScript({\n muonExecutablePath: paths.muonExecutablePath,\n projectConfigPath: paths.projectConfigPath,\n overrideConfigPath: paths.overrideConfigPath,\n platform,\n }),\n );\n if (platform !== \"win32\") {\n await chmod(paths.launchScriptPath, 0o700);\n }\n};\n\nexport const startMuonViteBrowserBridge = async ({\n server,\n pluginOptions,\n platform,\n architecture,\n environment,\n}: MuonViteSessionOptions): Promise<void> => {\n const openValue = getServerOpenValue(server);\n if (openValue === false || server.httpServer === null) {\n return;\n }\n\n const target = getDefaultMuonPrepareTarget(platform, architecture);\n const muonPath = resolveMuonRuntimePath({\n root: server.config.root,\n target,\n muonPath: pluginOptions.muonPath,\n });\n const cefPath =\n pluginOptions.cefPath === undefined\n ? undefined\n : resolveFromRoot(server.config.root, pluginOptions.cefPath);\n const stagePath =\n pluginOptions.stagePath === undefined\n ? resolve(server.config.root, \".muon\", target)\n : resolveFromRoot(server.config.root, pluginOptions.stagePath);\n const preparedRuntime = await runMuonPrepare({\n muonPath,\n cefPath,\n stageDir: stagePath,\n target,\n cacheDir: environment.MUON_CACHE_DIR,\n force: false,\n quiet: false,\n prepareExecutablePath: undefined,\n environment,\n cwd: server.config.root,\n });\n if (preparedRuntime.stagePath === undefined) {\n throw new Error(\"muon-prepare did not return a staged runtime path.\");\n }\n const paths = await createRuntimePaths(\n server,\n preparedRuntime.stagePath,\n platform,\n );\n await writeLaunchScript(paths, platform);\n const previousBrowser = environment.BROWSER;\n environment.BROWSER = paths.launchScriptPath;\n\n let cleanupPromise: Promise<void> | undefined = undefined;\n const cleanup = async (): Promise<void> => {\n if (cleanupPromise !== undefined) {\n return cleanupPromise;\n }\n cleanupPromise = (async () => {\n if (previousBrowser === undefined) {\n delete environment.BROWSER;\n } else {\n environment.BROWSER = previousBrowser;\n }\n await rm(paths.temporaryDirectory, { recursive: true, force: true });\n })();\n return cleanupPromise;\n };\n\n const originalClose = server.close.bind(server);\n server.close = async (): Promise<void> => {\n try {\n await originalClose();\n } finally {\n await cleanup();\n }\n };\n server.httpServer.once(\"close\", () => {\n void cleanup();\n });\n server.httpServer.once(\"listening\", () => {\n writeMuonOverrideConfig(server, openValue, paths.overrideConfigPath);\n });\n};\n","// muon - Multi-platform GUI application framework that uses CEF as its backend\n// Copyright (c) Kouji Matsui. (@kekyo@mi.kekyo.net)\n// Under MIT.\n// https://github.com/kekyo/muon\n\nimport type { Plugin } from \"vite\";\nimport type { ResolvedConfig } from \"vite\";\nimport { isAbsolute, resolve } from \"node:path\";\n\nimport { buildMuonApp, type MuonBuildOptions } from \"./build.js\";\nimport { startMuonViteBrowserBridge } from \"./vite-internals.js\";\n\n/**\n * Options for generating Muon app distributions after Vite build.\n */\nexport interface MuonViteBuildOptions {\n /**\n * Target aliases or internal target names to build.\n */\n targets?: readonly string[];\n\n /**\n * Build every supported target from the installed package.\n */\n allTargets?: boolean;\n\n /**\n * File name used for the app launcher.\n *\n * @remarks The .exe suffix is added automatically for Windows targets.\n */\n appName?: string;\n\n /**\n * Parent directory that receives dist-linux-amd64/ style outputs.\n */\n outputRoot?: string;\n\n /**\n * Muon config path to embed.\n */\n configPath?: string;\n\n /**\n * Directory containing package runtime/ and native/ folders.\n *\n * @remarks This defaults to the installed muon package dist directory.\n */\n packageDirectory?: string;\n\n /**\n * Asset salt override for deterministic tests.\n *\n * @remarks Production builds should omit this option.\n */\n assetSalt?: Uint8Array;\n}\n\n/**\n * Options for the Muon Vite development plugin.\n */\nexport interface MuonVitePluginOptions {\n /**\n * Directory containing muon-core runtime files such as muon-core and plugins.\n *\n * @remarks Relative paths are resolved from the Vite project root. When omitted,\n * the packaged runtime at dist/runtime/<target> is used.\n */\n muonPath?: string;\n\n /**\n * Directory containing CEF files, or a CEF archive root with Release/Resources.\n *\n * @remarks Relative paths are resolved from the Vite project root. When omitted,\n * muon-prepare downloads and caches the tested CEF artifact from muonPath.\n */\n cefPath?: string;\n\n /**\n * Runtime staging directory used for development startup.\n *\n * @remarks Relative paths are resolved from the Vite project root. Defaults to\n * .muon/<target>.\n */\n stagePath?: string;\n\n /**\n * Build app distributions from Vite output.\n *\n * @remarks Defaults to true during Vite build. Set false to disable the build\n * hook while keeping the development bridge enabled.\n */\n build?: boolean | MuonViteBuildOptions;\n}\n\n/**\n * Creates a Vite plugin that launches Muon through Vite's server.open flow.\n *\n * @param options Muon runtime location used for development startup.\n * @returns Vite plugin instance.\n */\nconst muon = (options: MuonVitePluginOptions = {}): Plugin => {\n let resolvedConfig: ResolvedConfig | undefined = undefined;\n\n return {\n name: \"muon\",\n configResolved: (config) => {\n resolvedConfig = config;\n },\n configureServer: async (server) => {\n await startMuonViteBrowserBridge({\n server,\n pluginOptions: options,\n platform: process.platform,\n architecture: process.arch,\n environment: process.env,\n });\n },\n closeBundle: async () => {\n if (resolvedConfig === undefined || resolvedConfig.command !== \"build\") {\n return;\n }\n if (options.build === false) {\n return;\n }\n\n const buildOptions =\n typeof options.build === \"object\" ? options.build : {};\n await buildMuonApp(createMuonBuildOptions(resolvedConfig, buildOptions));\n },\n };\n};\n\nconst createMuonBuildOptions = (\n config: ResolvedConfig,\n buildOptions: MuonViteBuildOptions,\n): MuonBuildOptions => {\n const outDir = isAbsolute(config.build.outDir)\n ? config.build.outDir\n : resolve(config.root, config.build.outDir);\n const options: MuonBuildOptions = {\n root: config.root,\n assetSourcePath: outDir,\n assetPrefix: \"main\",\n };\n\n if (buildOptions.allTargets !== undefined) {\n options.allTargets = buildOptions.allTargets;\n }\n if (buildOptions.targets !== undefined) {\n options.targets = buildOptions.targets;\n }\n if (buildOptions.appName !== undefined) {\n options.appName = buildOptions.appName;\n }\n if (buildOptions.outputRoot !== undefined) {\n options.outputRoot = buildOptions.outputRoot;\n }\n if (buildOptions.configPath !== undefined) {\n options.configPath = buildOptions.configPath;\n }\n if (buildOptions.packageDirectory !== undefined) {\n options.packageDirectory = buildOptions.packageDirectory;\n }\n if (buildOptions.assetSalt !== undefined) {\n options.assetSalt = buildOptions.assetSalt;\n }\n\n return options;\n};\n\nexport default muon;\n"],"mappings":";;;;;;;;;;;;;;;;AA8EA,IAAM,sBACJ,WAC6B;CAC7B,MAAM,OAAO,OAAO,OAAO,OAAO;CAClC,OAAO,SAAS,QAAQ,OAAO,SAAS,WAAW,OAAO;AAC5D;AAEA,IAAM,mBAAmB,MAAc,UAAA,GAAA,UAAA,YAC1B,IAAI,IAAI,QAAA,GAAA,UAAA,SAAe,MAAM,IAAI;AAE9C,IAAM,kBACJ,OAAO,cAAc,WACjB,aAAA,GAAA,UAAA,UAAA,GAAA,SAAA,eAAA,CAAA,EACkC,GAAG,CAAC;;;;;;;AAQ5C,IAAa,0BAA0B,EACrC,MACA,QACA,UACA,mBAAmB,sBAEnB,aAAa,KAAA,KAAA,GAAA,UAAA,MACJ,kBAAkB,WAAW,MAAM,IACxC,gBAAgB,MAAM,QAAQ;AAEpC,IAAa,yBACX,aACA,cAAA,GAAA,UAAA,MAEK,aAAa,aAAa,UAAU,kBAAkB,WAAW;AAExE,IAAM,2BAA2B,aAC/B,aAAa,UAAU,kBAAkB;AAE3C,IAAM,cAAc,UAClB,IAAI,MAAM,WAAW,KAAK,OAAO,EAAE;AAErC,IAAM,4BACJ,MACA,aACY,aAAa,UAAU,UAAA,MAAM,QAAQ,IAAI,KAAA,GAAA,UAAA,SAAY,IAAI;AAEvE,IAAM,+BAA+B,EACnC,oBACA,mBACA,yBACqC;;kBAErB,WAAW,kBAAkB,EAAE;4BACrB,WAAW,yBAAyB,oBAAoB,OAAO,CAAC,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