Skip to content

Commit 91240fe

Browse files
committed
Add a function to merge user specified dependencies into default dependencies
Based on electron-userland/electron-installer-redhat#98
1 parent 233ac31 commit 91240fe

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/dependencies.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const _ = require('lodash')
34
const semver = require('semver')
45

56
/**
@@ -56,5 +57,23 @@ module.exports = {
5657
getGConfDepends: getGConfDepends,
5758
getGTKDepends: getGTKDepends,
5859
getTrashDepends: getTrashDepends,
59-
getUUIDDepends: getUUIDDepends
60+
getUUIDDepends: getUUIDDepends,
61+
62+
/**
63+
* Merge the user specified dependencies (from either the API or the CLI) with the respective
64+
* default dependencies, given the `dependencyKey`.
65+
*
66+
* @param {object} data - the user-specified data
67+
* @param {string} dependencyKey - the dependency type (e.g., `depends` for Debian
68+
* runtime dependencies)
69+
* @param {object} defaults - the default options for the installer module
70+
*
71+
*/
72+
mergeUserSpecified: function mergeUserSpecified (data, dependencyKey, defaults) {
73+
if (data.options) { // options passed programmatically
74+
return _.union(defaults[dependencyKey], data.options[dependencyKey])
75+
} else { // options passed via command-line
76+
return _.union(defaults[dependencyKey], data[dependencyKey])
77+
}
78+
}
6079
}

test/dependencies.js

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const _ = require('lodash')
34
const dependencies = require('../src/dependencies')
45
const test = require('ava')
56

@@ -68,3 +69,22 @@ test('getUUIDDepends: returns nothing pre-4.0', t => {
6869
test('getUUIDDepends: returns uuid as of 4.0', t => {
6970
t.is(dependencies.getUUIDDepends('4.0.0', dependencyMap)[0], dependencyMap.uuid)
7071
})
72+
73+
function testMergeUserSpecified (t, dataPath) {
74+
const defaults = {
75+
dependencies: ['lsb', 'libXScrnSaver']
76+
}
77+
const data = _.set({}, dataPath, ['dbus', 'dbus', 'lsb'])
78+
79+
const actual = dependencies.mergeUserSpecified(data, 'dependencies', defaults)
80+
actual.sort()
81+
t.deepEqual(actual, ['dbus', 'libXScrnSaver', 'lsb'])
82+
}
83+
84+
test('mergeUserSpecified with API options', t => {
85+
testMergeUserSpecified(t, 'options.dependencies')
86+
})
87+
88+
test('mergeUserSpecified with CLI options', t => {
89+
testMergeUserSpecified(t, 'dependencies')
90+
})

0 commit comments

Comments
 (0)