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

Breaks if no package.json is present #6

Closed
wants to merge 3 commits into from

Conversation

jimbuck
Copy link
Contributor

@jimbuck jimbuck commented Jul 11, 2016

If there is no package.json available then the path is null and you can't stop it from breaking.

Even if you manually provide the projectName in options it will still break. This adds a few simple checks to prevent it from blowing up when you do provide the name.

I've also added an appropriate test, which properly fails when run without the changes to index.js and correctly passes once added.

opts = Object.assign({projectName: require(pkgPath).name}, opts);
}

if (!opts || !opts.projectName) {
throw new Error('Project name could not be inferred. Please specify the `projectName` option.');
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would rather do:

const pkgPath = pkgUp.sync(parentDir);

opts = Object.assign({
    // if the package.json was not found, avoid breaking with `require(null)`.
    projectName: pkgPath && require(pkgPath).name
}, opts);

if (!opts.projectName) {
    throw new Error('Project name could not be inferred. Please specify the `projectName` option.');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tons of ways to handle this null value. I will update it to match yours, nice and clean.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, totally subjective. Both work equally fine :)

@sindresorhus
Copy link
Owner

Looks good.

Just curious, why is there no package.json available?

@sindresorhus
Copy link
Owner

Can you fix the merge conflict? Sorry, I had a local fix that I pushed by accident now.

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 11, 2016

This is limited to select installs of Electron apps (depending on how they are packaged) but I use this one by @szwacz. I'm not sure if there are any other downsides, but I figured an unavoidable exception like this could be a problem for others as well.

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 11, 2016

And no worries about the merge conflict. I'll fix that once I get home (done at the office for today).

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 11, 2016

I just noticed the test you added still has .only on it. Do you want to fix that before I merge? Or you want me to take care of that right now?

@sindresorhus
Copy link
Owner

Ugh, not again. Fixed in master. Thanks for noticing.

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 12, 2016

No problem, happens to the best of us!

sindresorhus pushed a commit that referenced this pull request Jul 12, 2016
If there is no `package.json` available then the path is `null` and you can't stop it from breaking.

Even if you manually provide the `projectName` in options it will still break. This adds a few simple checks to prevent it from blowing up when you do provide the name.

I've also added an appropriate test, which properly fails when run without the changes to `index.js` and correctly passes once added.

Closes #6
@sindresorhus
Copy link
Owner

Thank you :)

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 12, 2016

My pleasure!

Quick (potentially silly) question: This does not say "merged", but instead closed with a commit that "I committed with you". Is that the result of Github squashing the commits? Or something you did to keep things clean? Next time should I have squashed my commits first?

@SamVerschueren
Copy link
Contributor

GitHub now has a button to squash and merge a PR so no need in doing that yourself, although you can off course :).

Not sure if Sindre uses the button though. Before there was a button to squash, he did everything "manually".

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 12, 2016

Hey @SamVerschueren, I've seen that but have yet to use it. I'm guessing he did things manually, hence the "closed" status as opposed to Github's "merged" status. Thanks for the insight!

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 12, 2016

Oh, and @sindresorhus, may I recommend a bump to electron-config, so that it can have the latest updates as well ("conf": "^0.10.0" restricts it to 0.10.*).

Thank you!

@sindresorhus
Copy link
Owner

I've seen that but have yet to use it. I'm guessing he did things manually, hence the "closed" status as opposed to Github's "merged" status. Thanks for the insight!

Yeah. I did it manually as I wanted to tweak something on merge. I could probably have used squash and then force pushed, but old habits die hard.

may I recommend a bump to electron-config

Done :)

@jimbuck
Copy link
Contributor Author

jimbuck commented Jul 12, 2016

Thank You!

:]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants