u1s1-cli 0.13.4 → 0.13.5
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/update.js +19 -8
- package/package.json +1 -1
package/dist/update.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { execSync,
|
|
1
|
+
import { execSync, spawnSync } from "node:child_process";
|
|
2
2
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { tmpdir } from "node:os";
|
|
@@ -65,14 +65,25 @@ async function portableSelfUpdate(latest) {
|
|
|
65
65
|
if (process.platform === "win32") {
|
|
66
66
|
console.log(`正在打开更新窗口(升级到 v${latest})…`);
|
|
67
67
|
console.log("更新在新窗口里进行,本窗口会退出;装完后重新打开终端运行 u1s1 即可。");
|
|
68
|
+
console.log("若新窗口没有出现,可手动在 PowerShell 运行: irm https://u1s1.io/releases/install.ps1 | iex");
|
|
68
69
|
// 不走 `cmd /c start`:start 只把**带引号**的首参当窗口标题,而 node 对
|
|
69
|
-
// 无空格参数不加引号,标题会被当成命令执行(0.13.1 翻车现场)
|
|
70
|
-
// Windows 上 detached
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
// 无空格参数不加引号,标题会被当成命令执行(0.13.1 翻车现场)。也不走
|
|
71
|
+
// spawn detached:Windows 上 detached 是 DETACHED_PROCESS——子进程**没有**
|
|
72
|
+
// 控制台,窗口根本不出现,0.13.2-0.13.4 的更新其实在隐形 powershell 里
|
|
73
|
+
// 跑完的(当时的注释把这个标志理解反了)。可靠开窗走 ShellExecute 语义:
|
|
74
|
+
// 同步跑一个无窗 launcher,由它 Start-Process 弹真窗口(ShellExecute 出的
|
|
75
|
+
// 进程完全独立,不随本进程退出)。路径经 $PSScriptRoot 传递,不往命令行
|
|
76
|
+
// 拼字符串,没有引号二次解析问题。
|
|
77
|
+
const dir = mkdtempSync(join(tmpdir(), "u1s1-update-"));
|
|
78
|
+
writeFileSync(join(dir, "update.ps1"), "irm https://u1s1.io/releases/install.ps1 | iex\n");
|
|
79
|
+
writeFileSync(join(dir, "launch.ps1"), "$inner = '-NoProfile -ExecutionPolicy Bypass -NoExit -File \"' + $PSScriptRoot + '\\update.ps1\"'\n" +
|
|
80
|
+
"Start-Process powershell -ArgumentList $inner\n");
|
|
81
|
+
const res = spawnSync("powershell.exe", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", join(dir, "launch.ps1")], { stdio: "ignore", windowsHide: true, timeout: 30_000 });
|
|
82
|
+
if (res.error || res.status !== 0) {
|
|
83
|
+
console.error("无法拉起更新窗口。请手动在 PowerShell 里运行:");
|
|
84
|
+
console.error(" irm https://u1s1.io/releases/install.ps1 | iex");
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
76
87
|
// 立刻退出释放 node.exe 的文件锁,让安装器能替换安装目录
|
|
77
88
|
process.exit(0);
|
|
78
89
|
}
|