Skip to content

Commit

Permalink
fix(install): Inherit optional property for resolutions (#7273)
Browse files Browse the repository at this point in the history
6040
  • Loading branch information
kaylie-alexa authored and arcanis committed Jun 6, 2019
1 parent 1089b39 commit b656953
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
6 changes: 6 additions & 0 deletions __tests__/commands/install/resolutions.js
Expand Up @@ -46,6 +46,12 @@ test.concurrent('install with --frozen-lockfile with resolutions', async (): Pro
}
});

test.concurrent('install with resolutions on optional dependencies should not resolve', (): Promise<void> => {
return runInstall({ignoreOptional: true}, {source: 'resolutions', cwd: 'optional-deps'}, async config => {
expect(await isPackagePresent(config, 'left-pad')).toEqual(false);
});
});

test.concurrent('install with exotic resolutions should override versions', (): Promise<void> => {
return runInstall({}, {source: 'resolutions', cwd: 'exotic-version'}, async config => {
expect(await getPackageVersion(config, 'left-pad')).toEqual('1.1.1');
Expand Down
10 changes: 10 additions & 0 deletions __tests__/fixtures/install/resolutions/optional-deps/package.json
@@ -0,0 +1,10 @@
{
"name": "project",
"version": "1.0.0",
"optionalDependencies": {
"left-pad": "^1.0.0"
},
"resolutions": {
"left-pad": "^1.1.1"
}
}
3 changes: 2 additions & 1 deletion src/cli/commands/check.js
Expand Up @@ -275,7 +275,8 @@ export async function run(config: Config, reporter: Reporter, flags: Object, arg
const remoteType = pkg._reference.remote.type;
const isLinkedDependency =
remoteType === 'link' || remoteType === 'workspace' || (remoteType === 'file' && config.linkFileDependencies);
if (isLinkedDependency) {
const isResolution = pkg._reference.hint === 'resolution';
if (isLinkedDependency || isResolution) {
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion src/cli/commands/install.js
@@ -1,5 +1,6 @@
/* @flow */

import objectPath from 'object-path';
import type {InstallationMethod} from '../../util/yarn-version.js';
import type {Reporter} from '../../reporters/index.js';
import type {ReporterSelectOption} from '../../reporters/types.js';
Expand Down Expand Up @@ -285,8 +286,9 @@ export class Install {

this.resolutionMap.init(this.resolutions);
for (const packageName of Object.keys(this.resolutionMap.resolutionsByPackage)) {
const optional = objectPath.has(manifest.optionalDependencies, packageName) && this.flags.ignoreOptional;
for (const {pattern} of this.resolutionMap.resolutionsByPackage[packageName]) {
resolutionDeps = [...resolutionDeps, {registry, pattern, optional: false, hint: 'resolution'}];
resolutionDeps = [...resolutionDeps, {registry, pattern, optional, hint: 'resolution'}];
}
}

Expand Down

0 comments on commit b656953

Please sign in to comment.