@@ -574,18 +574,16 @@ function applyPatchsetDryRun(payload: ApplyPatchsetPayload): LocalOpResult {
574574 */
575575function 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
591589function 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