Skip to content

Commit

Permalink
fix(package): Update cosmiconfig to version 5.0.2 (#444)
Browse files Browse the repository at this point in the history
* fix(package): update cosmiconfig to version 5.0.2
* chore(package): update lockfile
* fix: Migrate to cosmiconfig v5

Closes #441
  • Loading branch information
sudo-suhas committed May 20, 2018
1 parent 9823d26 commit 5731c37
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"app-root-path": "^2.0.1",
"chalk": "^2.3.1",
"commander": "^2.14.1",
"cosmiconfig": "^4.0.0",
"cosmiconfig": "^5.0.2",
"debug": "^3.1.0",
"dedent": "^0.7.0",
"execa": "^0.9.0",
Expand Down
24 changes: 16 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,28 @@ if (process.stdout.isTTY) {

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

function loadConfig(configPath) {
const explorer = cosmiconfig('lint-staged', {
searchPlaces: [
'package.json',
`.lintstagedrc`,
`.lintstagedrc.json`,
`.lintstagedrc.yaml`,
`.lintstagedrc.yml`,
`lint-staged.config.js`
]
})

return configPath ? explorer.load(configPath) : explorer.search()
}

/**
* Root lint-staged function that is called from .bin
*/
module.exports = function lintStaged(logger = console, configPath, debugMode) {
debug('Loading config using `cosmiconfig`')

const explorer = cosmiconfig('lint-staged', {
configPath,
rc: '.lintstagedrc',
rcExtensions: true
})

return explorer
.load()
return loadConfig(configPath)
.then(result => {
if (result == null) throw errConfigNotFound

Expand Down
7 changes: 1 addition & 6 deletions test/__mocks__/cosmiconfig.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
const actual = require.requireActual('cosmiconfig')
const mock = jest.genMockFromModule('cosmiconfig')

function cosmiconfig(name, options) {
if (options.configPath) {
return actual(name, options)
}

return mock(name, options)
return actual(name, options)
}

module.exports = jest.fn(cosmiconfig)
2 changes: 1 addition & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const replaceSerializer = (from, to) => ({

const mockCosmiconfigWith = result => {
cosmiconfig.mockImplementationOnce(() => ({
load: () => Promise.resolve(result)
search: () => Promise.resolve(result)
}))
}

Expand Down
11 changes: 3 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1149,14 +1149,13 @@ [email protected], core-util-is@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"

cosmiconfig@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-4.0.0.tgz#760391549580bbd2df1e562bc177b13c290972dc"
cosmiconfig@^5.0.2:
version "5.0.2"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.0.2.tgz#03f8965ae4675317a0015b4a5a48a470d9baeada"
dependencies:
is-directory "^0.3.1"
js-yaml "^3.9.0"
parse-json "^4.0.0"
require-from-string "^2.0.1"

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
version "5.1.0"
Expand Down Expand Up @@ -4049,10 +4048,6 @@ require-directory@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"

require-from-string@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/require-from-string/-/require-from-string-2.0.1.tgz#c545233e9d7da6616e9d59adfb39fc9f588676ff"

require-main-filename@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1"
Expand Down

0 comments on commit 5731c37

Please sign in to comment.