kibana/packages/kbn-cli-dev-mode/README.md
Pierre Gayvallet 265cc76247
Remove core->cli dependency (#95145)
* extract http_tools to package

* fix readme

* start moving stuff

* cleaning up `isDevCliParent`

* choose bootstrap script

* fix bootstrap script logic

* fix watch paths logic

* import REPO_ROOT from correct package

* create the @kbn/crypto package

* update core's `dev` config

* only export bootstrap function

* extract sslConfig to http-tools package

* fix core types

* fix optimizer tests

* fix cli_dev_mode tests

* fix basePath proxy tests

* update generated doc

* fix unit tests

* create @kbn/dev-cli-mode package

* remove useless comment

* self-review NITS

* update CODEOWNERS file

* add devOnly flag

* use variable for DEV_MODE_PATH

* review comments

* fix logger/log adapter

* fix log calls in base path proxy server

* address some review comments

* rename @kbn/http-tools to @kbn/server-http-tools

* more review comments

* move test to correct file

* add comment on getBootstrapScript

* fix lint

* lint

* add cli-dev-mode to eslint dev packages

* review comments

* update yarn.lock

* Revert "[ci] skip building ts refs when not necessary (#95739)"

This reverts commit e46a74f7
2021-03-30 13:39:32 +02:00

37 lines
2.4 KiB
Markdown

# `CliDevMode`
A class that manages the alternate behavior of the Kibana cli when using the `--dev` flag. This mode provides several useful features in a single CLI for a nice developer experience:
- automatic server restarts when code changes
- runs the `@kbn/optimizer` to build browser bundles
- runs a base path proxy which helps developers test that they are writing code which is compatible with custom basePath settings while they work
- pauses requests when the server or optimizer are not ready to handle requests so that when users load Kibana in the browser it's always using the code as it exists on disk
To accomplish this, and to make it easier to test, the `CliDevMode` class manages several objects:
## `Watcher`
The `Watcher` manages a [chokidar](https://github.com/paulmillr/chokidar) instance to watch the server files, logs about file changes observed and provides an observable to the `DevServer` via its `serverShouldRestart$()` method.
## `DevServer`
The `DevServer` object is responsible for everything related to running and restarting the Kibana server process:
- listens to restart notifications from the `Watcher` object, sending `SIGKILL` to the existing server and launching a new instance with the current code
- writes the stdout/stderr logs from the Kibana server to the parent process
- gracefully kills the process if the SIGINT signal is sent
- kills the server if the SIGTERM signal is sent, process.exit() is used, a second SIGINT is sent, or the gracefull shutdown times out
- proxies SIGHUP notifications to the child process, though the core team is working on migrating this functionality to the KP and making this unnecessary
## `Optimizer`
The `Optimizer` object manages a `@kbn/optimizer` instance, adapting its configuration and logging to the data available to the CLI.
## `BasePathProxyServer`
This proxy injects a random three character base path in the URL that Kibana is served from to help ensure that Kibana features
are written to adapt to custom base path configurations from users.
The basePathProxy also has another important job, ensuring that requests don't fail because the server is restarting and
that the browser receives front-end assets containing all saved changes. We accomplish this by observing the ready state of
the `Optimizer` and `DevServer` objects and pausing all requests through the proxy until both objects report that
they aren't building/restarting based on recently saved changes.