diff --git a/CHANGELOG.md b/CHANGELOG.md index 3969ea3aa..6e3cb08f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com). ## [Unreleased] +### Fixed +- [`no-extraneous-dependencies`]: `packageDir` option with array value was clobbering package deps instead of merging them ([#1175] thanks [@aravindet]) + ## [2.14.0] - 2018-08-13 * 69e0187 (HEAD -> master, source/master, origin/master, origin/HEAD) Merge pull request #1151 from jf248/jsx diff --git a/src/rules/no-extraneous-dependencies.js b/src/rules/no-extraneous-dependencies.js index ec9eedaa2..528bb827b 100644 --- a/src/rules/no-extraneous-dependencies.js +++ b/src/rules/no-extraneous-dependencies.js @@ -42,9 +42,12 @@ function getDependencies(context, packageDir) { if (!isEmpty(paths)) { // use rule config to find package.json paths.forEach(dir => { - Object.assign(packageContent, extractDepFields( + const _packageContent = extractDepFields( JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8')) - )) + ) + Object.keys(packageContent).forEach(depsKey => + Object.assign(packageContent[depsKey], _packageContent[depsKey]) + ) }) } else { // use closest package.json diff --git a/tests/files/monorepo/package.json b/tests/files/monorepo/package.json index 3ed889ddf..cf0b87ffa 100644 --- a/tests/files/monorepo/package.json +++ b/tests/files/monorepo/package.json @@ -1,5 +1,8 @@ { "private": true, + "dependencies": { + "right-pad": "^1.0.1" + }, "devDependencies": { "left-pad": "^1.2.0" } diff --git a/tests/src/rules/no-extraneous-dependencies.js b/tests/src/rules/no-extraneous-dependencies.js index 10012f6b4..c29c8e5bd 100644 --- a/tests/src/rules/no-extraneous-dependencies.js +++ b/tests/src/rules/no-extraneous-dependencies.js @@ -90,6 +90,22 @@ ruleTester.run('no-extraneous-dependencies', rule, { code: 'import leftpad from "left-pad";', options: [{packageDir: packageDirMonoRepoRoot}], }), + test({ + code: 'import react from "react";', + options: [{packageDir: [packageDirMonoRepoRoot, packageDirMonoRepoWithNested]}], + }), + test({ + code: 'import leftpad from "left-pad";', + options: [{packageDir: [packageDirMonoRepoRoot, packageDirMonoRepoWithNested]}], + }), + test({ + code: 'import leftpad from "left-pad";', + options: [{packageDir: [packageDirMonoRepoWithNested, packageDirMonoRepoRoot]}], + }), + test({ + code: 'import rightpad from "right-pad";', + options: [{packageDir: [packageDirMonoRepoRoot, packageDirMonoRepoWithNested]}], + }), ], invalid: [ test({