You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: PUBLISH.md
+75Lines changed: 75 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -235,3 +235,78 @@ npm init
235
235
236
236
Occasionally, npm registry might have issues. Check [npm status](https://status.npmjs.org/) to ensure the service is operational.
237
237
238
+
239
+
240
+
241
+
I see the issue – your script is getting caught in an infinite loop because the `version` script in package.json is calling `version.sh`, which then triggers the npm version command, which in turn calls the `version` script again, creating an endless cycle.
242
+
243
+
Let's fix the `version.sh` script to prevent this infinite loop:
244
+
245
+
246
+
247
+
I've fixed the infinite loop issue in your versioning script. There are two main problems that were causing this:
248
+
249
+
## 1. Script Infinite Loop Issue
250
+
251
+
The infinite loop was occurring because:
252
+
253
+
1. Your package.json had a `"version": "bash version.sh"` script
254
+
2. When you ran `npm version` or the script itself called `npm version`, it triggered this script
255
+
3. Which in turn ran `version.sh` again, creating an endless loop
256
+
257
+
## 2. Solutions Implemented
258
+
259
+
I've made two important changes to fix this:
260
+
261
+
### A. Updated version.sh Script:
262
+
263
+
1. **Added detection for npm lifecycle events**:
264
+
```bash
265
+
# Detect if being run from npm script to prevent infinite loop
266
+
if [ "$npm_lifecycle_event"="version" ];then
267
+
echo"Running from npm version hook - skipping automatic versioning"
268
+
exit 0
269
+
fi
270
+
```
271
+
272
+
2. **Changed how the version is updated in package.json**:
273
+
- Instead of using `npm version` which triggers hooks, it directly modifies package.json with Node.js
274
+
- This avoids the npm lifecycle hooks that were causing the infinite loop
275
+
276
+
3. **Added better error handling for git commands**:
277
+
- The script now continues even if git push fails
278
+
- It properly handles the case where package-lock.json is ignored by git
0 commit comments