-
Notifications
You must be signed in to change notification settings - Fork 27
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
Plugin Meta Extractor: Initial version #805
Conversation
f1c92ea
to
64b9943
Compare
a095ce4
to
31a4815
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.
Great work on this @mckn and @leventebalogh ! 👏
I've left a few comments for consideration.
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.
Think this looks really cool. Awesome work on this!
Some high level questions from me.
In real world scenarios today, can it be the case that an app plugin conditionally configures an extension? For example only registering an extension link in case a certain feature toggle is enabled. In that case, will it be problematic that extensions are extracted at build time rather than runtime?
If I understand correctly, we can traverse the AST also in the case the entry file is a javascript file. So in theory we could support extraction also for javascript plugins? It seems we use the typechecker in a few places in the code. Are we targeting typescript plugins only?
I understand this is still in experimental phase, but I'm curious to know how this fits into the story around registering extensions. Do you think using this tool to extract extensions built time could become a requirement, or would we support extracting them runtime too? How does this relate to the reactive extensions registry feature (that is not merged yet)?
Are you imagine the generated content to go into the plugin.json or how are you imagine this to be consumed within grafana? |
@sunker Thanks for the questions!
Unfortunately we don't yet support every dynamic pattern with this tool for registering extensions from a plugin (we only support basic chained method calls on the AppPlugin instance at this point) - however we are planning to do so in the future. (Something like this can also be done in the chained-method-call pattern: returning
I am afraid this will only work properly for plugins written in typescript at this point (
This tool is planned to be used seamlessly in our plugin build configuration that is provided by create-plugin, however the meta-info it generates will only be used to decide when a plugin should be preloaded. (Plugins will still be able to dynamically register an extension point, for these scenarios - at least for now - we will always need to preload the plugin.) |
Hmm, after discussing this with @jackw and @mckn we decided to not put it in |
4162173
to
925b993
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 think this looks great! A question regarding the webpack plugin. Will it update the plugin.json in the /dist
folder or the one in /src
?
That's a good question. It only updates the one in the |
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
918a35c
to
a826493
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.
Awesome work on this @mckn and @leventebalogh . 🚀
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
🚀 PR was released in |
What is this?
The Plugin Meta Extractor (
@grafana/plugin-meta-extractor
) is a new package that can be used to extract meta-information from the plugin's source code. The goal is to be able to automatically generate static information about the plugin without needing the plugin-dev to care about these (e.g. extension point information).View README
PR for adding the plugin to our webpack config
What kind of meta-data?
Currently we only extract basic information about the extensions that the plugin registers.
Supported plugin format
The tool currently only recognises extensions that are registered in the following format:
How does it work?
It uses the typescript AST to find usages of the functions that register extensions. The package also exposes a Webpack plugin that can be used to generate a meta-info file during the build of the plugin.
How to use it?
CLI
npm install
cd packages/plugin-meta-extractor
npm run build
./dist/bin/run.js ~/my-grafana-plugin/src/module.ts
_(prints to the console)npm link
to depend on the local version of the package while developingCode
Webpack
What data does it give back?
It always returns with a valid JSON in the following format:
Todo
entry: "./module.ts"
entry: ["./module.ts", "./datasource/module.ts"]
entry: { module: "./module.ts" }
📦 Published PR as canary version:
Canary Versions
✨ Test out this PR locally via:
npm install @grafana/plugin-meta-extractor@0.0.1-canary.805.f998cc3.0 # or yarn add @grafana/plugin-meta-extractor@0.0.1-canary.805.f998cc3.0