Skip to content

Selective versions resolutions #3868

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

Closed
Closed
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
20 changes: 17 additions & 3 deletions __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,23 @@ export function explodeLockfile(lockfile: string): Array<string> {
}

export async function getPackageVersion(config: Config, packagePath: string): Promise<string> {
const loc = path.join(config.cwd, `node_modules/${packagePath.replace(/\//g, '/node_modules/')}/package.json`);
const json = JSON.parse(await fs.readFile(loc));
return json.version;
return (await getPackageManifest(config, packagePath)).version;
}

export function getPackageManifest(config: Config, packagePath: string): Promise<any> {
return fs.readJson(getPackageManifestPath(config, packagePath));
}

export function getPackageManifestPath(config: Config, packagePath: string): string {
return path.join(getPackagePath(config, packagePath), 'package.json');
}

export function isPackagePresent(config: Config, packagePath: string): Promise<boolean> {
return fs.exists(getPackagePath(config, packagePath));
}

export function getPackagePath(config: Config, packagePath: string): string {
return path.join(config.cwd, `node_modules/${packagePath.replace(/\//g, '/node_modules/')}`);
}

export function makeConfigFromDirectory(cwd: string, reporter: Reporter, flags: Object = {}): Promise<Config> {
Expand Down
10 changes: 5 additions & 5 deletions __tests__/commands/install/integration-deduping.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* @flow */

import {getPackageVersion, runInstall} from '../_helpers.js';
import {getPackageVersion, getPackageManifestPath, runInstall} from '../_helpers.js';
import * as fs from '../../../src/util/fs.js';

const path = require('path');
Expand Down Expand Up @@ -204,8 +204,8 @@ test.concurrent('install should hardlink repeated dependencies', (): Promise<voi
// B@1 -> A@2
// C@1 -> A@2 (this is hardlink to B@1->A@2)
return runInstall({linkDuplicates: true}, 'hardlink-repeated-dependencies', async config => {
const b_a = await fs.stat(path.join(config.cwd, 'node_modules/b/node_modules/a/package.json'));
const c_a = await fs.stat(path.join(config.cwd, 'node_modules/c/node_modules/a/package.json'));
const b_a = await fs.stat(getPackageManifestPath(config, 'b/a'));
const c_a = await fs.stat(getPackageManifestPath(config, 'c/a'));
expect(b_a.ino).toEqual(c_a.ino);
});
});
Expand All @@ -215,8 +215,8 @@ test.concurrent('install should not hardlink repeated dependencies if linkDuplic
// B@1 -> A@2
// C@1 -> A@2
return runInstall({linkDuplicates: false}, 'hardlink-repeated-dependencies', async config => {
const b_a = await fs.stat(path.join(config.cwd, 'node_modules/b/node_modules/a/package.json'));
const c_a = await fs.stat(path.join(config.cwd, 'node_modules/c/node_modules/a/package.json'));
const b_a = await fs.stat(getPackageManifestPath(config, 'b/a'));
const c_a = await fs.stat(getPackageManifestPath(config, 'c/a'));
expect(b_a.ino).not.toEqual(c_a.ino);
});
});
Expand Down
9 changes: 3 additions & 6 deletions __tests__/commands/install/integration-hoisting.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* @flow */

import {getPackageVersion, runInstall} from '../_helpers.js';
import * as fs from '../../../src/util/fs.js';

const path = require('path');
import {getPackageVersion, isPackagePresent, runInstall} from '../_helpers.js';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

Expand All @@ -21,8 +18,8 @@ test.concurrent(
'install hoister should not install prioritised popular transitive devDependencies in --prod mode',
(): Promise<void> => {
return runInstall({production: true}, 'install-prod-prioritized-popular-transitive-dev-dep', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'a'))).toEqual(false);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'b'))).toEqual(false);
expect(await isPackagePresent(config, 'a')).toEqual(false);
expect(await isPackagePresent(config, 'b')).toEqual(false);
});
},
);
4 changes: 2 additions & 2 deletions __tests__/commands/install/lockfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as reporters from '../../../src/reporters/index.js';
import {Install} from '../../../src/cli/commands/install.js';
import Lockfile from '../../../src/lockfile/wrapper.js';
import * as fs from '../../../src/util/fs.js';
import {getPackageVersion, runInstall} from '../_helpers.js';
import {getPackageVersion, isPackagePresent, runInstall} from '../_helpers.js';
import {promisify} from '../../../src/util/promise';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
Expand Down Expand Up @@ -152,7 +152,7 @@ test.concurrent('install have a clean node_modules after lockfile update (branch
await reinstall.init();

expect(await getPackageVersion(config, 'dep-a')).toEqual('1.2.0');
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-b'))).toEqual(false);
expect(await isPackagePresent(config, 'dep-b')).toEqual(false);
});
});

Expand Down
29 changes: 29 additions & 0 deletions __tests__/commands/install/resolutions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* @flow */

import {getPackageVersion, isPackagePresent, runInstall} from '../_helpers.js';

test.concurrent('install with simple exact resolutions should override all versions', (): Promise<void> => {
return runInstall({}, {source: 'resolutions', cwd: 'simple-exact'}, async config => {
expect(await getPackageVersion(config, 'a')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'd1')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'd2')).toEqual('1.0.0');
expect(await isPackagePresent(config, 'a/d1')).toEqual(false);
expect(await isPackagePresent(config, 'a/d2')).toEqual(false);
expect(await isPackagePresent(config, 'b/d1')).toEqual(false);
expect(await isPackagePresent(config, 'b/d2')).toEqual(false);
});
});

test.concurrent('install with subtree exact resolutions should override subtree versions', (): Promise<void> => {
return runInstall({}, {source: 'resolutions', cwd: 'subtree-exact'}, async config => {
expect(await getPackageVersion(config, 'a')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'd1')).toEqual('3.0.0');
expect(await getPackageVersion(config, 'b/d1')).toEqual('2.0.0');
expect(await getPackageVersion(config, 'd2')).toEqual('1.0.0');
expect(await isPackagePresent(config, 'a/d1')).toEqual(false);
expect(await isPackagePresent(config, 'a/d2')).toEqual(false);
expect(await isPackagePresent(config, 'b/d2')).toEqual(false);
});
});
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/a-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "a",
"version": "1.0.0",
"dependencies": {
"d1": "file:../d1-1"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/a-2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "a",
"version": "2.0.0",
"dependencies": {
"d1": "file:../d1-2"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/b-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "b",
"version": "1.0.0",
"dependencies": {
"d1": "file:../d1-2"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/c-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "c",
"version": "1.0.0",
"dependencies": {
"a": "file:../a-2"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/d1-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "d1",
"version": "1.0.0",
"dependencies": {
"d2": "file:../d2-1"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/d1-2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "d1",
"version": "2.0.0",
"dependencies": {
"d2": "file:../d2-1"
}
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/install/resolutions/d1-3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "d1",
"version": "3.0.0",
"dependencies": {
"d2": "file:../d2-1"
}
}
4 changes: 4 additions & 0 deletions __tests__/fixtures/install/resolutions/d2-1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "d2",
"version": "1.0.0"
}
11 changes: 11 additions & 0 deletions __tests__/fixtures/install/resolutions/simple-exact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"a": "file:../a-1",
"b": "file:../b-1"
},
"resolutions": {
"**/d1": "file:../d1-2"
}
}
11 changes: 11 additions & 0 deletions __tests__/fixtures/install/resolutions/subtree-exact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"a": "file:../a-1",
"b": "file:../b-1"
},
"resolutions": {
"a/d1": "file:../d1-3"
}
}