cc-viewer 1.6.257 → 1.6.260

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/cli.js CHANGED
@@ -202,9 +202,12 @@ function injectCliJs() {
202
202
  if (content.includes(INJECT_START)) {
203
203
  return 'exists';
204
204
  }
205
- const lines = content.split('\n');
205
+ // 保留主导 EOL:若原文件 CRLF,注入完仍 CRLF(否则 split('\n')+join('\n') 会把 Win 文件
206
+ // 一次性转 LF,git/编辑器抱怨混合行尾且对哈希签名敏感的脚本可能失效)。
207
+ const eol = content.includes('\r\n') ? '\r\n' : '\n';
208
+ const lines = content.split(/\r?\n/);
206
209
  lines.splice(2, 0, INJECT_BLOCK);
207
- writeFileSync(cliPath, lines.join('\n'));
210
+ writeFileSync(cliPath, lines.join(eol));
208
211
  return 'injected';
209
212
  }
210
213
 
@@ -379,9 +382,16 @@ async function runCliMode(extraClaudeArgs = [], cwd, noOpen = false) {
379
382
  const url = `${protocol}://127.0.0.1:${port}`;
380
383
  if (!noOpen) {
381
384
  try {
382
- const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
383
- const { execSync } = await import('node:child_process');
384
- execSync(`${cmd} ${url}`, { stdio: 'ignore', timeout: 5000 });
385
+ // URL & cmd.exe 下会被当命令分隔符切断 query;用 spawn 数组传参避免 shell interpolation。
386
+ // Win `start` cmd.exe 内置不是 .exe,必须 shell:true;用 spawn + 数组让 Node 自己 escape。
387
+ // 第二个 arg '""' `start` 的 window-title 占位(否则 start 会把 URL 当 title)。
388
+ const { spawn } = await import('node:child_process');
389
+ if (process.platform === 'win32') {
390
+ spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore', detached: true, windowsHide: true }).unref();
391
+ } else {
392
+ const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
393
+ spawn(cmd, [url], { stdio: 'ignore', detached: true }).unref();
394
+ }
385
395
  } catch {}
386
396
  }
387
397
 
@@ -469,9 +479,16 @@ async function runSdkMode(extraClaudeArgs = [], cwd, noOpen = false) {
469
479
  const url = `${protocol}://127.0.0.1:${port}`;
470
480
  if (!noOpen) {
471
481
  try {
472
- const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
473
- const { execSync } = await import('node:child_process');
474
- execSync(`${cmd} ${url}`, { stdio: 'ignore', timeout: 5000 });
482
+ // URL & cmd.exe 下会被当命令分隔符切断 query;用 spawn 数组传参避免 shell interpolation。
483
+ // Win `start` cmd.exe 内置不是 .exe,必须 shell:true;用 spawn + 数组让 Node 自己 escape。
484
+ // 第二个 arg '""' `start` 的 window-title 占位(否则 start 会把 URL 当 title)。
485
+ const { spawn } = await import('node:child_process');
486
+ if (process.platform === 'win32') {
487
+ spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore', detached: true, windowsHide: true }).unref();
488
+ } else {
489
+ const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
490
+ spawn(cmd, [url], { stdio: 'ignore', detached: true }).unref();
491
+ }
475
492
  } catch {}
476
493
  }
477
494
 
@@ -533,9 +550,16 @@ async function runCliModeWorkspaceSelector(extraClaudeArgs = [], noOpen = false)
533
550
  const url = `${wsProtocol}://127.0.0.1:${port}`;
534
551
  if (!noOpen) {
535
552
  try {
536
- const cmd = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'start' : 'xdg-open';
537
- const { execSync } = await import('node:child_process');
538
- execSync(`${cmd} ${url}`, { stdio: 'ignore', timeout: 5000 });
553
+ // URL & cmd.exe 下会被当命令分隔符切断 query;用 spawn 数组传参避免 shell interpolation。
554
+ // Win `start` cmd.exe 内置不是 .exe,必须 shell:true;用 spawn + 数组让 Node 自己 escape。
555
+ // 第二个 arg '""' `start` 的 window-title 占位(否则 start 会把 URL 当 title)。
556
+ const { spawn } = await import('node:child_process');
557
+ if (process.platform === 'win32') {
558
+ spawn('cmd.exe', ['/c', 'start', '""', url], { stdio: 'ignore', detached: true, windowsHide: true }).unref();
559
+ } else {
560
+ const cmd = process.platform === 'darwin' ? 'open' : 'xdg-open';
561
+ spawn(cmd, [url], { stdio: 'ignore', detached: true }).unref();
562
+ }
539
563
  } catch {}
540
564
  }
541
565