Skip to content

Commit

Permalink
Replace find-root and pkg-config by pkg-conf
Browse files Browse the repository at this point in the history
pkg-conf can find config without throwing exceptions. It returns an
empty object by default, simplifying logic. And, usefully, it lets you
determine the path of the loaded `package.json` file.

pkg-config caches the JSON, though not the file resolution. I doubt the
caching has any measurable impact when it comes to `standard-engine` and
its use. Caching could be implemented on top of pkg-conf if necessary
though.
  • Loading branch information
novemberborn committed Jan 8, 2017
1 parent b579ea1 commit 6061b4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 7 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ module.exports.cli = require('./bin/cmd')
module.exports.linter = Linter

var deglob = require('deglob')
var findRoot = require('find-root')
var homeOrTmp = require('home-or-tmp')
var path = require('path')
var pkgConfig = require('pkg-config')
var pkgConf = require('pkg-conf')

var DEFAULT_PATTERNS = [
'**/*.js',
Expand Down Expand Up @@ -135,19 +134,12 @@ Linter.prototype.parseOpts = function (opts) {
setEnvs(opts.envs || opts.env)
setParser(opts.parser)

var root
try { root = findRoot(opts.cwd) } catch (e) {}
if (root) {
var packageOpts = pkgConfig(self.cmd, { root: false, cwd: opts.cwd })

if (packageOpts) {
setIgnore(packageOpts.ignore)
setGlobals(packageOpts.globals || packageOpts.global)
setPlugins(packageOpts.plugins || packageOpts.plugin)
setEnvs(packageOpts.envs || packageOpts.env)
if (!opts.parser) setParser(packageOpts.parser)
}
}
var packageOpts = pkgConf.sync(self.cmd, { cwd: opts.cwd })
setIgnore(packageOpts.ignore)
setGlobals(packageOpts.globals || packageOpts.global)
setPlugins(packageOpts.plugins || packageOpts.plugin)
setEnvs(packageOpts.envs || packageOpts.env)
if (!opts.parser) setParser(packageOpts.parser)

function setIgnore (ignore) {
if (!ignore) return
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
},
"dependencies": {
"deglob": "^2.1.0",
"find-root": "^1.0.0",
"get-stdin": "^5.0.1",
"home-or-tmp": "^2.0.0",
"minimist": "^1.1.0",
"pkg-config": "^1.0.1"
"pkg-conf": "^2.0.0"
},
"devDependencies": {
"babel-eslint": "^7.1.1",
Expand Down

0 comments on commit 6061b4f

Please # to comment.