-
Notifications
You must be signed in to change notification settings - Fork 121
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
build: enable linking charts library to kibana #1164
Conversation
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.
Tested locally and I love how fast we can now test the changes to the library directly within Kibana!
Thanks Nick, that's awesome!!!
packages/link_kibana/main.js
Outdated
if (action === 'Link') { | ||
const { appLinkRelativePath } = await inquirer.prompt({ | ||
name: 'appLinkRelativePath', | ||
message: 'Enter path to applitcation directory to link', |
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.
typo
🎉 This PR is included in version 30.0.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
Adds a new command line aid for linking charts library to kibana.
Important features:
Entry command:
You will be prompted to
Link
,Unlink
orWatch mode
.Link
- Starts linking process and ends in watch mode to update built filesUnlink
- Cleans up all changes related to the linking processWatch mode
- Skips linking and just starts watching. Requires previous link. Used if something really bad happens and the watchers give up, or you accidentally quit the watch mode.Linking
Linking requires you to bootstrap and start kibana before linking.
The only other prompt is for the relative path from
@elastic/charts
directory tokibana
directory.The script does all of the following:
@elastic/charts
is watch modelinkedPackages
require statements with relative paths (require("react")
becomesrequire("../path/to/kibana/react")
)@kbn/ui-shared-deps
in watch modeThe struggle 😫
The
@kbn/ui-shared-deps
package is used, to my best understanding, as a poor-mansyarn resolution
creating a single export for singlton packages and packages needing consistent versions. Most important isreact
as hooks require the use of the same react instance. Linking charts to kibana would enable kibana to use the linked react but that local charts would use the localreact
(i.e.elastic-charts/node_modules_react
).If we then attempt to link
react
in charts to point at react in kibana, it would use the correct react (i.e.path/to/kibana/node_modules/react
BUT the way that webpack bundles@kbn/ui-shared-deps
this will not be the same instance of react and thus still throwing the dreaded invalid hook call warning so symlinkingreact
does not work.The solution is to replace all the paths in the built chart
dist
output to thier relative path to the kibanareact
. This will use the webpack exported instance ofreact
from@kbn/ui-shared-deps
. This however is not going to work just replacing thereact
since other packages likereact-redux
point to react internally and since that is thereact-redux
local to charts it will be wrong yet again. So the solution is to replacereact
,react-dom
,react-redux
andredux
. So every change that happens in charts needs to be built, swap the links and build@kbn/ui-shared-deps
to be reflected in kibana.The good news is that there are no changes to src in either kibana nor charts for linking to take place. This makes it easy to cleanup the linked files once no longer needed.
But how do I know it's linked and what charts directory is linked?
I added a console.log to clearly indicate when charts is linked and was chart directory is linked.
Limitations
.ts
files, notscss
nvm install
to update kibana on the fly, requires user to update node manually.