mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
2 commits
Author | SHA1 | Message | Date | |
---|---|---|---|---|
|
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:** [` |
||
|
5a86b583df
|
[Files] Move <FileUpload /> and <FilePicker /> 👉🏻 packages/shared-ux/file (#146284)
## Summary This is a refactor: * Move `FilesContext`, `FilePicker` and `UploadFile` components to `packages/shared-ux/file` as packages * Renamed `UploadFile` to `FileUpload` for more consistency * Also created `packages/shared-ux/file/types` and added `useBehaviourSubject` to `packages/shared-ux/file/util` (we can consider moving this elsewhere since that function is not necessarily tied to the files domain). * Removed the storybook config from `files` public plugin since there are no more components there ## How to test 👉🏻 `yarn storybook shared_ux` to see the components in a lab environment OR 👉🏻 `yarn start --run-examples` then "Developer examples" > "Files example" to see the components being used in Kibana Look out for any regressions: for example, in the `FileImage` component importing `import bh from 'blurhash'` caused a regression because blurhash does not expose a default export. This was fixed by doing: `import * as bh from 'blurhash`. ## Notes * With this change, we needed to move `FilesClient` interface to packages since it is used by the components. However, we also wanted to keep `FilesClient` interface as it is currently exported from `files` plugin because it exposes methods that only the server of `files` plugin should know about (e.g., the metrics endpoint). I created the `BaseFilesClient` in the packages directory that is extended in the `files` plugin as needed. This is a snapshot of the types as they are provided from the server implementation and will need to be updated/maintained by hand from here on out. * With `BaseFilesClient` in `packages`, we lost the type check between `files` server endpoints and the client methods. To re-establish this link the `CreateRouteDefinition` type helper got a parameter where the client method can be passed in to do checks that the server inputs (query, param and body) as well as outputs (the responses) match what the client expects using the `X extends Y ? X : unknown` capability of TS. See this in action in, for example `src/plugins/files/server/routes/find.ts`. DX will be: if these ever get out of sync, the server values for `query`, `param` or `body` will map to `unknown` causing a type issue when trying to use these values. This can only be fixed by bringing the `FilesClient` types in sync with the server types. * Server endpoints that should match expected `FilesClient` inputs/outputs should use the `CreateRouteDefinition` type helper, but if the endpoint does not need to map to a client method we can always skip using `CreateRouteDefinition`. Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> |