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

Use read-pkg-up over pkg-up. #680

Merged
merged 5 commits into from
Dec 15, 2016
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
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