Skip to content

Commit

Permalink
chore(openBrowser): sync with upstream
Browse files Browse the repository at this point in the history
(cherry picked from commit f078c46)
  • Loading branch information
sodatea committed May 25, 2019
1 parent 6f085d3 commit 78bc1db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions packages/@vue/cli-shared-utils/lib/openBrowser.js
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down Expand Up @@ -85,26 +85,26 @@ 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
}
}

/**
* 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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vue/cli-shared-utils/package.json
Expand Up @@ -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",
Expand Down

0 comments on commit 78bc1db

Please sign in to comment.