UNPKG

react-router-ga

Version:

[![Downloads](https://img.shields.io/npm/dm/react-router-ga)](https://npm.im/react-router-ga) [![Version](https://img.shields.io/npm/v/react-router-ga)](https://npm.im/react-router-ga) [![License](https://img.shields.io/npm/l/react-router-ga)](https://ope

35 lines (27 loc) 955 B
'use strict'; const open = require('opn'); const isAbsoluteUrl = require('is-absolute-url'); function runOpen(uri, options, log) { // https://github.com/webpack/webpack-dev-server/issues/1990 let openOptions = { wait: false }; let openOptionValue = ''; if (typeof options.open === 'string') { openOptions = Object.assign({}, openOptions, { app: options.open }); openOptionValue = `: "${options.open}"`; } const pages = typeof options.openPage === 'string' ? [options.openPage] : options.openPage || ['']; return Promise.all( pages.map((page) => { const pageUrl = page && isAbsoluteUrl(page) ? page : `${uri}${page}`; return open(pageUrl, openOptions).catch(() => { log.warn( `Unable to open "${pageUrl}" in browser${openOptionValue}. If you are running in a headless environment, please do not use the --open flag` ); }); }) ); } module.exports = runOpen;