-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[interpreter/loadPlugins] avoid deleting globals added by plugins #27171
[interpreter/loadPlugins] avoid deleting globals added by plugins #27171
Conversation
bb9022b
to
c071bb9
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Pinging @elastic/kibana-canvas |
I decided I should write tests for the |
eba776d
to
a34b276
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this conceptually, we just need to make sure nothing break.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
// `a` is `functions` and `b` is `server` | ||
/\/canvas\/canvas_plugin\/(?!functions\/server)([^\/]+\/[^\/]+)/, | ||
// ignore paths matching `/canvas/canvas_plugin/` | ||
/\/canvas\/canvas_plugin\//, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By sharing the server_code_transformer with @kbn/interpreter
I was able to pre-transpile the server code in the canvas_plugin_src and remove this customization.
This comment has been minimized.
This comment has been minimized.
…generator-runtime-global
Thanks for the review, but we've changed the approach pretty dramatically due to issues/complexity caused by mocking out the module system
This comment has been minimized.
This comment has been minimized.
e58dc9a
to
5853717
Compare
💚 Build Succeeded |
delete global[key]; | ||
} | ||
}); | ||
delete global.canvas; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some documentation to this logic, to make it clear why we're adding, registering and then deleting the global?
Are there any other globals we should consider deleting? Forgive the terminology, but perhaps a registry of globals to delete would help, even if it's a bit derivative...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We add the global for plugins to use. They all use canvas.register
, so the global needs to exist when the code is run (ie. when require(path)
is run).
My understanding is that it's removed to avoid complaints from our test runners, which check for added globals in the node runtime and fail if any are unexpectedly added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of questions, nothing worth blocking the PR over though.
@@ -6,6 +6,9 @@ | |||
|
|||
const path = require('path'); | |||
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |||
const { | |||
createServerCodeTransformer, | |||
} = require('@kbn/interpreter/tasks/build/server_code_transformer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The interpreter seems like a weird place to import build configuration from. It's also weird that it's importing something that wouldn't be part of the published package.
Do you think putting this in another package (currently existing or not) would make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really don't want to have hundreds of packages in two years, so no to another package. I think this is fine, we don't publish these packages and if we want to we can figure something out then.
@@ -42,6 +42,8 @@ export function runMochaCli() { | |||
|
|||
// check that we aren't leaking any globals | |||
process.argv.push('--check-leaks'); | |||
// prevent globals injected from canvas plugins from triggering leak check | |||
process.argv.push('--globals', 'core,regeneratorRuntime,_'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of fragile, but at least future globals will break the CI.
I do wonder, is there a way to remove that lodash global?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, thought I approved this already. LGTM.
…astic#27171) Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins. resolves elastic#27162
…astic#27171) Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins. resolves elastic#27162
…7171) (#27852) Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins. resolves #27162
…7171) (#27851) Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins. resolves #27162
6.6 ffe58f4 |
…astic#27171) Plugins loaded by the `@kbn/interpreter` can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup the `canvas` global after loading the canvas plugins. resolves elastic#27162
Plugins loaded by the
@kbn/interpreter
can sometimes setup global values while loading, like the regeneratorRuntime for instance, but the current plugin loading code is deleting every global that was added during plugin load. This changes the logic to only cleanup thecanvas
global after loading the canvas plugins.resolves #27162