@@ -781,23 +781,6 @@ export class InstallManager {
781781 }
782782
783783 // Run "npm install" in the common folder
784-
785- // NOTE:
786- // we do NOT install optional dependencies for Rush, as it seems that optional dependencies do not
787- // work properly with shrinkwrap. Consider the "fsevents" package. This is a Mac specific package
788- // which is an optional second-order dependency. Optional dependencies work by attempting to install
789- // the package, but removes the package if the install failed.
790- // This means that someone running generate on a Mac WILL have fsevents included in their shrinkwrap.
791- // When someone using Windows attempts to install from the shrinkwrap, the install will fail.
792- //
793- // If someone generates the shrinkwrap using Windows, then fsevents will NOT be listed in the shrinkwrap.
794- // When someone using Mac attempts to install from the shrinkwrap, (as of NPM 4), they will NOT have the
795- // optional dependency installed.
796- //
797- // One possible solution would be to have the shrinkwrap include information about whether the dependency
798- // is optional or not, but it does not appear to do so. Also, this would result in strange behavior where
799- // people would have different node_modules based on their system.
800-
801784 const installArgs : string [ ] = [ 'install' ] ;
802785 this . _pushConfigurationArgs ( installArgs , options ) ;
803786
@@ -975,15 +958,34 @@ export class InstallManager {
975958 */
976959 private _pushConfigurationArgs ( args : string [ ] , options : IInstallManagerOptions ) : void {
977960 if ( this . _rushConfiguration . packageManager === 'npm' ) {
978- args . push ( '--no-optional' ) ;
961+ if ( semver . lt ( this . _rushConfiguration . packageManagerToolVersion , '5.0.0' ) ) {
962+ // NOTE:
963+ //
964+ // When using an npm version older than v5.0.0, we do NOT install optional dependencies for
965+ // Rush, because npm does not generate the shrinkwrap file consistently across platforms.
966+ //
967+ // Consider the "fsevents" package. This is a Mac specific package
968+ // which is an optional second-order dependency. Optional dependencies work by attempting to install
969+ // the package, but removes the package if the install failed.
970+ // This means that someone running generate on a Mac WILL have fsevents included in their shrinkwrap.
971+ // When someone using Windows attempts to install from the shrinkwrap, the install will fail.
972+ //
973+ // If someone generates the shrinkwrap using Windows, then fsevents will NOT be listed in the shrinkwrap.
974+ // When someone using Mac attempts to install from the shrinkwrap, they will NOT have the
975+ // optional dependency installed.
976+ //
977+ // This issue has been fixed as of npm v5.0.0: https://github.com/npm/npm/releases/tag/v5.0.0
978+ //
979+ // For more context, see https://github.com/Microsoft/web-build-tools/issues/761#issuecomment-428689600
980+ args . push ( '--no-optional' ) ;
981+ }
979982 args . push ( '--cache' , this . _rushConfiguration . npmCacheFolder ) ;
980983 args . push ( '--tmp' , this . _rushConfiguration . npmTmpFolder ) ;
981984
982985 if ( options . collectLogFile ) {
983986 args . push ( '--verbose' ) ;
984987 }
985988 } else if ( this . _rushConfiguration . packageManager === 'pnpm' ) {
986- args . push ( '--no-optional' ) ;
987989 args . push ( '--store' , this . _rushConfiguration . pnpmStoreFolder ) ;
988990
989991 // we are using the --no-lock flag for now, which unfortunately prints a warning, but should be OK
@@ -1009,7 +1011,6 @@ export class InstallManager {
10091011 args . push ( '--strict-peer-dependencies' ) ;
10101012 }
10111013 } else if ( this . _rushConfiguration . packageManager === 'yarn' ) {
1012- args . push ( '--ignore-optional' ) ;
10131014 args . push ( '--link-folder' , 'yarn-link' ) ;
10141015 args . push ( '--cache-folder' , this . _rushConfiguration . yarnCacheFolder ) ;
10151016
0 commit comments