Skip to content

Commit a1abcfd

Browse files
committed
fix: stay on chalk-cjs instead of picocolors for now
1 parent 8f26944 commit a1abcfd

File tree

13 files changed

+140
-104
lines changed

13 files changed

+140
-104
lines changed

.changeset/slow-llamas-fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
feat: reduce installation size by replacing several dependencies:
66

7-
- `chalk` -> `picocolors`
7+
- `chalk` -> `chalk-cjs`
88
- `json-stable-stringify` -> `@nolyfill/json-stable-stringify`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@
8181
"dependencies": {
8282
"@nolyfill/json-stable-stringify": "^1.0.30",
8383
"@yarnpkg/lockfile": "^1.1.0",
84+
"chalk-cjs": "^5.2.0",
8485
"ci-info": "^3.7.0",
8586
"cross-spawn": "^7.0.3",
8687
"find-yarn-workspace-root": "^2.0.0",
8788
"fs-extra": "^10.0.0",
8889
"klaw-sync": "^6.0.0",
8990
"minimist": "^1.2.6",
9091
"open": "^7.4.2",
91-
"picocolors": "^1.1.1",
9292
"semver": "^7.5.3",
9393
"slash": "^3.0.0",
9494
"tmp": "^0.0.33",

src/applyPatches.ts

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import colors from "chalk-cjs"
12
import { existsSync, writeFileSync } from "fs-extra"
23
import { posix } from "path"
3-
import { blue, bold, cyan, green, red, yellow } from "picocolors"
44
import semver from "semver"
55
import { hashFile } from "./hash"
66
import { logPatchSequenceError } from "./makePatch"
@@ -44,7 +44,7 @@ function getInstalledPackageVersion({
4444
}
4545

4646
let err =
47-
`${red("Error:")} Patch file found for package ${posix.basename(
47+
`${colors.red("Error:")} Patch file found for package ${posix.basename(
4848
pathSpecifier,
4949
)}` + ` which is not present at ${relative(".", packageDir)}`
5050

@@ -53,7 +53,7 @@ function getInstalledPackageVersion({
5353
5454
If this package is a dev dependency, rename the patch file to
5555
56-
${bold(patchFilename.replace(".patch", ".dev.patch"))}
56+
${colors.bold(patchFilename.replace(".patch", ".dev.patch"))}
5757
`
5858
}
5959
throw new PatchApplicationError(err)
@@ -64,7 +64,7 @@ function getInstalledPackageVersion({
6464
const result = semver.valid(version)
6565
if (result === null) {
6666
throw new PatchApplicationError(
67-
`${red(
67+
`${colors.red(
6868
"Error:",
6969
)} Version string '${version}' cannot be parsed from ${join(
7070
packageDir,
@@ -84,9 +84,9 @@ function logPatchApplication(patchDetails: PatchedPackageDetails) {
8484
})`
8585
: ""
8686
console.log(
87-
`${bold(patchDetails.pathSpecifier)}@${
87+
`${colors.bold(patchDetails.pathSpecifier)}@${
8888
patchDetails.version
89-
}${sequenceString} ${green("✔")}`,
89+
}${sequenceString} ${colors.green("✔")}`,
9090
)
9191
}
9292

@@ -109,7 +109,7 @@ export function applyPatchesForApp({
109109
const groupedPatches = getGroupedPatches(patchesDirectory)
110110

111111
if (groupedPatches.numPatchFiles === 0) {
112-
console.log(blue("No patch files found"))
112+
console.log(colors.blue("No patch files found"))
113113
return
114114
}
115115

@@ -139,10 +139,10 @@ export function applyPatchesForApp({
139139

140140
const problemsSummary = []
141141
if (warnings.length) {
142-
problemsSummary.push(yellow(`${warnings.length} warning(s)`))
142+
problemsSummary.push(colors.yellow(`${warnings.length} warning(s)`))
143143
}
144144
if (errors.length) {
145-
problemsSummary.push(red(`${errors.length} error(s)`))
145+
problemsSummary.push(colors.red(`${errors.length} error(s)`))
146146
}
147147

148148
if (problemsSummary.length) {
@@ -200,8 +200,8 @@ export function applyPatchesForPackage({
200200
appliedPatches.push(unappliedPatches.shift()!)
201201
} else {
202202
console.log(
203-
red("Error:"),
204-
`The patches for ${bold(pathSpecifier)} have changed.`,
203+
colors.red("Error:"),
204+
`The patches for ${colors.bold(pathSpecifier)} have changed.`,
205205
`You should reinstall your node_modules folder to make sure the package is up to date`,
206206
)
207207
process.exit(1)
@@ -248,7 +248,9 @@ export function applyPatchesForPackage({
248248
if (!installedPackageVersion) {
249249
// it's ok we're in production mode and this is a dev only package
250250
console.log(
251-
`Skipping dev-only ${bold(pathSpecifier)}@${version} ${blue("✔")}`,
251+
`Skipping dev-only ${colors.bold(
252+
pathSpecifier,
253+
)}@${version} ${colors.blue("✔")}`,
252254
)
253255
continue
254256
}
@@ -424,7 +426,10 @@ export function applyPatch({
424426
const errors: string[] | undefined = bestEffort ? [] : undefined
425427
executeEffects(forward, { dryRun: false, cwd, bestEffort, errors })
426428
if (errors?.length) {
427-
console.log("Saving errors to", cyan(bold("./patch-package-errors.log")))
429+
console.log(
430+
"Saving errors to",
431+
colors.cyan(colors.bold("./patch-package-errors.log")),
432+
)
428433
writeFileSync("patch-package-errors.log", errors.join("\n\n"))
429434
process.exit(0)
430435
}
@@ -458,18 +463,20 @@ function createVersionMismatchWarning({
458463
path: string
459464
}) {
460465
return `
461-
${yellow("Warning:")} patch-package detected a patch file version mismatch
466+
${colors.yellow(
467+
"Warning:",
468+
)} patch-package detected a patch file version mismatch
462469
463470
Don't worry! This is probably fine. The patch was still applied
464471
successfully. Here's the deets:
465472
466473
Patch file created for
467474
468-
${packageName}@${bold(originalVersion)}
475+
${packageName}@${colors.bold(originalVersion)}
469476
470477
applied to
471478
472-
${packageName}@${bold(actualVersion)}
479+
${packageName}@${colors.bold(actualVersion)}
473480
474481
At path
475482
@@ -479,7 +486,7 @@ ${yellow("Warning:")} patch-package detected a patch file version mismatch
479486
breakage even though the patch was applied successfully. Make sure the package
480487
still behaves like you expect (you wrote tests, right?) and then run
481488
482-
${bold(`patch-package ${pathSpecifier}`)}
489+
${colors.bold(`patch-package ${pathSpecifier}`)}
483490
484491
to update the version in the patch file name and make this warning go away.
485492
`
@@ -497,8 +504,8 @@ function createBrokenPatchFileError({
497504
pathSpecifier: string
498505
}) {
499506
return `
500-
${red(bold("**ERROR**"))} ${red(
501-
`Failed to apply patch for package ${bold(packageName)} at path`,
507+
${colors.red(colors.bold("**ERROR**"))} ${colors.red(
508+
`Failed to apply patch for package ${colors.bold(packageName)} at path`,
502509
)}
503510
504511
${path}
@@ -537,13 +544,15 @@ function createPatchApplicationFailureError({
537544
pathSpecifier: string
538545
}) {
539546
return `
540-
${red(bold("**ERROR**"))} ${red(
541-
`Failed to apply patch for package ${bold(packageName)} at path`,
547+
${colors.red(colors.bold("**ERROR**"))} ${colors.red(
548+
`Failed to apply patch for package ${colors.bold(packageName)} at path`,
542549
)}
543550
544551
${path}
545552
546-
This error was caused because ${bold(packageName)} has changed since you
553+
This error was caused because ${colors.bold(
554+
packageName,
555+
)} has changed since you
547556
made the patch file for it. This introduced conflicts with your patch,
548557
just like a merge conflict in Git when separate incompatible changes are
549558
made to the same piece of code.
@@ -562,8 +571,8 @@ ${red(bold("**ERROR**"))} ${red(
562571
563572
Info:
564573
Patch file: patches/${patchFilename}
565-
Patch was made for version: ${green(bold(originalVersion))}
566-
Installed version: ${red(bold(actualVersion))}
574+
Patch was made for version: ${colors.green(colors.bold(originalVersion))}
575+
Installed version: ${colors.red(colors.bold(actualVersion))}
567576
`
568577
}
569578

@@ -575,7 +584,9 @@ function createUnexpectedError({
575584
error: Error
576585
}) {
577586
return `
578-
${red(bold("**ERROR**"))} ${red(`Failed to apply patch file ${bold(filename)}`)}
587+
${colors.red(colors.bold("**ERROR**"))} ${colors.red(
588+
`Failed to apply patch file ${colors.bold(filename)}`,
589+
)}
579590
580591
${error.stack}
581592

src/createIssue.ts

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

src/detectPackageManager.ts

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

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

99
function printNoYarnLockfileError() {
1010
console.log(`
11-
${red(bold("**ERROR**"))} ${red(
11+
${colors.red(colors.bold("**ERROR**"))} ${colors.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-
${red(bold("**ERROR**"))} ${red(
19+
${colors.red(colors.bold("**ERROR**"))} ${colors.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,8 +27,10 @@ dependencies.`,
2727

2828
function printSelectingDefaultMessage() {
2929
console.info(
30-
`${bold("patch-package")}: you have both yarn.lock and package-lock.json
31-
Defaulting to using ${bold("npm")}
30+
`${colors.bold(
31+
"patch-package",
32+
)}: you have both yarn.lock and package-lock.json
33+
Defaulting to using ${colors.bold("npm")}
3234
You can override this setting by passing --use-yarn or deleting
3335
package-lock.json if you don't need it
3436
`,

0 commit comments

Comments
 (0)