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