zixulu 1.80.2 → 1.80.3
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.js +67 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/syncVscode.ts +67 -5
package/dist/index.js
CHANGED
|
@@ -5312,7 +5312,7 @@ async function pathExists(path) {
|
|
|
5312
5312
|
}
|
|
5313
5313
|
}
|
|
5314
5314
|
|
|
5315
|
-
// Windows
|
|
5315
|
+
// Windows 上优先查找 code.cmd,避免直接调用 Code.exe 打开编辑器窗口
|
|
5316
5316
|
async function resolveCodeCli() {
|
|
5317
5317
|
if (process.platform !== "win32") return "code"
|
|
5318
5318
|
|
|
@@ -5328,7 +5328,6 @@ async function resolveCodeCli() {
|
|
|
5328
5328
|
const pathDirs = process.env.PATH?.split(delimiter).filter(Boolean) ?? []
|
|
5329
5329
|
for (const dir of pathDirs) {
|
|
5330
5330
|
candidates.add(join(dir, "code.cmd"))
|
|
5331
|
-
candidates.add(join(dir, "code.exe"))
|
|
5332
5331
|
candidates.add(join(dir, "code"))
|
|
5333
5332
|
}
|
|
5334
5333
|
|
|
@@ -5339,16 +5338,69 @@ async function resolveCodeCli() {
|
|
|
5339
5338
|
throw new Error("未找到 VS Code 命令行工具,请先安装 VS Code,并确认安装时勾选了“添加到 PATH”")
|
|
5340
5339
|
}
|
|
5341
5340
|
|
|
5341
|
+
/**
|
|
5342
|
+
* @param {string} value
|
|
5343
|
+
*/
|
|
5344
|
+
function quoteWindowsArg(value) {
|
|
5345
|
+
return "\\"" + value.replace(/"/g, "\\"\\"") + "\\""
|
|
5346
|
+
}
|
|
5347
|
+
|
|
5348
|
+
/**
|
|
5349
|
+
* @param {string[]} args
|
|
5350
|
+
* @param {string} output
|
|
5351
|
+
*/
|
|
5352
|
+
function isCliCommandSuccessful(args, output) {
|
|
5353
|
+
if (args.includes("--install-extension")) return output.includes("was successfully installed.") || output.includes("is already installed.")
|
|
5354
|
+
if (args.includes("--uninstall-extension")) return output.includes("was successfully uninstalled.") || output.includes("is not installed.")
|
|
5355
|
+
return false
|
|
5356
|
+
}
|
|
5357
|
+
|
|
5358
|
+
/**
|
|
5359
|
+
* @param {Buffer | string} data
|
|
5360
|
+
* @param {string[]} chunks
|
|
5361
|
+
* @param {NodeJS.WriteStream} stream
|
|
5362
|
+
*/
|
|
5363
|
+
function writeChildOutput(data, chunks, stream) {
|
|
5364
|
+
const text = data.toString()
|
|
5365
|
+
chunks.push(text)
|
|
5366
|
+
stream.write(text)
|
|
5367
|
+
}
|
|
5368
|
+
|
|
5342
5369
|
/**
|
|
5343
5370
|
* @param {string} command
|
|
5344
5371
|
* @param {string[]} args
|
|
5345
5372
|
*/
|
|
5346
5373
|
function spawnAsync(command, args) {
|
|
5347
5374
|
return new Promise((resolve, reject) => {
|
|
5348
|
-
|
|
5375
|
+
// Windows 不能直接 spawn .cmd 或 .bat 文件,需要交给 cmd.exe 执行
|
|
5376
|
+
const needCmdShell = process.platform === "win32" && /\\.(cmd|bat)$/i.test(command)
|
|
5377
|
+
const chunks = []
|
|
5378
|
+
const child = needCmdShell
|
|
5379
|
+
? spawn(
|
|
5380
|
+
process.env.ComSpec ?? "cmd.exe",
|
|
5381
|
+
["/d", "/s", "/c", "\\"" + quoteWindowsArg(command) + " " + args.map(quoteWindowsArg).join(" ") + "\\""],
|
|
5382
|
+
{
|
|
5383
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
5384
|
+
windowsVerbatimArguments: true,
|
|
5385
|
+
},
|
|
5386
|
+
)
|
|
5387
|
+
: spawn(command, args, { stdio: ["ignore", "pipe", "pipe"] })
|
|
5388
|
+
|
|
5389
|
+
child.stdout?.on("data", data => writeChildOutput(data, chunks, process.stdout))
|
|
5390
|
+
child.stderr?.on("data", data => writeChildOutput(data, chunks, process.stderr))
|
|
5349
5391
|
child.on("error", reject)
|
|
5350
5392
|
child.on("exit", code => {
|
|
5351
|
-
|
|
5393
|
+
const output = chunks.join("")
|
|
5394
|
+
|
|
5395
|
+
if (code !== 0) {
|
|
5396
|
+
if (isCliCommandSuccessful(args, output)) {
|
|
5397
|
+
console.warn(\`VS Code 命令退出码为 \${code},但操作已完成,继续执行后续步骤\`)
|
|
5398
|
+
return resolve(0)
|
|
5399
|
+
}
|
|
5400
|
+
|
|
5401
|
+
return reject(new Error(\`Command failed with code \${code}: \${command} \${args.join(" ")}\`))
|
|
5402
|
+
}
|
|
5403
|
+
|
|
5352
5404
|
resolve(0)
|
|
5353
5405
|
})
|
|
5354
5406
|
})
|
|
@@ -5360,8 +5412,18 @@ ${needUserDir ? ` const userDir = homedir()
|
|
|
5360
5412
|
` : ""}${options.includes(VscodeSyncOption.插件) ? ` const extensionsDir = join(workspaceDir, "extensions")
|
|
5361
5413
|
const codeCli = await resolveCodeCli()
|
|
5362
5414
|
const dir = await readdir(extensionsDir)
|
|
5415
|
+
const extensionErrors = []
|
|
5363
5416
|
for (const ext of dir) {
|
|
5364
|
-
|
|
5417
|
+
try {
|
|
5418
|
+
await spawnAsync(codeCli, ["--install-extension", join(extensionsDir, ext), "--force"])
|
|
5419
|
+
} catch (error) {
|
|
5420
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
5421
|
+
extensionErrors.push(\`\${ext}: \${message}\`)
|
|
5422
|
+
console.error(\`扩展同步失败:\${ext}\`)
|
|
5423
|
+
}
|
|
5424
|
+
}
|
|
5425
|
+
if (extensionErrors.length > 0) {
|
|
5426
|
+
throw new Error(\`以下扩展同步失败:\\n\${extensionErrors.join("\\n")}\`)
|
|
5365
5427
|
}
|
|
5366
5428
|
` : ""}${options.includes(VscodeSyncOption.配置) ? ` const codeUserDir = join(userDir, "AppData", "Roaming", "Code", "User")
|
|
5367
5429
|
await mkdir(codeUserDir, { recursive: true })
|