Skip to content

Commit

Permalink
Update deepmerge
Browse files Browse the repository at this point in the history
  • Loading branch information
matatk committed Nov 1, 2017
1 parent 98554df commit 35bf647
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
12 changes: 9 additions & 3 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
"addons-linter": "~0.28",
"archiver": "~2.1",
"chalk": "~2.3",
"deepmerge": "~1.5",
"deepmerge": "~2.0",
"eslint": "~4.10",
"fs-extra": "~4.0",
"is-mergeable-object": "~1.1",
"jsdom": "~11.3",
"one-svg-to-many-sized-pngs": "github:matatk/one-svg-to-many-sized-pngs",
"rimraf": "~2.6",
Expand Down
25 changes: 23 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
const path = require('path')
const fse = require('fs-extra')
const chalk = require('chalk')
const deepmerge = require('deepmerge')
const merge = require('deepmerge')
const archiver = require('archiver')
const oneSvgToManySizedPngs = require('one-svg-to-many-sized-pngs')
const packageJson = require(path.join('..', 'package.json'))
// For restoring pre-2.0.0 deepmerge behaviour...
const isMergeableObject = require('is-mergeable-object')
const emptyTarget = value => Array.isArray(value) ? [] : {}
const clone = (value, options) => merge(emptyTarget(value), value, options)

const extName = packageJson.name
const extVersion = packageJson.version
Expand Down Expand Up @@ -125,9 +129,26 @@ function mergeManifest(browser) {
const commonJson = require(common)
const extraJson = require(extra)

function oldArrayMerge(target, source, optionsArgument) {
const destination = target.slice()

source.forEach(function(e, i) {
if (typeof destination[i] === 'undefined') {
const cloneRequested = !optionsArgument || optionsArgument.clone !== false
const shouldClone = cloneRequested && isMergeableObject(e)
destination[i] = shouldClone ? clone(e, optionsArgument) : e
} else if (isMergeableObject(e)) {
destination[i] = merge(target[i], e, optionsArgument)
} else if (target.indexOf(e) === -1) {
destination.push(e)
}
})
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 = deepmerge(extraJson, commonJson)
const merged = merge(extraJson, commonJson, { arrayMerge: oldArrayMerge })
merged.version = extVersion
fse.writeFileSync(
path.join(pathToBuild(browser), 'manifest.json'),
Expand Down

0 comments on commit 35bf647

Please sign in to comment.