@@ -174,6 +174,13 @@ class VersionCommand extends Command {
174
174
175
175
this . runPackageLifecycle = createRunner ( this . options ) ;
176
176
177
+ // don't execute recursively if run from a poorly-named script
178
+ this . runRootLifecycle = / ^ ( p r e | p o s t ) ? v e r s i o n $ / . test ( process . env . npm_lifecycle_event )
179
+ ? stage => {
180
+ this . logger . warn ( "lifecycle" , "Skipping root %j because it has already been called" , stage ) ;
181
+ }
182
+ : stage => this . runPackageLifecycle ( this . project . manifest , stage ) ;
183
+
177
184
const tasks = [
178
185
( ) => this . getVersionsForUpdates ( ) ,
179
186
versions => this . setUpdatesForVersions ( versions ) ,
@@ -403,7 +410,7 @@ class VersionCommand extends Command {
403
410
// @see https://docs.npmjs.com/misc/scripts
404
411
405
412
// exec preversion lifecycle in root (before all updates)
406
- chain = chain . then ( ( ) => this . runPackageLifecycle ( this . project . manifest , "preversion" ) ) ;
413
+ chain = chain . then ( ( ) => this . runRootLifecycle ( "preversion" ) ) ;
407
414
408
415
const actions = [
409
416
pkg => this . runPackageLifecycle ( pkg , "preversion" ) . then ( ( ) => pkg ) ,
@@ -487,7 +494,7 @@ class VersionCommand extends Command {
487
494
}
488
495
489
496
// exec version lifecycle in root (after all updates)
490
- chain = chain . then ( ( ) => this . runPackageLifecycle ( this . project . manifest , "version" ) ) ;
497
+ chain = chain . then ( ( ) => this . runRootLifecycle ( "version" ) ) ;
491
498
492
499
if ( this . commitAndTag ) {
493
500
chain = chain . then ( ( ) => gitAdd ( Array . from ( changedFiles ) , this . execOpts ) ) ;
@@ -515,7 +522,7 @@ class VersionCommand extends Command {
515
522
) ;
516
523
517
524
// run postversion, if set, in the root directory
518
- chain = chain . then ( ( ) => this . runPackageLifecycle ( this . project . manifest , "postversion" ) ) ;
525
+ chain = chain . then ( ( ) => this . runRootLifecycle ( "postversion" ) ) ;
519
526
520
527
return chain ;
521
528
}
0 commit comments