From c4000fbdbb76d0731bc37a0300df1f64b1081ea2 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 6 Apr 2020 18:01:54 +0200 Subject: [PATCH 1/2] feat: reuse existing chrome tab if possible - Move from open to better-opn - Feature available on chrome only unfortunately --- lib/core/package.json | 2 +- lib/core/src/server/build-dev.js | 8 +++++--- yarn.lock | 11 +++++++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/core/package.json b/lib/core/package.json index c34bbbf2153e..62c27f6c0be4 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -58,6 +58,7 @@ "babel-plugin-emotion": "^10.0.20", "babel-plugin-macros": "^2.8.0", "babel-preset-minify": "^0.5.0 || 0.6.0-alpha.5", + "better-opn": "^1.0.0", "boxen": "^4.1.0", "case-sensitive-paths-webpack-plugin": "^2.2.0", "chalk": "^3.0.0", @@ -85,7 +86,6 @@ "lazy-universal-dotenv": "^3.0.1", "micromatch": "^4.0.2", "node-fetch": "^2.6.0", - "open": "^7.0.1", "pkg-dir": "^4.2.0", "pnp-webpack-plugin": "1.6.4", "postcss-flexbugs-fixes": "^4.1.0", diff --git a/lib/core/src/server/build-dev.js b/lib/core/src/server/build-dev.js index 7c4a049e4e24..58e02713225a 100644 --- a/lib/core/src/server/build-dev.js +++ b/lib/core/src/server/build-dev.js @@ -9,7 +9,7 @@ import chalk from 'chalk'; import { logger, colors, instance as npmLog } from '@storybook/node-logger'; import fetch from 'node-fetch'; import Cache from 'file-system-cache'; -import open from 'open'; +import open from 'better-opn'; import boxen from 'boxen'; import semver from 'semver'; import dedent from 'ts-dedent'; @@ -234,13 +234,15 @@ async function outputStats(previewStats, managerStats) { } function openInBrowser(address) { - open(address).catch(() => { + try { + open(address); + } catch (error) { logger.error(dedent` Could not open ${address} inside a browser. If you're running this command inside a docker container or on a CI, you need to pass the '--ci' flag to prevent opening a browser by default. `); - }); + } } export async function buildDevStandalone(options) { diff --git a/yarn.lock b/yarn.lock index a92157457966..9315f7361809 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7342,6 +7342,13 @@ better-assert@~1.0.0: dependencies: callsite "1.0.0" +better-opn@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/better-opn/-/better-opn-1.0.0.tgz#0454e4bb9115c6a9e4e5744417dd9c97fb9fce41" + integrity sha512-q3eO2se4sFbTERB1dFBDdjTiIIpRohMErpwBX21lhPvmgmQNNrcQj0zbWRhMREDesJvyod9kxBS3kOtdAvkB/A== + dependencies: + open "^6.4.0" + bfj@^6.1.1: version "6.1.2" resolved "https://registry.yarnpkg.com/bfj/-/bfj-6.1.2.tgz#325c861a822bcb358a41c78a33b8e6e2086dde7f" @@ -21679,7 +21686,7 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" -open@7.0.3, open@^7.0.1, open@^7.0.2: +open@7.0.3, open@^7.0.2: version "7.0.3" resolved "https://registry.yarnpkg.com/open/-/open-7.0.3.tgz#db551a1af9c7ab4c7af664139930826138531c48" integrity sha512-sP2ru2v0P290WFfv49Ap8MF6PkzGNnGlAwHweB4WR4mr5d2d0woiCluUeJ218w7/+PmoBy9JmYgD5A4mLcWOFA== @@ -21687,7 +21694,7 @@ open@7.0.3, open@^7.0.1, open@^7.0.2: is-docker "^2.0.0" is-wsl "^2.1.1" -open@^6.3.0: +open@^6.3.0, open@^6.4.0: version "6.4.0" resolved "https://registry.yarnpkg.com/open/-/open-6.4.0.tgz#5c13e96d0dc894686164f18965ecfe889ecfc8a9" integrity sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg== From 8f3046bd2643e316634647e2361fc8b975b133ff Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Tue, 7 Apr 2020 09:28:32 +0200 Subject: [PATCH 2/2] chore: upgrade better-opn to 2.0.0 --- lib/core/package.json | 2 +- yarn.lock | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/core/package.json b/lib/core/package.json index 62c27f6c0be4..740dbbf0c1fd 100644 --- a/lib/core/package.json +++ b/lib/core/package.json @@ -58,7 +58,7 @@ "babel-plugin-emotion": "^10.0.20", "babel-plugin-macros": "^2.8.0", "babel-preset-minify": "^0.5.0 || 0.6.0-alpha.5", - "better-opn": "^1.0.0", + "better-opn": "^2.0.0", "boxen": "^4.1.0", "case-sensitive-paths-webpack-plugin": "^2.2.0", "chalk": "^3.0.0", diff --git a/yarn.lock b/yarn.lock index 9315f7361809..da3f8a341a7d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7342,12 +7342,12 @@ better-assert@~1.0.0: dependencies: callsite "1.0.0" -better-opn@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/better-opn/-/better-opn-1.0.0.tgz#0454e4bb9115c6a9e4e5744417dd9c97fb9fce41" - integrity sha512-q3eO2se4sFbTERB1dFBDdjTiIIpRohMErpwBX21lhPvmgmQNNrcQj0zbWRhMREDesJvyod9kxBS3kOtdAvkB/A== +better-opn@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/better-opn/-/better-opn-2.0.0.tgz#c70d198e51164bdc220306a28a885d9ac7a14c44" + integrity sha512-PPbGRgO/K0LowMHbH/JNvaV3qY3Vt+A2nH28fzJxy16h/DfR5OsVti6ldGl6S9SMsyUqT13sltikiAVtI6tKLA== dependencies: - open "^6.4.0" + open "^7.0.3" bfj@^6.1.1: version "6.1.2" @@ -21686,7 +21686,7 @@ onetime@^5.1.0: dependencies: mimic-fn "^2.1.0" -open@7.0.3, open@^7.0.2: +open@7.0.3, open@^7.0.2, open@^7.0.3: version "7.0.3" resolved "https://registry.yarnpkg.com/open/-/open-7.0.3.tgz#db551a1af9c7ab4c7af664139930826138531c48" integrity sha512-sP2ru2v0P290WFfv49Ap8MF6PkzGNnGlAwHweB4WR4mr5d2d0woiCluUeJ218w7/+PmoBy9JmYgD5A4mLcWOFA== @@ -21694,7 +21694,7 @@ open@7.0.3, open@^7.0.2: is-docker "^2.0.0" is-wsl "^2.1.1" -open@^6.3.0, open@^6.4.0: +open@^6.3.0: version "6.4.0" resolved "https://registry.yarnpkg.com/open/-/open-6.4.0.tgz#5c13e96d0dc894686164f18965ecfe889ecfc8a9" integrity sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==