@cc-claw/code 0.6.115 → 0.6.117
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/install.js +41 -0
- package/package.json +1 -1
package/install.js
CHANGED
|
@@ -399,6 +399,39 @@ async function downloadRipgrep(platform, binDir) {
|
|
|
399
399
|
}
|
|
400
400
|
}
|
|
401
401
|
|
|
402
|
+
// #410:把 npm 自动生成的全局入口(<prefix>/cc-code.cmd|.ps1)改写为直起 exe。
|
|
403
|
+
// 全局安装时 __dirname = <prefix>/node_modules/@cc-claw/code,故 prefix 根为
|
|
404
|
+
// __dirname/../../..。仅在能定位到 npm 生成的 wrapper 时才覆盖;任何失败都不
|
|
405
|
+
// 阻塞安装(此时 exe 同目录 bin/cc-code.cmd|.ps1 仍可直起)。
|
|
406
|
+
function overwriteNpmGlobalWrapper(binDirPath) {
|
|
407
|
+
try {
|
|
408
|
+
const prefixRoot = join(__dirname, "..", "..", "..");
|
|
409
|
+
const exePath = join(binDirPath, "cc-code.exe");
|
|
410
|
+
// 全局 cmd 用相对自身的路径引用 exe,避免硬编码绝对路径(prefix 可能含空格)
|
|
411
|
+
const cmdTarget = join(prefixRoot, "cc-code.cmd");
|
|
412
|
+
const ps1Target = join(prefixRoot, "cc-code.ps1");
|
|
413
|
+
|
|
414
|
+
// 防御:仅当 exe 存在且全局 wrapper 也存在(确是 npm 全局安装布局)时才覆盖
|
|
415
|
+
if (!existsSync(exePath)) return;
|
|
416
|
+
if (!existsSync(cmdTarget) && !existsSync(ps1Target)) return;
|
|
417
|
+
|
|
418
|
+
// exe 相对 prefix 根的路径:node_modules/@cc-claw/code/bin/cc-code.exe
|
|
419
|
+
const relExe = join("node_modules", "@cc-claw", "code", "bin", "cc-code.exe");
|
|
420
|
+
|
|
421
|
+
writeFileSync(
|
|
422
|
+
cmdTarget,
|
|
423
|
+
`@echo off\r\n"%~dp0${relExe.replace(/\//g, "\\")}" %*\r\n`
|
|
424
|
+
);
|
|
425
|
+
writeFileSync(
|
|
426
|
+
ps1Target,
|
|
427
|
+
`$basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent\r\n& "$basedir\\${relExe.replace(/\//g, "\\")}" @args\r\nexit $LASTEXITCODE\r\n`
|
|
428
|
+
);
|
|
429
|
+
console.log(" Rewrote npm global wrapper to launch cc-code.exe directly (Ctrl+C fix).");
|
|
430
|
+
} catch (err) {
|
|
431
|
+
console.log(` global wrapper rewrite skipped: ${err.message}`);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
402
435
|
async function main() {
|
|
403
436
|
const key = getPlatformKey();
|
|
404
437
|
const platform = PLATFORMS[key];
|
|
@@ -445,6 +478,14 @@ async function main() {
|
|
|
445
478
|
const binDirPath = join(__dirname, "bin");
|
|
446
479
|
writeFileSync(join(binDirPath, "cc-code.cmd"), `@echo off\r\n"%~dp0cc-code.exe" %*\r\n`);
|
|
447
480
|
writeFileSync(join(binDirPath, "cc-code.ps1"), `$basedir = Split-Path $MyInvocation.MyCommand.Definition -Parent\r\n& "$basedir\\cc-code.exe" @args\r\nexit $LASTEXITCODE\r\n`);
|
|
481
|
+
|
|
482
|
+
// #410:npm 全局入口(<prefix>/cc-code.cmd|.ps1)由 npm 依据 package.json
|
|
483
|
+
// 的 bin(指向 node 脚本 bin/cc-code)自动生成,会经 node 以 execFileSync
|
|
484
|
+
// 拉起 exe。Ctrl+C 的 CTRL_C_EVENT 广播给整个控制台进程组时,node 父进程
|
|
485
|
+
// 无 handler 被终止,连带拖死 cc-code.exe(其 SetConsoleCtrlHandler 拦截
|
|
486
|
+
// 因此失效),表现为任意状态按 Ctrl+C 直接退出 TUI。这里把全局入口改写为
|
|
487
|
+
// 直起 exe,去掉 node 中间层,进程组内只剩 cc-code.exe,handler 正常生效。
|
|
488
|
+
overwriteNpmGlobalWrapper(binDirPath);
|
|
448
489
|
}
|
|
449
490
|
|
|
450
491
|
console.log(`cc-code ${VERSION} installed successfully.`);
|