@bobfrankston/npmglobalize 1.0.35 → 1.0.37

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 (3) hide show
  1. package/README.md +38 -0
  2. package/lib.js +57 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -184,6 +184,44 @@ git config core.eol lf # Force LF line endings
184
184
 
185
185
  This ensures consistent line endings across Windows, macOS, and Linux, preventing "modified file" issues caused by line ending differences.
186
186
 
187
+ ### 🔍 Understanding "Detached HEAD" Error
188
+
189
+ **What is Detached HEAD?**
190
+ Your git repository is not currently on a branch (like `master` or `main`). This happens when you:
191
+ - Check out a specific commit: `git checkout abc123`
192
+ - Check out a tag: `git checkout v1.0.0`
193
+ - Have some git operations leave you in this state
194
+
195
+ **Why does it matter?**
196
+ Publishing requires being on a branch so commits and tags can be properly tracked in your repository history.
197
+
198
+ **Common scenarios:**
199
+
200
+ 1. **Just fixing files with `--conform`:**
201
+ ```bash
202
+ npmglobalize --conform # ✓ Files get fixed, then exits with helpful message
203
+ ```
204
+ The files are already updated! You don't need to run it again.
205
+
206
+ 2. **Want to publish (have commits to keep):**
207
+ ```bash
208
+ git checkout -B master # Moves master branch to current commit (merges)
209
+ npmglobalize # Now works normally
210
+ ```
211
+ The `-B` flag moves your branch pointer to include the detached commits.
212
+
213
+ 3. **Want to publish (no commits made, safe to discard):**
214
+ ```bash
215
+ git checkout master # Just switch back to branch
216
+ npmglobalize # Now works normally
217
+ ```
218
+
219
+ 4. **Force publish anyway (not recommended):**
220
+ ```bash
221
+ npmglobalize --force # Proceeds despite detached HEAD
222
+ ```
223
+ Warning: Commits may be hard to track later.
224
+
187
225
  ## Command Reference
188
226
 
189
227
  ### Release Options
package/lib.js CHANGED
@@ -1276,11 +1276,65 @@ export async function globalize(cwd, options = {}) {
1276
1276
  return false;
1277
1277
  }
1278
1278
  if (currentGitStatus.isDetachedHead && !force) {
1279
- console.error(colors.red('ERROR: Detached HEAD state. Use --force to continue anyway.'));
1280
- return false;
1279
+ if (conform && !noPublish) {
1280
+ // Conform already happened earlier, just exit gracefully
1281
+ console.log('');
1282
+ console.log(colors.green('✓ Files have been updated successfully!'));
1283
+ console.log(' • .gitignore updated');
1284
+ console.log(' • .npmignore updated');
1285
+ console.log(' • .gitattributes created/updated (LF line endings)');
1286
+ console.log(' • Git configured: core.autocrlf=false, core.eol=lf');
1287
+ console.log('');
1288
+ console.log(colors.yellow('ℹ What is "Detached HEAD"?'));
1289
+ console.log(' Your git repository is not on a branch (master, main, etc.)');
1290
+ console.log(' This happens after checking out a specific commit or tag.');
1291
+ console.log(' Publishing requires being on a branch so git can track changes.');
1292
+ console.log('');
1293
+ console.log(colors.yellow('✓ Good news: Your files are already fixed!'));
1294
+ console.log(colors.yellow(' You don\'t need to run --conform again.'));
1295
+ console.log('');
1296
+ console.log(colors.yellow('To publish, merge back to your branch:'));
1297
+ console.log(' git checkout -B master \x1b[2m# moves master to current commit\x1b[0m');
1298
+ console.log(' npmglobalize \x1b[2m# will now work normally\x1b[0m');
1299
+ console.log('');
1300
+ console.log(colors.yellow('Or if you haven\'t made commits yet:'));
1301
+ console.log(' git checkout master \x1b[2m# just switch back\x1b[0m');
1302
+ console.log('');
1303
+ return true; // Success - conform was completed
1304
+ }
1305
+ else if (noPublish) {
1306
+ // Just doing non-publish operations, detached HEAD is fine
1307
+ console.log(colors.yellow('Note: Detached HEAD state (no publishing will occur)'));
1308
+ }
1309
+ else {
1310
+ console.log('');
1311
+ console.error(colors.red('ERROR: Cannot publish from Detached HEAD state'));
1312
+ console.log('');
1313
+ console.log(colors.yellow('ℹ What is "Detached HEAD"?'));
1314
+ console.log(' Your git repository is not on a branch (master, main, etc.)');
1315
+ console.log(' This happens after checking out a specific commit or tag.');
1316
+ console.log(' Publishing requires being on a branch so git can track changes.');
1317
+ console.log('');
1318
+ console.log(colors.yellow('To fix this (if you have commits to keep):'));
1319
+ console.log(' git checkout -B master \x1b[2m# moves master branch to current commit\x1b[0m');
1320
+ console.log(' npmglobalize \x1b[2m# will now work\x1b[0m');
1321
+ console.log('');
1322
+ console.log(colors.yellow('Or if you haven\'t made commits (safe to discard):'));
1323
+ console.log(' git checkout master \x1b[2m# just switch back to branch\x1b[0m');
1324
+ console.log(' npmglobalize \x1b[2m# will now work\x1b[0m');
1325
+ console.log('');
1326
+ console.log(colors.yellow('Or force publish anyway (risky):'));
1327
+ console.log(' npmglobalize --force \x1b[2m# proceeds despite detached HEAD\x1b[0m');
1328
+ console.log('');
1329
+ return false;
1330
+ }
1281
1331
  }
1282
1332
  if (currentGitStatus.isDetachedHead && force) {
1283
- console.log(colors.yellow('Warning: Detached HEAD state - continuing with --force'));
1333
+ console.log('');
1334
+ console.log(colors.yellow('⚠ Warning: Publishing from Detached HEAD state (--force)'));
1335
+ console.log(' This means you\'re not on a branch. The published commits may be');
1336
+ console.log(' hard to track. Consider: git checkout master && git merge HEAD');
1337
+ console.log('');
1284
1338
  }
1285
1339
  // Check if local branch is behind remote
1286
1340
  if (currentGitStatus.isBehindRemote && !dryRun) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",