Skip to content

Commit d59fad7

Browse files
sudo-suhasokonet
authored andcommitted
fix: Make app package.json load error tolerant (#479)
1 parent c350a0e commit d59fad7

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"test:watch": "jest --watch"
2626
},
2727
"dependencies": {
28-
"app-root-path": "^2.0.1",
2928
"chalk": "^2.3.1",
3029
"commander": "^2.14.1",
3130
"cosmiconfig": "^5.0.2",

src/findBin.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
'use strict'
22

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

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

9+
// Find and load the package.json at the root of the project.
10+
let pkg
11+
try {
12+
// eslint-disable-next-line import/no-dynamic-require, global-require
13+
pkg = require(`${process.cwd()}/package.json`)
14+
debug('Loaded package.json using `process.cwd()`')
15+
} catch (ignore) {
16+
debug('Could not load package.json using `process.cwd()`')
17+
pkg = {}
18+
}
19+
1220
const cache = new Map()
1321

1422
module.exports = function findBin(cmd) {

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ anymatch@^2.0.0:
124124
micromatch "^3.1.4"
125125
normalize-path "^2.1.1"
126126

127-
app-root-path@^2.0.1:
128-
version "2.1.0"
129-
resolved "https://registry.yarnpkg.com/app-root-path/-/app-root-path-2.1.0.tgz#98bf6599327ecea199309866e8140368fd2e646a"
130-
131127
append-transform@^1.0.0:
132128
version "1.0.0"
133129
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-1.0.0.tgz#046a52ae582a228bd72f58acfbe2967c678759ab"

0 commit comments

Comments
 (0)