Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 1ac72c7

Browse files
blackbaud-brandonhareBobby Earl
authored and
Bobby Earl
committed
Updated merge library, added tests for overrides and recursive merging. (#288)
* Updated merge library, added tests for overrides and recursive merging. * Removed console logs. * Replaced webpack merge with lodash merge. * Updated test to account for arrays * Updated package to be exact.
1 parent 10698dc commit 1ac72c7

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

config/sky-pages/sky-pages.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
const fs = require('fs-extra');
55
const path = require('path');
6-
const merge = require('merge');
6+
const merge = require('lodash.merge');
77
const logger = require('../../utils/logger');
88

99
/**
@@ -59,7 +59,7 @@ module.exports = {
5959
hierarchy.forEach(file => {
6060
if (fs.existsSync(file.filePath)) {
6161
logger.info(`Merging ${file.fileName}`);
62-
merge.recursive(skyuxConfig, readConfig(file.filePath));
62+
skyuxConfig = merge(skyuxConfig, readConfig(file.filePath));
6363
}
6464
});
6565

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"karma-sourcemap-loader": "0.3.7",
7474
"karma-webpack": "2.0.3",
7575
"loader-utils": "1.1.0",
76+
"lodash.merge": "4.6.0",
7677
"merge": "1.2.0",
7778
"ngc-webpack": "3.0.0",
7879
"node-sass": "4.5.3",

test/config-sky-pages.spec.js

+23
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ describe('config sky-pages', () => {
6767
if (!isSpaDirectory && isDefaultConfig) {
6868
config.a = 1; // Merged through entire process
6969
config.z = 9; // Unique to this file
70+
config.o = {
71+
keyOne: 'keyOne',
72+
keyTwo: {
73+
nestedTwo: 'nestedTwo'
74+
}
75+
}; // Testing recursive merge
76+
config.n = {
77+
toDelete: true
78+
}; // Testing merge override
79+
config.arr = ['stringOne', 'stringTwo'] // Testing array values not concatenated
7080

7181
// Asking for builder's skyuxconfig.build.json
7282
} else if (!isSpaDirectory && isCommandConfig) {
@@ -87,6 +97,14 @@ describe('config sky-pages', () => {
8797
config.b = 3;
8898
config.c = 2;
8999
config.w = 6; // Unique to this file
100+
config.o = {
101+
keyOne: 'changed',
102+
keyTwo: {
103+
nestedTwo: 'changed'
104+
}
105+
};
106+
config.n = null;
107+
config.arr = ['stringOne', 'stringThree'];
90108
}
91109

92110
return config;
@@ -106,6 +124,11 @@ describe('config sky-pages', () => {
106124
expect(config.x).toEqual(7);
107125
expect(config.y).toEqual(8);
108126
expect(config.z).toEqual(9);
127+
expect(config.o.keyOne).toEqual('changed');
128+
expect(config.o.keyTwo.nestedTwo).toEqual('changed');
129+
expect(config.n).toEqual(null);
130+
expect(config.arr.length).toBe(2);
131+
expect(config.arr).not.toContain('stringTwo');
109132

110133
expect(logger.info.calls.allArgs()).toEqual([
111134
['Merging App Builder skyuxconfig.json'],

0 commit comments

Comments
 (0)