function cfnCustomizer()

in components/base/packages/assembly-tasks/lib/helpers/cfn-merge-helper.js [141:185]


function cfnCustomizer(targetValue, srcValue, key) {
  // if the given cfn key is an array that should not be concatenated
  if (arrayReplaceNotConcatenate(key)) return undefined;

  // Check if the given cfn key may be an array
  if (mayBeArray(key) || _.isArray(targetValue) || _.isArray(srcValue)) {
    const uniqueByIdProp = uniqueById(getIdPropName(key));
    if (_.isArray(targetValue) && _.isArray(srcValue)) {
      // source and target are both arrays
      // For example, the target CFN may have
      // Action:
      //  - someAction
      // and source CFN may have
      // Action:
      //  - someOtherAction
      return uniqueByIdProp(_.concat(targetValue, srcValue));
    }
    if (_.isArray(targetValue) && srcValue && !_.isArray(srcValue)) {
      // target is an array but the source is not
      // For example, the target CFN may have
      // Action:
      //  - someAction
      // and source CFN may have
      // Action: someOtherAction
      targetValue.push(srcValue);
      return uniqueByIdProp(targetValue);
    }
    if (_.isArray(srcValue) && targetValue && !_.isArray(targetValue)) {
      // source value is an array but the target value is not (i.e., inverse of the above case)
      return uniqueByIdProp(_.concat([targetValue], srcValue));
    }
    if (srcValue && !_.isArray(srcValue) && targetValue && !_.isArray(targetValue)) {
      // source and target both are not arrays
      // For example, the target CFN may have
      // Action: someAction
      // and source CFN may have
      // Action: someOtherAction
      if (srcValue === targetValue) {
        return targetValue;
      }
      return uniqueByIdProp([targetValue, srcValue]);
    }
  }
  return undefined;
}