Skip to content

Commit

Permalink
build: Use additional deepmerge convenience function (#326)
Browse files Browse the repository at this point in the history
This simplifies the "combine" array merging technique.

Fixes #324
  • Loading branch information
matatk authored Dec 15, 2019
1 parent 0017bcb commit 8bc2e91
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"archiver-promise": "~1.0",
"chalk": "~2.4",
"conventional-changelog-moulded-angular": "github:matatk/conventional-changelog-moulded-angular#0.2.0",
"deepmerge": "~3.2",
"deepmerge": "~4.2",
"eslint": "~5.16",
"fs-extra": "~7.0",
"husky": "~1.3",
Expand Down
25 changes: 9 additions & 16 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,31 +367,24 @@ function mergeManifest(browser) {
const commonJson = require(common)
const extraJson = require(extra)

// For pre-2.0.0 deepmerge behaviour...
// https://github.com/KyleAMathews/deepmerge#examples (and scroll a bit)
const emptyTarget = value => Array.isArray(value) ? [] : {}
const clone = (value, options) => merge(emptyTarget(value), value, options)

function legacyArrayMerge(target, source, options) {
function combineMerge(target, source, options) {
const destination = target.slice()

source.forEach(function(e, i) {
if (typeof destination[i] === 'undefined') {
const cloneRequested = options.clone !== false
const shouldClone = cloneRequested && options.isMergeableObject(e)
destination[i] = shouldClone ? clone(e, options) : e
} else if (options.isMergeableObject(e)) {
destination[i] = merge(target[i], e, options)
} else if (target.indexOf(e) === -1) {
destination.push(e)
source.forEach((item, index) => {
if (typeof destination[index] === 'undefined') {
destination[index] = options.cloneUnlessOtherwiseSpecified(item, options)
} else if (options.isMergeableObject(item)) {
destination[index] = merge(target[index], item, options)
} else if (target.indexOf(item) === -1) {
destination.push(item)
}
})
return destination
}

// Merging this way 'round just happens to make it so that, when merging
// the arrays of scripts to include, the compatibility one comes first.
const merged = merge(extraJson, commonJson, { arrayMerge: legacyArrayMerge })
const merged = merge(extraJson, commonJson, { arrayMerge: combineMerge })
merged.version = extVersion
fs.writeFileSync(
path.join(pathToBuild(browser), 'manifest.json'),
Expand Down

0 comments on commit 8bc2e91

Please sign in to comment.