@bobfrankston/npmglobalize 1.0.30 → 1.0.32

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 (4) hide show
  1. package/cli.js +3 -0
  2. package/lib.d.ts +2 -0
  3. package/lib.js +62 -7
  4. package/package.json +1 -1
package/cli.js CHANGED
@@ -186,6 +186,9 @@ function parseArgs(args) {
186
186
  case '--rebase':
187
187
  options.rebase = true;
188
188
  break;
189
+ case '--show':
190
+ options.show = true;
191
+ break;
189
192
  case '--update-deps':
190
193
  options.updateDeps = true;
191
194
  break;
package/lib.d.ts CHANGED
@@ -49,6 +49,8 @@ export interface GlobalizeOptions {
49
49
  fixTags?: boolean;
50
50
  /** Automatically rebase if local is behind remote */
51
51
  rebase?: boolean;
52
+ /** Show package.json dependency changes */
53
+ show?: boolean;
52
54
  }
53
55
  /** Read and parse package.json from a directory */
54
56
  export declare function readPackageJson(dir: string): any;
package/lib.js CHANGED
@@ -1085,7 +1085,7 @@ export function getToolVersion() {
1085
1085
  }
1086
1086
  export async function globalize(cwd, options = {}) {
1087
1087
  const { bump = 'patch', noPublish = false, cleanup = false, install = false, wsl = false, force = false, files = true, dryRun = false, quiet = true, verbose = false, init = false, gitVisibility = 'private', npmVisibility = 'public', message, conform = false, asis = false, updateDeps = false, updateMajor = false, publishDeps = true, // Default to publishing deps for safety
1088
- forcePublish = false, fix = false, fixTags = false, rebase = false } = options;
1088
+ forcePublish = false, fix = false, fixTags = false, rebase = false, show = false } = options;
1089
1089
  // Show tool version
1090
1090
  const toolVersion = getToolVersion();
1091
1091
  console.log(colors.italic(`npmglobalize v${toolVersion}`));
@@ -1344,6 +1344,27 @@ export async function globalize(cwd, options = {}) {
1344
1344
  const transformResult = transformDeps(pkg, cwd, verbose, forcePublish);
1345
1345
  if (transformResult.transformed) {
1346
1346
  console.log(' Dependencies transformed.');
1347
+ // Show dependency changes if requested
1348
+ if (show || verbose) {
1349
+ console.log('');
1350
+ console.log(colors.italic('Dependency changes:'));
1351
+ for (const key of DEP_KEYS) {
1352
+ const backupKey = '.' + key;
1353
+ if (pkg[backupKey]) {
1354
+ console.log('');
1355
+ console.log(colors.yellow(`${key}:`));
1356
+ const original = pkg[backupKey];
1357
+ const transformed = pkg[key];
1358
+ for (const [name, origValue] of Object.entries(original)) {
1359
+ const newValue = transformed?.[name];
1360
+ console.log(` ${name}:`);
1361
+ console.log(` ${colors.red('- ' + origValue)}`);
1362
+ console.log(` ${colors.green('+ ' + newValue)}`);
1363
+ }
1364
+ }
1365
+ }
1366
+ console.log('');
1367
+ }
1347
1368
  // Check if target packages need to be published
1348
1369
  if (transformResult.unpublished.length > 0) {
1349
1370
  console.log('');
@@ -1520,14 +1541,45 @@ export async function globalize(cwd, options = {}) {
1520
1541
  // Version bump
1521
1542
  console.log(`Bumping version (${bump})...`);
1522
1543
  if (!dryRun) {
1544
+ // Temporarily disable postversion hook to prevent double-publishing
1545
+ const pkg = readPackageJson(cwd);
1546
+ const originalPostversion = pkg.scripts?.postversion;
1547
+ let postversDisabled = false;
1548
+ if (originalPostversion && originalPostversion.includes('npm publish')) {
1549
+ if (verbose) {
1550
+ console.log('Temporarily disabling postversion hook to prevent double-publish...');
1551
+ }
1552
+ delete pkg.scripts.postversion;
1553
+ writePackageJson(cwd, pkg);
1554
+ postversDisabled = true;
1555
+ // Commit this change so working directory is clean for version bump
1556
+ const addResult = runCommand('git', ['add', 'package.json'], { cwd, silent: true });
1557
+ if (addResult.success) {
1558
+ runCommand('git', ['commit', '-m', 'Temporarily disable postversion hook'], { cwd, silent: true });
1559
+ }
1560
+ }
1523
1561
  try {
1524
- // Use libnpmversion - disable git operations to avoid conflicts with postversion hooks
1525
- // We handle git push ourselves after successful npm publish
1562
+ // Use libnpmversion - it will create commit and tag automatically
1526
1563
  const newVersion = await libversion(bump, {
1527
1564
  path: cwd,
1528
- 'git-tag-version': true, // Create git commit and tag
1529
- 'commit-hooks': false // Skip git hooks to prevent postversion from running
1565
+ 'git-tag-version': true
1530
1566
  });
1567
+ // Restore postversion hook
1568
+ if (postversDisabled && originalPostversion) {
1569
+ const updatedPkg = readPackageJson(cwd);
1570
+ if (!updatedPkg.scripts)
1571
+ updatedPkg.scripts = {};
1572
+ updatedPkg.scripts.postversion = originalPostversion;
1573
+ writePackageJson(cwd, updatedPkg);
1574
+ // Commit the restoration
1575
+ const addResult = runCommand('git', ['add', 'package.json'], { cwd, silent: true });
1576
+ if (addResult.success) {
1577
+ runCommand('git', ['commit', '--amend', '--no-edit'], { cwd, silent: true });
1578
+ }
1579
+ if (verbose) {
1580
+ console.log('Restored postversion hook');
1581
+ }
1582
+ }
1531
1583
  console.log(colors.green(`Version bumped to ${newVersion}`));
1532
1584
  }
1533
1585
  catch (error) {
@@ -1729,11 +1781,11 @@ export async function globalize(cwd, options = {}) {
1729
1781
  console.error(colors.green('Solution: Wait a few more minutes and try again'));
1730
1782
  console.error('');
1731
1783
  }
1732
- else if (output.includes('403') || output.includes('forbidden')) {
1784
+ else if (output.includes('403') || output.includes('forbidden') || output.includes('cannot publish over')) {
1733
1785
  // Check if it's the "version already published" case
1734
1786
  if (output.includes('cannot publish over') || output.includes('previously published')) {
1735
1787
  // Extract the version number from the error if possible
1736
- const versionMatch = output.match(/versions?:\s*(\d+\.\d+\.\d+)/);
1788
+ const versionMatch = output.match(/versions?[:\s]+(\d+\.\d+\.\d+)/);
1737
1789
  const failedVersion = versionMatch ? versionMatch[1] : null;
1738
1790
  // Check if this is the version we just bumped to
1739
1791
  const currentPkgVersion = readPackageJson(cwd).version;
@@ -1748,6 +1800,9 @@ export async function globalize(cwd, options = {}) {
1748
1800
  console.error('');
1749
1801
  console.error('Verify with: ' + colors.yellow(`npm view ${pkg.name}@${currentPkgVersion}`));
1750
1802
  console.error('');
1803
+ console.error(colors.yellow('Note: You may have a postversion script that auto-publishes.'));
1804
+ console.error(colors.yellow('npmglobalize will now skip that hook to prevent this issue.'));
1805
+ console.error('');
1751
1806
  // Treat as success and continue
1752
1807
  console.log(colors.green('✓ Treating as successful publish'));
1753
1808
  // Don't return false - let it continue to push git tags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",