Skip to content

Commit 687fc90

Browse files
hyperz111iiroj
authored andcommitted
refactor: replace micromatch with picomatch
1 parent 26dadf9 commit 687fc90

4 files changed

Lines changed: 46 additions & 83 deletions

File tree

.changeset/few-meteors-report.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'lint-staged': minor
3+
---
4+
5+
Replace `micromatch` with `picomatch` to reduce dependencies.

lib/generateTasks.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22

3-
import micromatch from 'micromatch'
3+
import picomatch from 'picomatch'
44

55
import { createDebug } from './debug.js'
66
import { normalizePath } from './normalizePath.js'
@@ -35,31 +35,23 @@ export const generateTasks = ({ config, cwd = process.cwd(), files, relative = f
3535
return !file.filepath.startsWith('..') && !path.isAbsolute(file.filepath)
3636
})
3737

38-
const matches = micromatch(
39-
filteredFiles.map((file) => file.filepath),
40-
pattern,
41-
{
42-
cwd,
43-
dot: true,
44-
// If the pattern doesn't look like a path, enable `matchBase` to
45-
// match against filenames in every directory. This makes `*.js`
46-
// match both `test.js` and `subdirectory/test.js`.
47-
matchBase: !pattern.includes('/'),
48-
posixSlashes: true,
49-
strictBrackets: true,
50-
}
51-
)
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+
})
5248

53-
const fileList = filteredFiles.flatMap((file) =>
54-
matches.includes(file.filepath)
55-
? [
56-
{
57-
filepath: normalizePath(relative ? file.filepath : path.resolve(cwd, file.filepath)),
58-
status: file.status,
59-
},
60-
]
61-
: []
62-
)
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+
}))
6355

6456
const task = { pattern, commands, fileList }
6557
debugLog('Generated task: \n%O', task)

package-lock.json

Lines changed: 23 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"dependencies": {
5151
"commander": "^14.0.3",
5252
"listr2": "^9.0.5",
53-
"micromatch": "^4.0.8",
53+
"picomatch": "^4.0.3",
5454
"string-argv": "^0.3.2",
5555
"tinyexec": "^1.0.4",
5656
"yaml": "^2.8.2"

0 commit comments

Comments
 (0)