summaryrefslogtreecommitdiff
path: root/deps/npm/lib/utils/open-url.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/lib/utils/open-url.js')
-rw-r--r--deps/npm/lib/utils/open-url.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/deps/npm/lib/utils/open-url.js b/deps/npm/lib/utils/open-url.js
index 7a48d2e868..e1ed2b3fab 100644
--- a/deps/npm/lib/utils/open-url.js
+++ b/deps/npm/lib/utils/open-url.js
@@ -5,9 +5,28 @@ const opener = require('opener')
// attempt to open URL in web-browser, print address otherwise:
module.exports = function open (url, errMsg, cb, browser = npm.config.get('browser')) {
- opener(url, { command: npm.config.get('browser') }, (er) => {
+ function printAlternateMsg () {
+ const json = npm.config.get('json')
+ const alternateMsg = json
+ ? JSON.stringify({
+ title: errMsg,
+ url
+ }, null, 2)
+ : `${errMsg}:\n\n${url}`
+
+ output(alternateMsg)
+ }
+
+ const skipBrowser = process.argv.indexOf('--no-browser') > -1
+
+ if (skipBrowser) {
+ printAlternateMsg()
+ return cb()
+ }
+
+ opener(url, { command: browser }, (er) => {
if (er && er.code === 'ENOENT') {
- output(`${errMsg}:\n\n${url}`)
+ printAlternateMsg()
return cb()
} else {
return cb(er)