|
1 | 1 | import path from 'node:path' |
2 | 2 |
|
3 | | -import picomatch from 'picomatch' |
4 | | - |
5 | 3 | import { createDebug } from './debug.js' |
| 4 | +import { matchFiles } from './matchFiles.js' |
6 | 5 | import { normalizePath } from './normalizePath.js' |
7 | 6 |
|
8 | 7 | const debugLog = createDebug('lint-staged:generateTasks') |
@@ -30,28 +29,15 @@ export const generateTasks = ({ config, cwd = process.cwd(), files, relative = f |
30 | 29 |
|
31 | 30 | // Only worry about children of the CWD unless the pattern explicitly |
32 | 31 | // specifies that it concerns a parent directory. |
33 | | - const filteredFiles = relativeFiles.filter((file) => { |
| 32 | + const includedFiles = relativeFiles.filter((file) => { |
34 | 33 | if (isParentDirPattern) return true |
35 | 34 | return !file.filepath.startsWith('..') && !path.isAbsolute(file.filepath) |
36 | 35 | }) |
37 | 36 |
|
38 | | - const isMatch = picomatch(pattern, { |
39 | | - cwd, |
40 | | - dot: true, |
41 | | - // If the pattern doesn't look like a path, enable `matchBase` to |
42 | | - // match against filenames in every directory. This makes `*.js` |
43 | | - // match both `test.js` and `subdirectory/test.js`. |
44 | | - matchBase: !pattern.includes('/'), |
45 | | - posixSlashes: true, |
46 | | - strictBrackets: true, |
47 | | - }) |
48 | | - |
49 | | - const fileList = filteredFiles |
50 | | - .filter((file) => isMatch(file.filepath)) |
51 | | - .map((file) => ({ |
52 | | - filepath: normalizePath(relative ? file.filepath : path.resolve(cwd, file.filepath)), |
53 | | - status: file.status, |
54 | | - })) |
| 37 | + const fileList = matchFiles(includedFiles, pattern, cwd).map((file) => ({ |
| 38 | + filepath: normalizePath(relative ? file.filepath : path.resolve(cwd, file.filepath)), |
| 39 | + status: file.status, |
| 40 | + })) |
55 | 41 |
|
56 | 42 | const task = { pattern, commands, fileList } |
57 | 43 | debugLog('Generated task: \n%O', task) |
|
0 commit comments