-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Update get-package-info #505
Changes from 1 commit
be3385d
e5f10ee
8f9427e
d735ad2
72ab0e7
a6a4616
2ad8aae
7853847
96bddad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,50 +23,77 @@ function getMetadata (opts, dir, cb) { | |
var props = [] | ||
if (!opts.name) props.push(['productName', 'name']) | ||
if (!opts['app-version']) props.push('version') | ||
if (!opts.version) props.push(['dependencies.electron', 'devDependencies.electron']) | ||
if (!opts.version) { | ||
props.push([ | ||
'dependencies.electron', | ||
'devDependencies.electron', | ||
'dependencies.electron-prebuilt', | ||
'devDependencies.electron-prebuilt' | ||
]) | ||
} | ||
|
||
// Name and version provided, no need to infer | ||
if (props.length === 0) 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) | ||
getPackageInfo(props, dir, (err, result) => { | ||
if (err && err.missingProps) { | ||
var requiredProps = ['productName', 'dependencies.electron'] | ||
var missingProps = err.missingProps.map(prop => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return Array.isArray(prop) ? prop[0] : prop | ||
}) | ||
} else { | ||
return inferNameAndVersionFromInstalled('electron', opts, result, cb) | ||
|
||
// Callback w/ error if there are required props that are missing | ||
if (missingProps.filter(prop => requiredProps.find(reqProp => prop === reqProp)).length !== 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd extract the conditional into a method for readability (and also lets you get rid of the comment. |
||
var messages = missingProps.map(function (missingProp) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
missingProp = Array.isArray(missingProp) ? missingProp[0] : missingProp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't you already do this earlier when declaring There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whoops. i really shouldn't make PRs at midnight on a work day |
||
if (missingProp === 'productName') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like you need to add a test for this conditional. |
||
return 'Unable to determine application name. Please specify an application name\n\n' + | ||
'For more information, please see\n' + | ||
'https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#name\n' | ||
} | ||
|
||
if (missingProp === 'dependencies.electron') { | ||
return 'Unable to determine Electron version. Please specify an Electron version\n\n' + | ||
'For more information, please see\n' + | ||
'https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#version\n' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if these error messages could be DRY'd up somehow. |
||
} | ||
}) | ||
|
||
err.message = messages.join('\n') + '\n' + err.message | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May want to hide original error message, since the message we add should be descriptive enough without it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The one that's sent by |
||
return cb(err) | ||
} else { | ||
// Missing props not required, can continue w/ partial result | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
result = err.result | ||
} | ||
} else if (err) { | ||
return cb(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would an IO error include an invalid |
||
} | ||
}) | ||
} | ||
|
||
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.productName) { | ||
debug('Inferring application name from productName or name in package.json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this debug statement more specific now with |
||
opts.name = result.values.productName | ||
} | ||
|
||
if (result.values.version) { | ||
debug('Inferring app-version from version in package.json') | ||
opts['app-version'] = result.values.version | ||
} | ||
if (result.values.version) { | ||
debug('Inferring app-version from version in package.json') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this debug statement more specific now with |
||
opts['app-version'] = result.values.version | ||
} | ||
|
||
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 | ||
if (result.values[`dependencies.electron`]) { | ||
var packageName = result.source[`dependencies.electron`].prop.split('.')[1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
resolve(packageName, { | ||
basedir: path.dirname(result.source[`dependencies.electron`].src) | ||
}, function (err, res, pkg) { | ||
if (err) return cb(err) | ||
debug(`Inferring target Electron version from ${packageName} dependency or devDependency in package.json`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this debug statement more specific now with |
||
opts.version = pkg.version | ||
return cb(null) | ||
}) | ||
} else { | ||
return cb(null) | ||
}) | ||
} else { | ||
return cb(null) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
function createSeries (opts, archs, platforms) { | ||
|
@@ -198,15 +225,7 @@ module.exports = function packager (opts, cb) { | |
debug(`Target Architectures: ${archs.join(', ')}`) | ||
|
||
getMetadata(opts, path.resolve(process.cwd(), opts.dir) || process.cwd(), function (err) { | ||
if (err) { | ||
err.message = 'Unable to determine application name or Electron version. ' + | ||
'Please specify an application name and Electron version.\n\n' + | ||
'For more infomation, please see \n' + | ||
'https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#name or \n' + | ||
'https://github.com/electron-userland/electron-packager/blob/master/docs/api.md#version\n\n' + | ||
err.message | ||
return cb(err) | ||
} | ||
if (err) return cb(err) | ||
|
||
debug(`Application name: ${opts.name}`) | ||
debug(`Target Electron version: ${opts.version}`) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function has gotten rather large. Can it be split up?