-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat(open): modify devServer.options.open
to take an object
#1770
feat(open): modify devServer.options.open
to take an object
#1770
Conversation
ad6d8c7
to
7b0e401
Compare
Codecov Report
@@ Coverage Diff @@
## master #1770 +/- ##
==========================================
+ Coverage 92.42% 92.79% +0.36%
==========================================
Files 25 25
Lines 964 971 +7
Branches 307 309 +2
==========================================
+ Hits 891 901 +10
+ Misses 70 67 -3
Partials 3 3
Continue to review full report at Codecov.
|
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.
Need tests.
7b0e401
to
ec7cb84
Compare
Hey @hiroppy. I added some tests for the config, but I didn't see anything in there testing the Thanks for helping maintain such an awesome project!!! |
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 very good, we need tests, just mock opn
package and check add arguments were passed in constructor of opn
/cc @dangreenisrael friendly ping |
Hey @evilebottnawi. We wound up not auto-open in the end so I'm not able to do it at work, and I don't have much extra time right now (I've got a 14 month old). That said, my plan is to try to get the tests written soon so this can land. Sorry for the delays |
const log = { | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
}; |
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 use just.spyOn
to better reading tests, thanks!
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.
We need to create log
anyway. Would you prefer:
const log = {
info: () => {}
warn: () => {}
}
const infoSpy = jest.spyOn(log, 'info')
const warnSpy = jest.spyOn(log, 'warn')
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.
???
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.
One note and we can merge, thanks for PR
lib/utils/status.js
Outdated
@@ -46,7 +46,7 @@ function status(uri, options, log, useColor) { | |||
let openOptions = {}; | |||
let openMessage = 'Unable to open browser'; | |||
|
|||
if (typeof options.open === 'string') { | |||
if (typeof options.open === 'string' || Array.isArray(options.open)) { |
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.
hm, why is array, based on docs https://github.com/sindresorhus/open it should be object
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.
Options is an object, which takes app
. App takes either a string or an array. https://www.npmjs.com/package/open#usage . This keeps with the existing API of this project, passing only the app
value for open
in options.
i.e:
{
open: "google chrome"
}
and
{
open: ['google chrome', '--incognito']
}
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.
Developers can want to use other options example: {wait: true}
, also in future package can accept more arguments
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.
Good call @evilebottnawi
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 should have some time tomorrow night to work on this again
lib/options.json
Outdated
{ | ||
"type": "array", | ||
"items": { | ||
"type": "string" |
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.
items, can be not only strings
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.
According to this, I believe they are only string https://www.npmjs.com/package/open#usage
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.
{wait: true}
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 think we should do this in other way.
- Let's make
open
will beBoolean
,String
orObject
if (Object.isObject(this.open)) {
openOptions = Object.assign({}, options.open);
}
I'm pretty sure the value of open's |
2096bc1
to
7b0560b
Compare
@evilebottnawi Based on what you requested (or my understanding of it), I made the following update: Allow for 3 options to pass as options.open:
As we are now doing now allowing for more complex (and possibly confusing) options to be passed in I have added logging aimed at making this more discoverable to a user. If they pass in an object with neither With that, I have also hard coded the open failure message, as config related info should now be caught earlier |
If you guys are +1 to this I’ll update the tests and relevant docs |
Bump |
CI fails
|
/cc @dangreenisrael need fix test problem |
I just wanted a +1 to the approach before I took the time to update the tests. I should have some time to get it done this weekend |
@dangreenisrael friendly ping |
I haven't forgotten about you guys. Just super busy. Thanks for the friendly ping tho |
de6aad9
to
0ec71b3
Compare
@evilebottnawi I updated this pr. I'll do below after merging.
|
https://www.npmjs.com/package/open Allow for 3 options to pass as options.open: - Boolean: runs without any options and thus uses the default browser - String: opens with the browser of your choice - Object: takes a settings object as defined by https://github.com/sindresorhus/open As we are now doing now allowing for more complex (and possibly confusing) options to be passed in I have added logging aimed at making this more discoverable to a user. If they pass in an object with neither `app` nor `wait` OR something that is not ( boolean | string | object ) they will get a warning telling them that they passed in an invalid config and a link to the `open` docs. With that, I have also hard coded the open failure message, as config related info should now be caught earlier
0ec71b3
to
8ff23b7
Compare
devServer.options
to take an arraydevServer.options.open
to take an object
8ff23b7
to
f4e919b
Compare
f4e919b
to
a3b06dc
Compare
need to update documentation (but I want to consider open types) |
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 good, one note
|
||
if (typeof options.open === 'string') { | ||
openOptions = { app: options.open }; | ||
openMessage += `: ${options.open}`; | ||
} else if (typeof options.open === 'object') { |
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.
Maybe add Array.isArray
?
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.
Is this still something people are still interested in. If so, can we agree on an interface in principle before any more code changes? |
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.
Two notes
expect(open).toBeCalledWith(uri, { app: ['Google Chrome', 'incognito'] }); | ||
}); | ||
}); | ||
}); |
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.
Please move this tests to https://github.com/webpack/webpack-dev-server/blob/master/test/server/open-option.test.js
openOptions = options.open; | ||
if (!options.app && !options.wait) { | ||
handleInvalidOptionsConfig(log, options.open); | ||
} |
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.
Why we need this? open package can add more option in future
/cc @dangreenisrael friendly ping |
Wow, totally forgot about this. I can try to look into in the next few weeks. If someone else wants to take it over I promise I won't be offended |
@dangreenisrael friendly ping - It would be super-useful to finally have proper "open" support for webpack. Do you think you can wrap this up soon? |
@stefan-winkler-diconium you can send another PR and fix problems described here |
I've got a broken thumb, so I won't be doing any non-work required coding for at least a month. Sorry |
This PR updates
devServer.options
to take an array, making it consistent with the underlying library, openhttps://www.npmjs.com/package/open
For Bugs and Features; did you add new tests?
I didn't see any tests for the unmodified code, I did however update the
options.json
schemaMotivation / Use-Case
This updates
devServer.options
to match the underlying library that is used in the implementation.#1769
Breaking Changes
N/A
Additional Info
N/A