From 6b4fdb8fffa2ccbb8c57702f6e1a268f3f0e16b2 Mon Sep 17 00:00:00 2001 From: RameshChoudhary Date: Tue, 15 Mar 2016 16:50:47 +0530 Subject: [PATCH] Modified mergeArrays function to accept arrays of different length. Modified mergeArrays function to accept arrays of different length and merge the content of arrays. --- lib/config-loader.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/config-loader.js b/lib/config-loader.js index c2baf32..fb99378 100644 --- a/lib/config-loader.js +++ b/lib/config-loader.js @@ -2,7 +2,7 @@ var fs = require('fs'); var path = require('path'); var debug = require('debug')('loopback:boot:config-loader'); var assert = require('assert'); - +var _=require('lodash'); var ConfigLoader = exports; /** @@ -276,8 +276,7 @@ function mergeSingleItemOrProperty(target, config, key, fullKey) { function mergeArrays(target, config, keyPrefix) { if (target.length !== config.length) { - return 'Cannot merge array values of different length' + - ' for the option `' + keyPrefix + '`.'; + return mergeArraysDiffLength(target, config); } // Use for(;;) to iterate over undefined items, for(in) would skip them. @@ -290,6 +289,12 @@ function mergeArrays(target, config, keyPrefix) { return null; // no error } +function mergeArraysDiffLength(target, config) { + var newTarget = _.cloneDeep(target, true); + Array.prototype.splice.apply(target, [0, target.length].concat(_.union(newTarget, config))); +} + + function hasCompatibleType(origValue, newValue) { if (origValue === null || origValue === undefined) return true;