Skip to content

Commit 2fc7aa3

Browse files
committed
fix(package): Update cosmiconfig to version 5.0.2 (#444)
* fix(package): update cosmiconfig to version 5.0.2 * chore(package): update lockfile * fix: Migrate to cosmiconfig v5 Closes #441
1 parent ec4f4f2 commit 2fc7aa3

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"app-root-path": "^2.0.1",
2929
"chalk": "^2.3.1",
3030
"commander": "^2.14.1",
31-
"cosmiconfig": "^4.0.0",
31+
"cosmiconfig": "^5.0.2",
3232
"debug": "^3.1.0",
3333
"dedent": "^0.7.0",
3434
"execa": "^0.9.0",

src/index.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@ if (process.stdout.isTTY) {
1818

1919
const errConfigNotFound = new Error('Config could not be found')
2020

21+
function loadConfig(configPath) {
22+
const explorer = cosmiconfig('lint-staged', {
23+
searchPlaces: [
24+
'package.json',
25+
`.lintstagedrc`,
26+
`.lintstagedrc.json`,
27+
`.lintstagedrc.yaml`,
28+
`.lintstagedrc.yml`,
29+
`lint-staged.config.js`
30+
]
31+
})
32+
33+
return configPath ? explorer.load(configPath) : explorer.search()
34+
}
35+
2136
/**
2237
* Root lint-staged function that is called from .bin
2338
*/
2439
module.exports = function lintStaged(logger = console, configPath, debugMode) {
2540
debug('Loading config using `cosmiconfig`')
2641

27-
const explorer = cosmiconfig('lint-staged', {
28-
configPath,
29-
rc: '.lintstagedrc',
30-
rcExtensions: true
31-
})
32-
33-
return explorer
34-
.load()
42+
return loadConfig(configPath)
3543
.then(result => {
3644
if (result == null) throw errConfigNotFound
3745

test/__mocks__/cosmiconfig.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
const actual = require.requireActual('cosmiconfig')
2-
const mock = jest.genMockFromModule('cosmiconfig')
32

43
function cosmiconfig(name, options) {
5-
if (options.configPath) {
6-
return actual(name, options)
7-
}
8-
9-
return mock(name, options)
4+
return actual(name, options)
105
}
116

127
module.exports = jest.fn(cosmiconfig)

test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const replaceSerializer = (from, to) => ({
1010

1111
const mockCosmiconfigWith = result => {
1212
cosmiconfig.mockImplementationOnce(() => ({
13-
load: () => Promise.resolve(result)
13+
search: () => Promise.resolve(result)
1414
}))
1515
}
1616

yarn.lock

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,14 +1149,13 @@ [email protected], core-util-is@~1.0.0:
11491149
version "1.0.2"
11501150
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
11511151

1152-
cosmiconfig@^4.0.0:
1153-
version "4.0.0"
1154-
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc"
1152+
cosmiconfig@^5.0.2:
1153+
version "5.0.2"
1154+
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.2.tgz#03f8965ae4675317a0015b4a5a48a470d9baeada"
11551155
dependencies:
11561156
is-directory "^0.3.1"
11571157
js-yaml "^3.9.0"
11581158
parse-json "^4.0.0"
1159-
require-from-string "^2.0.1"
11601159

11611160
cross-spawn@^5.0.1, cross-spawn@^5.1.0:
11621161
version "5.1.0"
@@ -4049,10 +4048,6 @@ require-directory@^2.1.1:
40494048
version "2.1.1"
40504049
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
40514050

4052-
require-from-string@^2.0.1:
4053-
version "2.0.1"
4054-
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.1.tgz#c545233e9d7da6616e9d59adfb39fc9f588676ff"
4055-
40564051
require-main-filename@^1.0.1:
40574052
version "1.0.1"
40584053
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"

0 commit comments

Comments
 (0)