muon-ui 0.2.0 → 0.4.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.
Files changed (47) hide show
  1. package/README.md +3 -2
  2. package/dist/cli.cjs +271 -11
  3. package/dist/cli.cjs.map +1 -1
  4. package/dist/index.cjs +2 -2
  5. package/dist/index.mjs +2 -2
  6. package/dist/native/linux64/muon-bootstrap +0 -0
  7. package/dist/native/linux64/muon-prepare +0 -0
  8. package/dist/native/linuxarm/muon-bootstrap +0 -0
  9. package/dist/native/linuxarm/muon-prepare +0 -0
  10. package/dist/native/linuxarm64/muon-bootstrap +0 -0
  11. package/dist/native/linuxarm64/muon-prepare +0 -0
  12. package/dist/native/windows32/muon-bootstrap.exe +0 -0
  13. package/dist/native/windows32/muon-prepare.exe +0 -0
  14. package/dist/native/windows64/muon-bootstrap.exe +0 -0
  15. package/dist/native/windows64/muon-prepare.exe +0 -0
  16. package/dist/runtime/linux64/LICENSE_muon +97 -0
  17. package/dist/runtime/linux64/libmuon-ui.so +0 -0
  18. package/dist/runtime/linux64/muon-core +0 -0
  19. package/dist/runtime/linuxarm/LICENSE_muon +97 -0
  20. package/dist/runtime/linuxarm/libmuon-ui.so +0 -0
  21. package/dist/runtime/linuxarm/muon-core +0 -0
  22. package/dist/runtime/linuxarm64/LICENSE_muon +97 -0
  23. package/dist/runtime/linuxarm64/libmuon-ui.so +0 -0
  24. package/dist/runtime/linuxarm64/muon-core +0 -0
  25. package/dist/runtime/windows32/LICENSE_muon +97 -0
  26. package/dist/runtime/windows32/libcardio.dll +0 -0
  27. package/dist/runtime/windows32/libgcc_s_dw2-1.dll +0 -0
  28. package/dist/runtime/windows32/libmuon-ui.dll +0 -0
  29. package/dist/runtime/windows32/libstdc++-6.dll +0 -0
  30. package/dist/runtime/windows32/muon-core.exe +0 -0
  31. package/dist/runtime/windows64/LICENSE_muon +97 -0
  32. package/dist/runtime/windows64/libcardio.dll +0 -0
  33. package/dist/runtime/windows64/libgcc_s_seh-1.dll +0 -0
  34. package/dist/runtime/windows64/libmuon-ui.dll +0 -0
  35. package/dist/runtime/windows64/libstdc++-6.dll +0 -0
  36. package/dist/runtime/windows64/muon-core.exe +0 -0
  37. package/dist/{build-BxDRaTmF.cjs → vite-options-C4evRLpv.cjs} +395 -29
  38. package/dist/vite-options-C4evRLpv.cjs.map +1 -0
  39. package/dist/vite.cjs +9 -230
  40. package/dist/vite.cjs.map +1 -1
  41. package/dist/vite.mjs +111 -36
  42. package/dist/vite.mjs.map +1 -1
  43. package/images/vscode.png +0 -0
  44. package/muon.d.ts +27 -0
  45. package/package.json +9 -8
  46. package/vite.d.ts +18 -2
  47. package/dist/build-BxDRaTmF.cjs.map +0 -1
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: muon-ui
3
- * version: 0.2.0
3
+ * version: 0.4.0
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: 6251ff88aafa8ae873657f39aed1ebba2fa329a4
8
+ * git.commit.hash: 44d549142c8cbfa13cb29d10be2568652a68bf50
9
9
  */
10
10
  //#region \0rolldown/runtime.js
11
11
  var __create = Object.create;
@@ -60,7 +60,7 @@ var getDefaultMuonPrepareTarget = (platform, architecture) => {
60
60
  throw new Error(`Unsupported Muon prepare target: platform=${platform}, arch=${architecture}`);
61
61
  };
62
62
  var getPrepareExecutableName = (platform) => platform === "win32" ? "muon-prepare.exe" : "muon-prepare";
