Skip to content
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

Fix packageDir array support #1176

Merged
merged 3 commits into from
Oct 10, 2018
Merged
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
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