Skip to content

Commit

Permalink
fix: Make app package.json load error tolerant (#479)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-suhas authored and okonet committed Aug 12, 2018
1 parent c350a0e commit d59fad7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -25,7 +25,6 @@
"test:watch": "jest --watch"
},
"dependencies": {
"app-root-path": "^2.0.1",
"chalk": "^2.3.1",
"commander": "^2.14.1",
"cosmiconfig": "^5.0.2",
Expand Down
14 changes: 11 additions & 3 deletions src/findBin.js
@@ -1,14 +1,22 @@
'use strict'

const parse = require('string-argv')
const appRoot = require('app-root-path')
const npmWhich = require('npm-which')(process.cwd())
const checkPkgScripts = require('./checkPkgScripts')

// Find and load the package.json at the root of the project.
const pkg = require(appRoot.resolve('package.json')) // eslint-disable-line import/no-dynamic-require
const debug = require('debug')('lint-staged:find-bin')

// Find and load the package.json at the root of the project.
let pkg
try {
// eslint-disable-next-line import/no-dynamic-require, global-require
pkg = require(`${process.cwd()}/package.json`)
debug('Loaded package.json using `process.cwd()`')
} catch (ignore) {
debug('Could not load package.json using `process.cwd()`')
pkg = {}
}

const cache = new Map()

module.exports = function findBin(cmd) {
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Expand Up @@ -124,10 +124,6 @@ anymatch@^2.0.0:
micromatch "^3.1.4"
normalize-path "^2.1.1"

app-root-path@^2.0.1:
version "2.1.0"
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.1.0.tgz#98bf6599327ecea199309866e8140368fd2e646a"

append-transform@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"
Expand Down

0 comments on commit d59fad7

Please sign in to comment.