63
- var moduleDirectory$1 = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
63
+ var moduleDirectory$2 = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
64
64
  var canExecute = async (path) => {
65
65
  try {
66
66
  await (0, node_fs_promises.access)(path, node_fs.constants.X_OK);
@@ -74,7 +74,7 @@ var resolveMuonPrepareExecutable = async (options) => {
74
74
  if (explicit !== void 0 && explicit !== "") return explicit;
75
75
  const executableName = getPrepareExecutableName(process.platform);
76
76
  const target = getDefaultMuonPrepareTarget(process.platform, process.arch);
77
- const candidates = [(0, node_path.join)(moduleDirectory$1, "native", target, executableName), (0, node_path.join)(moduleDirectory$1, "..", "dist", "native", target, executableName)];
77
+ const candidates = [(0, node_path.join)(moduleDirectory$2, "native", target, executableName), (0, node_path.join)(moduleDirectory$2, "..", "dist", "native", target, executableName)];
78
78
  for (const candidate of candidates) if (await canExecute(candidate)) return candidate;
79
79
  return candidates[0] ?? executableName;
80
80
  };
@@ -137,6 +137,36 @@ var runMuonPrepare = async (options) => {
137
137
  };
138
138
  };
139
139
  //#endregion
140
+ //#region src/gitignore.ts
141
+ var muonGitignoreEntry = ".muon/";
142
+ var isMissingFileError = (error) => error instanceof Error && error.code === "ENOENT";
143
+ var hasMuonGitignoreEntry = (content) => content.split(/\r?\n/).map((line) => line.trim()).some((line) => line === muonGitignoreEntry || line === `/${muonGitignoreEntry}` || line === ".muon" || line === "/.muon");
144
+ /**
145
+ * Adds the Muon staging directory to a project .gitignore file.
146
+ *
147
+ * @param root Project root containing the .gitignore file.
148
+ * @returns Gitignore update result.
149
+ */
150
+ var ensureMuonGitignoreEntry = async (root) => {
151
+ const gitignorePath = (0, node_path.join)(root, ".gitignore");
152
+ let content = "";
153
+ try {
154
+ content = await (0, node_fs_promises.readFile)(gitignorePath, "utf8");
155
+ } catch (error) {
156
+ if (!isMissingFileError(error)) throw error;
157
+ }
158
+ if (hasMuonGitignoreEntry(content)) return {
159
+ gitignorePath,
160
+ changed: false
161
+ };
162
+ const separator = content.length > 0 && !content.endsWith("\n") ? "\n" : "";
163
+ await (0, node_fs_promises.writeFile)(gitignorePath, `${content}${separator}${muonGitignoreEntry}\n`);
164
+ return {
165
+ gitignorePath,
166
+ changed: true
167
+ };
168
+ };
169
+ //#endregion
140
170
  //#region ../node_modules/json5/dist/index.js
141
171
  var require_dist = /* @__PURE__ */ __commonJSMin(((exports, module) => {
142
172
  (function(global, factory) {
@@ -1414,7 +1444,7 @@ var encodeTaggedBytes = (tag, bytes) => Buffer.concat([
1414
1444
  encodeVarUint(BigInt(bytes.length)),
1415
1445
  Buffer.from(bytes)
1416
1446
  ]);
1417
- var isJsonObject$1 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1447
+ var isJsonObject$2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
1418
1448
  var isPath = (path, first, second) => path.length === 2 && path[0] === first && path[1] === second;
1419
1449
  var isHexString = (value) => value.length % 2 === 0 && /^[0-9a-fA-F]*$/.test(value);
1420
1450
  var decodeHexString = (value) => {
@@ -1447,7 +1477,7 @@ var encodeTlvValue = (value, path) => {
1447
1477
  encodeVarUint(BigInt(value.length)),
1448
1478
  ...value.map((entry) => encodeTlvValue(entry, path))
1449
1479
  ]);
1450
- if (isJsonObject$1(value)) {
1480
+ if (isJsonObject$2(value)) {
1451
1481
  const entries = Object.entries(value);
1452
1482
  return Buffer.concat([
1453
1483
  Buffer.from([tlvObjectTag]),
@@ -1561,7 +1591,7 @@ var findMuonBootstrapEmbeddedConfigSlot = (content) => {
1561
1591
  if (candidate === void 0) throw new Error("Embedded muon-bootstrap config slot was not found.");
1562
1592
  return candidate;
1563
1593
  };
1564
- var fileExists$1 = async (path) => {
1594
+ var fileExists$2 = async (path) => {
1565
1595
  try {
1566
1596
  return (await (0, node_fs_promises.stat)(path)).isFile();
1567
1597
  } catch {
@@ -1577,10 +1607,10 @@ var resolveMuonConfigInputPath = async (configPath) => {
1577
1607
  "muon.json"
1578
1608
  ]) {
1579
1609
  const candidate = (0, node_path.join)(directory, fileName);
1580
- if (await fileExists$1(candidate)) return candidate;
1610
+ if (await fileExists$2(candidate)) return candidate;
1581
1611
  }
1582
1612
  }
1583
- if (!await fileExists$1(configPath)) throw new Error(`muon config does not exist: ${configPath}`);
1613
+ if (!await fileExists$2(configPath)) throw new Error(`muon config does not exist: ${configPath}`);
1584
1614
  return configPath;
1585
1615
  };
1586
1616
  var readMuonConfigInput = async (configPath) => {
@@ -1793,13 +1823,13 @@ var defaultConfigFileNames = [
1793
1823
  "muon.jsonc",
1794
1824
  "muon.json"
1795
1825
  ];
1796
- var appConfigFromPath = "./assets.zip";
1826
+ var appConfigSourcePath = "./assets.zip";
1797
1827
  var defaultAppName = "muon-app";
1798
1828
  var muonLicenseFileName = "LICENSE_muon";
1799
1829
  var directoryMode = 493;
1800
1830
  var executableMode = 493;
1801
1831
  var assetSaltByteLength = 16;
1802
- var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
1832
+ var moduleDirectory$1 = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
1803
1833
  /**
1804
1834
  * Returns the host target used by muon build when no explicit target is passed.
1805
1835
  */
@@ -1849,7 +1879,7 @@ var buildMuonApp = async (options = {}) => {
1849
1879
  };
1850
1880
  var resolvePackageDirectory = (packageDirectory) => {
1851
1881
  if (packageDirectory !== void 0) return (0, node_path.resolve)(packageDirectory);
1852
- return moduleDirectory;
1882
+ return moduleDirectory$1;
1853
1883
  };
1854
1884
  var resolveBuildTargets = (options) => {
1855
1885
  if (options.allTargets === true) return [...allTargets];
@@ -1857,7 +1887,7 @@ var resolveBuildTargets = (options) => {
1857
1887
  return [getDefaultMuonBuildTarget()];
1858
1888
  };
1859
1889
  var resolveAssetInput = (root, assetSourcePath, assetPrefix, buildConfig) => {
1860
- const configuredAssetSourcePath = assetSourcePath === void 0 ? readConfigAssetFrom(buildConfig.config) : void 0;
1890
+ const configuredAssetSourcePath = assetSourcePath === void 0 ? readConfigAssetSourcePath(buildConfig.config) : void 0;
1861
1891
  return {
1862
1892
  sourcePath: assetSourcePath !== void 0 ? (0, node_path.resolve)(root, assetSourcePath) : configuredAssetSourcePath !== void 0 ? (0, node_path.resolve)(buildConfig.directory, configuredAssetSourcePath) : (0, node_path.resolve)(root, "assets"),
1863
1893
  prefix: normalizeZipPrefix(assetPrefix ?? "")
@@ -1888,24 +1918,24 @@ var readBuildConfig = async (root, configPath) => {
1888
1918
  directory: (0, node_path.dirname)(resolvedConfigPath)
1889
1919
  };
1890
1920
  };
1891
- var readConfigAssetFrom = (sourceConfig) => {
1921
+ var readConfigAssetSourcePath = (sourceConfig) => {
1892
1922
  const sourceAsset = sourceConfig.asset;
1893
1923
  if (sourceAsset === void 0) return;
1894
- if (!isJsonObject(sourceAsset)) throw new Error("muon.json asset must be an object when present.");
1895
- const sourceAssetFrom = sourceAsset.from;
1896
- if (sourceAssetFrom === void 0) return;
1897
- if (typeof sourceAssetFrom !== "string") throw new Error("muon.json asset.from must be a string when present.");
1898
- return sourceAssetFrom;
1924
+ if (!isJsonObject$1(sourceAsset)) throw new Error("muon.json asset must be an object when present.");
1925
+ const sourceAssetPath = sourceAsset.sourcePath;
1926
+ if (sourceAssetPath === void 0) return;
1927
+ if (typeof sourceAssetPath !== "string") throw new Error("muon.json asset.sourcePath must be a string when present.");
1928
+ return sourceAssetPath;
1899
1929
  };
1900
1930
  var resolveConfigPath = async (root, configPath) => {
1901
1931
  if (configPath !== void 0) {
1902
1932
  const resolvedPath = (0, node_path.resolve)(root, configPath);
1903
- if (await fileExists(resolvedPath)) return resolvedPath;
1933
+ if (await fileExists$1(resolvedPath)) return resolvedPath;
1904
1934
  throw new Error(`Muon config file does not exist: ${resolvedPath}`);
1905
1935
  }
1906
1936
  for (const fileName of defaultConfigFileNames) {
1907
1937
  const candidatePath = (0, node_path.join)(root, fileName);
1908
- if (await fileExists(candidatePath)) return candidatePath;
1938
+ if (await fileExists$1(candidatePath)) return candidatePath;
1909
1939
  }
1910
1940
  };
1911
1941
  var readJsonObjectFile = async (filePath, label) => {
@@ -1913,15 +1943,15 @@ var readJsonObjectFile = async (filePath, label) => {
1913
1943
  try {
1914
1944
  content = await (0, node_fs_promises.readFile)(filePath, "utf8");
1915
1945
  } catch (error) {
1916
- throw new Error(`${label} could not be read: ${filePath}: ${getErrorMessage(error)}`);
1946
+ throw new Error(`${label} could not be read: ${filePath}: ${getErrorMessage$1(error)}`);
1917
1947
  }
1918
1948
  let parsed;
1919
1949
  try {
1920
1950
  parsed = (0, import_dist.parse)(content);
1921
1951
  } catch (error) {
1922
- throw new Error(`${label} could not be parsed: ${filePath}: ${getErrorMessage(error)}`);
1952
+ throw new Error(`${label} could not be parsed: ${filePath}: ${getErrorMessage$1(error)}`);
1923
1953
  }
1924
- if (!isJsonObject(parsed)) throw new Error(`${label} must contain a JSON object: ${filePath}`);
1954
+ if (!isJsonObject$1(parsed)) throw new Error(`${label} must contain a JSON object: ${filePath}`);
1925
1955
  return parsed;
1926
1956
  };
1927
1957
  var buildMuonTarget = async (input) => {
@@ -2042,12 +2072,12 @@ var createZipArchive = (entries) => {
2042
2072
  };
2043
2073
  var createEmbeddedConfig = (sourceConfig, asset) => {
2044
2074
  const sourceAsset = sourceConfig.asset;
2045
- if (sourceAsset !== void 0 && !isJsonObject(sourceAsset)) throw new Error("muon.json asset must be an object when present.");
2075
+ if (sourceAsset !== void 0 && !isJsonObject$1(sourceAsset)) throw new Error("muon.json asset must be an object when present.");
2046
2076
  return {
2047
2077
  ...sourceConfig,
2048
2078
  asset: {
2049
2079
  ...sourceAsset ?? {},
2050
- from: appConfigFromPath,
2080
+ sourcePath: appConfigSourcePath,
2051
2081
  signature: asset.signature,
2052
2082
  salt: asset.salt
2053
2083
  }
@@ -2081,7 +2111,7 @@ var statOrUndefined = async (path) => {
2081
2111
  return;
2082
2112
  }
2083
2113
  };
2084
- var fileExists = async (path) => {
2114
+ var fileExists$1 = async (path) => {
2085
2115
  try {
2086
2116
  await (0, node_fs_promises.access)(path, node_fs.constants.F_OK);
2087
2117
  return true;
@@ -2089,11 +2119,311 @@ var fileExists = async (path) => {
2089
2119
  return false;
2090
2120
  }
2091
2121
  };
2092
- var isJsonObject = (value) => {
2122
+ var isJsonObject$1 = (value) => {
2093
2123
  return typeof value === "object" && value !== null && !Array.isArray(value);
2094
2124
  };
2125
+ var getErrorMessage$1 = (error) => error instanceof Error ? error.message : String(error);
2126
+ //#endregion
2127
+ //#region src/vite-internals.ts
2128
+ var resolveFromRoot = (root, path) => (0, node_path.isAbsolute)(path) ? path : (0, node_path.resolve)(root, path);
2129
+ var moduleDirectory = typeof __dirname === "string" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)({}.url));
2130
+ var defaultProjectConfigFileNames = [
2131
+ "muon.json5",
2132
+ "muon.jsonc",
2133
+ "muon.json"
2134
+ ];
2135
+ var muonRecycleExitCode = 88;
2136
+ /**
2137
+ * Resolves the muon-core runtime directory used by the Vite plugin.
2138
+ *
2139
+ * @param options Runtime path resolution inputs.
2140
+ * @returns Absolute or package-relative runtime directory path.
2141
+ */
2142
+ var resolveMuonRuntimePath = ({ root, target, muonPath, packageDirectory = moduleDirectory }) => muonPath === void 0 ? (0, node_path.join)(packageDirectory, "runtime", target) : resolveFromRoot(root, muonPath);
2143
+ var getMuonExecutablePath = (runtimePath, platform) => (0, node_path.join)(runtimePath, platform === "win32" ? "muon-core.exe" : "muon-core");
2144
+ var getLaunchScriptFileName = (platform) => platform === "win32" ? "open-muon.cmd" : "open-muon.sh";
2145
+ var quotePosix = (value) => `'${value.replaceAll("'", "'\\''")}'`;
2146
+ var getPlatformDirectoryName = (path, platform) => platform === "win32" ? node_path.win32.dirname(path) : (0, node_path.dirname)(path);
2147
+ var getOptionalPosixValue = (value) => value === void 0 ? "''" : quotePosix(value);
2148
+ var createPosixMuonLaunchScript = ({ muonExecutablePath, projectConfigPath, overrideConfigPath }) => `#!/usr/bin/env bash
2149
+ set -euo pipefail
2150
+ MUON_RECYCLE_EXIT_CODE=${muonRecycleExitCode}
2151
+ MUON_EXECUTABLE=${quotePosix(muonExecutablePath)}
2152
+ MUON_EXECUTABLE_DIRECTORY=${quotePosix(getPlatformDirectoryName(muonExecutablePath, "linux"))}
2153
+ MUON_PROJECT_CONFIG=${getOptionalPosixValue(projectConfigPath)}
2154
+ MUON_OVERRIDE_CONFIG=${quotePosix(overrideConfigPath)}
2155
+
2156
+ MUON_CONFIG_ARGS=()
2157
+ if [[ -n "$MUON_PROJECT_CONFIG" ]]; then
2158
+ if [[ ! -f "$MUON_PROJECT_CONFIG" ]]; then
2159
+ echo "Muon startup failed: project config does not exist: $MUON_PROJECT_CONFIG" >&2
2160
+ exit 1
2161
+ fi
2162
+ MUON_CONFIG_ARGS+=("-c" "$MUON_PROJECT_CONFIG")
2163
+ fi
2164
+
2165
+ if [[ ! -x "$MUON_EXECUTABLE" ]]; then
2166
+ echo "Muon startup failed: executable does not exist or is not executable: $MUON_EXECUTABLE" >&2
2167
+ exit 1
2168
+ fi
2169
+
2170
+ if [[ ! -f "$MUON_OVERRIDE_CONFIG" ]]; then
2171
+ echo "Muon startup failed: generated override config does not exist: $MUON_OVERRIDE_CONFIG" >&2
2172
+ exit 1
2173
+ fi
2174
+ MUON_CONFIG_ARGS+=("-c" "$MUON_OVERRIDE_CONFIG")
2175
+
2176
+ cd "$MUON_EXECUTABLE_DIRECTORY"
2177
+ while true; do
2178
+ set +e
2179
+ "$MUON_EXECUTABLE" "\${MUON_CONFIG_ARGS[@]}"
2180
+ MUON_EXIT_CODE=$?
2181
+ set -e
2182
+ if [[ "$MUON_EXIT_CODE" -ne "$MUON_RECYCLE_EXIT_CODE" ]]; then
2183
+ exit "$MUON_EXIT_CODE"
2184
+ fi
2185
+ done
2186
+ `;
2187
+ var escapeWindowsCmdValue = (value) => value.replaceAll("%", "%%").replaceAll("\r", "").replaceAll("\n", "");
2188
+ var getOptionalWindowsCmdValue = (value) => value === void 0 ? "" : escapeWindowsCmdValue(value);
2189
+ var createWindowsMuonLaunchScript = ({ muonExecutablePath, projectConfigPath, overrideConfigPath }) => `@echo off
2190
+ setlocal
2191
+ set "MUON_RECYCLE_EXIT_CODE=${muonRecycleExitCode}"
2192
+ set "MUON_EXECUTABLE=${escapeWindowsCmdValue(muonExecutablePath)}"
2193
+ set "MUON_EXECUTABLE_DIRECTORY=${escapeWindowsCmdValue(getPlatformDirectoryName(muonExecutablePath, "win32"))}"
2194
+ set "MUON_PROJECT_CONFIG=${getOptionalWindowsCmdValue(projectConfigPath)}"
2195
+ set "MUON_OVERRIDE_CONFIG=${escapeWindowsCmdValue(overrideConfigPath)}"
2196
+
2197
+ if not exist "%MUON_EXECUTABLE%" (
2198
+ echo Muon startup failed: executable does not exist: %MUON_EXECUTABLE% 1>&2
2199
+ exit /b 1
2200
+ )
2201
+
2202
+ if not exist "%MUON_OVERRIDE_CONFIG%" (
2203
+ echo Muon startup failed: generated override config does not exist: %MUON_OVERRIDE_CONFIG% 1>&2
2204
+ exit /b 1
2205
+ )
2206
+
2207
+ pushd "%MUON_EXECUTABLE_DIRECTORY%"
2208
+ :muon_recycle_loop
2209
+ if defined MUON_PROJECT_CONFIG (
2210
+ if not exist "%MUON_PROJECT_CONFIG%" (
2211
+ echo Muon startup failed: project config does not exist: %MUON_PROJECT_CONFIG% 1>&2
2212
+ popd
2213
+ exit /b 1
2214
+ )
2215
+ "%MUON_EXECUTABLE%" -c "%MUON_PROJECT_CONFIG%" -c "%MUON_OVERRIDE_CONFIG%"
2216
+ ) else (
2217
+ "%MUON_EXECUTABLE%" -c "%MUON_OVERRIDE_CONFIG%"
2218
+ )
2219
+ set "MUON_EXIT_CODE=%ERRORLEVEL%"
2220
+ if "%MUON_EXIT_CODE%"=="%MUON_RECYCLE_EXIT_CODE%" goto muon_recycle_loop
2221
+ popd
2222
+ exit /b %MUON_EXIT_CODE%
2223
+ `;
2224
+ var createMuonLaunchScript = (options) => options.platform === "win32" ? createWindowsMuonLaunchScript(options) : createPosixMuonLaunchScript(options);
2225
+ var getBaseUrl = (server) => server.resolvedUrls?.local[0] ?? server.resolvedUrls?.network[0];
2226
+ var getWebSocketOrigin = (startUrl) => {
2227
+ const url = new URL(startUrl);
2228
+ if (url.protocol === "https:") url.protocol = "wss:";
2229
+ else if (url.protocol === "http:") url.protocol = "ws:";
2230
+ return url.origin;
2231
+ };
2232
+ var createMuonOverrideConfig = (startUrl, enableDebugger) => {
2233
+ const origin = new URL(startUrl).origin;
2234
+ return {
2235
+ ...enableDebugger ? { cdp: { enable: true } } : {},
2236
+ browser: {
2237
+ startPage: startUrl,
2238
+ ...enableDebugger ? { keybind: {
2239
+ devtools: "f12",
2240
+ recycle: "ctrl+f12"
2241
+ } } : {},
2242
+ plugin: { allow: [`${origin}/**`] }
2243
+ },
2244
+ network: { allow: [`${origin}/**`, `${getWebSocketOrigin(startUrl)}/**`] }
2245
+ };
2246
+ };
2247
+ var writeMuonOverrideConfig = (server, overrideConfigPath, enableDebugger) => {
2248
+ const startUrl = getBaseUrl(server);
2249
+ if (startUrl === void 0) {
2250
+ server.config.logger.warn("Muon Vite plugin could not resolve a Vite URL.");
2251
+ return false;
2252
+ }
2253
+ (0, node_fs.writeFileSync)(overrideConfigPath, `${JSON.stringify(createMuonOverrideConfig(startUrl, enableDebugger), null, 2)}\n`);
2254
+ return true;
2255
+ };
2256
+ var createRuntimePaths = async (server, stagePath, platform, projectConfigPath) => {
2257
+ const temporaryDirectory = await (0, node_fs_promises.mkdtemp)((0, node_path.join)((0, node_os.tmpdir)(), "muon-vite-"));
2258
+ return {
2259
+ temporaryDirectory,
2260
+ launchScriptPath: (0, node_path.join)(temporaryDirectory, getLaunchScriptFileName(platform)),
2261
+ overrideConfigPath: (0, node_path.join)(temporaryDirectory, "muon.vite.json"),
2262
+ projectConfigPath,
2263
+ muonExecutablePath: getMuonExecutablePath(stagePath, platform)
2264
+ };
2265
+ };
2266
+ var fileExists = async (path) => {
2267
+ try {
2268
+ await (0, node_fs_promises.access)(path, node_fs.constants.F_OK);
2269
+ return true;
2270
+ } catch {
2271
+ return false;
2272
+ }
2273
+ };
2274
+ var isJsonObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2095
2275
  var getErrorMessage = (error) => error instanceof Error ? error.message : String(error);
2276
+ var resolveProjectConfigPath = async (server) => {
2277
+ for (const fileName of defaultProjectConfigFileNames) {
2278
+ const candidatePath = (0, node_path.join)(server.config.root, fileName);
2279
+ if (!await fileExists(candidatePath)) continue;
2280
+ try {
2281
+ if (!isJsonObject((0, import_dist.parse)(await (0, node_fs_promises.readFile)(candidatePath, "utf8")))) throw new Error("muon config root must be an object");
2282
+ return candidatePath;
2283
+ } catch (error) {
2284
+ server.config.logger.warn(`Muon project config will be ignored because it could not be read or parsed: ${candidatePath}: ${getErrorMessage(error)}`);
2285
+ return;
2286
+ }
2287
+ }
2288
+ server.config.logger.warn(`Muon project config was not found in ${server.config.root}; launching with generated Vite config only.`);
2289
+ };
2290
+ var writeLaunchScript = async (paths, platform) => {
2291
+ await (0, node_fs_promises.writeFile)(paths.launchScriptPath, createMuonLaunchScript({
2292
+ muonExecutablePath: paths.muonExecutablePath,
2293
+ projectConfigPath: paths.projectConfigPath,
2294
+ overrideConfigPath: paths.overrideConfigPath,
2295
+ platform
2296
+ }));
2297
+ if (platform !== "win32") await (0, node_fs_promises.chmod)(paths.launchScriptPath, 448);
2298
+ };
2299
+ var quoteWindowsCommandArgument = (value) => `"${value.replaceAll("\"", "\\\"")}"`;
2300
+ var launchMuon = (paths, platform, server) => {
2301
+ const child = (0, node_child_process.spawn)(platform === "win32" ? "cmd.exe" : paths.launchScriptPath, platform === "win32" ? [
2302
+ "/d",
2303
+ "/s",
2304
+ "/c",
2305
+ quoteWindowsCommandArgument(paths.launchScriptPath)
2306
+ ] : [], {
2307
+ detached: true,
2308
+ stdio: "ignore",
2309
+ windowsHide: false
2310
+ });
2311
+ child.once("error", (error) => {
2312
+ server.config.logger.warn(`Muon startup failed: ${getErrorMessage(error)}`);
2313
+ });
2314
+ child.unref();
2315
+ };
2316
+ var startMuonViteBrowserBridge = async ({ server, pluginOptions, platform, architecture, environment }) => {
2317
+ await ensureMuonGitignoreEntry(server.config.root);
2318
+ if (pluginOptions.open === false || server.httpServer === null) return;
2319
+ const target = getDefaultMuonPrepareTarget(platform, architecture);
2320
+ const preparedRuntime = await runMuonPrepare({
2321
+ muonPath: resolveMuonRuntimePath({
2322
+ root: server.config.root,
2323
+ target,
2324
+ muonPath: pluginOptions.muonPath
2325
+ }),
2326
+ cefPath: pluginOptions.cefPath === void 0 ? void 0 : resolveFromRoot(server.config.root, pluginOptions.cefPath),
2327
+ stageDir: pluginOptions.stagePath === void 0 ? (0, node_path.resolve)(server.config.root, ".muon", target) : resolveFromRoot(server.config.root, pluginOptions.stagePath),
2328
+ target,
2329
+ cacheDir: environment.MUON_CACHE_DIR,
2330
+ force: false,
2331
+ quiet: false,
2332
+ prepareExecutablePath: void 0,
2333
+ environment,
2334
+ cwd: server.config.root
2335
+ });
2336
+ if (preparedRuntime.stagePath === void 0) throw new Error("muon-prepare did not return a staged runtime path.");
2337
+ const paths = await createRuntimePaths(server, preparedRuntime.stagePath, platform, await resolveProjectConfigPath(server));
2338
+ await writeLaunchScript(paths, platform);
2339
+ let cleanupPromise = void 0;
2340
+ const cleanup = async () => {
2341
+ if (cleanupPromise !== void 0) return cleanupPromise;
2342
+ cleanupPromise = (async () => {
2343
+ await (0, node_fs_promises.rm)(paths.temporaryDirectory, {
2344
+ recursive: true,
2345
+ force: true
2346
+ });
2347
+ })();
2348
+ return cleanupPromise;
2349
+ };
2350
+ const originalClose = server.close.bind(server);
2351
+ server.close = async () => {
2352
+ try {
2353
+ await originalClose();
2354
+ } finally {
2355
+ await cleanup();
2356
+ }
2357
+ };
2358
+ server.httpServer.once("close", () => {
2359
+ cleanup();
2360
+ });
2361
+ server.httpServer.once("listening", () => {
2362
+ if (writeMuonOverrideConfig(server, paths.overrideConfigPath, pluginOptions.enableDebugger !== false)) launchMuon(paths, platform, server);
2363
+ });
2364
+ };
2365
+ //#endregion
2366
+ //#region src/vite-options.ts
2367
+ /**
2368
+ * Metadata symbol used to recover `muon()` plugin options from `vite.config.*`.
2369
+ */
2370
+ var muonVitePluginOptionsSymbol = Symbol.for("muon.vite.plugin.options");
2371
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2372
+ var isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
2373
+ var isMuonViteBuildOptions = (value) => {
2374
+ if (!isRecord(value)) return false;
2375
+ return (value.targets === void 0 || isStringArray(value.targets)) && (value.allTargets === void 0 || typeof value.allTargets === "boolean") && (value.appName === void 0 || typeof value.appName === "string") && (value.outputRoot === void 0 || typeof value.outputRoot === "string") && (value.configPath === void 0 || typeof value.configPath === "string") && (value.packageDirectory === void 0 || typeof value.packageDirectory === "string") && (value.assetSalt === void 0 || value.assetSalt instanceof Uint8Array);
2376
+ };
2377
+ var isMuonVitePluginOptions = (value) => {
2378
+ if (!isRecord(value)) return false;
2379
+ return (value.muonPath === void 0 || typeof value.muonPath === "string") && (value.cefPath === void 0 || typeof value.cefPath === "string") && (value.stagePath === void 0 || typeof value.stagePath === "string") && (value.open === void 0 || typeof value.open === "boolean") && (value.enableDebugger === void 0 || typeof value.enableDebugger === "boolean") && (value.build === void 0 || typeof value.build === "boolean" || isMuonViteBuildOptions(value.build));
2380
+ };
2381
+ /**
2382
+ * Attaches raw Muon Vite plugin options to a plugin instance.
2383
+ *
2384
+ * @param plugin Plugin object.
2385
+ * @param options Raw plugin options.
2386
+ * @returns Plugin object with internal Muon metadata.
2387
+ */
2388
+ var attachMuonVitePluginOptions = (plugin, options) => {
2389
+ Object.defineProperty(plugin, muonVitePluginOptionsSymbol, {
2390
+ configurable: false,
2391
+ enumerable: false,
2392
+ value: { ...options },
2393
+ writable: false
2394
+ });
2395
+ return plugin;
2396
+ };
2397
+ /**
2398
+ * Reads raw Muon Vite plugin options from a plugin instance.
2399
+ *
2400
+ * @param plugin Candidate plugin object.
2401
+ * @returns Attached Muon options, if present.
2402
+ */
2403
+ var getMuonVitePluginOptions = (plugin) => {
2404
+ if (!isRecord(plugin)) return;
2405
+ const options = plugin[muonVitePluginOptionsSymbol];
2406
+ return isMuonVitePluginOptions(options) ? options : void 0;
2407
+ };
2408
+ /**
2409
+ * Resolves nested Vite plugin option values into a flat list.
2410
+ *
2411
+ * @param pluginOptions Raw `plugins` field from a Vite config.
2412
+ * @returns Flat plugin object list.
2413
+ */
2414
+ var flattenVitePluginOptions = async (pluginOptions) => {
2415
+ const resolvedValue = await pluginOptions;
2416
+ if (resolvedValue === null || resolvedValue === void 0 || !resolvedValue) return [];
2417
+ if (Array.isArray(resolvedValue)) return (await Promise.all(resolvedValue.map((entry) => flattenVitePluginOptions(entry)))).flat();
2418
+ return [resolvedValue];
2419
+ };
2096
2420
  //#endregion
2421
+ Object.defineProperty(exports, "attachMuonVitePluginOptions", {
2422
+ enumerable: true,
2423
+ get: function() {
2424
+ return attachMuonVitePluginOptions;
2425
+ }
2426
+ });
2097
2427
  Object.defineProperty(exports, "buildMuonApp", {
2098
2428
  enumerable: true,
2099
2429
  get: function() {
@@ -2118,23 +2448,59 @@ Object.defineProperty(exports, "embedMuonConfigInRuntime", {
2118
2448
  return embedMuonConfigInRuntime;
2119
2449
  }
2120
2450
  });
2451
+ Object.defineProperty(exports, "ensureMuonGitignoreEntry", {
2452
+ enumerable: true,
2453
+ get: function() {
2454
+ return ensureMuonGitignoreEntry;
2455
+ }
2456
+ });
2457
+ Object.defineProperty(exports, "flattenVitePluginOptions", {
2458
+ enumerable: true,
2459
+ get: function() {
2460
+ return flattenVitePluginOptions;
2461
+ }
2462
+ });
2121
2463
  Object.defineProperty(exports, "getDefaultMuonPrepareTarget", {
2122
2464
  enumerable: true,
2123
2465
  get: function() {
2124
2466
  return getDefaultMuonPrepareTarget;
2125
2467
  }
2126
2468
  });
2469
+ Object.defineProperty(exports, "getMuonExecutablePath", {
2470
+ enumerable: true,
2471
+ get: function() {
2472
+ return getMuonExecutablePath;
2473
+ }
2474
+ });
2475
+ Object.defineProperty(exports, "getMuonVitePluginOptions", {
2476
+ enumerable: true,
2477
+ get: function() {
2478
+ return getMuonVitePluginOptions;
2479
+ }
2480
+ });
2127
2481
  Object.defineProperty(exports, "require_dist", {
2128
2482
  enumerable: true,
2129
2483
  get: function() {
2130
2484
  return require_dist;
2131
2485
  }
2132
2486
  });
2487
+ Object.defineProperty(exports, "resolveMuonRuntimePath", {
2488
+ enumerable: true,
2489
+ get: function() {
2490
+ return resolveMuonRuntimePath;
2491
+ }
2492
+ });
2133
2493
  Object.defineProperty(exports, "runMuonPrepare", {
2134
2494
  enumerable: true,
2135
2495
  get: function() {
2136
2496
  return runMuonPrepare;
2137
2497
  }
2138
2498
  });
2499
+ Object.defineProperty(exports, "startMuonViteBrowserBridge", {
2500
+ enumerable: true,
2501
+ get: function() {
2502
+ return startMuonViteBrowserBridge;
2503
+ }
2504
+ });
2139
2505
 
2140
- //# sourceMappingURL=build-BxDRaTmF.cjs.map
2506
+ //# sourceMappingURL=vite-options-C4evRLpv.cjs.map