File tree Expand file tree Collapse file tree 2 files changed +38
-32
lines changed Expand file tree Collapse file tree 2 files changed +38
-32
lines changed Original file line number Diff line number Diff line change 1- import { cosmiconfig } from 'cosmiconfig'
21import debug from 'debug'
32import inspect from 'object-inspect'
43
4+ import { loadConfig } from './loadConfig.js'
55import { PREVENTED_EMPTY_COMMIT , GIT_ERROR , RESTORE_STASH_EXAMPLE } from './messages.js'
66import { printTaskOutput } from './printTaskOutput.js'
77import { runAll } from './runAll.js'
@@ -16,37 +16,6 @@ import { validateOptions } from './validateOptions.js'
1616
1717const debugLog = debug ( 'lint-staged' )
1818
19- const resolveConfig = ( configPath ) => {
20- try {
21- return require . resolve ( configPath )
22- } catch {
23- return configPath
24- }
25- }
26-
27- const loadConfig = ( configPath ) => {
28- const explorer = cosmiconfig ( 'lint-staged' , {
29- searchPlaces : [
30- 'package.json' ,
31- '.lintstagedrc' ,
32- '.lintstagedrc.json' ,
33- '.lintstagedrc.yaml' ,
34- '.lintstagedrc.yml' ,
35- '.lintstagedrc.mjs' ,
36- '.lintstagedrc.js' ,
37- '.lintstagedrc.cjs' ,
38- 'lint-staged.config.mjs' ,
39- 'lint-staged.config.js' ,
40- 'lint-staged.config.cjs' ,
41- ] ,
42- loaders : {
43- '.mjs' : ( path ) => import ( path ) . then ( ( module ) => module . default ) ,
44- } ,
45- } )
46-
47- return configPath ? explorer . load ( resolveConfig ( configPath ) ) : explorer . search ( )
48- }
49-
5019/**
5120 * @typedef {(...any) => void } LogFunction
5221 * @typedef {{ error: LogFunction, log: LogFunction, warn: LogFunction } } Logger
Original file line number Diff line number Diff line change 1+ import { cosmiconfig } from 'cosmiconfig'
2+
3+ const dynamicImport = ( path ) => import ( path ) . then ( ( module ) => module . default )
4+
5+ const resolveConfig = ( configPath ) => {
6+ try {
7+ return require . resolve ( configPath )
8+ } catch {
9+ return configPath
10+ }
11+ }
12+
13+ /**
14+ * @param {string } [configPath]
15+ */
16+ export const loadConfig = ( configPath ) => {
17+ const explorer = cosmiconfig ( 'lint-staged' , {
18+ searchPlaces : [
19+ 'package.json' ,
20+ '.lintstagedrc' ,
21+ '.lintstagedrc.json' ,
22+ '.lintstagedrc.yaml' ,
23+ '.lintstagedrc.yml' ,
24+ '.lintstagedrc.mjs' ,
25+ '.lintstagedrc.js' ,
26+ '.lintstagedrc.cjs' ,
27+ 'lint-staged.config.mjs' ,
28+ 'lint-staged.config.js' ,
29+ 'lint-staged.config.cjs' ,
30+ ] ,
31+ loaders : {
32+ '.mjs' : dynamicImport ,
33+ } ,
34+ } )
35+
36+ return configPath ? explorer . load ( resolveConfig ( configPath ) ) : explorer . search ( )
37+ }
You can’t perform that action at this time.
0 commit comments