File tree Expand file tree Collapse file tree 1 file changed +30
-3
lines changed Expand file tree Collapse file tree 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) {
191191 throw new Error(`AppSpec file must include property '${keyName}'`);
192192}
193193
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
196223 return undefined;
197224 }
198225
199226 return value;
200227}
201228
202229function cleanNullKeys(obj) {
203- return JSON.parse(JSON.stringify(obj, undefinedOrNullReplacer ));
230+ return JSON.parse(JSON.stringify(obj, emptyValueReplacer ));
204231}
205232
206233function removeIgnoredAttributes(taskDef) {
You can’t perform that action at this time.
0 commit comments