-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16844 from richorrichard/15316-open-storybook-in-…
…default-browser CLI: Fix open storybook in default browser
- Loading branch information
Showing
7 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
import { logger } from '@storybook/node-logger'; | ||
import open from 'better-opn'; | ||
import betterOpn from 'better-opn'; // betterOpn alias used because also loading open | ||
import open from 'open'; | ||
import getDefaultBrowser from 'x-default-browser'; | ||
import dedent from 'ts-dedent'; | ||
|
||
export function openInBrowser(address: string) { | ||
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. | ||
`); | ||
} | ||
getDefaultBrowser(async (err: any, res: any) => { | ||
try { | ||
if (res.isChrome || res.isChromium) { | ||
// We use betterOpn for Chrome because it is better at handling which chrome tab | ||
// or window the preview loads in. | ||
betterOpn(address); | ||
} else { | ||
await 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. | ||
`); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters