tt-help-cli-ycl 1.4.94 → 1.4.95
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/package.json +1 -1
- package/src/watchdog/upgrader.js +11 -3
package/package.json
CHANGED
package/src/watchdog/upgrader.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { exec, spawn } from "child_process";
|
|
10
10
|
import { readFileSync, openSync } from "fs";
|
|
11
|
-
import { fileURLToPath } from "url";
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from "url";
|
|
12
12
|
import { dirname, join } from "path";
|
|
13
13
|
import { homedir, tmpdir } from "os";
|
|
14
14
|
|
|
@@ -135,7 +135,10 @@ async function verifyUpgradedPackage(beforeVersion) {
|
|
|
135
135
|
/** 冒烟:spawn 子进程加载新版主模块(仅加载不执行业务),能加载则代码/依赖基本可用 */
|
|
136
136
|
function smokeTestMainModule(timeoutMs = 15_000) {
|
|
137
137
|
return new Promise((resolve) => {
|
|
138
|
-
|
|
138
|
+
// 必须转成 file:// URL:Windows 上裸的 C:\... 路径会被 ESM loader 当作协议 c: 而报错
|
|
139
|
+
const mainModulePath = pathToFileURL(
|
|
140
|
+
join(__dirname, "..", "..", "src", "main.js"),
|
|
141
|
+
).href;
|
|
139
142
|
const code = `import(${JSON.stringify(
|
|
140
143
|
mainModulePath,
|
|
141
144
|
)}).then(()=>process.exit(0)).catch((e)=>{console.error(e&&e.message||e);process.exit(1)})`;
|
|
@@ -393,7 +396,12 @@ export function spawnUpgrader({
|
|
|
393
396
|
}
|
|
394
397
|
|
|
395
398
|
// 直接运行时自动进入独立升级器模式
|
|
396
|
-
|
|
399
|
+
// 必须显式 --upgrade 才执行(防误调用:如 --help 或无参数时不应触发真实 npm install)
|
|
400
|
+
if (
|
|
401
|
+
process.argv[1] &&
|
|
402
|
+
fileURLToPath(import.meta.url) === process.argv[1] &&
|
|
403
|
+
process.argv.includes("--upgrade")
|
|
404
|
+
) {
|
|
397
405
|
runUpgradeMode(process.argv.slice(2)).catch((e) => {
|
|
398
406
|
console.error(`[upgrade-proc] 升级器异常: ${e.message}`);
|
|
399
407
|
process.exit(1);
|