diff --git a/packages/es-dev-server/package.json b/packages/es-dev-server/package.json index b2f7770fb..1ad6717fc 100644 --- a/packages/es-dev-server/package.json +++ b/packages/es-dev-server/package.json @@ -103,6 +103,7 @@ "@types/node-fetch": "^2.3.7", "@types/puppeteer": "^2.0.0", "@types/request": "^2.48.1", + "@types/whatwg-url": "^6.4.0", "abort-controller": "^3.0.0", "chai": "^4.2.0", "koa-proxies": "^0.8.1", diff --git a/packages/es-dev-server/src/config.js b/packages/es-dev-server/src/config.js index e8b826fc6..bce9f423a 100644 --- a/packages/es-dev-server/src/config.js +++ b/packages/es-dev-server/src/config.js @@ -192,11 +192,6 @@ export function createConfig(config) { openPath = basePath ? `${basePath}/` : '/'; } - // make sure path properly starts a / - if (!openPath.startsWith('/')) { - openPath = `/${openPath}`; - } - return { appIndex, appIndexDir, diff --git a/packages/es-dev-server/src/start-server.js b/packages/es-dev-server/src/start-server.js index 21f243d5f..233d0dc42 100644 --- a/packages/es-dev-server/src/start-server.js +++ b/packages/es-dev-server/src/start-server.js @@ -1,8 +1,17 @@ import opn from 'opn'; import chokidar from 'chokidar'; import portfinder from 'portfinder'; +import { URL } from 'url'; import { createServer } from './create-server.js'; +function isValidURL(str) { + try { + return !!new URL(str); + } catch (error) { + return false; + } +} + /** @param {import('./config.js').InternalConfig} cfg */ export async function startServer(cfg, fileWatcher = chokidar.watch([])) { const result = createServer(cfg, fileWatcher); @@ -68,7 +77,15 @@ export async function startServer(cfg, fileWatcher = chokidar.watch([])) { } if (cfg.openBrowser) { - opn(`http${cfg.http2 ? 's' : ''}://${prettyHost}:${port}${cfg.openPath}`); + const openPath = (() => { + if (isValidURL(cfg.openPath)) { + return cfg.openPath; + } + + return new URL(cfg.openPath, `http${cfg.http2 ? 's' : ''}://${prettyHost}:${port}`).href; + })(); + + opn(openPath); } resolve(); diff --git a/yarn.lock b/yarn.lock index ac6078474..be8d69284 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2106,16 +2106,16 @@ standard-version "^7.0.1" "@open-wc/testing-karma-bs@file:./packages/testing-karma-bs": - version "1.3.4" + version "1.3.6" dependencies: - "@open-wc/testing-karma" "^3.2.4" + "@open-wc/testing-karma" "^3.2.6" "@types/node" "^11.13.0" karma-browserstack-launcher "^1.0.0" "@open-wc/testing-karma@file:./packages/testing-karma": - version "3.2.4" + version "3.2.6" dependencies: - "@open-wc/karma-esm" "^2.10.4" + "@open-wc/karma-esm" "^2.10.6" axe-core "^3.3.1" karma "^4.1.0" karma-chrome-launcher "^2.0.0" @@ -2653,6 +2653,13 @@ resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e" integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ== +"@types/whatwg-url@^6.4.0": + version "6.4.0" + resolved "https://registry.yarnpkg.com/@types/whatwg-url/-/whatwg-url-6.4.0.tgz#1e59b8c64bc0dbdf66d037cf8449d1c3d5270237" + integrity sha512-tonhlcbQ2eho09am6RHnHOgvtDfDYINd5rgxD+2YSkKENooVCFsWizJz139MQW/PV8FfClyKrNe9ZbdHrSCxGg== + dependencies: + "@types/node" "*" + "@vue/babel-helper-vue-jsx-merge-props@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@vue/babel-helper-vue-jsx-merge-props/-/babel-helper-vue-jsx-merge-props-1.0.0.tgz#048fe579958da408fb7a8b2a3ec050b50a661040"