Skip to content

Commit b580a32

Browse files
Simplify resolvePatchContent to accept the patch object directly
Instead of passing path, patch content, and action as separate args, pass the whole patch object and let the function destructure what it needs.
1 parent 25c491b commit b580a32

1 file changed

Lines changed: 8 additions & 20 deletions

File tree

src/lib/init/local-ops.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,16 @@ function applyPatchsetDryRun(payload: ApplyPatchsetPayload): LocalOpResult {
574574
*/
575575
function resolvePatchContent(
576576
absPath: string,
577-
filePath: string,
578-
rawContent: string,
579-
action: string
577+
patch: ApplyPatchsetPayload["params"]["patches"][number]
580578
): string {
581-
if (!filePath.endsWith(".json")) {
582-
return rawContent;
579+
if (!patch.path.endsWith(".json")) {
580+
return patch.patch;
583581
}
584-
if (action === "modify") {
582+
if (patch.action === "modify") {
585583
const existing = fs.readFileSync(absPath, "utf-8");
586-
return prettyPrintJson(rawContent, detectJsonIndent(existing));
584+
return prettyPrintJson(patch.patch, detectJsonIndent(existing));
587585
}
588-
return prettyPrintJson(rawContent, DEFAULT_JSON_INDENT);
586+
return prettyPrintJson(patch.patch, DEFAULT_JSON_INDENT);
589587
}
590588

591589
function applyPatchset(
@@ -619,12 +617,7 @@ function applyPatchset(
619617
case "create": {
620618
const dir = path.dirname(absPath);
621619
fs.mkdirSync(dir, { recursive: true });
622-
const content = resolvePatchContent(
623-
absPath,
624-
patch.path,
625-
patch.patch,
626-
patch.action
627-
);
620+
const content = resolvePatchContent(absPath, patch);
628621
fs.writeFileSync(absPath, content, "utf-8");
629622
applied.push({ path: patch.path, action: "create" });
630623
break;
@@ -637,12 +630,7 @@ function applyPatchset(
637630
data: { applied },
638631
};
639632
}
640-
const content = resolvePatchContent(
641-
absPath,
642-
patch.path,
643-
patch.patch,
644-
patch.action
645-
);
633+
const content = resolvePatchContent(absPath, patch);
646634
fs.writeFileSync(absPath, content, "utf-8");
647635
applied.push({ path: patch.path, action: "modify" });
648636
break;

0 commit comments

Comments
 (0)