lint-staged 16.1.1 → 16.1.2
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/chunkFiles.js +5 -1
- package/lib/gitWorkflow.js +17 -2
- package/lib/resolveGitRepo.js +29 -29
- package/lib/runAll.js +0 -2
- package/package.json +1 -1
package/lib/chunkFiles.js
CHANGED
|
@@ -52,7 +52,11 @@ export const chunkFiles = ({ files, baseDir, maxArgLength = null, relative = fal
|
|
|
52
52
|
return [normalizedFiles] // wrap in an array to return a single chunk
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
/** Calculate total character length of all filepaths, with added spaces in between */
|
|
56
|
+
const fileListLength =
|
|
57
|
+
normalizedFiles.reduce((sum, file) => sum + file.filepath.length, 0) +
|
|
58
|
+
Math.max(normalizedFiles.length - 1, 0)
|
|
59
|
+
|
|
56
60
|
debugLog(
|
|
57
61
|
`Resolved an argument string length of ${fileListLength} characters from ${normalizedFiles.length} files`
|
|
58
62
|
)
|
package/lib/gitWorkflow.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
1
2
|
import path from 'node:path'
|
|
2
3
|
|
|
3
4
|
import debug from 'debug'
|
|
@@ -279,8 +280,22 @@ export class GitWorkflow {
|
|
|
279
280
|
// These additions per chunk are run "serially" to prevent race conditions.
|
|
280
281
|
// Git add creates a lockfile in the repo causing concurrent operations to fail.
|
|
281
282
|
for (const files of this.matchedFileChunks) {
|
|
282
|
-
|
|
283
|
-
|
|
283
|
+
const accessCheckedFiles = await Promise.allSettled(
|
|
284
|
+
files.map(async (f) => {
|
|
285
|
+
if (f.status === 'D') {
|
|
286
|
+
await fs.access(f.filepath)
|
|
287
|
+
return f.filepath // File is no longer deleted and can be added
|
|
288
|
+
} else {
|
|
289
|
+
return f.filepath
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
const addableFiles = accessCheckedFiles.flatMap((r) =>
|
|
295
|
+
r.status === 'fulfilled' ? [r.value] : []
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
await this.execGit(['add', '--', ...addableFiles])
|
|
284
299
|
}
|
|
285
300
|
|
|
286
301
|
debugLog('Done adding task modifications to index!')
|
package/lib/resolveGitRepo.js
CHANGED
|
@@ -8,53 +8,53 @@ import { normalizePath } from './normalizePath.js'
|
|
|
8
8
|
const debugLog = debug('lint-staged:resolveGitRepo')
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* @example ".git"
|
|
11
|
+
* Relative path up to the repo top-level directory
|
|
12
|
+
* @example "../"
|
|
14
13
|
*/
|
|
15
|
-
const
|
|
16
|
-
/**
|
|
17
|
-
* Absolute repo top-level directory
|
|
18
|
-
*
|
|
19
|
-
* @example <caption>Git on macOS</caption>
|
|
20
|
-
* "/Users/iiro/Documents/git/lint-staged"
|
|
21
|
-
*
|
|
22
|
-
* @example <caption>Git for Windows</caption>
|
|
23
|
-
* "C:\Users\iiro\Documents\git\lint-staged"
|
|
24
|
-
*
|
|
25
|
-
* @example <caption>Git installed with MSYS2, this doesn't work when used as CWD with Node.js child_process</caption>
|
|
26
|
-
* "/c/Users/iiro/Documents/git/lint-staged"
|
|
27
|
-
*/
|
|
28
|
-
const topLevelPromise = execGit(['rev-parse', '--show-toplevel'], { cwd })
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Absolute .git directory, similar to top-level
|
|
32
|
-
*
|
|
33
|
-
* @example "/Users/iiro/Documents/git/lint-staged/.git"
|
|
34
|
-
*/
|
|
35
|
-
const absoluteGitDirPromise = execGit(['rev-parse', '--absolute-git-dir'], { cwd })
|
|
14
|
+
const CDUP = '--show-cdup'
|
|
36
15
|
|
|
37
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Absolute repo top-level directory
|
|
18
|
+
*
|
|
19
|
+
* @example <caption>Git on macOS</caption>
|
|
20
|
+
* "/Users/iiro/Documents/git/lint-staged"
|
|
21
|
+
*
|
|
22
|
+
* @example <caption>Git for Windows</caption>
|
|
23
|
+
* "C:\Users\iiro\Documents\git\lint-staged"
|
|
24
|
+
*
|
|
25
|
+
* @example <caption>Git installed with MSYS2, this doesn't work when used as CWD with Node.js child_process</caption>
|
|
26
|
+
* "/c/Users/iiro/Documents/git/lint-staged"
|
|
27
|
+
*/
|
|
28
|
+
const TOPLEVEL = '--show-toplevel'
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Absolute .git directory, similar to top-level
|
|
32
|
+
*
|
|
33
|
+
* @example "/Users/iiro/Documents/git/lint-staged/.git"
|
|
34
|
+
*/
|
|
35
|
+
const ABSOLUTE_GIT_DIR = '--absolute-git-dir'
|
|
41
36
|
|
|
42
37
|
/** Resolve git directory and possible submodule paths */
|
|
43
38
|
export const resolveGitRepo = async (cwd = process.cwd()) => {
|
|
44
39
|
try {
|
|
45
40
|
debugLog('Resolving git repo from `%s`', cwd)
|
|
46
41
|
|
|
42
|
+
/** Git rev-parse returns all three flag values on separate lines */
|
|
43
|
+
const revParseOutput = await execGit(['rev-parse', CDUP, TOPLEVEL, ABSOLUTE_GIT_DIR], {
|
|
44
|
+
cwd,
|
|
45
|
+
})
|
|
46
|
+
const [relativeTopLevelDir, topLevel, absoluteGitDir] = revParseOutput.split('\n')
|
|
47
|
+
|
|
47
48
|
// Unset GIT_DIR before running any git operations in case it's pointing to an incorrect location
|
|
48
49
|
debugLog('Unset GIT_DIR (was `%s`)', process.env.GIT_DIR)
|
|
49
50
|
delete process.env.GIT_DIR
|
|
50
51
|
debugLog('Unset GIT_WORK_TREE (was `%s`)', process.env.GIT_WORK_TREE)
|
|
51
52
|
delete process.env.GIT_WORK_TREE
|
|
52
53
|
|
|
53
|
-
const relativeTopLevelDir = await execGit(['rev-parse', '--show-cdup'], { cwd })
|
|
54
54
|
const topLevelDir = normalizePath(path.join(cwd, relativeTopLevelDir))
|
|
55
55
|
debugLog('Resolved git repository top-level directory to be `%s`', topLevelDir)
|
|
56
56
|
|
|
57
|
-
const relativeGitConfigDir =
|
|
57
|
+
const relativeGitConfigDir = path.relative(topLevel, absoluteGitDir)
|
|
58
58
|
const gitConfigDir = normalizePath(path.join(topLevelDir, relativeGitConfigDir))
|
|
59
59
|
debugLog('Resolved git config directory to be `%s`', gitConfigDir)
|
|
60
60
|
|
package/lib/runAll.js
CHANGED