grafana/runtime: Expose SystemJS from @grafana/runtime (#17927)

In 4281344 the loadPluginCss util was migrated to @grafana/runtime package. This made SystemJS to fail loading the css files for a plugin. Root cause was that core and runtime used different SystemJS instances.

To solve the issue, I am exposing SystemJS from @grafana/runtime package to make sure we are always using the same instance. Also, the SystemJS dependency was moved to runtime.
This commit is contained in:
Dominik Prokop
2019-07-04 13:32:09 +02:00
committed by GitHub
parent 19ae5351fb
commit cf37b5439f
6 changed files with 22 additions and 23 deletions

View File

@@ -13,9 +13,7 @@ jest.mock('app/core/core', () => {
};
});
/* tslint:disable:import-blacklist */
import System from 'systemjs/dist/system.js';
import { SystemJS } from '@grafana/runtime';
import { AppPluginMeta, PluginMetaInfo, PluginType, PluginIncludeType, AppPlugin } from '@grafana/ui';
import { importAppPlugin } from './plugin_loader';
@@ -34,11 +32,11 @@ describe('Load App', () => {
const modulePath = 'my/custom/plugin/module';
beforeAll(() => {
System.set(modulePath, System.newModule({ plugin: app }));
SystemJS.set(modulePath, SystemJS.newModule({ plugin: app }));
});
afterAll(() => {
System.delete(modulePath);
SystemJS.delete(modulePath);
});
it('should call init and set meta', async () => {
@@ -52,7 +50,7 @@ describe('Load App', () => {
};
// Check that we mocked the import OK
const m = await System.import(modulePath);
const m = await SystemJS.import(modulePath);
expect(m.plugin).toBe(app);
const loaded = await importAppPlugin(meta);
@@ -79,11 +77,11 @@ describe('Load Legacy App', () => {
const modulePath = 'my/custom/legacy/plugin/module';
beforeAll(() => {
System.set(modulePath, System.newModule(app));
SystemJS.set(modulePath, SystemJS.newModule(app));
});
afterAll(() => {
System.delete(modulePath);
SystemJS.delete(modulePath);
});
it('should call init and set meta for legacy app', async () => {

View File

@@ -1,8 +1,7 @@
/* tslint:disable:import-blacklist */
import System from 'systemjs/dist/system.js';
import _ from 'lodash';
import * as sdk from 'app/plugins/sdk';
import kbn from 'app/core/utils/kbn';
// tslint:disable:import-blacklist
import moment from 'moment';
import angular from 'angular';
import jquery from 'jquery';
@@ -31,7 +30,6 @@ import * as d3 from 'd3';
import * as grafanaData from '@grafana/data';
import * as grafanaUI from '@grafana/ui';
import * as grafanaRuntime from '@grafana/runtime';
export { loadPluginCss } from '@grafana/runtime';
// rxjs
import { Observable, Subject } from 'rxjs';
@@ -41,9 +39,9 @@ const bust = `?_cache=${Date.now()}`;
function locate(load) {
return load.address + bust;
}
System.registry.set('plugin-loader', System.newModule({ locate: locate }));
grafanaRuntime.SystemJS.registry.set('plugin-loader', grafanaRuntime.SystemJS.newModule({ locate: locate }));
System.config({
grafanaRuntime.SystemJS.config({
baseURL: 'public',
defaultExtension: 'js',
packages: {
@@ -65,7 +63,7 @@ System.config({
});
function exposeToPlugin(name: string, component: any) {
System.registerDynamic(name, [], true, (require, exports, module) => {
grafanaRuntime.SystemJS.registerDynamic(name, [], true, (require, exports, module) => {
module.exports = component;
});
}
@@ -161,7 +159,7 @@ export function importPluginModule(path: string): Promise<any> {
if (builtIn) {
return Promise.resolve(builtIn);
}
return System.import(path);
return grafanaRuntime.SystemJS.import(path);
}
export function importDataSourcePlugin(meta: DataSourcePluginMeta): Promise<DataSourcePlugin<any>> {