Skip to content

Commit

Permalink
Merge pull request #31 from vagonpidarasov/master
Browse files Browse the repository at this point in the history
include-resolutions option added
  • Loading branch information
Arcanemagus authored Jul 3, 2018
2 parents 1ccba60 + 5ba6839 commit d6538e6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ allowing a potential issue to arise if `[email protected]` was installed and not
updated before installing. The output also tells you that although the
_minimum_ allowed version is too low, the _maximum_ allowed version does
satisfy the `peerDependencies` requirement.


If you use resolutions section in your package.json file in order to resolve some unmet peer dependencies
and want the program to take it into the account run it with include-resolutions option:

```
> check-peer-deps --include-resolutions=true
```

Read more about resolutions: https://yarnpkg.com/lang/en/docs/selective-version-resolutions/
7 changes: 7 additions & 0 deletions __tests__/check-peer-deps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ test('Finds nothing wrong with no peerDependencies in the tree', async () => {
expect(output.stdout).toBe('');
expect(output.stderr).toBe('');
});

test('Finds nothing wrong with a broken dependency tree backed up with resolutions', async () => {
expect.assertions(2);
const output = await runCPD(['--include-resolutions=true'], { cwd: path.join(fixtures, 'peerDepWithResolution') });
expect(output.stdout).toBe('');
expect(output.stderr).toBe('');
});
1 change: 1 addition & 0 deletions __tests__/fixtures/peerDepWithResolution/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!node_modules/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions __tests__/fixtures/peerDepWithResolution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"eslint": "4.9.0",
"eslint-config-airbnb-base": "12.1.0"
},
"resolutions": {
"eslint-config-airbnb-base/eslint": "4.0.9"
}
}
27 changes: 27 additions & 0 deletions check-peer-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ const optionDefinitions = [
'peerDependency has been satisfied',
defaultValue: false,
},
{
name: 'include-resolutions',
description: 'Check for resolutions section of package.json when checking whether a peerDependency has been satisfied',
defaultValue: false,
},
{
name: 'max-retries',
description: 'Specify how many retries are allowed for [underline]{npm} commands',
Expand Down Expand Up @@ -63,6 +68,7 @@ let options;
const deps = new Map();
const npmVers = new Map();
const peerDeps = new Map();
const resolutions = new Map();

const log = (value) => {
if (options.debug) {
Expand All @@ -80,6 +86,16 @@ const addDeps = (dependencies) => {
});
};

const addResolutions = (res) => {
if (!res) {
return;
}
Object.entries(res).forEach((entry) => {
const [name, range] = entry;
resolutions.set(name, range);
});
};

const readPackageConfig = async (path) => {
let packageConfig = {};
try {
Expand Down Expand Up @@ -206,6 +222,13 @@ const checkPeerDependencies = async (peerDependencies, name) =>
}
}

if (resolutions.has(`${name}/${peerDepName}`)) {
const minAllowedVer = resolutions.get(`${name}/${peerDepName}`);
if (semver.satisfies(minAllowedVer, peerDepRange)) {
found = true;
}
}

if (!found) {
console.error(`A dependency satisfying ${name}'s peerDependency of '${peerDepName}@${peerDepRange}' was not found!`);

Expand All @@ -232,6 +255,10 @@ const findDependencies = async () => {
// Get the dependencies to process
addDeps(packageConfig.dependencies);

if (options['include-resolutions'] && packageConfig.resolutions) {
addResolutions(packageConfig.resolutions);
}

if (!options['no-include-dev'] && packageConfig.devDependencies) {
addDeps(packageConfig.devDependencies);
}
Expand Down

0 comments on commit d6538e6

Please sign in to comment.