Skip to content

Commit 93924ab

Browse files
SukkaWJounQin
andauthored
refactor: replace chalk and multimatch (#180)
Co-authored-by: JounQin <[email protected]>
1 parent ed34de4 commit 93924ab

File tree

5 files changed

+39
-51
lines changed

5 files changed

+39
-51
lines changed

.changeset/two-beds-collect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pretty-quick': minor
3+
---
4+
5+
refactor: replace `chalk` and `multimatch` with their lightweight and performant alternatives

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
"prettier": "^2.0.0"
4848
},
4949
"dependencies": {
50-
"chalk": "^4.1.2",
5150
"execa": "^4.1.0",
5251
"find-up": "^4.1.0",
5352
"ignore": "^5.3.0",
5453
"mri": "^1.2.0",
55-
"multimatch": "^5.0.0",
54+
"picocolors": "^1.0.0",
55+
"picomatch": "^3.0.1",
5656
"tslib": "^2.6.2"
5757
},
5858
"devDependencies": {
@@ -64,6 +64,7 @@
6464
"@total-typescript/ts-reset": "^0.5.1",
6565
"@types/jest": "^29.5.11",
6666
"@types/mock-fs": "^4.13.4",
67+
"@types/picomatch": "^2.3.3",
6768
"@unts/patch-package": "^8.0.0",
6869
"clean-pkg-json": "^1.2.0",
6970
"eslint": "^8.56.0",

src/cli.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

3-
import chalk from 'chalk'
43
import mri from 'mri'
4+
import picocolors from 'picocolors'
55

66
import prettyQuick from '.'
77

@@ -16,36 +16,36 @@ const prettyQuickResult = prettyQuick(process.cwd(), {
1616
...args,
1717
onFoundSinceRevision: (scm, revision) => {
1818
console.log(
19-
`🔍 Finding changed files since ${chalk.bold(scm)} revision ${chalk.bold(
20-
revision,
21-
)}.`,
19+
`🔍 Finding changed files since ${picocolors.bold(
20+
scm,
21+
)} revision ${picocolors.bold(revision)}.`,
2222
)
2323
},
2424

2525
onFoundChangedFiles: changedFiles => {
2626
console.log(
27-
`🎯 Found ${chalk.bold(changedFiles.length)} changed ${
27+
`🎯 Found ${picocolors.bold(changedFiles.length)} changed ${
2828
changedFiles.length === 1 ? 'file' : 'files'
2929
}.`,
3030
)
3131
},
3232

3333
onPartiallyStagedFile: file => {
34-
console.log(`✗ Found ${chalk.bold('partially')} staged file ${file}.`)
34+
console.log(`✗ Found ${picocolors.bold('partially')} staged file ${file}.`)
3535
},
3636

3737
onWriteFile: file => {
38-
console.log(`✍️ Fixing up ${chalk.bold(file)}.`)
38+
console.log(`✍️ Fixing up ${picocolors.bold(file)}.`)
3939
},
4040

4141
onCheckFile: (file, isFormatted) => {
4242
if (!isFormatted) {
43-
console.log(`⛔️ Check failed: ${chalk.bold(file)}`)
43+
console.log(`⛔️ Check failed: ${picocolors.bold(file)}`)
4444
}
4545
},
4646

4747
onExamineFile: file => {
48-
console.log(`🔍 Examining ${chalk.bold(file)}.`)
48+
console.log(`🔍 Examining ${picocolors.bold(file)}.`)
4949
},
5050
})
5151

@@ -55,7 +55,7 @@ if (prettyQuickResult.success) {
5555
if (prettyQuickResult.errors.includes('PARTIALLY_STAGED_FILE')) {
5656
console.log(
5757
'✗ Partially staged files were fixed up.' +
58-
` ${chalk.bold('Please update stage before committing')}.`,
58+
` ${picocolors.bold('Please update stage before committing')}.`,
5959
)
6060
}
6161
if (prettyQuickResult.errors.includes('BAIL_ON_WRITE')) {

src/createMatcher.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
import path from 'path'
44

5-
import multimatch from 'multimatch'
5+
import picomatch from 'picomatch'
66

77
export default (pattern: string[] | string | undefined) => {
88
// Match everything if no pattern was given
99
if (typeof pattern !== 'string' && !Array.isArray(pattern)) {
1010
return () => true
1111
}
1212
const patterns = Array.isArray(pattern) ? pattern : [pattern]
13-
return (file: string) =>
14-
multimatch(path.normalize(file), patterns, { dot: true }).length > 0
13+
14+
const isMatch = picomatch(patterns, { dot: true })
15+
return (file: string) => isMatch(path.normalize(file))
1516
}

yarn.lock

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,13 +4146,6 @@ __metadata:
41464146
languageName: node
41474147
linkType: hard
41484148

4149-
"@types/minimatch@npm:^3.0.3":
4150-
version: 3.0.5
4151-
resolution: "@types/minimatch@npm:3.0.5"
4152-
checksum: 517a8ea1bfad4cc9d2563fc70c3ecd9afb13f9ef2b2cb06f8910989baf199d24f2fc6a8ccaae16a27c856e022b311042ca67ff42ffbda48750f2f84a5bf48716
4153-
languageName: node
4154-
linkType: hard
4155-
41564149
"@types/minimist@npm:^1.2.0":
41574150
version: 1.2.5
41584151
resolution: "@types/minimist@npm:1.2.5"
@@ -4229,6 +4222,13 @@ __metadata:
42294222
languageName: node
42304223
linkType: hard
42314224

4225+
"@types/picomatch@npm:^2.3.3":
4226+
version: 2.3.3
4227+
resolution: "@types/picomatch@npm:2.3.3"
4228+
checksum: 761493d528c5dcfeab4a82637d833d6154bac5a5ed4af1cc30fe6f0bbe14111e4d30413414151d842484dad75368194a165f1bc9350289f414f1d0fa2311d77c
4229+
languageName: node
4230+
linkType: hard
4231+
42324232
"@types/prettier@npm:^2.0.0":
42334233
version: 2.7.3
42344234
resolution: "@types/prettier@npm:2.7.3"
@@ -4983,13 +4983,6 @@ __metadata:
49834983
languageName: node
49844984
linkType: hard
49854985

4986-
"array-differ@npm:^3.0.0":
4987-
version: 3.0.0
4988-
resolution: "array-differ@npm:3.0.0"
4989-
checksum: 6d87a752b56b9e9b29b617d7092173ac3b418d77621077eb7d7637a143b8df6019d59fe98cb3ba8ceba2677ad9904220dabd816f762c1cd5afaa3eec14db3b92
4990-
languageName: node
4991-
linkType: hard
4992-
49934986
"array-ify@npm:^1.0.0":
49944987
version: 1.0.0
49954988
resolution: "array-ify@npm:1.0.0"
@@ -5083,13 +5076,6 @@ __metadata:
50835076
languageName: node
50845077
linkType: hard
50855078

5086-
"arrify@npm:^2.0.1":
5087-
version: 2.0.1
5088-
resolution: "arrify@npm:2.0.1"
5089-
checksum: 2a19726815590d829e07998aefa2c352bd9061e58bf4391ffffa227129995841a710bef2d8b4c9408a6b0679d96c96bd23764bdbcc29bb21666c976816093972
5090-
languageName: node
5091-
linkType: hard
5092-
50935079
"assign-symbols@npm:^1.0.0":
50945080
version: 1.0.0
50955081
resolution: "assign-symbols@npm:1.0.0"
@@ -12572,19 +12558,6 @@ __metadata:
1257212558
languageName: node
1257312559
linkType: hard
1257412560

12575-
"multimatch@npm:^5.0.0":
12576-
version: 5.0.0
12577-
resolution: "multimatch@npm:5.0.0"
12578-
dependencies:
12579-
"@types/minimatch": "npm:^3.0.3"
12580-
array-differ: "npm:^3.0.0"
12581-
array-union: "npm:^2.1.0"
12582-
arrify: "npm:^2.0.1"
12583-
minimatch: "npm:^3.0.4"
12584-
checksum: 93fcf94313d5a62c9eac21cda21201651af7ad4fdb89c3e35d8b6031568d656f0a7a79c7275bdb2e3446994e9b7ee317b8a8cdf81c74d30e52dc8d92a2aba48b
12585-
languageName: node
12586-
linkType: hard
12587-
1258812561
"mustache@npm:^4.2.0":
1258912562
version: 4.2.0
1259012563
resolution: "mustache@npm:4.2.0"
@@ -13437,6 +13410,13 @@ __metadata:
1343713410
languageName: node
1343813411
linkType: hard
1343913412

13413+
"picomatch@npm:^3.0.1":
13414+
version: 3.0.1
13415+
resolution: "picomatch@npm:3.0.1"
13416+
checksum: d8b119f925c16361e4727f2bf651f73f856cc658affae9b8bde33af1c33436fd18f76cfd64c85b841272c2ee93e48d331457c81fd9d43586812b3f6595baa810
13417+
languageName: node
13418+
linkType: hard
13419+
1344013420
"pidtree@npm:0.6.0":
1344113421
version: 0.6.0
1344213422
resolution: "pidtree@npm:0.6.0"
@@ -13729,8 +13709,8 @@ __metadata:
1372913709
"@total-typescript/ts-reset": ^0.5.1
1373013710
"@types/jest": ^29.5.11
1373113711
"@types/mock-fs": ^4.13.4
13712+
"@types/picomatch": ^2.3.3
1373213713
"@unts/patch-package": ^8.0.0
13733-
chalk: ^4.1.2
1373413714
clean-pkg-json: ^1.2.0
1373513715
eslint: ^8.56.0
1373613716
eslint-config-prettier: ^9.1.0
@@ -13743,8 +13723,9 @@ __metadata:
1374313723
lint-staged: ^13.2.2
1374413724
mock-fs: ^4.14.0
1374513725
mri: ^1.2.0
13746-
multimatch: ^5.0.0
1374713726
npm-run-all: ^4.1.5
13727+
picocolors: ^1.0.0
13728+
picomatch: ^3.0.1
1374813729
prettier: ^2.8.8
1374913730
pretty-quick: "link:."
1375013731
simple-git-hooks: ^2.9.0

0 commit comments

Comments
 (0)