MCPcopy Index your code
hub / github.com/ds300/patch-package / readPatch

Function readPatch

src/patch/read.ts:8–66  ·  view source on GitHub ↗
({
  patchFilePath,
  patchDetails,
  patchDir,
}: {
  patchFilePath: string
  patchDetails: PackageDetails
  patchDir: string
})

Source from the content-addressed store, hash-verified

6import { parsePatchFile, PatchFilePart } from "./parse"
7
8export function readPatch({
9 patchFilePath,
10 patchDetails,
11 patchDir,
12}: {
13 patchFilePath: string
14 patchDetails: PackageDetails
15 patchDir: string
16}): PatchFilePart[] {
17 try {
18 return parsePatchFile(readFileSync(patchFilePath).toString())
19 } catch (e) {
20 const fixupSteps: string[] = []
21 const relativePatchFilePath = normalize(
22 relative(process.cwd(), patchFilePath),
23 )
24 const patchBaseDir = relativePatchFilePath.slice(
25 0,
26 relativePatchFilePath.indexOf(patchDir),
27 )
28 if (patchBaseDir) {
29 fixupSteps.push(`cd ${patchBaseDir}`)
30 }
31 fixupSteps.push(
32 `patch -p1 -i ${relativePatchFilePath.slice(
33 relativePatchFilePath.indexOf(patchDir),
34 )}`,
35 )
36 fixupSteps.push(`npx patch-package ${patchDetails.pathSpecifier}`)
37 if (patchBaseDir) {
38 fixupSteps.push(
39 `cd ${relative(resolve(process.cwd(), patchBaseDir), process.cwd())}`,
40 )
41 }
42
43 console.log(`
44${chalk.red.bold("**ERROR**")} ${chalk.red(
45 `Failed to apply patch for package ${chalk.bold(
46 patchDetails.humanReadablePathSpecifier,
47 )}`,
48 )}
49
50 This happened because the patch file ${relativePatchFilePath} could not be parsed.
51
52 If you just upgraded patch-package, you can try running:
53
54 ${fixupSteps.join("\n ")}
55
56 Otherwise, try manually creating the patch file again.
57
58 If the problem persists, please submit a bug report:
59
60 https://github.com/ds300/patch-package/issues/new?title=Patch+file+parse+error&body=%3CPlease+attach+the+patch+file+in+question%3E
61
62`)
63 process.exit(1)
64 }
65 return []

Callers 2

applyPatchFunction · 0.90
read.test.tsFile · 0.90

Calls 3

parsePatchFileFunction · 0.90
relativeFunction · 0.90
resolveFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…