mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 09:25:43 +01:00
Resolve plugin SystemJS modules to their correct bundle location
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user