1
+ import colors from "chalk-cjs"
1
2
import { existsSync , writeFileSync } from "fs-extra"
2
3
import { posix } from "path"
3
- import { blue , bold , cyan , green , red , yellow } from "picocolors"
4
4
import semver from "semver"
5
5
import { hashFile } from "./hash"
6
6
import { logPatchSequenceError } from "./makePatch"
@@ -44,7 +44,7 @@ function getInstalledPackageVersion({
44
44
}
45
45
46
46
let err =
47
- `${ red ( "Error:" ) } Patch file found for package ${ posix . basename (
47
+ `${ colors . red ( "Error:" ) } Patch file found for package ${ posix . basename (
48
48
pathSpecifier ,
49
49
) } ` + ` which is not present at ${ relative ( "." , packageDir ) } `
50
50
@@ -53,7 +53,7 @@ function getInstalledPackageVersion({
53
53
54
54
If this package is a dev dependency, rename the patch file to
55
55
56
- ${ bold ( patchFilename . replace ( ".patch" , ".dev.patch" ) ) }
56
+ ${ colors . bold ( patchFilename . replace ( ".patch" , ".dev.patch" ) ) }
57
57
`
58
58
}
59
59
throw new PatchApplicationError ( err )
@@ -64,7 +64,7 @@ function getInstalledPackageVersion({
64
64
const result = semver . valid ( version )
65
65
if ( result === null ) {
66
66
throw new PatchApplicationError (
67
- `${ red (
67
+ `${ colors . red (
68
68
"Error:" ,
69
69
) } Version string '${ version } ' cannot be parsed from ${ join (
70
70
packageDir ,
@@ -84,9 +84,9 @@ function logPatchApplication(patchDetails: PatchedPackageDetails) {
84
84
} )`
85
85
: ""
86
86
console . log (
87
- `${ bold ( patchDetails . pathSpecifier ) } @${
87
+ `${ colors . bold ( patchDetails . pathSpecifier ) } @${
88
88
patchDetails . version
89
- } ${ sequenceString } ${ green ( "✔" ) } `,
89
+ } ${ sequenceString } ${ colors . green ( "✔" ) } `,
90
90
)
91
91
}
92
92
@@ -109,7 +109,7 @@ export function applyPatchesForApp({
109
109
const groupedPatches = getGroupedPatches ( patchesDirectory )
110
110
111
111
if ( groupedPatches . numPatchFiles === 0 ) {
112
- console . log ( blue ( "No patch files found" ) )
112
+ console . log ( colors . blue ( "No patch files found" ) )
113
113
return
114
114
}
115
115
@@ -139,10 +139,10 @@ export function applyPatchesForApp({
139
139
140
140
const problemsSummary = [ ]
141
141
if ( warnings . length ) {
142
- problemsSummary . push ( yellow ( `${ warnings . length } warning(s)` ) )
142
+ problemsSummary . push ( colors . yellow ( `${ warnings . length } warning(s)` ) )
143
143
}
144
144
if ( errors . length ) {
145
- problemsSummary . push ( red ( `${ errors . length } error(s)` ) )
145
+ problemsSummary . push ( colors . red ( `${ errors . length } error(s)` ) )
146
146
}
147
147
148
148
if ( problemsSummary . length ) {
@@ -200,8 +200,8 @@ export function applyPatchesForPackage({
200
200
appliedPatches . push ( unappliedPatches . shift ( ) ! )
201
201
} else {
202
202
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.` ,
205
205
`You should reinstall your node_modules folder to make sure the package is up to date` ,
206
206
)
207
207
process . exit ( 1 )
@@ -248,7 +248,9 @@ export function applyPatchesForPackage({
248
248
if ( ! installedPackageVersion ) {
249
249
// it's ok we're in production mode and this is a dev only package
250
250
console . log (
251
- `Skipping dev-only ${ bold ( pathSpecifier ) } @${ version } ${ blue ( "✔" ) } ` ,
251
+ `Skipping dev-only ${ colors . bold (
252
+ pathSpecifier ,
253
+ ) } @${ version } ${ colors . blue ( "✔" ) } `,
252
254
)
253
255
continue
254
256
}
@@ -424,7 +426,10 @@ export function applyPatch({
424
426
const errors : string [ ] | undefined = bestEffort ? [ ] : undefined
425
427
executeEffects ( forward , { dryRun : false , cwd, bestEffort, errors } )
426
428
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
+ )
428
433
writeFileSync ( "patch-package-errors.log" , errors . join ( "\n\n" ) )
429
434
process . exit ( 0 )
430
435
}
@@ -458,18 +463,20 @@ function createVersionMismatchWarning({
458
463
path : string
459
464
} ) {
460
465
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
462
469
463
470
Don't worry! This is probably fine. The patch was still applied
464
471
successfully. Here's the deets:
465
472
466
473
Patch file created for
467
474
468
- ${ packageName } @${ bold ( originalVersion ) }
475
+ ${ packageName } @${ colors . bold ( originalVersion ) }
469
476
470
477
applied to
471
478
472
- ${ packageName } @${ bold ( actualVersion ) }
479
+ ${ packageName } @${ colors . bold ( actualVersion ) }
473
480
474
481
At path
475
482
@@ -479,7 +486,7 @@ ${yellow("Warning:")} patch-package detected a patch file version mismatch
479
486
breakage even though the patch was applied successfully. Make sure the package
480
487
still behaves like you expect (you wrote tests, right?) and then run
481
488
482
- ${ bold ( `patch-package ${ pathSpecifier } ` ) }
489
+ ${ colors . bold ( `patch-package ${ pathSpecifier } ` ) }
483
490
484
491
to update the version in the patch file name and make this warning go away.
485
492
`
@@ -497,8 +504,8 @@ function createBrokenPatchFileError({
497
504
pathSpecifier : string
498
505
} ) {
499
506
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` ,
502
509
) }
503
510
504
511
${ path }
@@ -537,13 +544,15 @@ function createPatchApplicationFailureError({
537
544
pathSpecifier : string
538
545
} ) {
539
546
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` ,
542
549
) }
543
550
544
551
${ path }
545
552
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
547
556
made the patch file for it. This introduced conflicts with your patch,
548
557
just like a merge conflict in Git when separate incompatible changes are
549
558
made to the same piece of code.
@@ -562,8 +571,8 @@ ${red(bold("**ERROR**"))} ${red(
562
571
563
572
Info:
564
573
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 ) ) }
567
576
`
568
577
}
569
578
@@ -575,7 +584,9 @@ function createUnexpectedError({
575
584
error : Error
576
585
} ) {
577
586
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
+ ) }
579
590
580
591
${ error . stack }
581
592
0 commit comments