Skip to content

Commit 9462bc6

Browse files
SukkaWJounQin
authored andcommitted
replace chalk with picocolors
1 parent feecfc9 commit 9462bc6

File tree

11 files changed

+2872
-2625
lines changed

11 files changed

+2872
-2625
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@
7979
},
8080
"dependencies": {
8181
"@yarnpkg/lockfile": "^1.1.0",
82-
"chalk": "^4.1.2",
8382
"ci-info": "^3.7.0",
8483
"cross-spawn": "^7.0.3",
8584
"find-yarn-workspace-root": "^2.0.0",
@@ -88,6 +87,7 @@
8887
"klaw-sync": "^6.0.0",
8988
"minimist": "^1.2.6",
9089
"open": "^7.4.2",
90+
"picocolors": "^1.0.0",
9191
"semver": "^7.5.3",
9292
"slash": "^2.0.0",
9393
"tmp": "^0.0.33",

src/applyPatches.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from "chalk"
1+
import picocolors from "picocolors"
22
import { writeFileSync } from "fs"
33
import { existsSync } from "fs-extra"
44
import { posix } from "path"
@@ -45,16 +45,17 @@ function getInstalledPackageVersion({
4545
}
4646

4747
let err =
48-
`${chalk.red("Error:")} Patch file found for package ${posix.basename(
49-
pathSpecifier,
50-
)}` + ` which is not present at ${relative(".", packageDir)}`
48+
`${picocolors.red(
49+
"Error:",
50+
)} Patch file found for package ${posix.basename(pathSpecifier)}` +
51+
` which is not present at ${relative(".", packageDir)}`
5152

5253
if (!isDevOnly && process.env.NODE_ENV === "production") {
5354
err += `
5455
5556
If this package is a dev dependency, rename the patch file to
5657
57-
${chalk.bold(patchFilename.replace(".patch", ".dev.patch"))}
58+
${picocolors.bold(patchFilename.replace(".patch", ".dev.patch"))}
5859
`
5960
}
6061
throw new PatchApplicationError(err)
@@ -65,7 +66,7 @@ function getInstalledPackageVersion({
6566
const result = semver.valid(version)
6667
if (result === null) {
6768
throw new PatchApplicationError(
68-
`${chalk.red(
69+
`${picocolors.red(
6970
"Error:",
7071
)} Version string '${version}' cannot be parsed from ${join(
7172
packageDir,
@@ -85,9 +86,9 @@ function logPatchApplication(patchDetails: PatchedPackageDetails) {
8586
})`
8687
: ""
8788
console.log(
88-
`${chalk.bold(patchDetails.pathSpecifier)}@${
89+
`${picocolors.bold(patchDetails.pathSpecifier)}@${
8990
patchDetails.version
90-
}${sequenceString} ${chalk.green("✔")}`,
91+
}${sequenceString} ${picocolors.green("✔")}`,
9192
)
9293
}
9394

@@ -110,7 +111,7 @@ export function applyPatchesForApp({
110111
const groupedPatches = getGroupedPatches(patchesDirectory)
111112

112113
if (groupedPatches.numPatchFiles === 0) {
113-
console.log(chalk.blueBright("No patch files found"))
114+
console.log(picocolors.blue("No patch files found"))
114115
return
115116
}
116117

@@ -140,10 +141,10 @@ export function applyPatchesForApp({
140141

141142
const problemsSummary = []
142143
if (warnings.length) {
143-
problemsSummary.push(chalk.yellow(`${warnings.length} warning(s)`))
144+
problemsSummary.push(picocolors.yellow(`${warnings.length} warning(s)`))
144145
}
145146
if (errors.length) {
146-
problemsSummary.push(chalk.red(`${errors.length} error(s)`))
147+
problemsSummary.push(picocolors.red(`${errors.length} error(s)`))
147148
}
148149

149150
if (problemsSummary.length) {
@@ -201,8 +202,8 @@ export function applyPatchesForPackage({
201202
appliedPatches.push(unappliedPatches.shift()!)
202203
} else {
203204
console.log(
204-
chalk.red("Error:"),
205-
`The patches for ${chalk.bold(pathSpecifier)} have changed.`,
205+
picocolors.red("Error:"),
206+
`The patches for ${picocolors.bold(pathSpecifier)} have changed.`,
206207
`You should reinstall your node_modules folder to make sure the package is up to date`,
207208
)
208209
process.exit(1)
@@ -249,9 +250,9 @@ export function applyPatchesForPackage({
249250
if (!installedPackageVersion) {
250251
// it's ok we're in production mode and this is a dev only package
251252
console.log(
252-
`Skipping dev-only ${chalk.bold(
253+
`Skipping dev-only ${picocolors.bold(
253254
pathSpecifier,
254-
)}@${version} ${chalk.blue("✔")}`,
255+
)}@${version} ${picocolors.blue("✔")}`,
255256
)
256257
continue
257258
}
@@ -429,7 +430,7 @@ export function applyPatch({
429430
if (errors?.length) {
430431
console.log(
431432
"Saving errors to",
432-
chalk.cyan.bold("./patch-package-errors.log"),
433+
picocolors.cyan(picocolors.bold("./patch-package-errors.log")),
433434
)
434435
writeFileSync("patch-package-errors.log", errors.join("\n\n"))
435436
process.exit(0)
@@ -464,18 +465,20 @@ function createVersionMismatchWarning({
464465
path: string
465466
}) {
466467
return `
467-
${chalk.yellow("Warning:")} patch-package detected a patch file version mismatch
468+
${picocolors.yellow(
469+
"Warning:",
470+
)} patch-package detected a patch file version mismatch
468471
469472
Don't worry! This is probably fine. The patch was still applied
470473
successfully. Here's the deets:
471474
472475
Patch file created for
473476
474-
${packageName}@${chalk.bold(originalVersion)}
477+
${packageName}@${picocolors.bold(originalVersion)}
475478
476479
applied to
477480
478-
${packageName}@${chalk.bold(actualVersion)}
481+
${packageName}@${picocolors.bold(actualVersion)}
479482
480483
At path
481484
@@ -485,7 +488,7 @@ ${chalk.yellow("Warning:")} patch-package detected a patch file version mismatch
485488
breakage even though the patch was applied successfully. Make sure the package
486489
still behaves like you expect (you wrote tests, right?) and then run
487490
488-
${chalk.bold(`patch-package ${pathSpecifier}`)}
491+
${picocolors.bold(`patch-package ${pathSpecifier}`)}
489492
490493
to update the version in the patch file name and make this warning go away.
491494
`
@@ -503,8 +506,8 @@ function createBrokenPatchFileError({
503506
pathSpecifier: string
504507
}) {
505508
return `
506-
${chalk.red.bold("**ERROR**")} ${chalk.red(
507-
`Failed to apply patch for package ${chalk.bold(packageName)} at path`,
509+
${picocolors.red(picocolors.bold("**ERROR**"))} ${picocolors.red(
510+
`Failed to apply patch for package ${picocolors.bold(packageName)} at path`,
508511
)}
509512
510513
${path}
@@ -543,13 +546,15 @@ function createPatchApplicationFailureError({
543546
pathSpecifier: string
544547
}) {
545548
return `
546-
${chalk.red.bold("**ERROR**")} ${chalk.red(
547-
`Failed to apply patch for package ${chalk.bold(packageName)} at path`,
549+
${picocolors.red(picocolors.bold("**ERROR**"))} ${picocolors.red(
550+
`Failed to apply patch for package ${picocolors.bold(packageName)} at path`,
548551
)}
549552
550553
${path}
551554
552-
This error was caused because ${chalk.bold(packageName)} has changed since you
555+
This error was caused because ${picocolors.bold(
556+
packageName,
557+
)} has changed since you
553558
made the patch file for it. This introduced conflicts with your patch,
554559
just like a merge conflict in Git when separate incompatible changes are
555560
made to the same piece of code.
@@ -568,8 +573,10 @@ ${chalk.red.bold("**ERROR**")} ${chalk.red(
568573
569574
Info:
570575
Patch file: patches/${patchFilename}
571-
Patch was made for version: ${chalk.green.bold(originalVersion)}
572-
Installed version: ${chalk.red.bold(actualVersion)}
576+
Patch was made for version: ${picocolors.green(
577+
picocolors.bold(originalVersion),
578+
)}
579+
Installed version: ${picocolors.red(picocolors.bold(actualVersion))}
573580
`
574581
}
575582

@@ -581,8 +588,8 @@ function createUnexpectedError({
581588
error: Error
582589
}) {
583590
return `
584-
${chalk.red.bold("**ERROR**")} ${chalk.red(
585-
`Failed to apply patch file ${chalk.bold(filename)}`,
591+
${picocolors.red(picocolors.bold("**ERROR**"))} ${picocolors.red(
592+
`Failed to apply patch file ${picocolors.bold(filename)}`,
586593
)}
587594
588595
${error.stack}

src/createIssue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from "chalk"
1+
import picocolors from "picocolors"
22
import open from "open"
33
import { stringify } from "querystring"
44
import { PackageManager } from "./detectPackageManager"
@@ -105,7 +105,7 @@ export function maybePrintIssueCreationPrompt(
105105
packageManager: PackageManager,
106106
) {
107107
if (vcs) {
108-
console.log(`💡 ${chalk.bold(packageDetails.name)} is on ${
108+
console.log(`💡 ${picocolors.bold(packageDetails.name)} is on ${
109109
vcs.provider
110110
}! To draft an issue based on your patch run
111111

src/detectPackageManager.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import fs from "fs-extra"
22
import { join } from "./path"
3-
import chalk from "chalk"
3+
import picocolors from "picocolors"
44
import process from "process"
55
import findWorkspaceRoot from "find-yarn-workspace-root"
66

77
export type PackageManager = "yarn" | "npm" | "npm-shrinkwrap"
88

99
function printNoYarnLockfileError() {
1010
console.log(`
11-
${chalk.red.bold("**ERROR**")} ${chalk.red(
11+
${picocolors.red(picocolors.bold("**ERROR**"))} ${picocolors.red(
1212
`The --use-yarn option was specified but there is no yarn.lock file`,
1313
)}
1414
`)
1515
}
1616

1717
function printNoLockfilesError() {
1818
console.log(`
19-
${chalk.red.bold("**ERROR**")} ${chalk.red(
19+
${picocolors.red(picocolors.bold("**ERROR**"))} ${picocolors.red(
2020
`No package-lock.json, npm-shrinkwrap.json, or yarn.lock file.
2121
2222
You must use either npm@>=5, yarn, or npm-shrinkwrap to manage this project's
@@ -27,10 +27,10 @@ dependencies.`,
2727

2828
function printSelectingDefaultMessage() {
2929
console.info(
30-
`${chalk.bold(
30+
`${picocolors.bold(
3131
"patch-package",
3232
)}: you have both yarn.lock and package-lock.json
33-
Defaulting to using ${chalk.bold("npm")}
33+
Defaulting to using ${picocolors.bold("npm")}
3434
You can override this setting by passing --use-yarn or deleting
3535
package-lock.json if you don't need it
3636
`,

src/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import chalk from "chalk"
1+
import picocolors from "picocolors"
22
import process from "process"
33
import minimist from "minimist"
44

@@ -32,7 +32,7 @@ const argv = minimist(process.argv.slice(2), {
3232
const packageNames = argv._
3333

3434
console.log(
35-
chalk.bold("patch-package"),
35+
picocolors.bold("patch-package"),
3636
// tslint:disable-next-line:no-var-requires
3737
require(join(__dirname, "../package.json")).version,
3838
)
@@ -49,15 +49,15 @@ if (argv.version || argv.v) {
4949
if ("rebase" in argv) {
5050
if (!argv.rebase) {
5151
console.log(
52-
chalk.red(
52+
picocolors.red(
5353
"You must specify a patch file name or number when rebasing patches",
5454
),
5555
)
5656
process.exit(1)
5757
}
5858
if (packageNames.length !== 1) {
5959
console.log(
60-
chalk.red(
60+
picocolors.red(
6161
"You must specify exactly one package name when rebasing patches",
6262
),
6363
)
@@ -133,9 +133,9 @@ Usage:
133133
1. Patching packages
134134
====================
135135
136-
${chalk.bold("patch-package")}
136+
${picocolors.bold("patch-package")}
137137
138-
Without arguments, the ${chalk.bold(
138+
Without arguments, the ${picocolors.bold(
139139
"patch-package",
140140
)} command will attempt to find and apply
141141
patch files to your project. It looks for files named like
@@ -144,11 +144,11 @@ Usage:
144144
145145
Options:
146146
147-
${chalk.bold("--patch-dir <dirname>")}
147+
${picocolors.bold("--patch-dir <dirname>")}
148148
149149
Specify the name for the directory in which the patch files are located.
150150
151-
${chalk.bold("--error-on-fail")}
151+
${picocolors.bold("--error-on-fail")}
152152
153153
Forces patch-package to exit with code 1 after failing.
154154
@@ -157,17 +157,17 @@ Usage:
157157
yarn.lock and package.json might get out of sync with node_modules,
158158
which can be very confusing.
159159
160-
--error-on-fail is ${chalk.bold("switched on")} by default on CI.
160+
--error-on-fail is ${picocolors.bold("switched on")} by default on CI.
161161
162162
See https://github.com/ds300/patch-package/issues/86 for background.
163163
164-
${chalk.bold("--error-on-warn")}
164+
${picocolors.bold("--error-on-warn")}
165165
166166
Forces patch-package to exit with code 1 after warning.
167167
168168
See https://github.com/ds300/patch-package/issues/314 for background.
169169
170-
${chalk.bold("--reverse")}
170+
${picocolors.bold("--reverse")}
171171
172172
Un-applies all patches.
173173
@@ -182,7 +182,7 @@ Usage:
182182
2. Creating patch files
183183
=======================
184184
185-
${chalk.bold("patch-package")} <package-name>${chalk.italic(
185+
${picocolors.bold("patch-package")} <package-name>${picocolors.italic(
186186
"[ <package-name>]",
187187
)}
188188
@@ -191,36 +191,36 @@ Usage:
191191
192192
Options:
193193
194-
${chalk.bold("--create-issue")}
194+
${picocolors.bold("--create-issue")}
195195
196196
For packages whose source is hosted on GitHub this option opens a web
197197
browser with a draft issue based on your diff.
198198
199-
${chalk.bold("--use-yarn")}
199+
${picocolors.bold("--use-yarn")}
200200
201201
By default, patch-package checks whether you use npm or yarn based on
202202
which lockfile you have. If you have both, it uses npm by default.
203203
Set this option to override that default and always use yarn.
204204
205-
${chalk.bold("--exclude <regexp>")}
205+
${picocolors.bold("--exclude <regexp>")}
206206
207207
Ignore paths matching the regexp when creating patch files.
208208
Paths are relative to the root dir of the package to be patched.
209209
210210
Default: 'package\\.json$'
211211
212-
${chalk.bold("--include <regexp>")}
212+
${picocolors.bold("--include <regexp>")}
213213
214214
Only consider paths matching the regexp when creating patch files.
215215
Paths are relative to the root dir of the package to be patched.
216216
217217
Default '.*'
218218
219-
${chalk.bold("--case-sensitive-path-filtering")}
219+
${picocolors.bold("--case-sensitive-path-filtering")}
220220
221221
Make regexps used in --include or --exclude filters case-sensitive.
222222
223-
${chalk.bold("--patch-dir")}
223+
${picocolors.bold("--patch-dir")}
224224
225225
Specify the name for the directory in which to put the patch files.
226226
`)

0 commit comments

Comments
 (0)