zcode-pro 0.19.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/zcode-pro.mjs +32 -9
- package/dist/inject.js +229 -127
- package/package.json +1 -1
- package/src/host/helper.mjs +325 -35
- package/src/host/main.mjs +8 -4
- package/src/host/setup.mjs +45 -42
- package/src/host/taskIndex.mjs +186 -6
- package/src/inject/core.js +23 -15
- package/src/inject/features/settings-dialog.js +85 -49
- package/src/inject/features/styles.js +1 -1
- package/src/inject/features/task-order.js +1 -1
- package/src/inject/features/title-gen.js +10 -1
- package/src/inject/features/title-lock.js +59 -1
- package/src/inject/features/ws-running.js +1 -1
- package/src/inject/provider-fields.js +2 -2
package/bin/zcode-pro.mjs
CHANGED
|
@@ -7,8 +7,7 @@ import { spawn, spawnSync } from 'node:child_process';
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
|
|
9
9
|
// 动态导入必须用 URL 对象:Windows 上绝对路径(C:\...)会被当作 c: 协议报错
|
|
10
|
-
const
|
|
11
|
-
const cliPath = fileURLToPath(cliUrl);
|
|
10
|
+
const cliPath = fileURLToPath(new URL('../cli.mjs', import.meta.url));
|
|
12
11
|
const argv = process.argv.slice(2);
|
|
13
12
|
|
|
14
13
|
async function runWithZcodeRuntime() {
|
|
@@ -17,21 +16,45 @@ async function runWithZcodeRuntime() {
|
|
|
17
16
|
const env = { ...process.env, ELECTRON_RUN_AS_NODE: '1' };
|
|
18
17
|
// 预检:注册表等来源找到的 ZCode 可能不完整(缺 resources/ICU 数据等),以 Node
|
|
19
18
|
// 模式跑不起来的直接抛错回退系统 node,避免启动器跟着报难懂的错误退出
|
|
19
|
+
// --no-warnings:node:sqlite 的 ExperimentalWarning 每次启动必然刷屏、用户
|
|
20
|
+
// 常误当成报错(在模块加载阶段同步打印,进程内拦不住),由调用方加旗标关闭
|
|
20
21
|
const pre = spawnSync(zcodeBin, ['-e', 'process.exit(0)'], { env, stdio: 'ignore' });
|
|
21
22
|
if (pre.status !== 0) throw new Error(`ZCode 运行时不可用(${zcodeBin})`);
|
|
22
23
|
await new Promise((resolve, reject) => {
|
|
23
|
-
const child = spawn(zcodeBin, [cliPath, ...argv], { stdio: 'inherit', env });
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const child = spawn(zcodeBin, ['--no-warnings', cliPath, ...argv], { stdio: 'inherit', env });
|
|
25
|
+
// spawn 成功才挂退出转发并 resolve。spawn 失败的 error 事件晚一拍才发,同步
|
|
26
|
+
// resolve 会把 reject 变成空操作(失败被吞、进程静默退 0、回退分支不触发);
|
|
27
|
+
// 且失败后 exit 是否触发文档未定义,退出转发提前挂载可能把回退拉起的进程
|
|
28
|
+
// 退成 0。失败时只走 reject → 回退分支
|
|
29
|
+
child.once('spawn', () => {
|
|
30
|
+
child.on('exit', (code, signal) => {
|
|
31
|
+
if (signal) process.kill(process.pid, signal);
|
|
32
|
+
else process.exit(code ?? 0);
|
|
33
|
+
});
|
|
34
|
+
resolve();
|
|
28
35
|
});
|
|
29
|
-
|
|
36
|
+
child.once('error', reject);
|
|
30
37
|
});
|
|
31
38
|
}
|
|
32
39
|
|
|
33
40
|
try {
|
|
34
41
|
await runWithZcodeRuntime();
|
|
35
42
|
} catch {
|
|
36
|
-
|
|
43
|
+
// 回退系统 node。不能在本进程 import cli.mjs:本进程没有 --no-warnings 旗标
|
|
44
|
+
//(进程已启动,无法追加),node:sqlite 的实验特性警告会刷屏——用户误当报错。
|
|
45
|
+
// 同样以带旗标的子进程重跑(npm 环境必有 node,spawn 自身路径可靠)
|
|
46
|
+
const child = spawn(process.execPath, ['--no-warnings', cliPath, ...argv], {
|
|
47
|
+
stdio: 'inherit', env: process.env,
|
|
48
|
+
});
|
|
49
|
+
child.once('error', (err) => {
|
|
50
|
+
console.error(`[zcodepro] failed to launch: ${err?.message || err}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
// 退出转发同样等 spawn 成功再挂(理由见 runWithZcodeRuntime 内注释)
|
|
54
|
+
child.once('spawn', () => {
|
|
55
|
+
child.on('exit', (code, signal) => {
|
|
56
|
+
if (signal) process.kill(process.pid, signal);
|
|
57
|
+
else process.exit(code ?? 0);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
37
60
|
}
|