diff --git a/packages/common/src/icon.js b/packages/common/src/icon.js index 1a4f9dd6f04bf96e33ed915585b5acb23aa890b0..35c047a694ae85ced867634244bae79c1c384e02 100644 --- a/packages/common/src/icon.js +++ b/packages/common/src/icon.js @@ -18,7 +18,7 @@ const errorIcon = ` `; export function getIconSVGURL(name) { - return commonUtils.getAssetURL('local/vpu-common/icons/' + encodeURI(name) + '.svg'); + return commonUtils.getAssetURL('vpu-common', 'icons/' + encodeURI(name) + '.svg'); } export function getIconCSS(name) { diff --git a/packages/common/test/unit.js b/packages/common/test/unit.js index 17d7f7f12cf74285e7dae2b11c33f18f179115bd..abca165ba7dbb378ad5fe46dc92c2c6c6acf6f71 100644 --- a/packages/common/test/unit.js +++ b/packages/common/test/unit.js @@ -39,7 +39,10 @@ suite('utils', () => { }); test('getAssetURL', () => { + // Backwards compat assert.equal(new URL(utils.getAssetURL("foo/bar")).pathname, "/foo/bar"); + // Normal usage + assert.equal(new URL(utils.getAssetURL('foobar', 'bar/quux')).pathname, "/local/foobar/bar/quux"); }); test('getThemeCSS', () => { diff --git a/packages/common/utils.js b/packages/common/utils.js index 695ebbeb9d8be0d1bc9da4f68083e2a292e8d116..af8d2fd421154d70005fbbdcec1cfceeebc3a959 100644 --- a/packages/common/utils.js +++ b/packages/common/utils.js @@ -199,12 +199,22 @@ export const dateToInputTimeString = (date) => { /** * Get an absolute path for assets given a relative path to the js bundle. * + * @param {string} pkg The package which provides the asset * @param {string} path The relative path based on the js bundle path */ -export const getAssetURL = (path) => { - return new URL(path, new URL('..', import.meta.url).href).href; +export const getAssetURL = (pkg, path) => { + let fullPath = ''; + if (path === undefined) { + // backwards compat: in case only one parameter is passed + // assume it is a full path + fullPath = pkg; + } else { + fullPath = 'local/' + pkg + '/' + path + } + return new URL(fullPath, new URL('..', import.meta.url).href).href; }; + /** * Poll <fn> every <interval> ms until <timeout> ms *