File tree 1 file changed +30
-3
lines changed
1 file changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -191,16 +191,43 @@ function findAppSpecKey(obj, keyName) {
191
191
throw new Error(`AppSpec file must include property '${keyName}'`);
192
192
}
193
193
194
- function undefinedOrNullReplacer(_, value) {
195
- if (value === null || value === undefined) {
194
+ function isEmptyValue(value) {
195
+ if (value === null || value === undefined || value === '') {
196
+ return true;
197
+ }
198
+
199
+ if (Array.isArray(value) && value.length === 0) {
200
+ return true;
201
+ }
202
+
203
+ if (typeof value === 'object' && Object.values(value).length === 0) {
204
+ return true;
205
+ }
206
+
207
+ return false;
208
+ }
209
+
210
+ function emptyValueReplacer(_, value) {
211
+ if (isEmptyValue(value)) {
212
+ return undefined;
213
+ }
214
+
215
+ if (typeof value === 'object') {
216
+ for (var childValue of Object.values(value)) {
217
+ if (!isEmptyValue(childValue)) {
218
+ // the object has at least one non-empty property
219
+ return value;
220
+ }
221
+ }
222
+ // the object has no non-empty property
196
223
return undefined;
197
224
}
198
225
199
226
return value;
200
227
}
201
228
202
229
function cleanNullKeys(obj) {
203
- return JSON.parse(JSON.stringify(obj, undefinedOrNullReplacer ));
230
+ return JSON.parse(JSON.stringify(obj, emptyValueReplacer ));
204
231
}
205
232
206
233
function removeIgnoredAttributes(taskDef) {
You can’t perform that action at this time.
0 commit comments