diff --git a/CHANGELOG.md b/CHANGELOG.md index 3969ea3aa..a0b8a590d 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]/[#1176], thanks [@aravindet] & [@pzhine]) + ## [2.14.0] - 2018-08-13 * 69e0187 (HEAD -> master, source/master, origin/master, origin/HEAD) Merge pull request #1151 from jf248/jsx @@ -493,6 +496,7 @@ for info on changes for earlier releases. [`memo-parser`]: ./memo-parser/README.md +[#1176]: https://github.com/benmosher/eslint-plugin-import/pull/1176 [#1151]: https://github.com/benmosher/eslint-plugin-import/pull/1151 [#1137]: https://github.com/benmosher/eslint-plugin-import/pull/1137 [#1135]: https://github.com/benmosher/eslint-plugin-import/pull/1135 @@ -578,6 +582,7 @@ for info on changes for earlier releases. [#314]: https://github.com/benmosher/eslint-plugin-import/pull/314 [#912]: https://github.com/benmosher/eslint-plugin-import/pull/912 +[#1175]: https://github.com/benmosher/eslint-plugin-import/issues/1175 [#1058]: https://github.com/benmosher/eslint-plugin-import/issues/1058 [#931]: https://github.com/benmosher/eslint-plugin-import/issues/931 [#886]: https://github.com/benmosher/eslint-plugin-import/issues/886 @@ -767,3 +772,5 @@ for info on changes for earlier releases. [@1pete]: https://github.com/1pete [@gajus]: https://github.com/gajus [@jf248]: https://github.com/jf248 +[@aravindet]: https://github.com/aravindet +[@pzhine]: https://github.com/pzhine 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({