@bobfrankston/npmglobalize 1.0.162 → 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 +50 -2
  2. package/package.json +9 -9
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. */
@@ -4667,8 +4707,16 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
4667
4707
  console.log(colors.dim(' --clean-nested-modules: nothing to clean'));
4668
4708
  }
4669
4709
  }
4670
- // Create tarball first
4671
- const packResult = runCommand('npm', ['pack'], { cwd, silent: true });
4710
+ // Create tarball first. Retry once on spurious Ctrl+C: a Ctrl+C
4711
+ // broadcast to the console group (e.g. from another tool sharing the
4712
+ // console) makes cmd.exe print "Terminate batch job (Y/N)?" and kill
4713
+ // npm.cmd. Our process survives, so a retry usually succeeds.
4714
+ let packResult = runCommand('npm', ['pack'], { cwd, silent: true });
4715
+ if (!packResult.success && /Terminate batch job|\^C/.test(packResult.output + packResult.stderr)) {
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})`));
4718
+ packResult = runCommand('npm', ['pack'], { cwd, silent: true });
4719
+ }
4672
4720
  // Restore stashed node_modules now that pack is done — must happen
4673
4721
  // before any subsequent install -g symlinks to these dep targets.
4674
4722
  if (stashedDepModules.length > 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.162",
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",
@@ -31,11 +31,11 @@
31
31
  "url": "https://github.com/BobFrankston/npmglobalize.git"
32
32
  },
33
33
  "dependencies": {
34
- "@bobfrankston/freezepak": "^0.1.7",
35
- "@bobfrankston/importgen": "^0.1.34",
34
+ "@bobfrankston/freezepak": "^0.1.8",
35
+ "@bobfrankston/importgen": "^0.1.35",
36
36
  "@bobfrankston/npmglobalize": "^1.0.153",
37
- "@bobfrankston/themecolors": "^0.1.5",
38
- "@bobfrankston/userconfig": "^1.0.7",
37
+ "@bobfrankston/themecolors": "^0.1.6",
38
+ "@bobfrankston/userconfig": "^1.0.8",
39
39
  "@npmcli/package-json": "^7.0.4",
40
40
  "json5": "^2.2.3",
41
41
  "libnpmversion": "^8.0.3",
@@ -61,11 +61,11 @@
61
61
  },
62
62
  ".transformedSnapshot": {
63
63
  "dependencies": {
64
- "@bobfrankston/freezepak": "^0.1.7",
65
- "@bobfrankston/importgen": "^0.1.34",
64
+ "@bobfrankston/freezepak": "^0.1.8",
65
+ "@bobfrankston/importgen": "^0.1.35",
66
66
  "@bobfrankston/npmglobalize": "^1.0.153",
67
- "@bobfrankston/themecolors": "^0.1.5",
68
- "@bobfrankston/userconfig": "^1.0.7",
67
+ "@bobfrankston/themecolors": "^0.1.6",
68
+ "@bobfrankston/userconfig": "^1.0.8",
69
69
  "@npmcli/package-json": "^7.0.4",
70
70
  "json5": "^2.2.3",
71
71
  "libnpmversion": "^8.0.3",