1
+ /** @typedef {import('./index').Logger } Logger */
2
+
1
3
import { pathToFileURL } from 'url'
2
4
3
5
import debug from 'debug'
@@ -56,20 +58,23 @@ const resolveConfig = (configPath) => {
56
58
}
57
59
58
60
/**
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
61
64
*/
62
- export const loadConfig = async ( configPath , logger ) => {
65
+ export const loadConfig = async ( { configPath, cwd } , logger ) => {
63
66
try {
64
67
if ( configPath ) {
65
68
debugLog ( 'Loading configuration from `%s`...' , configPath )
66
69
} else {
67
- debugLog ( 'Searching for configuration...' )
70
+ debugLog ( 'Searching for configuration from `%s` ...' , cwd )
68
71
}
69
72
70
73
const explorer = lilconfig ( 'lint-staged' , { searchPlaces, loaders } )
71
74
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 ) )
73
78
if ( ! result ) return null
74
79
75
80
// config is a promise when using the `dynamicImport` loader
@@ -79,7 +84,7 @@ export const loadConfig = async (configPath, logger) => {
79
84
80
85
return config
81
86
} catch ( error ) {
82
- debugLog ( 'Failed to load configuration from `%s`' , configPath )
87
+ debugLog ( 'Failed to load configuration!' )
83
88
logger . error ( error )
84
89
return null
85
90
}
0 commit comments