kibana/packages
Spencer afb09ccf8a
Transpile packages on demand, validate all TS projects (#146212)
## Dearest Reviewers 👋 

I've been working on this branch with @mistic and @tylersmalley and
we're really confident in these changes. Additionally, this changes code
in nearly every package in the repo so we don't plan to wait for reviews
to get in before merging this. If you'd like to have a concern
addressed, please feel free to leave a review, but assuming that nobody
raises a blocker in the next 24 hours we plan to merge this EOD pacific
tomorrow, 12/22.

We'll be paying close attention to any issues this causes after merging
and work on getting those fixed ASAP. 🚀

---

The operations team is not confident that we'll have the time to achieve
what we originally set out to accomplish by moving to Bazel with the
time and resources we have available. We have also bought ourselves some
headroom with improvements to babel-register, optimizer caching, and
typescript project structure.

In order to make sure we deliver packages as quickly as possible (many
teams really want them), with a usable and familiar developer
experience, this PR removes Bazel for building packages in favor of
using the same JIT transpilation we use for plugins.

Additionally, packages now use `kbn_references` (again, just copying the
dx from plugins to packages).

Because of the complex relationships between packages/plugins and in
order to prepare ourselves for automatic dependency detection tools we
plan to use in the future, this PR also introduces a "TS Project Linter"
which will validate that every tsconfig.json file meets a few
requirements:

1. the chain of base config files extended by each config includes
`tsconfig.base.json` and not `tsconfig.json`
1. the `include` config is used, and not `files`
2. the `exclude` config includes `target/**/*`
3. the `outDir` compiler option is specified as `target/types`
1. none of these compiler options are specified: `declaration`,
`declarationMap`, `emitDeclarationOnly`, `skipLibCheck`, `target`,
`paths`

4. all references to other packages/plugins use their pkg id, ie:
	
	```js
    // valid
    {
      "kbn_references": ["@kbn/core"]
    }
    // not valid
    {
      "kbn_references": [{ "path": "../../../src/core/tsconfig.json" }]
    }
    ```

5. only packages/plugins which are imported somewhere in the ts code are
listed in `kbn_references`

This linter is not only validating all of the tsconfig.json files, but
it also will fix these config files to deal with just about any
violation that can be produced. Just run `node scripts/ts_project_linter
--fix` locally to apply these fixes, or let CI take care of
automatically fixing things and pushing the changes to your PR.

> **Example:** [`64e93e5`
(#146212)](64e93e5806)
When I merged main into my PR it included a change which removed the
`@kbn/core-injected-metadata-browser` package. After resolving the
conflicts I missed a few tsconfig files which included references to the
now removed package. The TS Project Linter identified that these
references were removed from the code and pushed a change to the PR to
remove them from the tsconfig.json files.

## No bazel? Does that mean no packages??
Nope! We're still doing packages but we're pretty sure now that we won't
be using Bazel to accomplish the 'distributed caching' and 'change-based
tasks' portions of the packages project.

This PR actually makes packages much easier to work with and will be
followed up with the bundling benefits described by the original
packages RFC. Then we'll work on documentation and advocacy for using
packages for any and all new code.

We're pretty confident that implementing distributed caching and
change-based tasks will be necessary in the future, but because of
recent improvements in the repo we think we can live without them for
**at least** a year.

## Wait, there are still BUILD.bazel files in the repo
Yes, there are still three webpack bundles which are built by Bazel: the
`@kbn/ui-shared-deps-npm` DLL, `@kbn/ui-shared-deps-src` externals, and
the `@kbn/monaco` workers. These three webpack bundles are still created
during bootstrap and remotely cached using bazel. The next phase of this
project is to figure out how to get the package bundling features
described in the RFC with the current optimizer, and we expect these
bundles to go away then. Until then any package that is used in those
three bundles still needs to have a BUILD.bazel file so that they can be
referenced by the remaining webpack builds.

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2022-12-22 19:00:29 -06:00
..
analytics Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
content-management Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
core Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
home Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ace Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-alerts Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ambient-common-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ambient-ftr-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ambient-storybook-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ambient-ui-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-analytics Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-apm-config-loader Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-apm-synthtrace Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-apm-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-axe-config Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-babel-plugin-package-imports Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-babel-preset Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-babel-register Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-babel-transform Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-bazel-packages Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-bazel-runner Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-cases-components Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-chart-icons Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ci-stats-core Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ci-stats-performance-metrics Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ci-stats-reporter Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-cli-dev-mode Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-coloring Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-config Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-config-mocks Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-config-schema Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-crypto Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-crypto-browser Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-cypress-config Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-datemath Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-dev-cli-errors Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-dev-cli-runner Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-dev-proc-runner Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-dev-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-doc-links Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-docs-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ebt-tools Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ecs Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-es Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-es-archiver Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-es-errors Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-es-query Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-es-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-eslint-config Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-eslint-plugin-disable Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-eslint-plugin-eslint Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-eslint-plugin-imports Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-expect Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-failed-test-reporter-cli Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-field-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-find-used-node-modules Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-flot-charts Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ftr-common-functional-services Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ftr-screenshot-filename Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-generate Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-get-repo-files Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-guided-onboarding Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-handlebars Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-hapi-mocks Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-health-gateway-server Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-i18n Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-i18n-react Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-import-resolver Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-interpreter Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-io-ts-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-jest-serializers Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-journeys Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-kibana-manifest-schema Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-language-documentation-popover Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-logging Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-logging-mocks Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-managed-vscode-config Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-managed-vscode-config-cli Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-mapbox-gl Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-monaco Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-optimizer Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-optimizer-webpack-helpers Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-osquery-io-ts-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-package-map Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-peggy Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-peggy-loader Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-performance-testing-dataset-extractor Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-plugin-discovery Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-plugin-generator Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-plugin-helpers Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-react-field Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-repo-info Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-repo-path Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-repo-source-classifier Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-repo-source-classifier-cli Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-rison Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-rule-data-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-safer-lodash-set Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-autocomplete Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-es-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-exception-list-components Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-hook-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-io-ts-alerting-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-io-ts-list-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-io-ts-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-io-ts-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-list-api Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-list-constants Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-list-hooks Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-list-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-rules Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-t-grid Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-securitysolution-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-server-http-tools Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-server-route-repository Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-shared-svg Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-shared-ux-utility Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-some-dev-log Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-sort-package-json Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-spec-to-console Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-std Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-stdio-dev-helpers Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-storybook Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-telemetry-tools Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-test Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-test-jest-helpers Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-test-subj-selector Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-timelion-grammar Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-tinymath Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-tooling-log Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ts-project-linter Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ts-project-linter-cli Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ts-projects Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ts-type-check-cli Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-typed-react-router-config Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ui-framework Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ui-shared-deps-npm Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ui-shared-deps-src Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-ui-theme Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-user-profile-components Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-utility-types Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-utility-types-jest Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-utils Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-web-worker-stub Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
kbn-yarn-lock-validator Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
shared-ux Transpile packages on demand, validate all TS projects (#146212) 2022-12-22 19:00:29 -06:00
README.md [kbn/pm] rewrite to avoid needing a build process (#136207) 2022-07-18 08:46:13 -07:00

Kibana-related packages

This folder contains packages that are intended for use in Kibana and Kibana plugins.

tl;dr:

  • Don't publish to npm registry
  • Always use the @kbn namespace
  • Always set "private": true in package.json

Using these packages

We no longer publish these packages to the npm registry. Now, instead of specifying a version when including these packages, we rely on yarn workspaces, which sets up a symlink to the package.

For example if you want to use the @kbn/i18n package in Kibana itself, you can specify the dependency like this:

"@kbn/i18n": "1.0.0"

However, if you want to use this from a Kibana plugin, you need to use a link: dependency and account for the relative location of the Kibana repo, so it would instead be:

"@kbn/i18n": "link:../../kibana/packages/kbn-i18n"

Creating a new package

Create a new sub-folder. The name of the folder should mirror the name in the package's package.json. E.g. if the name is @kbn/i18n the folder name should be kbn-i18n.

All new packages should use the @kbn namespace, and should be marked with "private": true.

Unit tests for a package

Currently there is only one tool being used in order to test packages which is Jest. Below we will explain how it should be done.

Jest

A package should follow the pattern of having .test.js files as siblings of the source code files, and these run by Jest.

A package using the .test.js naming convention will have those tests automatically picked up by Jest and run by the unit test runner, currently mapped to the Kibana test script in the root package.json.

  • yarn test runs all unit tests.
  • yarn jest runs all Jest tests in Kibana.

In order for the plugin or package to use Jest, a jest.config.js file must be present in it's root. However, there are safeguards for this in CI should a test file be added without a corresponding config file.


Each package can also specify its own test script in the package's package.json, for cases where you'd prefer to run the tests from the local package directory.