Resolve plugin SystemJS modules to their correct bundle location

This commit is contained in:
Sebastian Sdorra
2020-10-14 08:06:15 +02:00
parent 5172fdb27d
commit a94993274a

View File

@@ -47,15 +47,7 @@ type PluginModule = {
const BundleLoader = {
name: "bundle-loader",
fetch: (plugin: PluginModule) => {
let url = plugin.address;
if (!url.endsWith(".bundle.js")) {
url += ".bundle.js";
}
if (url.includes("@scm-manager/")) {
url = url.replace("@scm-manager/", "");
}
return fetch(url, {
return fetch(plugin.address, {
credentials: "same-origin",
headers: {
Cache: "no-cache",
@@ -82,6 +74,29 @@ SystemJS.config({
}
});
// We have to patch the resolve methods of SystemJS
// in order to resolve the correct bundle url for plugins
const resolveModuleUrl = (key: string) => {
if (key.startsWith("@scm-manager/scm-") && key.endsWith("-plugin")) {
const pluginName = key.replace("@scm-manager/", "");
return urls.withContextPath(`/assets/${pluginName}.bundle.js`);
}
return key;
};
const defaultResolve = SystemJS.resolve;
SystemJS.resolve = function(key, parentName) {
const module = resolveModuleUrl(key);
return defaultResolve.apply(this, [module, parentName]);
};
const defaultResolveSync = SystemJS.resolveSync;
SystemJS.resolveSync = function(key, parentName) {
const module = resolveModuleUrl(key);
return defaultResolveSync.apply(this, [module, parentName]);
};
const expose = (name: string, cmp: any, defaultCmp?: any) => {
let mod = cmp;
if (defaultCmp) {