@morlay/zephyr-desktop-bundle 0.0.0-stage → 0.2.0-alpha.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/dist/index.mjs ADDED
@@ -0,0 +1,571 @@
1
+ import { Injectable, Logger, inject, provide } from "@morlay/zephyr";
2
+ import { access, mkdir, readFile, rm, writeFile } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { BuildSteps, CliError, CliMode, Command, Workspace, runBuild } from "@morlay/zephyr-cli";
6
+ import { execFile, spawn } from "node:child_process";
7
+ import { promisify } from "node:util";
8
+ import sharp from "sharp";
9
+ import { a as appRootOf, i as appDataHomeOf, n as PackagerDefault, o as userDataDirOf, r as __decorate, t as Packager } from "./packager-2pDsExRM.mjs";
10
+ import { createRequire } from "node:module";
11
+ import { homedir } from "node:os";
12
+ import { createServer } from "node:net";
13
+ // src/electron-builder.ts
14
+ /**
15
+ * 把配置与布局推导成 electron-builder 的配置。
16
+ * @param input - 工作区配置、布局与壳目录。
17
+ * @returns 配置对象。
18
+ * @throws CliError 缺 `desktop.id` / `desktop.name`。
19
+ */
20
+ function electronBuilderConfigOf(input) {
21
+ const desktop = input.resolved.config.desktop;
22
+ if (desktop === void 0) throw new CliError("配置里没有 desktop 段:desktop bundle 需要 desktop.id 与 desktop.name。");
23
+ return {
24
+ electronVersion: input.electronVersion,
25
+ appId: desktop.id,
26
+ productName: desktop.name,
27
+ artifactName: "${productName}-${version}-${os}-${arch}.${ext}",
28
+ asar: true,
29
+ asarUnpack: ["**/*.node"],
30
+ npmRebuild: false,
31
+ directories: { output: join(input.layout.root, "app") },
32
+ files: [
33
+ "dist/**",
34
+ "bootstrap.mjs",
35
+ "package.json"
36
+ ],
37
+ extraResources: [{
38
+ from: join(input.layout.root, "desktop.json"),
39
+ to: "desktop.json"
40
+ }],
41
+ mac: {
42
+ category: "public.app-category.developer-tools",
43
+ identity: null,
44
+ ...input.icons?.mac === void 0 ? {} : { icon: input.icons.mac }
45
+ },
46
+ win: input.icons?.win === void 0 ? {} : { icon: input.icons.win },
47
+ linux: {
48
+ category: "Development",
49
+ ...input.icons?.linux === void 0 ? {} : { icon: input.icons.linux }
50
+ }
51
+ };
52
+ }
53
+ // src/icons.ts
54
+ /** macOS iconset 的尺寸与文件名(`iconutil` 只认这套命名)。 */
55
+ const MAC_ICONSET_SIZES = [
56
+ [16, "icon_16x16.png"],
57
+ [32, "icon_16x16@2x.png"],
58
+ [32, "icon_32x32.png"],
59
+ [64, "icon_32x32@2x.png"],
60
+ [128, "icon_128x128.png"],
61
+ [256, "icon_128x128@2x.png"],
62
+ [256, "icon_256x256.png"],
63
+ [512, "icon_256x256@2x.png"],
64
+ [512, "icon_512x512.png"],
65
+ [1024, "icon_512x512@2x.png"]
66
+ ];
67
+ /** 等比缩放的透明底(图标不能有白边)。 */
68
+ const CONTAIN_BACKGROUND = {
69
+ r: 0,
70
+ g: 0,
71
+ b: 0,
72
+ alpha: 0
73
+ };
74
+ /**
75
+ * 生成三平台图标。
76
+ * @param options - 工作区、产物根与 `desktop.icon` 的相对路径。
77
+ * @returns 各平台图标的绝对路径(没配图标就是空对象)。
78
+ * @throws CliError 图标文件不存在。
79
+ */
80
+ async function prepareIcons(options) {
81
+ if (options.icon === void 0 || options.icon === "") return {};
82
+ const source = resolve(options.workspace, options.icon);
83
+ if (!await exists(source)) throw new CliError(`配置里的 desktop.icon 指向的文件不存在:${source}`);
84
+ const outDir = join(options.outRoot, "icon");
85
+ await rm(outDir, {
86
+ recursive: true,
87
+ force: true
88
+ });
89
+ await mkdir(outDir, { recursive: true });
90
+ const png512 = join(outDir, "icon-512.png");
91
+ await sharp(source).resize(512, 512, {
92
+ fit: "contain",
93
+ background: CONTAIN_BACKGROUND
94
+ }).png().toFile(png512);
95
+ let icons = {
96
+ linux: png512,
97
+ win: png512
98
+ };
99
+ if (process.platform === "darwin") {
100
+ const iconset = join(outDir, "icon.iconset");
101
+ await mkdir(iconset, { recursive: true });
102
+ for (const [size, name] of MAC_ICONSET_SIZES) await sharp(source).resize(size, size, {
103
+ fit: "contain",
104
+ background: CONTAIN_BACKGROUND
105
+ }).png().toFile(join(iconset, name));
106
+ const icns = join(outDir, "icon.icns");
107
+ await promisify(execFile)("iconutil", [
108
+ "-c",
109
+ "icns",
110
+ iconset,
111
+ "-o",
112
+ icns
113
+ ]);
114
+ icons = {
115
+ ...icons,
116
+ mac: icns
117
+ };
118
+ }
119
+ return icons;
120
+ }
121
+ /**
122
+ * 文件在不在。
123
+ * @param path - 绝对路径。
124
+ * @returns 判断结果。
125
+ */
126
+ async function exists(path) {
127
+ try {
128
+ await access(path);
129
+ return true;
130
+ } catch {
131
+ return false;
132
+ }
133
+ }
134
+ // src/commands/bundle.ts
135
+ /**
136
+ * Electron 版本:`electron` 是壳的 peer,由仓库里装的那份决定。
137
+ *
138
+ * 用 `import.meta.resolve` 拿到包的**入口文件**,包根就是它的目录(`electron` 的入口在包根)。
139
+ * app 目录是应用闭包、没有 `electron`,所以这个版本必须显式交给 electron-builder。
140
+ * @returns 版本号(如 `45.2.3`)。
141
+ * @throws CliError 解析不到 electron。
142
+ */
143
+ async function electronVersionOf() {
144
+ try {
145
+ const entry = import.meta.resolve("electron");
146
+ return JSON.parse(await readFile(join(dirname(fileURLToPath(entry)), "package.json"), "utf8")).version;
147
+ } catch {
148
+ throw new CliError("解析不到 electron 的版本:壳的 peer 依赖没装(先 pnpm install)。");
149
+ }
150
+ }
151
+ let BundleCommand = class BundleCommand extends Command {
152
+ path = ["desktop", "bundle"];
153
+ description = "打一个静态、无签名的桌面应用目录(缺省不产安装包)";
154
+ params = { install: {
155
+ kind: "boolean",
156
+ description: "打完之后装进系统应用目录"
157
+ } };
158
+ steps = inject(BuildSteps);
159
+ packager = inject(Packager);
160
+ resolved = inject(Workspace);
161
+ logger = inject(Logger);
162
+ /**
163
+ * @param input - 参数(目前只有 `--install`)。
164
+ * @returns 退出码。
165
+ */
166
+ async run(input) {
167
+ try {
168
+ return await this.bundleAll(input);
169
+ } catch (error) {
170
+ process.exitCode = 1;
171
+ process.once("beforeExit", () => {
172
+ process.exitCode = 1;
173
+ });
174
+ throw error;
175
+ }
176
+ }
177
+ /**
178
+ * 真正的打包流程(构建 → 身份与图标 → 配置推导 → 打包 → 可选安装)。
179
+ * @param input - 参数(目前只有 `--install`)。
180
+ * @returns 退出码。
181
+ */
182
+ async bundleAll(input) {
183
+ const layout = this.resolved.layout;
184
+ await runBuild({
185
+ resolved: this.resolved,
186
+ layout
187
+ }, this.steps);
188
+ await mkdir(layout.root, { recursive: true });
189
+ await writeFile(join(layout.root, "desktop.json"), JSON.stringify(this.resolved.config.desktop ?? {}, null, 2), "utf8");
190
+ const icons = await prepareIcons({
191
+ workspace: this.resolved.workspace,
192
+ outRoot: layout.root,
193
+ icon: this.resolved.config.desktop?.icon
194
+ });
195
+ const config = electronBuilderConfigOf({
196
+ resolved: this.resolved,
197
+ layout,
198
+ electronVersion: await electronVersionOf(),
199
+ ...Object.keys(icons).length === 0 ? {} : { icons }
200
+ });
201
+ const result = await this.packager.pack(config, {
202
+ appDir: join(layout.root, "shell-app"),
203
+ profileDir: layout.root,
204
+ workspace: this.resolved.workspace,
205
+ logFile: join(layout.root, "bundle.log")
206
+ });
207
+ this.logger.info("[bundle] 产物:%s", result.appDir);
208
+ if (input.params.install === true) {
209
+ const target = await this.packager.install(result);
210
+ this.logger.info("[bundle] 已安装:%s", target);
211
+ }
212
+ return 0;
213
+ }
214
+ };
215
+ BundleCommand = __decorate([Injectable({ multi: true })], BundleCommand);
216
+ // src/commands/desktop.ts
217
+ let DesktopCommand = class DesktopCommand extends Command {
218
+ path = ["desktop"];
219
+ description = "桌面形态:dev 在壳里跑开发形态,bundle 打成应用目录";
220
+ params = {};
221
+ logger = inject(Logger);
222
+ /**
223
+ * @returns 退出码 2(父命令只做分组,不该被当命令执行)。
224
+ */
225
+ async run(_input) {
226
+ this.logger.info("用法: zephyr desktop <dev|bundle>");
227
+ return 2;
228
+ }
229
+ };
230
+ DesktopCommand = __decorate([Injectable({ multi: true })], DesktopCommand);
231
+ // src/page-port.ts
232
+ /** 端口文件名(在 `userData` 下)。 */
233
+ const PAGE_PORT_FILE = "page-port";
234
+ /** 首次兜底的端口(与宿主 `WebServer` 的缺省一致)。 */
235
+ const DEFAULT_PORT = 3080;
236
+ /** 可用端口的下界:1024 以下是系统保留段。 */
237
+ const MIN_PORT = 1024;
238
+ /** 可用端口的上界。 */
239
+ const MAX_PORT = 65535;
240
+ /**
241
+ * 解析端口文件(坏内容当「没有」:文件是上一个进程写的,形状不可信)。
242
+ * @param raw - 文件内容。
243
+ * @returns 端口,或 `undefined`。
244
+ */
245
+ function parsePort(raw) {
246
+ if (raw === void 0) return void 0;
247
+ const text = raw.trim();
248
+ if (!/^\d+$/u.test(text)) return void 0;
249
+ const value = Number(text);
250
+ return value >= MIN_PORT && value <= MAX_PORT ? value : void 0;
251
+ }
252
+ /**
253
+ * 记下这个端口(写不了就算了:下次重新探一个)。
254
+ * @param userData - `userData` 目录。
255
+ * @param port - 端口。
256
+ * @returns 写完成。
257
+ */
258
+ async function rememberPort(userData, port) {
259
+ await mkdir(userData, { recursive: true });
260
+ await writeFile(join(userData, PAGE_PORT_FILE), `${String(port)}\n`, "utf8").catch(() => void 0);
261
+ }
262
+ /**
263
+ * 这次该用哪个端口。
264
+ *
265
+ * 三条规矩:① `--port` 显式值优先,**写回**(用户显式选的 origin 就是新的归属);② 记住的端口空着
266
+ * 就用它;③ 被外部进程占着就报冲突(返回 `conflict`,由调用方抛可操作的错误),**不自动换**——换了
267
+ * 等于把页面存储另起一份。只有「没有记录」与「记录损坏」才重新选并写回。
268
+ * @param input - `userData`、显式值与替身动作。
269
+ * @returns 选好的端口,或冲突。
270
+ */
271
+ async function portFor(input) {
272
+ const probe = input.probe ?? isPortFree;
273
+ const pick = input.pick ?? freePort;
274
+ if (input.explicit !== void 0) {
275
+ await rememberPort(input.userData, input.explicit);
276
+ return {
277
+ kind: "ok",
278
+ port: input.explicit,
279
+ source: "explicit"
280
+ };
281
+ }
282
+ const record = await portRecordOf(input.userData);
283
+ if (record.port !== void 0) {
284
+ if (await probe(record.port)) return {
285
+ kind: "ok",
286
+ port: record.port,
287
+ source: "remembered"
288
+ };
289
+ return {
290
+ kind: "conflict",
291
+ port: record.port
292
+ };
293
+ }
294
+ const port = await pick();
295
+ await rememberPort(input.userData, port);
296
+ return {
297
+ kind: "ok",
298
+ port,
299
+ source: record.corrupt ? "corrupt" : "fresh"
300
+ };
301
+ }
302
+ /**
303
+ * 端口冲突时给用户的可操作提示(三条出口,都写明代价)。
304
+ * @param input - 被占的端口与 `userData` 目录。
305
+ * @returns 多行提示。
306
+ */
307
+ function portConflictHint(input) {
308
+ const file = join(input.userData, PAGE_PORT_FILE);
309
+ return [
310
+ `页面端口 ${String(input.port)}(记在 ${file})被别的进程占着。`,
311
+ "不自动换端口:换了 origin,页面存储(localStorage / IndexedDB)会另起一份。三条出口:",
312
+ ` · 关掉占用它的进程:lsof -nP -iTCP:${String(input.port)} -sTCP:LISTEN`,
313
+ ` · 换端口重起:zephyr desktop dev --port <新端口>(origin 会变,页面存储另起一份)`,
314
+ ` · 换一份 userData(并行多个工作区时就这么办):zephyr desktop dev --user-data-dir <目录>`
315
+ ].join("\n");
316
+ }
317
+ /**
318
+ * 端口能不能绑(能绑 = 现在没人占)。
319
+ * @param port - 端口。
320
+ * @returns 判断结果。
321
+ */
322
+ async function isPortFree(port) {
323
+ return new Promise((done) => {
324
+ const server = createServer();
325
+ server.once("error", () => done(false));
326
+ server.listen(port, "127.0.0.1", () => {
327
+ server.close(() => done(true));
328
+ });
329
+ });
330
+ }
331
+ /**
332
+ * 探一个空闲端口(**只在首次 / 记录损坏时用**:它会让 origin 变化)。
333
+ * @returns 端口。
334
+ */
335
+ async function freePort() {
336
+ return new Promise((resolvePort, reject) => {
337
+ const server = createServer();
338
+ server.once("error", reject);
339
+ server.listen(0, "127.0.0.1", () => {
340
+ const address = server.address();
341
+ const port = typeof address === "object" && address !== null ? address.port : DEFAULT_PORT;
342
+ server.close(() => resolvePort(port));
343
+ });
344
+ });
345
+ }
346
+ /**
347
+ * 读端口记录:区分「没有文件」与「文件在但坏了」。
348
+ * @param userData - `userData` 目录。
349
+ * @returns 端口(可能没有)与「是否损坏」。
350
+ */
351
+ async function portRecordOf(userData) {
352
+ const raw = await readFile(join(userData, PAGE_PORT_FILE), "utf8").catch(() => void 0);
353
+ if (raw === void 0) return { corrupt: false };
354
+ const port = parsePort(raw);
355
+ return port === void 0 ? { corrupt: true } : {
356
+ port,
357
+ corrupt: false
358
+ };
359
+ }
360
+ // src/commands/dev.ts
361
+ let DesktopDevCommand = class DesktopDevCommand extends Command {
362
+ path = ["desktop", "dev"];
363
+ description = "在 Electron 壳里跑工作区(开发形态:宿主在壳内,页面走 dev server)";
364
+ params = { userDataDir: {
365
+ kind: "string",
366
+ description: "壳的 userData 目录(缺省 <appData>/<desktop.id>/dev/electron;并行跑多个工作区时用它区分)"
367
+ } };
368
+ mode = inject(CliMode);
369
+ resolved = inject(Workspace);
370
+ logger = inject(Logger);
371
+ /**
372
+ * @returns 壳进程的退出码。
373
+ */
374
+ async run(input) {
375
+ const electron = resolveElectron();
376
+ const shellMain = resolveShellMain();
377
+ const userData = await this.ensureUserData(explicitUserDataDir(input));
378
+ const choice = await portFor({
379
+ userData,
380
+ explicit: this.mode.port
381
+ });
382
+ if (choice.kind === "conflict") throw new CliError(portConflictHint({
383
+ port: choice.port,
384
+ userData
385
+ }));
386
+ this.logPortChoice(choice.port, choice.source, userData);
387
+ const port = choice.port;
388
+ const server = this.startDevServer(port);
389
+ /**
390
+ * 收尾:先收壳、再收 dev server,最后**自己退出**。
391
+ *
392
+ * 早先只在 SIGINT 里杀 server、然后继续 `await` 壳退出——Ctrl+C 之后 CLI 就挂在那里不动了
393
+ * (壳不响应 SIGINT、server 已经没了,谁也不会叫醒它)。
394
+ * @param code - 退出码(SIGINT 128+2,SIGTERM 128+15)。
395
+ */
396
+ const shutdown = (code) => {
397
+ if (!server.killed && server.exitCode === null) server.kill("SIGTERM");
398
+ setImmediate(() => process.exit(code));
399
+ };
400
+ process.once("SIGINT", () => shutdown(130));
401
+ process.once("SIGTERM", () => shutdown(143));
402
+ await this.waitForServer(port);
403
+ this.logger.info("[desktop dev] 起壳:%s", shellMain);
404
+ const { ELECTRON_RUN_AS_NODE: _runAsNode, NODE_OPTIONS: _pnpmNodeOptions, ...inherited } = process.env;
405
+ const loader = resolveLoader();
406
+ const child = spawn(electron, [shellMain], {
407
+ stdio: "inherit",
408
+ env: {
409
+ ...inherited,
410
+ ZEPHYR_DESKTOP_MODE: "dev",
411
+ ZEPHYR_DESKTOP_NO_SANDBOX: "1",
412
+ ZEPHYR_DESKTOP_DEBUG: process.env.ZEPHYR_DESKTOP_DEBUG ?? "1",
413
+ ...loader === void 0 ? {} : { NODE_OPTIONS: `--import ${loader}` },
414
+ ZEPHYR_DESKTOP_USER_DATA: userData,
415
+ ZEPHYR_DESKTOP_WORKSPACE: this.mode.workspace,
416
+ ZEPHYR_DESKTOP_DATA_DIR: this.mode.dataDir,
417
+ ZEPHYR_DESKTOP_DATA_DIR_SPEC: this.mode.dataDirSpec,
418
+ ZEPHYR_DESKTOP_URL: `http://127.0.0.1:${String(port)}/`
419
+ }
420
+ });
421
+ return new Promise((resolve, reject) => {
422
+ child.on("error", reject);
423
+ child.on("exit", (code, signal) => {
424
+ if (!server.killed && server.exitCode === null) server.kill("SIGTERM");
425
+ resolve(code ?? (signal === null ? 0 : 1));
426
+ });
427
+ const forward = () => {
428
+ if (!child.killed && child.exitCode === null) child.kill("SIGTERM");
429
+ };
430
+ process.once("SIGINT", forward);
431
+ process.once("SIGTERM", forward);
432
+ });
433
+ }
434
+ /**
435
+ * 确保壳的 userData 目录存在(Electron 的 `setPath` 不会替你建目录)。
436
+ *
437
+ * 默认值 `<appData>/<desktop.id>/dev/electron`(**不住产物根**:`runBuild` 会整目录删掉
438
+ * `node_modules/.zephyr`);**显式值优先**:`--user-data-dir` > `ZEPHYR_DESKTOP_USER_DATA` > 默认。
439
+ * @param fromFlag - `--user-data-dir` 的值(没有就是 `undefined`)。
440
+ * @returns 绝对路径。
441
+ * @throws CliError 显式值为空且配置里没有 `desktop.id`(目录按它算)。
442
+ */
443
+ async ensureUserData(fromFlag) {
444
+ const fromEnv = process.env.ZEPHYR_DESKTOP_USER_DATA;
445
+ const explicit = fromFlag !== void 0 && fromFlag !== "" ? fromFlag : fromEnv === void 0 || fromEnv === "" ? void 0 : fromEnv;
446
+ const dir = explicit ?? userDataDirOf(appRootOf({
447
+ appDataHome: appDataHomeOf(process.env, process.platform, homedir()),
448
+ desktopId: this.desktopIdOf(),
449
+ form: "dev"
450
+ }));
451
+ await mkdir(dir, { recursive: true });
452
+ this.logger.info("[desktop dev] userData:%s(%s)", dir, explicit === void 0 ? "缺省 <appData>/<desktop.id>/dev/electron" : "显式指定");
453
+ return dir;
454
+ }
455
+ /**
456
+ * 打一行端口来源(origin 会不会变,看这一行)。
457
+ * @param port - 选中的端口。
458
+ * @param source - 端口从哪来。
459
+ * @param userData - userData 目录(提示文件位置)。
460
+ */
461
+ logPortChoice(port, source, userData) {
462
+ const why = {
463
+ remembered: "沿用上次,origin 不变",
464
+ fresh: `首次选择,记在 ${join(userData, "page-port")},origin 不变下次`,
465
+ corrupt: "端口记录损坏,已重新选择(页面存储将另起)",
466
+ explicit: "--port 显式指定并已写回:origin 已变,页面存储将另起"
467
+ };
468
+ this.logger.info("[desktop dev] 页面端口:%s(%s)", String(port), why[source]);
469
+ }
470
+ /**
471
+ * 桌面身份的应用 id(应用根的第一段)。
472
+ * @returns 反向域名 id。
473
+ * @throws CliError 配置里没有 `desktop` 段。
474
+ */
475
+ desktopIdOf() {
476
+ const desktopId = this.resolved.config.desktop?.id;
477
+ if (desktopId === void 0) throw new CliError("桌面形态需要 desktop.id:userData 的应用根按它算(或用 ZEPHYR_DESKTOP_USER_DATA 显式指定)。");
478
+ return desktopId;
479
+ }
480
+ /**
481
+ * 起 dev server 子进程(自己再跑一次 CLI 的 `dev`)。
482
+ * @param port - 期望的端口。
483
+ * @returns 子进程。
484
+ */
485
+ startDevServer(port) {
486
+ return spawn("pnpm", [
487
+ "exec",
488
+ "zephyr",
489
+ "dev",
490
+ this.mode.workspace
491
+ ], {
492
+ stdio: "inherit",
493
+ env: {
494
+ ...process.env,
495
+ PORT: String(port)
496
+ },
497
+ cwd: this.mode.workspace
498
+ });
499
+ }
500
+ /**
501
+ * 等页面端口可用。
502
+ * @param port - 端口。
503
+ */
504
+ async waitForServer(port) {
505
+ const deadline = Date.now() + 6e4;
506
+ for (;;) {
507
+ try {
508
+ if ((await fetch(`http://127.0.0.1:${String(port)}/`)).ok) return;
509
+ } catch {}
510
+ if (Date.now() > deadline) throw new CliError(`dev server 60s 内没起来(http://127.0.0.1:${String(port)}/):先单独跑一次 zephyr dev 看报错。`);
511
+ await new Promise((resolve) => setTimeout(resolve, 500));
512
+ }
513
+ }
514
+ };
515
+ DesktopDevCommand = __decorate([Injectable({ multi: true })], DesktopDevCommand);
516
+ /**
517
+ * `--user-data-dir` 的显式值(比环境变量更具体,所以排在它前面)。
518
+ * @param input - 命令输入(参数表)。
519
+ * @returns 路径,或 `undefined`(没给)。
520
+ */
521
+ function explicitUserDataDir(input) {
522
+ const value = input.params["userDataDir"];
523
+ return typeof value === "string" && value !== "" ? value : void 0;
524
+ }
525
+ /**
526
+ * electron 可执行文件:`electron` 包在 Node 里 export 出来就是它的二进制路径。
527
+ * @returns 可执行文件路径。
528
+ */
529
+ function resolveElectron() {
530
+ const require = createRequire(import.meta.url);
531
+ try {
532
+ return require("electron");
533
+ } catch {
534
+ throw new CliError("没有装 electron:desktop dev 需要它(peerDependency)。");
535
+ }
536
+ }
537
+ /**
538
+ * 本仓库的 TS 运行时入口(`register.mjs`):壳里加载 `.ts` 靠它。
539
+ * @returns `register.mjs` 的绝对路径;没装就是 `undefined`。
540
+ */
541
+ function resolveLoader() {
542
+ const require = createRequire(import.meta.url);
543
+ try {
544
+ return require.resolve("@morlay/dsh-oxc-node");
545
+ } catch {
546
+ return;
547
+ }
548
+ }
549
+ /**
550
+ * 壳的主进程入口:由壳包自己的 `main` 字段决定(产物是 `dist/main.mjs`)。
551
+ * @returns 入口绝对路径。
552
+ */
553
+ function resolveShellMain() {
554
+ const require = createRequire(import.meta.url);
555
+ try {
556
+ const manifestPath = require.resolve("@morlay/zephyr-desktop-shell/package.json");
557
+ const manifest = require(manifestPath);
558
+ return join(dirname(manifestPath), manifest.main ?? "dist/main.mjs");
559
+ } catch {
560
+ throw new CliError("没有找到 @morlay/zephyr-desktop-shell:桌面形态需要它。");
561
+ }
562
+ }
563
+ // src/provide.ts
564
+ /** 桌面形态的清单。 */
565
+ const provideDesktopBundle = provide([
566
+ DesktopCommand,
567
+ DesktopDevCommand,
568
+ BundleCommand,
569
+ PackagerDefault
570
+ ]);
571
+ export { BundleCommand, DesktopCommand, DesktopDevCommand, Packager, PackagerDefault, electronBuilderConfigOf, provideDesktopBundle };