-
-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathpatchYarn.ts
41 lines (37 loc) Β· 1.03 KB
/
patchYarn.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { red, yellow } from "chalk"
import { existsSync } from "fs"
import { join } from "path"
import { applyPatch } from "./applyPatches"
import { bold, green } from "chalk"
const yarnPatchFile = join(__dirname, "../yarn.patch")
export default function patchYarn(appPath: string) {
try {
applyPatch(yarnPatchFile)
const yarnVersion = require(join(
appPath,
"node_modules",
"yarn",
"package.json",
)).version
console.log(`${bold("yarn")}@${yarnVersion} ${green("β")}`)
} catch (e) {
if (existsSync(join(appPath, "node_modules", "yarn"))) {
printIncompatibleYarnError()
} else {
printNoYarnWarning()
}
}
}
function printIncompatibleYarnError() {
console.error(`
${red.bold("***ERROR***")}
${red(`This version of patch-package in incompatible with your current local
version of yarn. Please update both.`)}
`)
}
function printNoYarnWarning() {
console.warn(`
${yellow.bold("***Warning***")}
You asked patch-package to patch yarn, but you don't seem to have yarn installed
`)
}