Skip to content

Commit

Permalink
[canvas/loadPlugins] avoid deleting globals added by plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Dec 13, 2018
1 parent 96338a7 commit c071bb9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/kbn-interpreter/src/server/server_registries.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,21 @@ export const populateServerRegistries = types => {
const remainingTypes = types;
const populatedTypes = {};

const globalKeys = Object.keys(global);

const loadType = () => {
const type = remainingTypes.pop();
getPluginPaths(type).then(paths => {
global.canvas = global.canvas || {};
global.canvas.register = d => registries[type].register(d);
const existingGlobal = global.canvas;
global.canvas = { register: d => registries[type].register(d) };

paths.forEach(path => {
require(path);
});

Object.keys(global).forEach(key => {
if (!globalKeys.includes(key)) {
delete global[key];
}
});
if (typeof existingGlobal !== 'undefined') {
global.canvas = existingGlobal;
} else {
delete global.canvas;
}

populatedTypes[type] = registries[type];
if (remainingTypes.length) loadType();
Expand Down

0 comments on commit c071bb9

Please sign in to comment.