@bobfrankston/npmglobalize 1.0.96 → 1.0.98

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.
@@ -31,7 +31,14 @@
31
31
  "Bash(npmglobalize:*)",
32
32
  "Bash(npm whoami:*)",
33
33
  "Bash(where npmglobalize:*)",
34
- "Bash(npm audit:*)"
34
+ "Bash(npm audit:*)",
35
+ "Bash(wsl npm:*)",
36
+ "Bash(find:*)",
37
+ "Bash(npx globalize:*)",
38
+ "Bash(globalize:*)",
39
+ "Bash(wztest:*)",
40
+ "Bash(xargs grep:*)",
41
+ "Bash(cmd.exe:*)"
35
42
  ]
36
43
  }
37
44
  }
package/index.d.ts CHANGED
@@ -3,5 +3,6 @@
3
3
  * npmglobalize - Main entry point
4
4
  */
5
5
  import './cli.js';
6
- export { globalize, globalizeWorkspace, GlobalizeOptions, WorkspaceResult } from './lib.js';
6
+ export { globalize, globalizeWorkspace } from './lib.js';
7
+ export type { GlobalizeOptions, WorkspaceResult } from './lib.js';
7
8
  //# sourceMappingURL=index.d.ts.map
package/lib.js CHANGED
@@ -71,6 +71,51 @@ function removeNulFiles(dir, visited = new Set()) {
71
71
  }
72
72
  return count;
73
73
  }
74
+ /** Repair a corrupted git index by rebuilding it.
75
+ * Handles "invalid object" / "Error building trees" errors caused by
76
+ * stale entries in .git/index referencing missing objects. */
77
+ function repairGitIndex(cwd) {
78
+ const indexPath = path.join(cwd, '.git', 'index');
79
+ try {
80
+ console.log(colors.yellow('Detected corrupted git index — rebuilding...'));
81
+ // Delete the corrupted index
82
+ if (fs.existsSync(indexPath)) {
83
+ fs.unlinkSync(indexPath);
84
+ }
85
+ // Rebuild from HEAD (reset index to match last commit)
86
+ const resetResult = spawnSafe('git', ['reset'], {
87
+ encoding: 'utf-8',
88
+ stdio: 'pipe',
89
+ cwd,
90
+ env: process.env
91
+ });
92
+ if (resetResult.status !== 0) {
93
+ // If no commits yet, just proceed — git add -A will build a fresh index
94
+ const stderr = resetResult.stderr || '';
95
+ if (!stderr.includes('does not have any commits')) {
96
+ console.error(colors.red('Failed to reset git index:'), stderr.trim());
97
+ return false;
98
+ }
99
+ }
100
+ // Re-stage all files
101
+ const addResult = spawnSafe('git', ['add', '-A'], {
102
+ encoding: 'utf-8',
103
+ stdio: 'pipe',
104
+ cwd,
105
+ env: process.env
106
+ });
107
+ if (addResult.status !== 0) {
108
+ console.error(colors.red('Failed to re-add files after index rebuild:'), (addResult.stderr || '').trim());
109
+ return false;
110
+ }
111
+ console.log(colors.green('✓ Git index rebuilt successfully'));
112
+ return true;
113
+ }
114
+ catch (err) {
115
+ console.error(colors.red('Failed to repair git index:'), err.message);
116
+ return false;
117
+ }
118
+ }
74
119
  /** Get npm command for current platform (npm.cmd on Windows, npm elsewhere) */
75
120
  function getNpmCommand() {
76
121
  return process.platform === 'win32' ? 'npm.cmd' : 'npm';
@@ -958,6 +1003,27 @@ export function runCommandOrThrow(cmd, args, options = {}) {
958
1003
  }
959
1004
  throw new Error('Failed to add safe.directory to git config.');
960
1005
  }
1006
+ // Detect corrupted git index and auto-repair
1007
+ if (cmd === 'git' && (stderr.includes('invalid object') || stderr.includes('Error building trees'))) {
1008
+ if (options.cwd && repairGitIndex(options.cwd)) {
1009
+ // Retry the original command
1010
+ const retry = spawnSafe(cmd, args, {
1011
+ encoding: 'utf-8',
1012
+ stdio: 'pipe',
1013
+ cwd: options.cwd,
1014
+ env: process.env,
1015
+ shell: needsShell
1016
+ });
1017
+ if (retry.status === 0) {
1018
+ return (retry.stdout || '') + (retry.stderr || '');
1019
+ }
1020
+ const retryStderr = retry.stderr || '';
1021
+ if (retryStderr.trim()) {
1022
+ console.error(colors.red(retryStderr.trim()));
1023
+ }
1024
+ throw new Error(`Command failed after git index repair: ${cmd} ${args.join(' ')}`);
1025
+ }
1026
+ }
961
1027
  // Show the error output
962
1028
  if (stderr.trim()) {
963
1029
  console.error(colors.red(stderr.trim()));
@@ -2350,7 +2416,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
2350
2416
  updateMajor,
2351
2417
  fix,
2352
2418
  conform, // Propagate conform to dependencies
2353
- publishDeps // Propagate so transitive deps also get published
2419
+ publishDeps, // Propagate so transitive deps also get published
2420
+ forcePublish // Propagate so transitive deps get force-published too
2354
2421
  });
2355
2422
  if (!depSuccess) {
2356
2423
  console.error(colors.red(`Failed to publish ${name}`));
@@ -2519,13 +2586,25 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
2519
2586
  }
2520
2587
  console.log(colors.yellow('Continuing with --force...'));
2521
2588
  }
2522
- const commitResult = runCommand('git', ['commit', '-m', commitMsg], { cwd });
2589
+ let commitResult = runCommand('git', ['commit', '-m', commitMsg], { cwd });
2523
2590
  if (!commitResult.success) {
2524
- console.error(colors.red('ERROR: Failed to commit changes:'), commitResult.stderr);
2525
- if (!force) {
2526
- return false;
2591
+ // Check for corrupted git index ("invalid object" / "Error building trees")
2592
+ // Run silently to capture stderr for detection
2593
+ const probe = runCommand('git', ['commit', '-m', commitMsg], { cwd, silent: true });
2594
+ const errText = probe.stderr + probe.output;
2595
+ if (errText.includes('invalid object') || errText.includes('Error building trees')) {
2596
+ if (repairGitIndex(cwd)) {
2597
+ // Retry commit after repair
2598
+ commitResult = runCommand('git', ['commit', '-m', commitMsg], { cwd });
2599
+ }
2600
+ }
2601
+ if (!commitResult.success) {
2602
+ console.error(colors.red('ERROR: Failed to commit changes:'), commitResult.stderr);
2603
+ if (!force) {
2604
+ return false;
2605
+ }
2606
+ console.log(colors.yellow('Continuing with --force...'));
2527
2607
  }
2528
- console.log(colors.yellow('Continuing with --force...'));
2529
2608
  }
2530
2609
  }
2531
2610
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.96",
3
+ "version": "1.0.98",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",