chore(openBrowser): sync with upstream

(cherry picked from commit f078c46fc3)
This commit is contained in:
Haoqun Jiang
2019-05-22 16:33:39 +08:00
parent 6f085d36a4
commit 78bc1dbecf
2 changed files with 10 additions and 10 deletions

View File

@@ -3,15 +3,15 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file at
* https://github.com/facebookincubator/create-react-app/blob/master/LICENSE
* https://github.com/facebook/create-react-app/blob/master/LICENSE
*/
const opn = require('opn')
const open = require('open')
const execa = require('execa')
const chalk = require('chalk')
const execSync = require('child_process').execSync
// https://github.com/sindresorhus/opn#app
// https://github.com/sindresorhus/open#app
const OSX_CHROME = 'google chrome'
const Actions = Object.freeze({
@@ -23,7 +23,7 @@ const Actions = Object.freeze({
function getBrowserEnv () {
// Attempt to honor this environment variable.
// It is specific to the operating system.
// See https://github.com/sindresorhus/opn#app for documentation.
// See https://github.com/sindresorhus/open#app for documentation.
const value = process.env.BROWSER
let action
if (!value) {
@@ -85,18 +85,18 @@ function startBrowserProcess (browser, url) {
}
// Another special case: on OS X, check if BROWSER has been set to "open".
// In this case, instead of passing `open` to `opn` (which won't work),
// In this case, instead of passing the string `open` to `open` function (which won't work),
// just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
// https://github.com/facebookincubator/create-react-app/pull/1690#issuecomment-283518768
// https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
if (process.platform === 'darwin' && browser === 'open') {
browser = undefined
}
// Fallback to opn
// Fallback to open
// (It will always open new tab)
try {
var options = { app: browser }
opn(url, options).catch(() => {}) // Prevent `unhandledRejection` error.
open(url, options).catch(() => {}) // Prevent `unhandledRejection` error.
return true
} catch (err) {
return false
@@ -104,7 +104,7 @@ function startBrowserProcess (browser, url) {
}
/**
* Reads the BROWSER evironment variable and decides what to do with it. Returns
* Reads the BROWSER environment variable and decides what to do with it. Returns
* true if it opened a browser or ran a node.js script, otherwise false.
*/
exports.openBrowser = function (url) {

View File

@@ -26,7 +26,7 @@
"launch-editor": "^2.2.1",
"lru-cache": "^5.1.1",
"node-ipc": "^9.1.1",
"opn": "^5.3.0",
"open": "^6.3.0",
"ora": "^3.4.0",
"request": "^2.87.0",
"request-promise-native": "^1.0.7",