From 2fc7aa3f4f2b94fa14187d5c5ab3c07b845ca6de Mon Sep 17 00:00:00 2001 From: Suhas Karanth Date: Sun, 13 May 2018 10:14:40 +0530 Subject: [PATCH] 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 --- package.json | 2 +- src/index.js | 24 ++++++++++++++++-------- test/__mocks__/cosmiconfig.js | 7 +------ test/index.spec.js | 2 +- yarn.lock | 11 +++-------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 66a9b4112..33bb21cb3 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/index.js b/src/index.js index 5dc41ed29..30e9fc3e5 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/test/__mocks__/cosmiconfig.js b/test/__mocks__/cosmiconfig.js index 5dd4ca163..86965f8c8 100644 --- a/test/__mocks__/cosmiconfig.js +++ b/test/__mocks__/cosmiconfig.js @@ -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) diff --git a/test/index.spec.js b/test/index.spec.js index a5da3b1f6..1eb8bfe35 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -10,7 +10,7 @@ const replaceSerializer = (from, to) => ({ const mockCosmiconfigWith = result => { cosmiconfig.mockImplementationOnce(() => ({ - load: () => Promise.resolve(result) + search: () => Promise.resolve(result) })) } diff --git a/yarn.lock b/yarn.lock index 7da01b6e5..734880e54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1149,14 +1149,13 @@ core-util-is@1.0.2, 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" @@ -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"