Skip to content

Commit

Permalink
Fix packageDir array support (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Hine authored and benmosher committed Oct 10, 2018
1 parent e8954db commit d3a58f8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 5 additions & 2 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/files/monorepo/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"private": true,
"dependencies": {
"right-pad": "^1.0.1"
},
"devDependencies": {
"left-pad": "^1.2.0"
}
Expand Down
16 changes: 16 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit d3a58f8

Please sign in to comment.