mirror of
https://github.com/grafana/grafana.git
synced 2025-01-02 04:07:15 -06:00
Sandbox: Use resolveCache to resolve plugin's code file as systemjs does (#75509)
* Sandbox: Use resolveCache to resolve plugin's code file as systemjs does * Add clarifying comments
This commit is contained in:
parent
720543f483
commit
2bbd5521fe
@ -1,6 +1,7 @@
|
||||
import { PluginMeta } from '@grafana/data';
|
||||
|
||||
import { transformPluginSourceForCDN } from '../cdn/utils';
|
||||
import { resolveWithCache } from '../loader/cache';
|
||||
import { isHostedOnCDN } from '../loader/utils';
|
||||
|
||||
import { SandboxEnvironment } from './types';
|
||||
@ -40,7 +41,7 @@ export async function loadScriptIntoSandbox(url: string, meta: PluginMeta, sandb
|
||||
|
||||
export async function getPluginCode(meta: PluginMeta): Promise<string> {
|
||||
if (isHostedOnCDN(meta.module)) {
|
||||
// should load plugin from a CDN
|
||||
// Load plugin from CDN, no need for "resolveWithCache" as CDN URLs already include the version
|
||||
const url = meta.module;
|
||||
const response = await fetch(url);
|
||||
let pluginCode = await response.text();
|
||||
@ -51,8 +52,10 @@ export async function getPluginCode(meta: PluginMeta): Promise<string> {
|
||||
});
|
||||
return pluginCode;
|
||||
} else {
|
||||
//local plugin loading
|
||||
const response = await fetch(meta.module);
|
||||
// local plugin. resolveWithCache will append a query parameter with its version
|
||||
// to ensure correct cached version is served
|
||||
const pluginCodeUrl = resolveWithCache(meta.module);
|
||||
const response = await fetch(pluginCodeUrl);
|
||||
let pluginCode = await response.text();
|
||||
pluginCode = patchPluginSourceMap(meta, pluginCode);
|
||||
pluginCode = patchPluginAPIs(pluginCode);
|
||||
|
Loading…
Reference in New Issue
Block a user