Skip to content

Commit a16659d

Browse files
authored
Merge pull request microsoft#878 from elliottsj/rush-install-optional
Install optional dependencies, except when using npm<5.0.0
2 parents 06a41f7 + 03e8c54 commit a16659d

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

apps/rush-lib/src/logic/InstallManager.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

apps/rush-lib/src/logic/npm/NpmLinkManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ export class NpmLinkManager extends BaseLinkManager {
296296
throw Error(`The dependency "${dependency.name}" needed by "${localPackage.name}"`
297297
+ ` was not found in the common folder -- do you need to run "rush install"?`);
298298
} else {
299-
console.log(colors.yellow('Skipping optional dependency: ' + dependency.name));
299+
console.log('Skipping optional dependency: ' + dependency.name);
300300
}
301301
}
302302
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"comment": "Install optional dependencies, except w/ npm<5.0.0",
5+
"packageName": "@microsoft/rush",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush",
10+
"email": "elliottsj@users.noreply.github.com"
11+
}

0 commit comments

Comments
 (0)