@bobfrankston/npmglobalize 1.0.24 → 1.0.25
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/lib.d.ts +6 -0
- package/lib.js +86 -18
- package/package.json +1 -1
package/lib.d.ts
CHANGED
|
@@ -99,6 +99,12 @@ export declare function getLatestGitTag(cwd: string): string | null;
|
|
|
99
99
|
export declare function gitTagExists(cwd: string, tag: string): boolean;
|
|
100
100
|
/** Delete a git tag */
|
|
101
101
|
export declare function deleteGitTag(cwd: string, tag: string): boolean;
|
|
102
|
+
/** Get all git tags */
|
|
103
|
+
export declare function getAllGitTags(cwd: string): string[];
|
|
104
|
+
/** Parse version from tag (e.g., 'v1.2.3' -> [1, 2, 3]) */
|
|
105
|
+
export declare function parseVersionTag(tag: string): number[] | null;
|
|
106
|
+
/** Compare two version arrays (returns -1 if a < b, 0 if equal, 1 if a > b) */
|
|
107
|
+
export declare function compareVersions(a: number[], b: number[]): number;
|
|
102
108
|
/** Fix version/tag mismatches */
|
|
103
109
|
export declare function fixVersionTagMismatch(cwd: string, pkg: any, verbose?: boolean): boolean;
|
|
104
110
|
/** Run a command and return success status */
|
package/lib.js
CHANGED
|
@@ -388,38 +388,81 @@ export function deleteGitTag(cwd, tag) {
|
|
|
388
388
|
return false;
|
|
389
389
|
}
|
|
390
390
|
}
|
|
391
|
+
/** Get all git tags */
|
|
392
|
+
export function getAllGitTags(cwd) {
|
|
393
|
+
try {
|
|
394
|
+
const result = spawnSync('git', ['tag', '-l'], {
|
|
395
|
+
encoding: 'utf-8',
|
|
396
|
+
stdio: 'pipe',
|
|
397
|
+
cwd
|
|
398
|
+
});
|
|
399
|
+
if (result.status === 0 && result.stdout) {
|
|
400
|
+
return result.stdout.trim().split('\n').filter(t => t.trim());
|
|
401
|
+
}
|
|
402
|
+
return [];
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
return [];
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
/** Parse version from tag (e.g., 'v1.2.3' -> [1, 2, 3]) */
|
|
409
|
+
export function parseVersionTag(tag) {
|
|
410
|
+
const match = tag.match(/^v?(\d+)\.(\d+)\.(\d+)/);
|
|
411
|
+
if (!match)
|
|
412
|
+
return null;
|
|
413
|
+
return [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])];
|
|
414
|
+
}
|
|
415
|
+
/** Compare two version arrays (returns -1 if a < b, 0 if equal, 1 if a > b) */
|
|
416
|
+
export function compareVersions(a, b) {
|
|
417
|
+
for (let i = 0; i < 3; i++) {
|
|
418
|
+
if (a[i] < b[i])
|
|
419
|
+
return -1;
|
|
420
|
+
if (a[i] > b[i])
|
|
421
|
+
return 1;
|
|
422
|
+
}
|
|
423
|
+
return 0;
|
|
424
|
+
}
|
|
391
425
|
/** Fix version/tag mismatches */
|
|
392
426
|
export function fixVersionTagMismatch(cwd, pkg, verbose = false) {
|
|
393
427
|
const pkgVersion = pkg.version;
|
|
394
428
|
if (!pkgVersion) {
|
|
395
429
|
return false; // No version in package.json
|
|
396
430
|
}
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
431
|
+
const currentVersion = parseVersionTag(pkgVersion);
|
|
432
|
+
if (!currentVersion) {
|
|
433
|
+
console.error(colors.yellow(`Warning: Could not parse package.json version: ${pkgVersion}`));
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
const allTags = getAllGitTags(cwd);
|
|
437
|
+
const tagsToDelete = [];
|
|
438
|
+
// Find all tags that are >= current package.json version
|
|
439
|
+
for (const tag of allTags) {
|
|
440
|
+
const tagVersion = parseVersionTag(tag);
|
|
441
|
+
if (tagVersion && compareVersions(tagVersion, currentVersion) >= 0) {
|
|
442
|
+
tagsToDelete.push(tag);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
if (tagsToDelete.length === 0) {
|
|
402
446
|
if (verbose) {
|
|
403
|
-
console.log(`
|
|
447
|
+
console.log(`No conflicting tags found (package.json is at v${pkgVersion})`);
|
|
404
448
|
}
|
|
405
449
|
return false;
|
|
406
450
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
if (deleteGitTag(cwd,
|
|
414
|
-
console.log(colors.green(
|
|
415
|
-
|
|
451
|
+
console.log(colors.yellow(`\nVersion/tag mismatch detected:`));
|
|
452
|
+
console.log(` package.json version: ${pkgVersion}`);
|
|
453
|
+
console.log(` Conflicting tags found: ${tagsToDelete.join(', ')}`);
|
|
454
|
+
console.log(colors.yellow('Deleting conflicting tags...'));
|
|
455
|
+
let deletedAny = false;
|
|
456
|
+
for (const tag of tagsToDelete) {
|
|
457
|
+
if (deleteGitTag(cwd, tag)) {
|
|
458
|
+
console.log(colors.green(` ✓ Deleted tag ${tag}`));
|
|
459
|
+
deletedAny = true;
|
|
416
460
|
}
|
|
417
461
|
else {
|
|
418
|
-
console.error(colors.red(
|
|
419
|
-
return false;
|
|
462
|
+
console.error(colors.red(` ✗ Failed to delete tag ${tag}`));
|
|
420
463
|
}
|
|
421
464
|
}
|
|
422
|
-
return
|
|
465
|
+
return deletedAny;
|
|
423
466
|
}
|
|
424
467
|
/** Run a command and return success status */
|
|
425
468
|
export function runCommand(cmd, args, options = {}) {
|
|
@@ -1431,6 +1474,31 @@ export async function globalize(cwd, options = {}) {
|
|
|
1431
1474
|
}
|
|
1432
1475
|
catch (retryError) {
|
|
1433
1476
|
console.error(colors.red('ERROR: Retry failed:'), retryError.message);
|
|
1477
|
+
// Show retry error details
|
|
1478
|
+
if (retryError.stderr || retryError.stdout || retryError.code) {
|
|
1479
|
+
if (retryError.stderr)
|
|
1480
|
+
console.error(' stderr:', retryError.stderr);
|
|
1481
|
+
if (retryError.stdout)
|
|
1482
|
+
console.error(' stdout:', retryError.stdout);
|
|
1483
|
+
if (retryError.code)
|
|
1484
|
+
console.error(' exit code:', retryError.code);
|
|
1485
|
+
}
|
|
1486
|
+
// Check if it's the same tag issue again
|
|
1487
|
+
const retryStderrLower = (retryError.stderr || '').toLowerCase();
|
|
1488
|
+
if (retryStderrLower.includes('tag') && retryStderrLower.includes('already exists')) {
|
|
1489
|
+
const retryTagMatch = retryError.stderr?.match(/tag '([^']+)' already exists/);
|
|
1490
|
+
const retryTagName = retryTagMatch ? retryTagMatch[1] : null;
|
|
1491
|
+
console.error(colors.red('\\nAnother tag conflict detected!'));
|
|
1492
|
+
console.error(colors.yellow('This suggests package.json version may have been bumped previously.'));
|
|
1493
|
+
console.error(colors.yellow('\\nSuggestions:'));
|
|
1494
|
+
if (retryTagName) {
|
|
1495
|
+
console.error(` 1. Delete the tag and reset package.json:`);
|
|
1496
|
+
console.error(` git tag -d ${retryTagName}`);
|
|
1497
|
+
console.error(` (Then manually adjust package.json version if needed)`);
|
|
1498
|
+
}
|
|
1499
|
+
console.error(' 2. Check git log and package.json history for version mismatches');
|
|
1500
|
+
console.error(' 3. Run: git tag -l | sort -V to see all version tags');
|
|
1501
|
+
}
|
|
1434
1502
|
if (!force) {
|
|
1435
1503
|
return false;
|
|
1436
1504
|
}
|