Skip to content

Commit

Permalink
fix: let implementing modules specify revision fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
malept committed May 24, 2019
1 parent 9410835 commit 9a3d720
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

const getHomePage = require('./gethomepage')

module.exports = function getDefaultsFromPackageJSON (pkg) {
/**
* Generate default configuration values from the given parsed `package.json`.
*
* @param pkg - the parsed `package.json` file
* @param fallbacks (optional) - fallback default value for certain options, currently:
* * `revision`
*/
module.exports = function getDefaultsFromPackageJSON (pkg, fallbacks = {}) {
return {
arch: undefined,
bin: pkg.name || 'electron',
Expand All @@ -19,6 +26,6 @@ module.exports = function getDefaultsFromPackageJSON (pkg) {
name: pkg.name || 'electron',
productDescription: pkg.productDescription || pkg.description,
productName: pkg.productName || pkg.name,
revision: pkg.revision || '1'
revision: pkg.revision || fallbacks.revision
}
}
7 changes: 6 additions & 1 deletion test/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('empty package.json', t => {
name: 'electron',
productDescription: undefined,
productName: undefined,
revision: '1'
revision: undefined
})
})

Expand All @@ -46,6 +46,11 @@ test('description and product description specified', t => {
t.is(defaults.productDescription, 'Product')
})

test('revision not specified with a fallback specified', t => {
const { revision } = getDefaultsFromPackageJSON({}, { revision: '1' })
t.is(revision, '1')
})

test('revision specified', t => {
const defaults = getDefaultsFromPackageJSON({ revision: '7' })
t.is(defaults.revision, '7')
Expand Down

0 comments on commit 9a3d720

Please sign in to comment.