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

Allow opn & update-notifier CLI deps to be optional. #2150

Merged
merged 5 commits into from
May 4, 2017
Merged

Conversation

paulirish
Copy link
Member

No description provided.

Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

Some spacing n stuff.

@@ -0,0 +1,50 @@
/**
* @license
* Copyright 2016 Google Inc. All rights reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

2017

export let opn = () => {
function shim(str: String, obj: Object) {
console.error('module `opn` not installed. Not opening browser.');
return [str, obj]
Copy link
Contributor

Choose a reason for hiding this comment

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

;

export let updateNotifier = () => {
function shim(obj: Object) {
console.error('module `update-notifier` not installed. Not checking for new version.');
return { notify: () => obj };
Copy link
Contributor

Choose a reason for hiding this comment

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

{notify: () => obj}

const pkg = require('../package.json');

// accept noop modules for these, so the real dependency is optional.
const opn = require('./shim-modules').opn();
Copy link
Member

Choose a reason for hiding this comment

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

should we do this or just try/catch their assignment and guard their usage with an if (opn) and if (updateNotifier)? They're used so rarely it seems easy to do the second option

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking the same, but we may have more of these in the future. It might be nice to keep our codebase clean rather than littering if with a bunch of forks.

Copy link
Member

Choose a reason for hiding this comment

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

it's just that for these two it's literally just

if (updateNotifier) {
  updateNotifier({pkg}).notify();
}

and

if (flags.view && opn) {
  opn(outputPath, {wait: false});
}

the new thing has logged warnings, which is nice, but it is a lot more code to get that same effect :)

Copy link
Member Author

Choose a reason for hiding this comment

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

the try/catch in the same file is really nasty and i really preferred moving it out into shim-modules.

so i think it's worth keeping that.

However, i'd be fine with guarding the calls so we don't need to mock their API.

Copy link
Member Author

Choose a reason for hiding this comment

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

i'd be fine with guarding the calls so we don't need to mock their API.

done

Copy link
Member Author

Choose a reason for hiding this comment

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

i'd be fine with guarding the calls so we don't need to mock their API.

done

undone. i think its worth the overhead to make sure silent failures aren't silent.

const pkg = require('../package.json');

// accept noop modules for these, so the real dependency is optional.
const opn = require('./shim-modules').opn();
Copy link
Collaborator

Choose a reason for hiding this comment

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

oooooh not literal optionalDependencies just handle them optionally :) I gotcha now

is there any benefit to having these be individual functions vs just inlining the exports? feels a little weird as functions

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

lgtm

const pkg = require('../package.json');

// accept noop modules for these, so the real dependency is optional.
const opn = require('./shim-modules').opn;
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: really up our es imports cred and do import {opn, updateNotifier} from './shim-modules'?

};
}

export {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👌 beautiful

@paulirish paulirish merged commit b2ccdfc into master May 4, 2017
@paulirish paulirish deleted the trycatchcli branch May 4, 2017 21:52
paulirish added a commit to paulirish/lighthouse that referenced this pull request May 5, 2017
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.

None yet

4 participants