Skip to content
Snippets Groups Projects
Commit 3e376843 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

getAssetURL: Explicitely pass a package name

This way we can change the full path/namespacing at a later point.
parent faa299f4
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
......@@ -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', () => {
......
......@@ -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
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment