mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -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:
@@ -1,6 +1,7 @@
|
|||||||
import { PluginMeta } from '@grafana/data';
|
import { PluginMeta } from '@grafana/data';
|
||||||
|
|
||||||
import { transformPluginSourceForCDN } from '../cdn/utils';
|
import { transformPluginSourceForCDN } from '../cdn/utils';
|
||||||
|
import { resolveWithCache } from '../loader/cache';
|
||||||
import { isHostedOnCDN } from '../loader/utils';
|
import { isHostedOnCDN } from '../loader/utils';
|
||||||
|
|
||||||
import { SandboxEnvironment } from './types';
|
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> {
|
export async function getPluginCode(meta: PluginMeta): Promise<string> {
|
||||||
if (isHostedOnCDN(meta.module)) {
|
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 url = meta.module;
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
let pluginCode = await response.text();
|
let pluginCode = await response.text();
|
||||||
@@ -51,8 +52,10 @@ export async function getPluginCode(meta: PluginMeta): Promise<string> {
|
|||||||
});
|
});
|
||||||
return pluginCode;
|
return pluginCode;
|
||||||
} else {
|
} else {
|
||||||
//local plugin loading
|
// local plugin. resolveWithCache will append a query parameter with its version
|
||||||
const response = await fetch(meta.module);
|
// to ensure correct cached version is served
|
||||||
|
const pluginCodeUrl = resolveWithCache(meta.module);
|
||||||
|
const response = await fetch(pluginCodeUrl);
|
||||||
let pluginCode = await response.text();
|
let pluginCode = await response.text();
|
||||||
pluginCode = patchPluginSourceMap(meta, pluginCode);
|
pluginCode = patchPluginSourceMap(meta, pluginCode);
|
||||||
pluginCode = patchPluginAPIs(pluginCode);
|
pluginCode = patchPluginAPIs(pluginCode);
|
||||||
|
|||||||
Reference in New Issue
Block a user