From 8df3c9a85f697fea4b68dfcdec6539658570626f Mon Sep 17 00:00:00 2001 From: wtgtybhertgeghgtwtg Date: Thu, 15 Dec 2016 05:06:00 -0700 Subject: [PATCH] Use `read-pkg-up` over `pkg-up`. (#680) * Use `read-pkg-up` over `pkg-up`. * Lint. * Fix `options` for `readPkgUp`. * Fix `pkg`. * Change line endings. --- package.json | 2 +- src/rules/no-extraneous-dependencies.js | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 16b762de8..9391f6d09 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/rules/no-extraneous-dependencies.js b/src/rules/no-extraneous-dependencies.js index b7955bb9a..166d4f843 100644 --- a/src/rules/no-extraneous-dependencies.js +++ b/src/rules/no-extraneous-dependencies.js @@ -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 || {}, @@ -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