-
-
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
Allow --open option to specify the browser to use #825
Changes from 13 commits
30c4fbd
b5f064e
5b7f8e0
15ec8d3
75ef717
d78c1ae
52ad1a2
f04bba3
8b64374
4d65ef1
2c32834
682d47e
a18ae9c
d3a46ae
9ca67c9
cb31c90
b847645
a230754
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules | |
/client/sockjs.bundle.js | ||
/coverage | ||
*.pem | ||
.idea/ | ||
/package-lock.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,7 @@ yargs.options({ | |
describe: "close when stdin ends" | ||
}, | ||
"open": { | ||
type: "boolean", | ||
type: "string", | ||
describe: "Open default browser" | ||
}, | ||
"useLocalIp": { | ||
|
@@ -337,7 +337,11 @@ function processOptions(wpOpt) { | |
options.disableHostCheck = true; | ||
|
||
if(argv["open"] || argv["open-page"]) { | ||
options.open = true; | ||
if(argv["open"] && argv["open"] !== "") { | ||
options.open = argv["open"]; | ||
} else { | ||
options.open = true; | ||
} | ||
options.openPage = argv["open-page"] || ""; | ||
} | ||
|
||
|
@@ -455,9 +459,15 @@ function reportReadiness(uri, options) { | |
if(options.historyApiFallback) | ||
console.log(`404s will fallback to ${colorInfo(useColor, options.historyApiFallback.index || "/index.html")}`); | ||
if(options.open) { | ||
open(uri + options.openPage).catch(function() { | ||
console.log("Unable to open browser. If you are running in a headless environment, please do not use the open flag."); | ||
}); | ||
if(argv["open"] && argv["open"] !== "") { | ||
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. you're already performing this check on line 340, and on 461 you're checking the truthy value of |
||
open(uri + options.openPage, { app: options.open }).catch(function() { | ||
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. not a fan of two nearly identical calls to (this is pseudo code, don't copy and paste it) var openOptions = {};
var openMessage = "Unable to open browser";
if (typeof options.open === "string") {
openOptions = { app: options.open };
openMessage =+ " : " + options.open;
}
open(uri + options.openPage, openOptions).catch(function () {
console.log(openMessage + "If you are running in a headless environment, please do not use the open flag.");
}); |
||
console.log(`Unable to open browser '${options.open}'. If you are running in a headless environment, please do not use the open flag.`); | ||
}); | ||
} else { | ||
open(uri + options.openPage).catch(function() { | ||
console.log("Unable to open browser. If you are running in a headless environment, please do not use the open flag."); | ||
}); | ||
} | ||
} | ||
if(options.bonjour) | ||
console.log("Broadcasting \"http\" with subtype of \"webpack\" via ZeroConf DNS (Bonjour)"); | ||
|
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.
you've changed the type for yargs to
string
on line 95, and an empty string is falsey - is there a reason you're checking the truthy value ofargs["open"]
and also checking that it's not empty?