diff --git a/__tests__/commands/install/resolutions.js b/__tests__/commands/install/resolutions.js index 0fbee2706d..65d7cfeb66 100644 --- a/__tests__/commands/install/resolutions.js +++ b/__tests__/commands/install/resolutions.js @@ -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 => { + 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 => { return runInstall({}, {source: 'resolutions', cwd: 'exotic-version'}, async config => { expect(await getPackageVersion(config, 'left-pad')).toEqual('1.1.1'); diff --git a/__tests__/fixtures/install/resolutions/optional-deps/package.json b/__tests__/fixtures/install/resolutions/optional-deps/package.json new file mode 100644 index 0000000000..eb5a904f39 --- /dev/null +++ b/__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" + } +} diff --git a/src/cli/commands/check.js b/src/cli/commands/check.js index 1c2cc2c925..a8bf842cb4 100644 --- a/src/cli/commands/check.js +++ b/src/cli/commands/check.js @@ -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; } diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 699f6a3379..af3f64f56a 100644 --- a/src/cli/commands/install.js +++ b/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'; @@ -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'}]; } }