Skip to content

Fix: respect patterns with "||" in the range during optimizeResolutions #4562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2017
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/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,12 @@ test('unbound transitive dependencies should not conflict with top level depende
});
});

test('manifest optimization respects versions with alternation', async () => {
await runInstall({flat: true}, 'optimize-version-with-alternation', async config => {
expect(await getPackageVersion(config, 'lodash')).toEqual('2.4.2');
});
});

test.concurrent('top level patterns should match after install', (): Promise<void> => {
return runInstall({}, 'top-level-pattern-check', async (config, reporter) => {
let integrityError = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "0.0.1",
"dependencies": {
"lodash": "^3.0.1 || ^2.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"b": "file:b",
"lodash": "2.4.2"
}
}
Binary file not shown.
16 changes: 12 additions & 4 deletions src/package-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,19 @@ export default class PackageResolver {
return;
}

// reverse sort, so we'll find the maximum satisfying version first
const availableVersions = this.getAllInfoForPatterns(collapsablePatterns).map(manifest => manifest.version);
const combinedRange = collapsablePatterns.map(pattern => normalizePattern(pattern).range).join(' ');
const singleVersion = semver.maxSatisfying(availableVersions, combinedRange);
if (singleVersion) {
this.collapsePackageVersions(name, singleVersion, collapsablePatterns);
availableVersions.sort(semver.rcompare);

const ranges = collapsablePatterns.map(pattern => normalizePattern(pattern).range);

// find the most recent version that satisfies all patterns (if one exists), and
// collapse to that version.
for (const version of availableVersions) {
if (ranges.every(range => semver.satisfies(version, range))) {
this.collapsePackageVersions(name, version, collapsablePatterns);
return;
}
}
}

Expand Down