Skip to content

Commit c7ea359

Browse files
committedJan 2, 2022
fix: search configuration starting from explicit cwd option
1 parent 5cceeb6 commit c7ea359

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed
 

‎lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const lintStaged = async (
5858
) => {
5959
await validateOptions({ shell }, logger)
6060

61-
const inputConfig = configObject || (await loadConfig(configPath, logger))
61+
const inputConfig = configObject || (await loadConfig({ configPath, cwd }, logger))
6262

6363
if (!inputConfig) {
6464
logger.error(`${ConfigNotFoundError.message}.`)

‎lib/loadConfig.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/** @typedef {import('./index').Logger} Logger */
2+
13
import { pathToFileURL } from 'url'
24

35
import debug from 'debug'
@@ -56,20 +58,23 @@ const resolveConfig = (configPath) => {
5658
}
5759

5860
/**
59-
* @param {string} [configPath]
60-
* @param {Logger} [logger]
61+
* @param {object} options
62+
* @param {string} [options.configPath] - Explicit path to a config file
63+
* @param {string} [options.cwd] - Current working directory
6164
*/
62-
export const loadConfig = async (configPath, logger) => {
65+
export const loadConfig = async ({ configPath, cwd }, logger) => {
6366
try {
6467
if (configPath) {
6568
debugLog('Loading configuration from `%s`...', configPath)
6669
} else {
67-
debugLog('Searching for configuration...')
70+
debugLog('Searching for configuration from `%s`...', cwd)
6871
}
6972

7073
const explorer = lilconfig('lint-staged', { searchPlaces, loaders })
7174

72-
const result = await (configPath ? explorer.load(resolveConfig(configPath)) : explorer.search())
75+
const result = await (configPath
76+
? explorer.load(resolveConfig(configPath))
77+
: explorer.search(cwd))
7378
if (!result) return null
7479

7580
// config is a promise when using the `dynamicImport` loader
@@ -79,7 +84,7 @@ export const loadConfig = async (configPath, logger) => {
7984

8085
return config
8186
} catch (error) {
82-
debugLog('Failed to load configuration from `%s`', configPath)
87+
debugLog('Failed to load configuration!')
8388
logger.error(error)
8489
return null
8590
}

0 commit comments

Comments
 (0)
Please sign in to comment.