@bobfrankston/npmglobalize 1.0.163 → 1.0.164

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.
Files changed (2) hide show
  1. package/lib.js +42 -1
  2. package/package.json +1 -1
package/lib.js CHANGED
@@ -10,6 +10,7 @@
10
10
  * Consider library-based approach if async operations or cross-platform issues arise.
11
11
  */
12
12
  import fs from 'fs';
13
+ import os from 'os';
13
14
  import path from 'path';
14
15
  import { execSync, spawnSync } from 'child_process';
15
16
  import { readConfig as readUserConfig, writeConfig as writeUserConfig, configDir } from '@bobfrankston/userconfig';
@@ -1642,6 +1643,45 @@ export function runCommand(cmd, args, options = {}) {
1642
1643
  return { success: false, output: '', stderr: error.message };
1643
1644
  }
1644
1645
  }
1646
+ /** Dump forensic info to a temp file when `npm pack` is killed by a spurious
1647
+ * Ctrl+C. Goal: correlate the failure with whatever else was attached to the
1648
+ * console (Claude Code wrapper, VS Code task, AV, etc.). Returns the log path. */
1649
+ function dumpPackCtrlcDiagnostics(pkg, cwd, packOutput, packStderr) {
1650
+ const ts = new Date().toISOString().replace(/[:.]/g, '-');
1651
+ const logPath = path.join(os.tmpdir(), `npmglobalize-pack-ctrlc-${ts}.log`);
1652
+ const lines = [];
1653
+ lines.push(`# npm pack Ctrl+C diagnostic — ${new Date().toISOString()}`);
1654
+ lines.push(`package: ${pkg?.name}@${pkg?.version}`);
1655
+ lines.push(`cwd: ${cwd}`);
1656
+ lines.push(`our pid: ${process.pid} ppid: ${process.ppid}`);
1657
+ lines.push(`platform: ${process.platform} node: ${process.version}`);
1658
+ for (const k of ['TERM_PROGRAM', 'WT_SESSION', 'CLAUDE_SESSION_ID', 'CLAUDECODE', 'VSCODE_PID', 'VSCODE_INJECTION', 'ComSpec']) {
1659
+ if (process.env[k])
1660
+ lines.push(`env ${k}: ${process.env[k]}`);
1661
+ }
1662
+ lines.push('');
1663
+ lines.push('## pack stdout (first 2KB)');
1664
+ lines.push(packOutput.slice(0, 2048));
1665
+ lines.push('');
1666
+ lines.push('## pack stderr (first 2KB)');
1667
+ lines.push(packStderr.slice(0, 2048));
1668
+ lines.push('');
1669
+ if (process.platform === 'win32') {
1670
+ try {
1671
+ const ps = spawnSafe('wmic', ['process', 'get', 'Name,ProcessId,ParentProcessId,SessionId,CommandLine', '/format:csv'], { encoding: 'utf-8', timeout: 5000 });
1672
+ lines.push('## process snapshot (wmic)');
1673
+ lines.push((ps.stdout || ps.stderr || '(no output)').slice(0, 64 * 1024));
1674
+ }
1675
+ catch (e) {
1676
+ lines.push(`## wmic failed: ${e?.message}`);
1677
+ }
1678
+ }
1679
+ try {
1680
+ fs.writeFileSync(logPath, lines.join('\n'));
1681
+ }
1682
+ catch { /* ignore */ }
1683
+ return logPath;
1684
+ }
1645
1685
  /** Install a package globally in WSL, auto-fixing the root-owned /usr/local/lib/node_modules
1646
1686
  * EACCES case by switching npm to a user prefix (~/.npm-global) and retrying once.
1647
1687
  * Output is captured (so we can scan for the error) and then mirrored to the terminal. */
@@ -4673,7 +4713,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
4673
4713
  // npm.cmd. Our process survives, so a retry usually succeeds.
4674
4714
  let packResult = runCommand('npm', ['pack'], { cwd, silent: true });
4675
4715
  if (!packResult.success && /Terminate batch job|\^C/.test(packResult.output + packResult.stderr)) {
4676
- console.error(colors.yellow(' npm pack interrupted by spurious Ctrl+C — retrying once...'));
4716
+ const logPath = dumpPackCtrlcDiagnostics(pkg, cwd, packResult.output, packResult.stderr);
4717
+ console.error(colors.yellow(` npm pack interrupted by spurious Ctrl+C — retrying once... (diag: ${logPath})`));
4677
4718
  packResult = runCommand('npm', ['pack'], { cwd, silent: true });
4678
4719
  }
4679
4720
  // Restore stashed node_modules now that pack is done — must happen
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.163",
3
+ "version": "1.0.164",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",