kibana/kbn_pm
Alex Szabo 08c5f0799d
[ci] Minor quick-checks updates (#215856)
## Summary
1 - `node scripts/prettier_topology_check` occasionally breaks with
`.gitignore` not being available, it's required for a globby call.
(https://buildkite.com/elastic/kibana-on-merge/builds/64944#0195c874-c2b0-436c-9752-91a6118dde9d)

2 - some scripts are run together by `yarn kbn run-in-packages` - this
script only logs AFTER a script finished successfully; when a script
like this fails, the failing script is not logged. This change logs
before to see what the error is. (ref:
https://elastic.slack.com/archives/C5UDAFZQU/p1742824259264329)
2025-04-08 09:26:14 +02:00
..
src [ci] Minor quick-checks updates (#215856) 2025-04-08 09:26:14 +02:00
README.mdx
tsconfig.json

---
id: kibDevDocsOpsKbnPm
slug: /kibana-dev-docs/ops/kbn-pm
title: "@kbn/pm"
description: 'The tool which bootstraps the repo and helps work with packages'
date: 2022-07-14
tags: ['kibana', 'dev', 'contributor', 'operations', 'packages', 'scripts']
---

`@kbn/pm` is the tool that we use to bootstrap the Kibana repository, build packages with Bazel, and run scripts in packages.

## commands

### `yarn kbn bootstrap`

Use this command to install dependencies, build packages, and prepare the repo for local development.

### `yarn kbn watch`

Use this command to build all packages and make sure that they are rebuilt as you make changes.

### and more!

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.

## Why isn't this TypeScript?

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:

 1. 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.
 2. 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:

 1. `@kbn/plugin-discovery` as we need to populate the `@kbn/package-map` to run Bazel
 2. `@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.