@bobfrankston/npmglobalize 1.0.25 → 1.0.26
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/README.md +29 -0
- package/cli.js +5 -0
- package/lib.d.ts +5 -0
- package/lib.js +79 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ cd your-package
|
|
|
19
19
|
npmglobalize # Transform + publish (patch version)
|
|
20
20
|
npmglobalize --minor # Bump minor version
|
|
21
21
|
npmglobalize --major # Bump major version
|
|
22
|
+
|
|
23
|
+
# Or run from anywhere with a path
|
|
24
|
+
npmglobalize y:\path\to\your-package
|
|
22
25
|
```
|
|
23
26
|
|
|
24
27
|
## Key Features
|
|
@@ -110,6 +113,24 @@ npmglobalize -np # --nopublish (formerly --apply)
|
|
|
110
113
|
npmglobalize --cleanup # Restore original file: references
|
|
111
114
|
```
|
|
112
115
|
|
|
116
|
+
### 🔧 Git Integration & Error Recovery
|
|
117
|
+
|
|
118
|
+
**Automatic tag conflict resolution**:
|
|
119
|
+
```bash
|
|
120
|
+
npmglobalize --fix-tags # Auto-fix version/tag mismatches
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
When a previous publish fails, git tags may conflict with package.json version. The `--fix-tags` option (or automatic detection) will clean up these conflicts.
|
|
124
|
+
|
|
125
|
+
**Automatic rebase** when local is behind remote:
|
|
126
|
+
```bash
|
|
127
|
+
npmglobalize --rebase # Auto-rebase if behind remote
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
For single-developer projects, this safely pulls remote changes before publishing.
|
|
131
|
+
|
|
132
|
+
**Note:** This tool is designed for single-developer, single-branch workflows where automatic rebase and tag cleanup are safe operations.
|
|
133
|
+
|
|
113
134
|
## Command Reference
|
|
114
135
|
|
|
115
136
|
### Release Options
|
|
@@ -160,6 +181,8 @@ npmglobalize --cleanup # Restore original file: references
|
|
|
160
181
|
--verbose Show detailed output
|
|
161
182
|
--conform Update .gitignore/.npmignore to best practices
|
|
162
183
|
--asis Skip ignore file checks
|
|
184
|
+
--fix-tags Automatically fix version/tag mismatches
|
|
185
|
+
--rebase Automatically rebase if local is behind remote
|
|
163
186
|
--help, -h Show help
|
|
164
187
|
--version, -v Show version
|
|
165
188
|
```
|
|
@@ -244,6 +267,12 @@ When publishing file: dependencies, checks if each version exists on npm:
|
|
|
244
267
|
# Basic release
|
|
245
268
|
npmglobalize
|
|
246
269
|
|
|
270
|
+
# Run on a different project
|
|
271
|
+
npmglobalize y:\dev\myproject
|
|
272
|
+
|
|
273
|
+
# Auto-fix tag conflicts and rebase
|
|
274
|
+
npmglobalize --fix-tags --rebase
|
|
275
|
+
|
|
247
276
|
# Release with updates and security fixes
|
|
248
277
|
npmglobalize --update-deps --fix
|
|
249
278
|
|
package/cli.js
CHANGED
|
@@ -52,6 +52,7 @@ Other Options:
|
|
|
52
52
|
--conform Update .gitignore/.npmignore to best practices
|
|
53
53
|
--asis Skip ignore file checks (or set "asis": true in .globalize.json5)
|
|
54
54
|
--fix-tags Automatically fix version/tag mismatches
|
|
55
|
+
--rebase Automatically rebase if local is behind remote
|
|
55
56
|
--help, -h Show this help
|
|
56
57
|
--version, -v Show version number
|
|
57
58
|
|
|
@@ -60,6 +61,7 @@ Examples:
|
|
|
60
61
|
npmglobalize y:\\path\\to\\project Run on a different project directory
|
|
61
62
|
npmglobalize --minor Release with minor version bump
|
|
62
63
|
npmglobalize --fix-tags Fix version/tag mismatches before running
|
|
64
|
+
npmglobalize --rebase Auto-rebase if behind remote
|
|
63
65
|
npmglobalize --update-deps Safe updates (minor/patch only)
|
|
64
66
|
npmglobalize --update-major Allow breaking changes (major updates)
|
|
65
67
|
npmglobalize -npd Skip auto-publishing file: deps (use with caution)
|
|
@@ -181,6 +183,9 @@ function parseArgs(args) {
|
|
|
181
183
|
case '--fix-tags':
|
|
182
184
|
options.fixTags = true;
|
|
183
185
|
break;
|
|
186
|
+
case '--rebase':
|
|
187
|
+
options.rebase = true;
|
|
188
|
+
break;
|
|
184
189
|
case '--update-deps':
|
|
185
190
|
options.updateDeps = true;
|
|
186
191
|
break;
|
package/lib.d.ts
CHANGED
|
@@ -47,6 +47,8 @@ export interface GlobalizeOptions {
|
|
|
47
47
|
fix?: boolean;
|
|
48
48
|
/** Automatically fix version/tag mismatches */
|
|
49
49
|
fixTags?: boolean;
|
|
50
|
+
/** Automatically rebase if local is behind remote */
|
|
51
|
+
rebase?: boolean;
|
|
50
52
|
}
|
|
51
53
|
/** Read and parse package.json from a directory */
|
|
52
54
|
export declare function readPackageJson(dir: string): any;
|
|
@@ -132,6 +134,7 @@ export interface GitStatus {
|
|
|
132
134
|
isDetachedHead: boolean;
|
|
133
135
|
currentBranch: string;
|
|
134
136
|
remoteBranch: string;
|
|
137
|
+
isBehindRemote: boolean;
|
|
135
138
|
}
|
|
136
139
|
export declare function getGitStatus(cwd: string): GitStatus;
|
|
137
140
|
/** Validate package.json for release */
|
|
@@ -147,6 +150,8 @@ export declare function runNpmAudit(cwd: string, fix?: boolean, verbose?: boolea
|
|
|
147
150
|
report: string;
|
|
148
151
|
hasVulnerabilities: boolean;
|
|
149
152
|
};
|
|
153
|
+
/** Get the version of npmglobalize itself */
|
|
154
|
+
export declare function getToolVersion(): string;
|
|
150
155
|
export declare function globalize(cwd: string, options?: GlobalizeOptions): Promise<boolean>;
|
|
151
156
|
declare const _default: {
|
|
152
157
|
globalize: typeof globalize;
|
package/lib.js
CHANGED
|
@@ -7,6 +7,7 @@ import { execSync, spawnSync } from 'child_process';
|
|
|
7
7
|
import readline from 'readline';
|
|
8
8
|
import libversion from 'libnpmversion';
|
|
9
9
|
import JSON5 from 'json5';
|
|
10
|
+
import { fileURLToPath } from 'url';
|
|
10
11
|
/** ANSI color codes */
|
|
11
12
|
const colors = {
|
|
12
13
|
red: (text) => `\x1b[31m${text}\x1b[0m`,
|
|
@@ -529,7 +530,8 @@ export function getGitStatus(cwd) {
|
|
|
529
530
|
hasMergeConflict: false,
|
|
530
531
|
isDetachedHead: false,
|
|
531
532
|
currentBranch: '',
|
|
532
|
-
remoteBranch: ''
|
|
533
|
+
remoteBranch: '',
|
|
534
|
+
isBehindRemote: false
|
|
533
535
|
};
|
|
534
536
|
// Check if git repo
|
|
535
537
|
const gitDir = path.join(cwd, '.git');
|
|
@@ -578,6 +580,18 @@ export function getGitStatus(cwd) {
|
|
|
578
580
|
catch (error) {
|
|
579
581
|
// Ignore - might not have tracking branch
|
|
580
582
|
}
|
|
583
|
+
// Check if local is behind remote
|
|
584
|
+
try {
|
|
585
|
+
const behind = execSync(`git log HEAD..origin/${status.currentBranch} --oneline 2>nul`, {
|
|
586
|
+
cwd,
|
|
587
|
+
encoding: 'utf-8',
|
|
588
|
+
stdio: ['pipe', 'pipe', 'ignore']
|
|
589
|
+
}).trim();
|
|
590
|
+
status.isBehindRemote = behind.length > 0;
|
|
591
|
+
}
|
|
592
|
+
catch (error) {
|
|
593
|
+
// Ignore - might not have tracking branch
|
|
594
|
+
}
|
|
581
595
|
}
|
|
582
596
|
return status;
|
|
583
597
|
}
|
|
@@ -1038,9 +1052,25 @@ export function runNpmAudit(cwd, fix = false, verbose = false) {
|
|
|
1038
1052
|
hasVulnerabilities
|
|
1039
1053
|
};
|
|
1040
1054
|
}
|
|
1055
|
+
/** Get the version of npmglobalize itself */
|
|
1056
|
+
export function getToolVersion() {
|
|
1057
|
+
try {
|
|
1058
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
1059
|
+
const pkgPath = path.join(__dirname, 'package.json');
|
|
1060
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
1061
|
+
return pkg.version || 'unknown';
|
|
1062
|
+
}
|
|
1063
|
+
catch (error) {
|
|
1064
|
+
return 'unknown';
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1041
1067
|
export async function globalize(cwd, options = {}) {
|
|
1042
1068
|
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
|
|
1043
|
-
forcePublish = false, fix = false, fixTags = false } = options;
|
|
1069
|
+
forcePublish = false, fix = false, fixTags = false, rebase = false } = options;
|
|
1070
|
+
// Show tool version
|
|
1071
|
+
const toolVersion = getToolVersion();
|
|
1072
|
+
console.log(colors.italic(`npmglobalize v${toolVersion}`));
|
|
1073
|
+
console.log('');
|
|
1044
1074
|
// Check ignore files first (unless cleanup mode)
|
|
1045
1075
|
if (!cleanup && !asis) {
|
|
1046
1076
|
const checkResult = checkIgnoreFiles(cwd, { conform, asis, verbose });
|
|
@@ -1163,6 +1193,38 @@ export async function globalize(cwd, options = {}) {
|
|
|
1163
1193
|
if (currentGitStatus.isDetachedHead && force) {
|
|
1164
1194
|
console.log(colors.yellow('Warning: Detached HEAD state - continuing with --force'));
|
|
1165
1195
|
}
|
|
1196
|
+
// Check if local branch is behind remote
|
|
1197
|
+
if (currentGitStatus.isBehindRemote && !dryRun) {
|
|
1198
|
+
console.log(colors.yellow('Local branch is behind remote.'));
|
|
1199
|
+
if (rebase) {
|
|
1200
|
+
console.log('Rebasing local changes (--rebase)...');
|
|
1201
|
+
const rebaseResult = runCommand('git', ['pull', '--rebase'], { cwd, silent: false });
|
|
1202
|
+
if (!rebaseResult.success) {
|
|
1203
|
+
console.error(colors.red('ERROR: Rebase failed.'));
|
|
1204
|
+
console.error('You may need to resolve conflicts manually.');
|
|
1205
|
+
if (!force) {
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
console.log(colors.yellow('Continuing with --force...'));
|
|
1209
|
+
}
|
|
1210
|
+
else {
|
|
1211
|
+
console.log(colors.green('✓ Successfully rebased'));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
else {
|
|
1215
|
+
console.error(colors.red('ERROR: Local branch is behind remote.'));
|
|
1216
|
+
console.error(colors.yellow('Your local repository needs to be updated before publishing.'));
|
|
1217
|
+
console.error('');
|
|
1218
|
+
console.error('To fix this:');
|
|
1219
|
+
console.error(colors.yellow(' 1. Run: npmglobalize --rebase (automatic)'));
|
|
1220
|
+
console.error(colors.yellow(' 2. Or manually: git pull --rebase'));
|
|
1221
|
+
console.error('');
|
|
1222
|
+
if (!force) {
|
|
1223
|
+
return false;
|
|
1224
|
+
}
|
|
1225
|
+
console.log(colors.yellow('Continuing with --force (git push may fail)...'));
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1166
1228
|
// Read package.json
|
|
1167
1229
|
const pkg = readPackageJson(cwd);
|
|
1168
1230
|
// Pre-flight check: fix version/tag mismatches if requested or if we detect issues
|
|
@@ -1451,7 +1513,21 @@ export async function globalize(cwd, options = {}) {
|
|
|
1451
1513
|
}
|
|
1452
1514
|
// Check for specific error conditions
|
|
1453
1515
|
const stderrLower = (error.stderr || '').toLowerCase();
|
|
1454
|
-
|
|
1516
|
+
const stdoutLower = (error.stdout || '').toLowerCase();
|
|
1517
|
+
const combinedOutput = stderrLower + ' ' + stdoutLower;
|
|
1518
|
+
if (combinedOutput.includes('non-fast-forward') || combinedOutput.includes('rejected') && combinedOutput.includes('behind')) {
|
|
1519
|
+
console.error(colors.yellow('\nYour local branch is behind the remote.'));
|
|
1520
|
+
console.error(colors.yellow('This usually means changes were pushed from another location.'));
|
|
1521
|
+
console.error(colors.yellow('\nTo fix this:'));
|
|
1522
|
+
console.error(' 1. Pull remote changes: git pull --rebase');
|
|
1523
|
+
console.error(' 2. Then run npmglobalize again');
|
|
1524
|
+
console.error(colors.yellow('\nOr to force push (use with caution):'));
|
|
1525
|
+
console.error(' git push --force-with-lease');
|
|
1526
|
+
if (!force) {
|
|
1527
|
+
return false;
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
else if (stderrLower.includes('tag') && stderrLower.includes('already exists')) {
|
|
1455
1531
|
// Extract tag name if possible
|
|
1456
1532
|
const tagMatch = error.stderr?.match(/tag '([^']+)' already exists/);
|
|
1457
1533
|
const tagName = tagMatch ? tagMatch[1] : null;
|