id | slug | title | description | date | tags | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
kibDevDocsOpsKbnPm |
/kibana-dev-docs/ops/kbn-pm |
@kbn/pm |
The tool which bootstraps the repo and helps work with packages |
2022-07-14 |
|
@kbn/pm
is the tool that we use to bootstrap the Kibana repository, build packages with Bazel, and run scripts in packages.
Use this command to install dependencies, build packages, and prepare the repo for local development.
Use this command to build all packages and make sure that they are rebuilt as you make changes.
There are several commands supported by @kbn/pm
, but rather than documenting them here they are documented in the help text. Please run yarn kbn --help
locally to see the most up-to-date info.
Since this tool is required for bootstrapping the repository it needs to work without any dependencies installed and without a build toolchain. We accomplish this by writing the tool in vanilla JS (shocker!) and using TypeScript to validate the code which is typed via heavy use of JSDoc comments.
In order to use import/export syntax and enhance the developer experience a little we use the .mjs
file extension.
In some cases we actually do use TypeScript files, just for defining complicated types. These files are then imported only in special TS-compatible JSDoc comments, so Node.js will never try to import them but they can be used to define types which are too complicated to define inline or in a JSDoc comment.
There are cases where @kbn/pm
relies on code from packages, mostly to prevent reimplementing common functionality. This can only be done in one of two ways:
- With a dynamic
await import(...)
statement that is always run after boostrap is complete, or is wrapped in a try/catch in case bootstrap didn't complete successfully. - By pulling in the source code of the un-built package.
Option 1 is used in several places, with contingencies in place in case bootstrap failed. Option 2 is used for two pieces of code which are needed in order to run bootstrap:
@kbn/plugin-discovery
as we need to populate the@kbn/package-map
to run Bazel@kbn/bazel-runner
as we want to have the logic for running bazel in a single location
Because we load these two packages from source, without being built, before bootstrap is ever run, they can not depend on other packages and must be written in Vanilla JS as well.