lint-staged 12.1.3 → 12.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/lint-staged.js +5 -4
- package/lib/index.js +1 -1
- package/lib/loadConfig.js +13 -14
- package/lib/makeCmdTasks.js +3 -2
- package/lib/resolveConfig.js +15 -0
- package/lib/resolveGitRepo.js +1 -1
- package/lib/resolveTaskFn.js +8 -7
- package/lib/runAll.js +1 -0
- package/package.json +1 -1
package/bin/lint-staged.js
CHANGED
|
@@ -44,10 +44,13 @@ cmdline
|
|
|
44
44
|
)
|
|
45
45
|
.parse(process.argv)
|
|
46
46
|
|
|
47
|
-
const
|
|
48
|
-
|
|
47
|
+
const cmdlineOptions = cmdline.opts()
|
|
48
|
+
|
|
49
|
+
if (cmdlineOptions.debug) {
|
|
49
50
|
debug.enable('lint-staged*')
|
|
50
51
|
}
|
|
52
|
+
|
|
53
|
+
const debugLog = debug('lint-staged:bin')
|
|
51
54
|
debugLog('Running `lint-staged@%s`', version)
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -68,8 +71,6 @@ const getMaxArgLength = () => {
|
|
|
68
71
|
}
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
const cmdlineOptions = cmdline.opts()
|
|
72
|
-
|
|
73
74
|
const options = {
|
|
74
75
|
allowEmpty: !!cmdlineOptions.allowEmpty,
|
|
75
76
|
concurrent: JSON.parse(cmdlineOptions.concurrent),
|
package/lib/index.js
CHANGED
|
@@ -58,7 +58,7 @@ const lintStaged = async (
|
|
|
58
58
|
) => {
|
|
59
59
|
await validateOptions({ shell }, logger)
|
|
60
60
|
|
|
61
|
-
const inputConfig = configObject || (await loadConfig(configPath, logger))
|
|
61
|
+
const inputConfig = configObject || (await loadConfig({ configPath, cwd }, logger))
|
|
62
62
|
|
|
63
63
|
if (!inputConfig) {
|
|
64
64
|
logger.error(`${ConfigNotFoundError.message}.`)
|
package/lib/loadConfig.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
/** @typedef {import('./index').Logger} Logger */
|
|
2
|
+
|
|
1
3
|
import { pathToFileURL } from 'url'
|
|
2
4
|
|
|
3
5
|
import debug from 'debug'
|
|
4
6
|
import { lilconfig } from 'lilconfig'
|
|
5
7
|
import YAML from 'yaml'
|
|
6
8
|
|
|
9
|
+
import { resolveConfig } from './resolveConfig.js'
|
|
10
|
+
|
|
7
11
|
const debugLog = debug('lint-staged:loadConfig')
|
|
8
12
|
|
|
9
13
|
/**
|
|
@@ -47,29 +51,24 @@ const loaders = {
|
|
|
47
51
|
noExt: yamlParse,
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
const resolveConfig = (configPath) => {
|
|
51
|
-
try {
|
|
52
|
-
return require.resolve(configPath)
|
|
53
|
-
} catch {
|
|
54
|
-
return configPath
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
54
|
/**
|
|
59
|
-
* @param {
|
|
60
|
-
* @param {
|
|
55
|
+
* @param {object} options
|
|
56
|
+
* @param {string} [options.configPath] - Explicit path to a config file
|
|
57
|
+
* @param {string} [options.cwd] - Current working directory
|
|
61
58
|
*/
|
|
62
|
-
export const loadConfig = async (configPath, logger) => {
|
|
59
|
+
export const loadConfig = async ({ configPath, cwd }, logger) => {
|
|
63
60
|
try {
|
|
64
61
|
if (configPath) {
|
|
65
62
|
debugLog('Loading configuration from `%s`...', configPath)
|
|
66
63
|
} else {
|
|
67
|
-
debugLog('Searching for configuration
|
|
64
|
+
debugLog('Searching for configuration from `%s`...', cwd)
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
const explorer = lilconfig('lint-staged', { searchPlaces, loaders })
|
|
71
68
|
|
|
72
|
-
const result = await (configPath
|
|
69
|
+
const result = await (configPath
|
|
70
|
+
? explorer.load(resolveConfig(configPath))
|
|
71
|
+
: explorer.search(cwd))
|
|
73
72
|
if (!result) return null
|
|
74
73
|
|
|
75
74
|
// config is a promise when using the `dynamicImport` loader
|
|
@@ -79,7 +78,7 @@ export const loadConfig = async (configPath, logger) => {
|
|
|
79
78
|
|
|
80
79
|
return config
|
|
81
80
|
} catch (error) {
|
|
82
|
-
debugLog('Failed to load configuration
|
|
81
|
+
debugLog('Failed to load configuration!')
|
|
83
82
|
logger.error(error)
|
|
84
83
|
return null
|
|
85
84
|
}
|
package/lib/makeCmdTasks.js
CHANGED
|
@@ -28,13 +28,14 @@ const getTitleLength = (renderer, columns = process.stdout.columns) => {
|
|
|
28
28
|
*
|
|
29
29
|
* @param {object} options
|
|
30
30
|
* @param {Array<string|Function>|string|Function} options.commands
|
|
31
|
+
* @param {string} options.cwd
|
|
31
32
|
* @param {Array<string>} options.files
|
|
32
33
|
* @param {string} options.gitDir
|
|
33
34
|
* @param {string} options.renderer
|
|
34
35
|
* @param {Boolean} shell
|
|
35
36
|
* @param {Boolean} verbose
|
|
36
37
|
*/
|
|
37
|
-
export const makeCmdTasks = async ({ commands, files, gitDir, renderer, shell, verbose }) => {
|
|
38
|
+
export const makeCmdTasks = async ({ commands, cwd, files, gitDir, renderer, shell, verbose }) => {
|
|
38
39
|
debugLog('Creating listr tasks for commands %o', commands)
|
|
39
40
|
const commandArray = Array.isArray(commands) ? commands : [commands]
|
|
40
41
|
const cmdTasks = []
|
|
@@ -61,7 +62,7 @@ export const makeCmdTasks = async ({ commands, files, gitDir, renderer, shell, v
|
|
|
61
62
|
|
|
62
63
|
// Truncate title to single line based on renderer
|
|
63
64
|
const title = cliTruncate(command, getTitleLength(renderer))
|
|
64
|
-
const task = resolveTaskFn({ command, files, gitDir, isFn, shell, verbose })
|
|
65
|
+
const task = resolveTaskFn({ command, cwd, files, gitDir, isFn, shell, verbose })
|
|
65
66
|
cmdTasks.push({ title, command, task })
|
|
66
67
|
}
|
|
67
68
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { createRequire } from 'module'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* require() does not exist for ESM, so we must create it to use require.resolve().
|
|
5
|
+
* @see https://nodejs.org/api/module.html#modulecreaterequirefilename
|
|
6
|
+
*/
|
|
7
|
+
const require = createRequire(import.meta.url)
|
|
8
|
+
|
|
9
|
+
export function resolveConfig(configPath) {
|
|
10
|
+
try {
|
|
11
|
+
return require.resolve(configPath)
|
|
12
|
+
} catch {
|
|
13
|
+
return configPath
|
|
14
|
+
}
|
|
15
|
+
}
|
package/lib/resolveGitRepo.js
CHANGED
|
@@ -54,7 +54,7 @@ export const resolveGitRepo = async (cwd = process.cwd()) => {
|
|
|
54
54
|
|
|
55
55
|
// read the path of the current directory relative to the top-level directory
|
|
56
56
|
// don't read the toplevel directly, it will lead to an posix conform path on non posix systems (cygwin)
|
|
57
|
-
const gitRel = normalize(await execGit(['rev-parse', '--show-prefix']))
|
|
57
|
+
const gitRel = normalize(await execGit(['rev-parse', '--show-prefix'], { cwd }))
|
|
58
58
|
const gitDir = determineGitDir(normalize(cwd), gitRel)
|
|
59
59
|
const gitConfigDir = normalize(await resolveGitConfigDir(gitDir))
|
|
60
60
|
|
package/lib/resolveTaskFn.js
CHANGED
|
@@ -68,20 +68,20 @@ const makeErr = (command, result, ctx) => {
|
|
|
68
68
|
*
|
|
69
69
|
* @param {Object} options
|
|
70
70
|
* @param {string} options.command — Linter task
|
|
71
|
+
* @param {string} [options.cwd]
|
|
71
72
|
* @param {String} options.gitDir - Current git repo path
|
|
72
73
|
* @param {Boolean} options.isFn - Whether the linter task is a function
|
|
73
74
|
* @param {Array<string>} options.files — Filepaths to run the linter task against
|
|
74
|
-
* @param {Boolean} [options.relative] — Whether the filepaths should be relative
|
|
75
75
|
* @param {Boolean} [options.shell] — Whether to skip parsing linter task for better shell support
|
|
76
76
|
* @param {Boolean} [options.verbose] — Always show task verbose
|
|
77
77
|
* @returns {function(): Promise<Array<string>>}
|
|
78
78
|
*/
|
|
79
79
|
export const resolveTaskFn = ({
|
|
80
80
|
command,
|
|
81
|
+
cwd = process.cwd(),
|
|
81
82
|
files,
|
|
82
83
|
gitDir,
|
|
83
84
|
isFn,
|
|
84
|
-
relative,
|
|
85
85
|
shell = false,
|
|
86
86
|
verbose = false,
|
|
87
87
|
}) => {
|
|
@@ -89,14 +89,15 @@ export const resolveTaskFn = ({
|
|
|
89
89
|
debugLog('cmd:', cmd)
|
|
90
90
|
debugLog('args:', args)
|
|
91
91
|
|
|
92
|
-
const execaOptions = {
|
|
93
|
-
if (relative) {
|
|
94
|
-
execaOptions.cwd = process.cwd()
|
|
95
|
-
} else if (/^git(\.exe)?/i.test(cmd) && gitDir !== process.cwd()) {
|
|
92
|
+
const execaOptions = {
|
|
96
93
|
// Only use gitDir as CWD if we are using the git binary
|
|
97
94
|
// e.g `npm` should run tasks in the actual CWD
|
|
98
|
-
|
|
95
|
+
cwd: /^git(\.exe)?/i.test(cmd) ? gitDir : cwd,
|
|
96
|
+
preferLocal: true,
|
|
97
|
+
reject: false,
|
|
98
|
+
shell,
|
|
99
99
|
}
|
|
100
|
+
|
|
100
101
|
debugLog('execaOptions:', execaOptions)
|
|
101
102
|
|
|
102
103
|
return async (ctx = getInitialState()) => {
|
package/lib/runAll.js
CHANGED