@@ -485,12 +485,24 @@ export default class InstallManager {
485485 'node_modules' ) ;
486486
487487 // This marker file indicates that the last "rush install" completed successfully
488- const markerFileExistedAtStart : boolean = fsx . existsSync ( this . commonNodeModulesMarkerFilename ) ;
488+ let markerFileExistedAndWasValidAtStart : boolean = false ;
489+
490+ if ( fsx . existsSync ( this . commonNodeModulesMarkerFilename ) ) {
491+ const markerFileContents : string = fsx . readFileSync ( this . commonNodeModulesMarkerFilename ) . toString ( ) ;
492+ const expectedFileContents : string =
493+ `${ this . _rushConfiguration . packageManager } @${ this . _rushConfiguration . packageManagerToolVersion } ` ;
494+ if ( markerFileContents === expectedFileContents ) {
495+ markerFileExistedAndWasValidAtStart = true ;
496+ }
497+ }
498+
499+ // @todo for PNPM, we should look at the lock file to determine if the store needs to be cleaned
500+ // ie even if the marker file does not exist, the store may be ok if there is no lock file
489501
490502 // If "--clean" or "--full-clean" was specified, or if the last install was interrupted,
491503 // then we will need to delete the node_modules folder. Otherwise, we can do an incremental
492504 // install.
493- const deletingNodeModules : boolean = installType !== InstallType . Normal || ! markerFileExistedAtStart ;
505+ const deletingNodeModules : boolean = installType !== InstallType . Normal || ! markerFileExistedAndWasValidAtStart ;
494506
495507 // Based on timestamps, can we skip this install entirely?
496508 if ( ! deletingNodeModules ) {
@@ -526,13 +538,13 @@ export default class InstallManager {
526538 console . log ( `Deleting the "npm-tmp" folder` ) ;
527539 this . _asyncRecycler . moveFolder ( this . _rushConfiguration . npmTmpFolder ) ;
528540
529- } else if ( installType === InstallType . UnsafePurge ) {
541+ } else {
530542 console . log ( `Deleting the "pnpm-store" folder` ) ;
531543 this . _asyncRecycler . moveFolder ( this . _rushConfiguration . pnpmStoreFolder ) ;
532544 }
533545 }
534546
535- if ( markerFileExistedAtStart ) {
547+ if ( markerFileExistedAndWasValidAtStart ) {
536548 // Delete the successful install file to indicate the install transaction has started
537549 fsx . unlinkSync ( this . commonNodeModulesMarkerFilename ) ;
538550 }
@@ -614,8 +626,14 @@ export default class InstallManager {
614626 // One possible solution would be to have the shrinkwrap include information about whether the dependency
615627 // is optional or not, but it does not appear to do so. Also, this would result in strange behavior where
616628 // people would have different node_modules based on their system.
629+ //
630+ // NOTE FOR PNPM:
631+ // PNPM does not appear to support the --no-optional flag at the moment
617632
618- const installArgs : string [ ] = [ 'install' , '--no-optional' ] ;
633+ const installArgs : string [ ] = [ 'install' ] ;
634+ if ( this . _rushConfiguration . packageManager === 'npm' ) {
635+ installArgs . push ( '--no-optional' ) ;
636+ }
619637 this . pushConfigurationArgs ( installArgs ) ;
620638
621639 console . log ( os . EOL + colors . bold ( `Running "${ this . _rushConfiguration . packageManager } install" in`
0 commit comments