Skip to content

Commit

Permalink
Merge pull request #445 from electron-userland/fix-version-inference-…
Browse files Browse the repository at this point in the history
…regression

fix version inference regression
  • Loading branch information
zeke authored Aug 11, 2016
2 parents 000c6e7 + ec614bf commit d5f1bd7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

* [CLI] ensure --out has either a string or null value (#442)
* Use `get-package-info` (again) to support finding prebuilt in parent directories (#445)

## [7.5.1] - 2016-08-06

Expand Down
54 changes: 36 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const debug = require('debug')('electron-packager')
const download = require('electron-download')
const extract = require('extract-zip')
const fs = require('fs-extra')
const prop = require('lodash.get')
const getPackageInfo = require('get-package-info')
const metadata = require('./package.json')
const os = require('os')
const path = require('path')
Expand Down Expand Up @@ -49,28 +49,46 @@ function validateList (list, supported, name) {
}

function getNameAndVersion (opts, dir, cb) {
var pkg = require(path.join(dir, 'package.json'))
var props = []
if (!opts.name) props.push(['productName', 'name'])
if (!opts.version) props.push(['dependencies.electron', 'devDependencies.electron'])

// Name and version provided, no need to infer
if (opts.name && opts.version) return cb(null)
if (props.length === 0) return cb(null)

// Infer name from package.json
opts.name = opts.name || prop(pkg, 'productName') || prop(pkg, 'name')

// Infer electron version from package.json
var electronVersion = prop(pkg, 'dependencies.electron') || prop(pkg, 'devDependencies.electron')
var electronPrebuiltVersion = prop(pkg, 'dependencies.electron-prebuilt') || prop(pkg, 'devDependencies.electron-prebuilt')
opts.version = opts.version || electronVersion || electronPrebuiltVersion

if (!electronVersion && !electronPrebuiltVersion) return cb(null)
// Search package.json files to infer name and version from
getPackageInfo(props, dir, function (err, result) {
if (err) {
// `get-package-info` exploded looking for `electron`. Try `electron-prebuilt` instead
props.pop()
props.push(['dependencies.electron-prebuilt', 'devDependencies.electron-prebuilt'])
getPackageInfo(props, dir, function (err, result) {
if (err) return cb(err)
return inferNameAndVersionFromInstalled('electron-prebuilt', opts, result, cb)
})
} else {
return inferNameAndVersionFromInstalled('electron', opts, result, cb)
}
})
}

var packageName = electronVersion ? 'electron' : 'electron-prebuilt'
resolve(packageName, {basedir: dir}, function (err, res, pkg) {
if (err) return cb(err)
debug('Inferring target Electron version from `' + packageName + '` dependency or devDependency in package.json')
opts.version = pkg.version
function inferNameAndVersionFromInstalled (packageName, opts, result, cb) {
if (result.values.productName) {
debug('Inferring application name from productName or name in package.json')
opts.name = result.values.productName
}
if (result.values[`dependencies.${packageName}`]) {
resolve(packageName, {
basedir: path.dirname(result.source[`dependencies.${packageName}`].src)
}, function (err, res, pkg) {
if (err) return cb(err)
debug(`Inferring target Electron version from ${packageName} dependency or devDependency in package.json`)
opts.version = pkg.version
return cb(null)
})
} else {
return cb(null)
})
}
}

function createSeries (opts, archs, platforms) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"electron-osx-sign": "^0.3.0",
"extract-zip": "^1.0.3",
"fs-extra": "^0.30.0",
"lodash.get": "^4.4.1",
"get-package-info": "^0.1.0",
"minimist": "^1.1.1",
"plist": "^1.1.0",
"rcedit": "^0.5.1",
Expand Down

0 comments on commit d5f1bd7

Please sign in to comment.