Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions __tests__/commands/install/resolutions.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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