Skip to content

Commit 054cb5e

Browse files
committed
Upgrade opn v5.3.0 to open v7.0.0
1 parent 5dbc506 commit 054cb5e

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

index.js

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
var chalk = require('colors-cli');
1111
var execSync = require('child_process').execSync;
1212
var spawn = require('cross-spawn');
13-
var opn = require('opn');
13+
var open = require('open');
1414

15-
// https://github.com/sindresorhus/opn#app
15+
// https://github.com/sindresorhus/open#app
1616
var OSX_CHROME = 'google chrome';
1717

1818
const Actions = Object.freeze({
@@ -24,8 +24,11 @@ const Actions = Object.freeze({
2424
function getBrowserEnv() {
2525
// Attempt to honor this environment variable.
2626
// It is specific to the operating system.
27-
// See https://github.com/sindresorhus/opn#app for documentation.
27+
// See https://github.com/sindresorhus/open#app for documentation.
2828
const value = process.env.BROWSER;
29+
const args = process.env.BROWSER_ARGS
30+
? process.env.BROWSER_ARGS.split(' ')
31+
: [];
2932
let action;
3033
if (!value) {
3134
// Default.
@@ -37,7 +40,7 @@ function getBrowserEnv() {
3740
} else {
3841
action = Actions.BROWSER;
3942
}
40-
return { action, value };
43+
return { action, value, args };
4144
}
4245

4346
function executeNodeScript(scriptPath, url) {
@@ -61,7 +64,7 @@ function executeNodeScript(scriptPath, url) {
6164
return true;
6265
}
6366

64-
function startBrowserProcess(browser, url) {
67+
function startBrowserProcess(browser, url, args) {
6568
// If we're on OS X, the user hasn't specifically
6669
// requested a different browser, we can try opening
6770
// Chrome with AppleScript. This lets us reuse an
@@ -93,34 +96,39 @@ function startBrowserProcess(browser, url) {
9396
browser = undefined;
9497
}
9598

96-
// Fallback to opn
99+
// If there are arguments, they must be passed as array with the browser
100+
if (typeof browser === 'string' && args.length > 0) {
101+
browser = [browser].concat(args);
102+
}
103+
104+
// Fallback to open
97105
// (It will always open new tab)
98106
try {
99-
var options = { app: browser };
100-
opn(url, options).catch(() => { }); // Prevent `unhandledRejection` error.
107+
var options = { app: browser, wait: false, url: true };
108+
open(url, options).catch(() => {}); // Prevent `unhandledRejection` error.
101109
return true;
102110
} catch (err) {
103111
return false;
104112
}
105113
}
106114

107115
/**
108-
* Reads the BROWSER evironment variable and decides what to do with it. Returns
116+
* Reads the BROWSER environment variable and decides what to do with it. Returns
109117
* true if it opened a browser or ran a node.js script, otherwise false.
110118
*/
111119
function openBrowser(url) {
112-
const { action, value } = getBrowserEnv();
120+
const { action, value, args } = getBrowserEnv();
113121
switch (action) {
114122
case Actions.NONE:
115123
// Special case: BROWSER="none" will prevent opening completely.
116124
return false;
117125
case Actions.SCRIPT:
118126
return executeNodeScript(value, url);
119127
case Actions.BROWSER:
120-
return startBrowserProcess(value, url);
128+
return startBrowserProcess(value, url, args);
121129
default:
122130
throw new Error('Not implemented.');
123131
}
124132
}
125133

126-
module.exports = openBrowser;
134+
module.exports = openBrowser;

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@
4444
"dependencies": {
4545
"colors-cli": "^1.0.13",
4646
"cross-spawn": "^6.0.5",
47-
"opn": "^5.3.0"
47+
"open": "^7.0.0"
4848
}
4949
}

0 commit comments

Comments
 (0)