fix: browser bug with plugins, and improve joining
This commit is contained in:
@@ -375,9 +375,20 @@ export class PluginHostService {
|
||||
return { module, moduleObjectUrl };
|
||||
}
|
||||
|
||||
return {
|
||||
module: await import(/* @vite-ignore */ entrypointUrl) as TojuClientPluginModule
|
||||
};
|
||||
try {
|
||||
return {
|
||||
module: await import(/* @vite-ignore */ entrypointUrl) as TojuClientPluginModule
|
||||
};
|
||||
} catch (error) {
|
||||
if (!entrypointUrl.startsWith('http://') && !entrypointUrl.startsWith('https://')) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const moduleObjectUrl = await this.createRemoteModuleObjectUrl(entrypointUrl);
|
||||
const module = await import(/* @vite-ignore */ moduleObjectUrl) as TojuClientPluginModule;
|
||||
|
||||
return { module, moduleObjectUrl };
|
||||
}
|
||||
}
|
||||
|
||||
private async createLocalModuleObjectUrl(entrypointUrl: string): Promise<string> {
|
||||
@@ -394,6 +405,18 @@ export class PluginHostService {
|
||||
return URL.createObjectURL(new Blob([source], { type: 'text/javascript' }));
|
||||
}
|
||||
|
||||
private async createRemoteModuleObjectUrl(entrypointUrl: string): Promise<string> {
|
||||
const response = await fetch(entrypointUrl, { headers: { Accept: 'text/javascript,*/*' } });
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Plugin entrypoint returned ${response.status}`);
|
||||
}
|
||||
|
||||
const source = await response.text();
|
||||
|
||||
return URL.createObjectURL(new Blob([`${source}\n//# sourceURL=${entrypointUrl}`], { type: 'text/javascript' }));
|
||||
}
|
||||
|
||||
private revokeModuleObjectUrl(pluginId: string): void {
|
||||
const moduleObjectUrl = this.activePlugins.get(pluginId)?.moduleObjectUrl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user