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

Function executeEffects

src/patch/apply.ts:6–110  ·  view source on GitHub ↗
(
  effects: ParsedPatchFile,
  {
    dryRun,
    bestEffort,
    errors,
    cwd,
  }: { dryRun: boolean; cwd?: string; errors?: string[]; bestEffort: boolean },
)

Source from the content-addressed store, hash-verified

4import { assertNever } from "../assertNever"
5
6export const executeEffects = (
7 effects: ParsedPatchFile,
8 {
9 dryRun,
10 bestEffort,
11 errors,
12 cwd,
13 }: { dryRun: boolean; cwd?: string; errors?: string[]; bestEffort: boolean },
14) => {
15 const inCwd = (path: string) => (cwd ? join(cwd, path) : path)
16 const humanReadable = (path: string) => relative(process.cwd(), inCwd(path))
17 effects.forEach((eff) => {
18 switch (eff.type) {
19 case "file deletion":
20 if (dryRun) {
21 if (!fs.existsSync(inCwd(eff.path))) {
22 throw new Error(
23 "Trying to delete file that doesn't exist: " +
24 humanReadable(eff.path),
25 )
26 }
27 } else {
28 // TODO: integrity checks
29 try {
30 fs.unlinkSync(inCwd(eff.path))
31 } catch (e) {
32 if (bestEffort) {
33 errors?.push(`Failed to delete file ${eff.path}`)
34 } else {
35 throw e
36 }
37 }
38 }
39 break
40 case "rename":
41 if (dryRun) {
42 // TODO: see what patch files look like if moving to exising path
43 if (!fs.existsSync(inCwd(eff.fromPath))) {
44 throw new Error(
45 "Trying to move file that doesn't exist: " +
46 humanReadable(eff.fromPath),
47 )
48 }
49 } else {
50 try {
51 fs.moveSync(inCwd(eff.fromPath), inCwd(eff.toPath))
52 } catch (e) {
53 if (bestEffort) {
54 errors?.push(
55 `Failed to rename file ${eff.fromPath} to ${eff.toPath}`,
56 )
57 } else {
58 throw e
59 }
60 }
61 }
62 break
63 case "file creation":

Callers 2

executeTestCaseFunction · 0.90
applyPatchFunction · 0.90

Calls 5

assertNeverFunction · 0.90
inCwdFunction · 0.85
humanReadableFunction · 0.85
isExecutableFunction · 0.85
applyPatchFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…