-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Update get-package-info #505
Conversation
This updates `get-package-info` to v1.0.0, which includes more helpful errors when failing to find all info requested. This lets us give better error messages, as well as ignore missing props for optional options.
} | ||
}) | ||
|
||
err.message = messages.join('\n') + '\n' + err.message |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
original error message
The one that's sent by get-package-info
? If so, perhaps it should be printed in a debug()
message.
err.message = messages.join('\n') + '\n' + err.message | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming app-version
is not a required option.
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.
app-version
isn't required. From docs/api.md
:
If neither [
app-version
option norversion
frompackage.json
] are provided, the version of Electron will be used.
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.
In general this looks good. However, there are some style nits (we use Node 4+ compatible ES6) and some new code needs to be covered by tests.
if (missingProps.filter(prop => requiredProps.find(reqProp => prop === reqProp)).length !== 0) { | ||
var messages = missingProps.map(function (missingProp) { | ||
missingProp = Array.isArray(missingProp) ? missingProp[0] : missingProp | ||
if (missingProp === 'productName') { |
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.
Looks like you need to add a test for this conditional.
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 comment
The 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 | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
app-version
isn't required. From docs/api.md
:
If neither [
app-version
option norversion
frompackage.json
] are provided, the version of Electron will be used.
} | ||
}) | ||
|
||
err.message = messages.join('\n') + '\n' + err.message |
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.
original error message
The one that's sent by get-package-info
? If so, perhaps it should be printed in a debug()
message.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this debug statement more specific now with result.source
?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this debug statement more specific now with result.source
?
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 comment
The reason will be displayed to describe this comment to others. Learn more.
let
|
||
// Callback w/ error if there are required props that are missing | ||
if (missingProps.filter(prop => requiredProps.find(reqProp => prop === reqProp)).length !== 0) { | ||
var messages = missingProps.map(function (missingProp) { |
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.
Use let
+ fat arrow syntax here?
// Callback w/ error if there are required props that are missing | ||
if (missingProps.filter(prop => requiredProps.find(reqProp => prop === reqProp)).length !== 0) { | ||
var messages = missingProps.map(function (missingProp) { | ||
missingProp = Array.isArray(missingProp) ? missingProp[0] : missingProp |
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.
Didn't you already do this earlier when declaring missingProps
?
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.
whoops. i really shouldn't make PRs at midnight on a work day
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this debug statement more specific now with result.source
?
Made changes from code review input. Looked into the test coverage, and it looks like the issue is stemming from the reason why @zeke opened #461 in the first place: it's picking up values from @malept's suggestions:
The issue with option 2 is that the feature of looking at parent package.json's is a required feature for project structures where app code is in a subdirectory with its own package.json. The idea is that the app package.json would have the I'm not so sure the issue in option 1 of having a package.json above the temp directory is going to be a huge issue. That seems like it'd be an extremely rare occurrence. If we need to, we can explicitly check if there is a stray package.json and fail the test w/ an informative error msg. |
I'm OK with you implementing option 1 in the way you describe. |
☝️ great point.
👍 |
let fixtureDir = path.join(__dirname, 'fixtures', fixtureSubdir) | ||
waterfall([ | ||
cb => fs.emptyDir(tmpdir, cb), | ||
(cb1, cb2) => fs.copy(fixtureDir, tmpdir, cb2 || cb1), // inconsistent cb arguments from fs.emptyDir |
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 is weird b/c fs.emptyDir doesn't return a consistent # of arguments, depending on whether the directory already exists or not. I've made an issue on the fs-extra
repo but this is the workaround for now.
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.
I've made an issue on the
fs-extra
repo
For reference: jprichardson/node-fs-extra#287
love too have tests fail at random on CI I've run the failing tests on loop on my laptop but I can't figure out what's causing those rare failures. Otherwise, the code is ready to be re-reviewed. Hopefully something pops out during review that tells us about the failures. |
I believe landing this is necessary to fix #513 |
Also highly doubtful that this module should be used at all. |
Why is that? Do you have an alternative proposal? |
So using this is the higher-level of it's upstream dependencies which are already high level of try-catch-ed |
If you wanna move the logic from get-package-info into electron-packager, that's fine by me. I initially made it a separate package so it wouldn't muck up the code here, and could be unit tested as well as tested thru electron-packager's integration tests. (Also I could have sworn the tests were failing before? I don't know how to avoid the coverage decrease, since it's the line that's triggered on some kind of I/O failure looking for package.jsons. |
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.
@rahatarmanahmed sorry about the delay, I've been busy.
If you wanna move the logic from get-package-info into electron-packager, that's fine by me.
I have no intention of moving the logic into Electron Packager. If it's not specific to how Electron Packager works, it shouldn't go in there.
Also I could have sworn the tests were failing before?
I reran the test. That's probably a bad sign about how inferring works that it times out intermittently.
getPackageInfo(props, dir, function (err, result) { | ||
if (err) return cb(err) | ||
return inferNameAndVersionFromInstalled('electron-prebuilt', opts, result, cb) | ||
getPackageInfo(props, dir, (err, result) => { |
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?
result = err.result | ||
} | ||
} else if (err) { | ||
return cb(err) |
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.
Would an IO error include an invalid package.json
? Just trying to think of ways to test this line.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
let
(I need to add ES6 rules to eslint...)
} | ||
|
||
function createInferMissingVersionTest (opts) { | ||
return function (t) { |
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.
Should use fat arrow function syntax when possible.
@malept moved the electron Good call on the invalid Tests seem to be failing due to some eslint peerdependency business, tho... 😞 |
WTF. I wanted to add Node 7 to CI anyway, I guess I need to mess with other dependencies too. |
Can't upgrade CI to use Node 7 until next week (blocked on AppVeyor). However, I upgraded |
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.
Apart from the refactors, 👍 looks good.
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 comment
The 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.
|
||
// Callback w/ error if there are required props that are missing | ||
if (missingProps.filter(prop => requiredProps.find(reqProp => prop === reqProp)).length !== 0) { | ||
let messages = missingProps.map(missingProp => { |
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.
Perhaps extract the map function into a top-level function named errorMessageForProperty
?
greeeeeeeeen 🤑 |
Thanks for persevering, @rahatarmanahmed 👊 |
Have you read the section in CONTRIBUTING.md about pull requests? Yes
Summarize your changes:
As discussed in #461, this updates
get-package-info
to v1.0.0, which includes more helpful errors when failing to find all info requested. This lets us give better error messages, as well as ignore missing props for optional options.Are your changes appropriately documented? N/A
Do your changes have sufficient test coverage? Not sure yet.
Does the testsuite pass successfully on your local machine? Yes