Skip to content

Commit

Permalink
Use read-pkg-up over pkg-up. (#680)
Browse files Browse the repository at this point in the history
* Use `read-pkg-up` over `pkg-up`.

* Lint.

* Fix `options` for `readPkgUp`.

* Fix `pkg`.

* Change line endings.
  • Loading branch information
wtgtybhertgeghgtwtg authored and benmosher committed Dec 15, 2016
1 parent d0d24b9 commit 8df3c9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"has": "^1.0.1",
"lodash.cond": "^4.3.0",
"minimatch": "^3.0.3",
"pkg-up": "^1.0.0"
"read-pkg-up": "^2.0.0"
},
"nyc": {
"require": [
Expand Down
15 changes: 6 additions & 9 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import fs from 'fs'
import path from 'path'
import pkgUp from 'pkg-up'
import readPkgUp from 'read-pkg-up'
import minimatch from 'minimatch'
import importType from '../core/importType'
import isStaticRequire from '../core/staticRequire'

function getDependencies(context) {
const filepath = pkgUp.sync(context.getFilename())
if (!filepath) {
return null
}

try {
const packageContent = JSON.parse(fs.readFileSync(filepath, 'utf8'))
const pkg = readPkgUp.sync({cwd: context.getFilename(), normalize: false})
if (!pkg || !pkg.pkg) {
return null
}
const packageContent = pkg.pkg
return {
dependencies: packageContent.dependencies || {},
devDependencies: packageContent.devDependencies || {},
Expand Down Expand Up @@ -46,7 +44,6 @@ function reportIfMissing(context, deps, depsOptions, node, name) {
const packageName = splitName[0][0] === '@'
? splitName.slice(0, 2).join('/')
: splitName[0]

const isInDeps = deps.dependencies[packageName] !== undefined
const isInDevDeps = deps.devDependencies[packageName] !== undefined
const isInOptDeps = deps.optionalDependencies[packageName] !== undefined
Expand Down

0 comments on commit 8df3c9a

Please sign in to comment.