Skip to content

Commit

Permalink
refactor(CLI): Upgrade to v7 of open library
Browse files Browse the repository at this point in the history
It's to unify open browser method with dashboard plugin, and this method feels more solid
  • Loading branch information
medikoo committed Jan 6, 2022
1 parent 95a61a2 commit 80fef65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 183 deletions.
173 changes: 0 additions & 173 deletions lib/utils/open.js

This file was deleted.

21 changes: 11 additions & 10 deletions lib/utils/openBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/* eslint-disable no-console */

const opn = require('./open');
const open = require('open');
const chalk = require('chalk');
const isDockerContainer = require('is-docker');
const { legacy, log, style } = require('@serverless/utils/log');
Expand All @@ -17,13 +17,14 @@ module.exports = function openBrowser(url) {
let browser = process.env.BROWSER;
if (browser === 'none' || isDockerContainer()) return;
if (process.platform === 'darwin' && browser === 'open') browser = undefined;
const options = { wait: false, app: browser };
opn(url, options).catch((err) => {
if (process.env.SLS_DEBUG) {
legacy.write(
`Serverless: ${chalk.red(`Opening of browser window errored with ${err.stack}`)}\n`
);
}
log.info(`Opening of browser window errored with ${err.stack}`);
});
open(url).then((subprocess) =>
subprocess.on('error', (err) => {
if (process.env.SLS_DEBUG) {
legacy.write(
`Serverless: ${chalk.red(`Opening of browser window errored with ${err.stack}`)}\n`
);
}
log.info(`Opening of browser window errored with ${err.stack}`);
})
);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"ncjsm": "^4.2.0",
"node-fetch": "^2.6.6",
"object-hash": "^2.2.0",
"open": "^7.4.2",
"path2": "^0.1.0",
"process-utils": "^4.0.0",
"promise-queue": "^2.2.5",
Expand Down

0 comments on commit 80fef65

Please sign in to comment.