diff --git a/packages/common/assets/index.html b/packages/common/assets/index.html index bae2d4adaf472c1650136179f7b073ccb72dcd3a..9469485ce866aa813cc129851db02d486629e48c 100644 --- a/packages/common/assets/index.html +++ b/packages/common/assets/index.html @@ -2,7 +2,7 @@ <html> <head> <meta charset="UTF-8"> - <script type="module" id="vpu-common-demo-src" src="demo.js"></script> + <script type="module" src="demo.js"></script> <style> body { font-family: sans; diff --git a/packages/common/test/unit.js b/packages/common/test/unit.js index 0f0d92e1c38d8f63942ccc6f742a107536322468..98b400493cc138dae127ae455b3118a671bf4a6b 100644 --- a/packages/common/test/unit.js +++ b/packages/common/test/unit.js @@ -43,7 +43,6 @@ suite('utils', () => { }); test('getAssetURL', () => { - utils.initAssetBaseURL(); assert.equal(new URL(utils.getAssetURL("foo/bar")).pathname, "/foo/bar"); }); diff --git a/packages/common/utils.js b/packages/common/utils.js index a0d3c469d23cb7815b8c0abece7b8f7f9277fba1..ed241a6dd159a5dfe62b721148c463e8c880b1ae 100644 --- a/packages/common/utils.js +++ b/packages/common/utils.js @@ -189,60 +189,17 @@ export const dateToInputTimeString = (date) => { return `${pad10(date.getHours())}:${pad10(date.getMinutes())}`; }; -let _assetBaseURL = null; - -/** - * Set the base url for future calls to getAssetURL() - * - * @param {string} [id] An optional id of the script tag to figure out the - * base bundle URL. - */ export const initAssetBaseURL = (id) => { - // We don't want future calls to change things - if (_assetBaseURL) - return; - - if (id) { - // Find the id added to the script tag - const elm = document.getElementById(id); - if (elm && elm.src) { - _assetBaseURL = elm.src; - } - } - - // In the (unlikely) event that we are bundled as a non-module - // we can use the old currentScript API - if (document.currentScript && document.currentScript.src) { - _assetBaseURL = document.currentScript.src; - } - - // XXX: Can't be parsed in (old) edge, but makes everything so much easier... - if (!_assetBaseURL) - _assetBaseURL = new URL('..', import.meta.url).href; + // No longer needed, remove your call }; /** * Get an absolute path for assets given a relative path to the js bundle. - * Call initAssetBaseURL() before this. * * @param {string} path The relative path based on the js bundle path */ export const getAssetURL = (path) => { - // Maybe initScriptURL() can do something without the id - if (!_assetBaseURL) { - initAssetBaseURL(); - } - - // We already found the path before, just go with it - if (_assetBaseURL) { - return new URL(path, _assetBaseURL).href; - } else { - console.error('Using getAssetURL(), but initAssetBaseURL() wasn\'t called yet'); - } - - // If all fails we just fall back to relative paths and hope the - // html is on the same path as the bundle - return path; + return new URL(path, new URL('..', import.meta.url).href).href; }; /** diff --git a/packages/common/vpu-common-demo.js b/packages/common/vpu-common-demo.js index 323acc882e3d01e5eedc7864c094a44db56c8199..9b5e1825dffc0c7215d6f435b3e239c211c53340 100644 --- a/packages/common/vpu-common-demo.js +++ b/packages/common/vpu-common-demo.js @@ -92,7 +92,6 @@ class VpuCommonDemo extends ScopedElementsMixin(LitElement) { } render() { - commonUtils.initAssetBaseURL('vpu-common-demo-src'); return html` <style> a:after {