Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: let implementing modules specify revision fallbacks #29

Merged
merged 2 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {object} pkg - the parsed `package.json` file
* @param {?object} fallbacks - 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