lint-staged 12.3.2 → 12.3.3
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/lib/runAll.js +20 -6
- package/package.json +1 -1
package/lib/runAll.js
CHANGED
|
@@ -80,7 +80,8 @@ export const runAll = async (
|
|
|
80
80
|
debugLog('Running all linter scripts...')
|
|
81
81
|
|
|
82
82
|
// Resolve relative CWD option
|
|
83
|
-
|
|
83
|
+
const hasExplicitCwd = !!cwd
|
|
84
|
+
cwd = hasExplicitCwd ? path.resolve(cwd) : process.cwd()
|
|
84
85
|
debugLog('Using working directory `%s`', cwd)
|
|
85
86
|
|
|
86
87
|
const ctx = getInitialState({ quiet })
|
|
@@ -120,6 +121,8 @@ export const runAll = async (
|
|
|
120
121
|
|
|
121
122
|
const configGroups = await getConfigGroups({ configObject, configPath, cwd, files }, logger)
|
|
122
123
|
|
|
124
|
+
const hasMultipleConfigs = Object.keys(configGroups).length > 1
|
|
125
|
+
|
|
123
126
|
// lint-staged 10 will automatically add modifications to index
|
|
124
127
|
// Warn user when their command includes `git add`
|
|
125
128
|
let hasDeprecatedGitAdd = false
|
|
@@ -138,21 +141,25 @@ export const runAll = async (
|
|
|
138
141
|
const matchedFiles = new Set()
|
|
139
142
|
|
|
140
143
|
for (const [configPath, { config, files }] of Object.entries(configGroups)) {
|
|
144
|
+
const relativeConfig = normalize(path.relative(cwd, configPath))
|
|
141
145
|
const stagedFileChunks = chunkFiles({ baseDir: gitDir, files, maxArgLength, relative })
|
|
142
146
|
|
|
147
|
+
// Use actual cwd if it's specified, or there's only a single config file.
|
|
148
|
+
// Otherwise use the directory of the config file for each config group,
|
|
149
|
+
// to make sure tasks are separated from each other.
|
|
150
|
+
const groupCwd = hasMultipleConfigs && !hasExplicitCwd ? path.dirname(configPath) : cwd
|
|
151
|
+
|
|
143
152
|
const chunkCount = stagedFileChunks.length
|
|
144
153
|
if (chunkCount > 1) {
|
|
145
154
|
debugLog('Chunked staged files from `%s` into %d part', configPath, chunkCount)
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
for (const [index, files] of stagedFileChunks.entries()) {
|
|
149
|
-
const relativeConfig = normalize(path.relative(cwd, configPath))
|
|
150
|
-
|
|
151
158
|
const chunkListrTasks = await Promise.all(
|
|
152
|
-
generateTasks({ config, cwd, files, relative }).map((task) =>
|
|
159
|
+
generateTasks({ config, cwd: groupCwd, files, relative }).map((task) =>
|
|
153
160
|
makeCmdTasks({
|
|
154
161
|
commands: task.commands,
|
|
155
|
-
cwd,
|
|
162
|
+
cwd: groupCwd,
|
|
156
163
|
files: task.fileList,
|
|
157
164
|
gitDir,
|
|
158
165
|
renderer: listrOptions.renderer,
|
|
@@ -161,7 +168,14 @@ export const runAll = async (
|
|
|
161
168
|
}).then((subTasks) => {
|
|
162
169
|
// Add files from task to match set
|
|
163
170
|
task.fileList.forEach((file) => {
|
|
164
|
-
|
|
171
|
+
// Make sure relative files are normalized to the
|
|
172
|
+
// group cwd, because other there might be identical
|
|
173
|
+
// relative filenames in the entire set.
|
|
174
|
+
const normalizedFile = path.isAbsolute(file)
|
|
175
|
+
? file
|
|
176
|
+
: normalize(path.join(groupCwd, file))
|
|
177
|
+
|
|
178
|
+
matchedFiles.add(normalizedFile)
|
|
165
179
|
})
|
|
166
180
|
|
|
167
181
|
hasDeprecatedGitAdd =
|