Skip to content

Commit

Permalink
fix(cli): merge config arrays via overwrite instead of concatenate
Browse files Browse the repository at this point in the history
BREAKING CHANGE: previously, we concatenated arrays, which is unlikely to be intended
  • Loading branch information
bmuenzenmeyer committed Aug 23, 2019
1 parent d8f5e12 commit 42e5f7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 9 additions & 2 deletions packages/cli/bin/cli-actions/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const writeJsonAsync = require('../utils').writeJsonAsync;

const defaultPatternlabConfig = patternlab.getDefaultConfig();

// https://github.com/TehShrike/deepmerge#overwrite-array
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;

const init = options =>
wrapAsync(function*() {
const sourceDir = 'source';
Expand Down Expand Up @@ -52,7 +55,9 @@ const init = options =>
projectDir
); // 3.1
if (newConf) {
patternlabConfig = merge(patternlabConfig, newConf); // 3.2
patternlabConfig = merge(patternlabConfig, newConf, {
arrayMerge: overwriteMerge,
}); // 3.2
}
spinner.succeed(`⊙ patternlab → Installed edition: ${edition}`);
}
Expand All @@ -65,7 +70,9 @@ const init = options =>
);
spinner.succeed(`⊙ patternlab → Installed starterkit: ${starterkit}`);
if (starterkitConfig) {
patternlabConfig = merge(patternlabConfig, starterkitConfig);
patternlabConfig = merge(patternlabConfig, starterkitConfig, {
arrayMerge: overwriteMerge,
});
}
} // 4
yield writeJsonAsync(
Expand Down
7 changes: 5 additions & 2 deletions packages/cli/bin/install-edition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const {
getJSONKey,
} = require('./utils');

// https://github.com/TehShrike/deepmerge#overwrite-array
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;

const installEdition = (edition, config, projectDir) => {
const pkg = require(path.resolve(projectDir, 'package.json'));

Expand Down Expand Up @@ -68,7 +71,7 @@ const installEdition = (edition, config, projectDir) => {
path.resolve(sourceDir, '../', 'helpers/test.js')
);

config = merge(config, editionConfig);
config = merge(config, editionConfig, { arrayMerge: overwriteMerge });
break;
}
// 4.3
Expand All @@ -91,7 +94,7 @@ const installEdition = (edition, config, projectDir) => {
path.resolve(sourceDir, '../', 'alter-twig.php')
);

config = merge(config, editionConfig);
config = merge(config, editionConfig, { arrayMerge: overwriteMerge });
break;
}
}
Expand Down

0 comments on commit 42e5f7b

Please sign in to comment.