File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,39 @@ describe('pListTask', () => {
212
212
{ forth : 'test2' } ,
213
213
] ) ;
214
214
} ) ;
215
+ it ( 'should delete value' , ( ) => {
216
+ let content : Record < string , any > = {
217
+ first : {
218
+ second : {
219
+ third : 'test' ,
220
+ } ,
221
+ } ,
222
+ } ;
223
+ const task : PlistTaskType = {
224
+ task : 'plist' ,
225
+ actions : [
226
+ {
227
+ set : {
228
+ first : {
229
+ second : {
230
+ $delete : true ,
231
+ } ,
232
+ } ,
233
+ } ,
234
+ strategy : 'merge' ,
235
+ } ,
236
+ ] ,
237
+ } ;
238
+
239
+ content = plistTask ( {
240
+ configPath : 'path/to/config' ,
241
+ task : task ,
242
+ content,
243
+ packageName : 'test-package' ,
244
+ } ) ;
245
+ expect ( content . first ) . toEqual ( { } ) ;
246
+ } ) ;
247
+
215
248
it ( 'should skip if condition not met' , ( ) => {
216
249
let content : Record < string , any > = {
217
250
first : {
Original file line number Diff line number Diff line change @@ -39,7 +39,13 @@ export function modifyObject(
39
39
}
40
40
} else {
41
41
/* eslint-disable @typescript-eslint/no-unsafe-return */
42
- const customizer = function ( objValue : any , srcValue : any ) {
42
+ const fieldsToDelete : [ Record < string , any > , string ] [ ] = [ ] ;
43
+ const customizer = function (
44
+ objValue : any ,
45
+ srcValue : any ,
46
+ field : string ,
47
+ objParent : Record < string , any >
48
+ ) {
43
49
if ( strategy == 'merge_concat' ) {
44
50
if ( Array . isArray ( objValue ) && Array . isArray ( srcValue ) ) {
45
51
return objValue . concat ( srcValue ) ;
@@ -61,6 +67,10 @@ export function modifyObject(
61
67
delete srcValue . $append ;
62
68
return objValue ;
63
69
}
70
+ if ( typeof srcValue === 'object' && srcValue . $delete ) {
71
+ fieldsToDelete . push ( [ objParent , field ] ) ;
72
+ return true ;
73
+ }
64
74
if (
65
75
Array . isArray ( objValue ) &&
66
76
typeof srcValue === 'object' &&
@@ -75,6 +85,7 @@ export function modifyObject(
75
85
} ;
76
86
77
87
content = mergeWith ( content , modifier , customizer ) ;
88
+ fieldsToDelete . forEach ( ( [ obj , field ] ) => delete obj [ field ] ) ;
78
89
/* eslint-enable @typescript-eslint/no-unsafe-return */
79
90
}
80
91
return content ;
You can’t perform that action at this time.
0 commit comments