Skip to content

Commit

Permalink
Fix packageDir array support
Browse files Browse the repository at this point in the history
  • Loading branch information
pzhine committed Sep 29, 2018
1 parent e8954db commit b86020d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 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] thanks [@aravindet])


## [2.14.0] - 2018-08-13
* 69e0187 (HEAD -> master, source/master, origin/master, origin/HEAD) Merge pull request #1151 from jf248/jsx
Expand Down
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 b86020d

Please sign in to comment.