mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
Resolve plugin SystemJS modules to their correct bundle location
This commit is contained in:
@@ -47,15 +47,7 @@ type PluginModule = {
|
|||||||
const BundleLoader = {
|
const BundleLoader = {
|
||||||
name: "bundle-loader",
|
name: "bundle-loader",
|
||||||
fetch: (plugin: PluginModule) => {
|
fetch: (plugin: PluginModule) => {
|
||||||
let url = plugin.address;
|
return fetch(plugin.address, {
|
||||||
if (!url.endsWith(".bundle.js")) {
|
|
||||||
url += ".bundle.js";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (url.includes("@scm-manager/")) {
|
|
||||||
url = url.replace("@scm-manager/", "");
|
|
||||||
}
|
|
||||||
return fetch(url, {
|
|
||||||
credentials: "same-origin",
|
credentials: "same-origin",
|
||||||
headers: {
|
headers: {
|
||||||
Cache: "no-cache",
|
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) => {
|
const expose = (name: string, cmp: any, defaultCmp?: any) => {
|
||||||
let mod = cmp;
|
let mod = cmp;
|
||||||
if (defaultCmp) {
|
if (defaultCmp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user