-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Move canvas interpreter to core #24041
Conversation
927a868
to
504dfd2
Compare
504dfd2
to
5697e42
Compare
💔 Build Failed |
77657d2
to
b548788
Compare
b548788
to
2cbced3
Compare
|
||
import clone from 'lodash.clone'; | ||
|
||
class PathsRegistry { |
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.
each plugin can register paths to this registry (during init) which we will search for function bundles.
export const getPluginPaths = type => { | ||
const typePath = pluginPaths[type]; | ||
if (!typePath) throw new Error(`Unknown type: ${type}`); | ||
const typePaths = pathsRegistry.get(type); |
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 get all the paths we need to search from the registry
|
||
import uuid from 'uuid/v4'; | ||
|
||
class PluginsLoadingState { |
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.
takes care of handling the plugin loading state on the client side. plugins call the loadBrowserPlugins()
, which is async function, inside a hack
. Everywhere we need loading of browser plugins to be complete, we should use this service to wait for all the browser plugins to be loaded.
|
||
pluginsLoaded.then(() => socket.emit('functionList', functionsRegistry.toJS())); | ||
pluginsLoadingState.loadingComplete().then(() => { | ||
socket.emit('functionList', functionsRegistry.toJS()); |
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.
wait for all the browser plugins to be loaded, then emit the functionList
|
||
export const getPluginStream = type => { | ||
const stream = ss(); | ||
const stream = ss({ | ||
separator: '\n', |
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.
not using the separator sometimes produces broken js files, when joining multiple webpack bundles
💔 Build Failed |
💔 Build Failed |
9dcbb16
to
1851fc8
Compare
💔 Build Failed |
jenkins, test this |
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 overall code LGTM.
I've currently only reviewed the code and didn't run any manual test already.
Will run them before closing my review
package.json
Outdated
"babel-plugin-inline-react-svg": "^0.5.4", | ||
"babel-plugin-mock-imports": "^0.0.5", | ||
"babel-plugin-pegjs-inline-precompile": "^0.1.0", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.14", | ||
"babel-register": "6.18.0", |
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.
Is there a specific reason for these plugins to be part of the dependencies
? Babel plugins are usually configured as devDependencies
import { includes } from 'lodash'; | ||
|
||
export function Arg(config) { | ||
if (config.name === '_') throw Error('Arg names must not be _. Use it in aliases instead.'); |
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.
nit: add curly bracket
this.multi = config.multi == null ? false : config.multi; | ||
this.resolve = config.resolve == null ? true : config.resolve; | ||
this.accepts = type => { | ||
if (!this.types.length) return true; |
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.
nit: add curly bracket
@@ -0,0 +1,69 @@ | |||
/* |
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.
As far as I know this is a new file. Can we directly rewrite this in typescript?
} | ||
|
||
register = (type, paths) => { | ||
if (!type) throw new Error(`Register requires a type`); |
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.
nit: add curly brackets
delete global._; | ||
|
||
if (remainingTypes.length) loadType(); | ||
else resolve(true); |
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.
nit: curly brackets
this.plugin('done', function (stats) { | ||
if (stats.compilation.errors && stats.compilation.errors.length) { | ||
if (isWatch) console.error(stats.compilation.errors[0]); | ||
else throw stats.compilation.errors[0]; |
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.
nit: curly brackets
|
||
import { resolve } from 'path'; | ||
|
||
const dir = resolve(__dirname, '..', '..', '..'); |
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.
👾👾👾
@@ -75,4 +75,7 @@ export const LICENSE_OVERRIDES = { | |||
'uglify-js@2.2.5': ['BSD'], | |||
'png-js@0.1.1': ['MIT'], | |||
'sha.js@2.4.11': ['BSD-3-Clause AND MIT'], | |||
|
|||
// TODO: can be removed once a new version is published | |||
'babel-plugin-mock-imports@0.0.5': ['MIT'], |
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.
there is a new version of babel-plugin-mock-imports
released 19 days ago :)
import plugins from './plugins'; | ||
import prepare from './prepare'; | ||
import test from './test'; | ||
|
||
export default function canvasTasks(gulp, gulpHelpers) { | ||
dev(gulp, gulpHelpers); | ||
peg(gulp, gulpHelpers); |
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.
is this entirely substituted by the pegjs common/lib/grammar.peg
command on package.json?
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.
except for the dev part (where it watches file for changes)
I've also tested canvas and seems that everything is working as expected |
💔 Build Failed |
the same functional test is also failing on master for the last few hours |
💔 Build Failed |
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've reviewed the changes. I've wrote down some TS comment that I think we need to adress
register = (type, paths) => { | ||
if (!type) throw new Error(`Register requires a type`); | ||
public register = (type: string, paths: any) => { | ||
if (!type) { |
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.
It's better to restrict it to string
or as my previous commit, restrict it to PathLike
} | ||
|
||
pathArray.forEach(p => { | ||
this._paths[lowerCaseType].push(p); | ||
// @ts-ignore | ||
this.paths.get(lowerCaseType).push(p); |
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.
since you are relatively sure that you have a map object with that name you can also be use the following this.paths.get(lowerCaseType)!.push(p);
You can also rewrite this in a more functional way like:
if (this.paths.has(lowerCaseType)) {
const currentPathArray = this.paths.get(lowerCaseType);
this.paths.set(lowerCaseType, [...currentPathArray, ...pathArray]);
} else {
this.paths.set(lowerCaseType, []);
}
|
||
get = (type) => { | ||
if (type === undefined) return []; | ||
public get = (type: string) => { |
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.
you should enforce the type output of this function:
public get = (type: string): string[] => {
so that in the future the return type is not dependant on the current implementation but depends on the method type signature: e.g. if in the future you change the implementation and add a code that return null, you will receive a warning/error from ts because of your method signature
get = (type) => { | ||
if (type === undefined) return []; | ||
public get = (type: string) => { | ||
if (type === undefined) { |
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.
so using typescript this never happen, but in the context of js/ts mix we have it's fine.
Maybe check if type
is something different from a string, because someone can also add in a number or a boolean, an object or null.
registerAll = (paths) => { | ||
Object.keys(paths).forEach(key => { | ||
this.register(key, paths[key]); | ||
public registerAll = (paths: any) => { |
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.
To keep it consistent with the rest of the file, it's better to use string
or PathLike
as type
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.
here paths is an object with { type: PathLike[], .... }
class PathsRegistry { | ||
private paths: Map<string, string[]>; |
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've read a bit where this code is executed, this should be a different type signature like
Map<string, PathLike[]>
using PathLike
from fs
lib. the PathLike
type should be then used in the rest of this file for a better type checking
💔 Build Failed |
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.
Looks good! Marco already covered a few comments I had, just added a couple more notes. I have not yet tested locally either; will wait to do that until everything is updated with master.
export function getType(node) { | ||
if (node == null) return 'null'; | ||
if (typeof node === 'object') { | ||
if (!node.type) throw new Error('Objects must have a type propery'); |
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.
missing t
in the word propery
if (!node.type) throw new Error('Objects must have a type propery'); | |
if (!node.type) throw new Error('Objects must have a type property'); |
}; | ||
|
||
toArray = () => { | ||
return Object.keys(this._paths).map(key => this.get(key)); |
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.
Would Object.values(this._paths);
have the same effect here? Or do we need to be calling this.get()
? Perhaps that was the intent due to the cloning...
get = (type) => { | ||
if (type === undefined) return []; | ||
const lowerCaseType = type.toLowerCase(); | ||
return this._paths[lowerCaseType] ? clone(this._paths[lowerCaseType]) : []; |
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.
if it is just a shallow clone, you could also do [...this._paths[lowerCaseType]]
instead of using lodash
|
||
setLoading() { | ||
const id = uuid(); | ||
this.states[id] = true; |
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.
It might be cleaner to do this.states = new Set();
in the constructor. That way you don't need to arbitrarily set true
here and can use add() delete() has()
throughout the rest of the class.
return; | ||
} | ||
return resolve(path, file); | ||
}).filter(path => path)).catch(); |
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.
what's .filter(path => path)
actually doing? and is the empty .catch
just there to swallow errors?
💔 Build Failed |
closed in favor of #25711 |
preparation for #23185
moves some parts of canvas to kibana core:
@kbn/interpreter
@kbn/interpreter
@kbn/interpreter
@kbn/interpreter
interpreter core_plugin
interpreter core_plugin
qa: nothing should change functionally
to test locally: