Skip to content

Commit

Permalink
Transpile packages on demand, validate all TS projects (#146212)
Browse files Browse the repository at this point in the history
## 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)](64e93e5)
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 <[email protected]>
  • Loading branch information
Spencer and kibanamachine authored Dec 23, 2022
1 parent e9c5c16 commit afb09cc
Show file tree
Hide file tree
Showing 2,421 changed files with 17,804 additions and 110,649 deletions.
5 changes: 2 additions & 3 deletions .bazelrc.common
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ query --incompatible_no_implicit_file_export
# Log configs
## different from default
common --color=yes
common --show_progress
common --noshow_progress
common --show_task_finish
common --show_progress_rate_limit=10
build --progress_report_interval=10
build --show_loading_progress
build --show_result=1
build --noshow_loading_progress

# Specifies desired output mode for running tests.
# Valid values are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,14 @@ export async function pickTestGroupRunOrder() {
groups: [
{
type: UNIT_TYPE,
defaultMin: 3,
defaultMin: 60,
maxMin: JEST_MAX_MINUTES,
overheadMin: 0.2,
names: jestUnitConfigs,
},
{
type: INTEGRATION_TYPE,
defaultMin: 10,
defaultMin: 60,
maxMin: JEST_MAX_MINUTES,
overheadMin: 0.2,
names: jestIntegrationConfigs,
Expand Down Expand Up @@ -389,7 +389,7 @@ export async function pickTestGroupRunOrder() {
label: 'Jest Tests',
command: getRequiredEnv('JEST_UNIT_SCRIPT'),
parallelism: unit.count,
timeout_in_minutes: 60,
timeout_in_minutes: 120,
key: 'jest',
agents: {
queue: 'n2-4-spot',
Expand All @@ -409,7 +409,7 @@ export async function pickTestGroupRunOrder() {
label: 'Jest Integration Tests',
command: getRequiredEnv('JEST_INTEGRATION_SCRIPT'),
parallelism: integration.count,
timeout_in_minutes: 60,
timeout_in_minutes: 120,
key: 'jest-integration',
agents: {
queue: 'n2-4-spot',
Expand Down
8 changes: 4 additions & 4 deletions .buildkite/scripts/steps/checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ export DISABLE_BOOTSTRAP_VALIDATION=false
.buildkite/scripts/bootstrap.sh

.buildkite/scripts/steps/checks/precommit_hook.sh
.buildkite/scripts/steps/checks/ftr_configs.sh
.buildkite/scripts/steps/checks/ts_projects.sh
.buildkite/scripts/steps/checks/bazel_packages.sh
.buildkite/scripts/steps/checks/verify_notice.sh
.buildkite/scripts/steps/checks/plugin_list_docs.sh
.buildkite/scripts/steps/checks/event_log.sh
.buildkite/scripts/steps/checks/telemetry.sh
.buildkite/scripts/steps/checks/ts_projects.sh
.buildkite/scripts/steps/checks/jest_configs.sh
.buildkite/scripts/steps/checks/plugin_list_docs.sh
.buildkite/scripts/steps/checks/bundle_limits.sh
.buildkite/scripts/steps/checks/i18n.sh
.buildkite/scripts/steps/checks/file_casing.sh
.buildkite/scripts/steps/checks/licenses.sh
.buildkite/scripts/steps/checks/plugins_with_circular_deps.sh
.buildkite/scripts/steps/checks/verify_notice.sh
.buildkite/scripts/steps/checks/test_projects.sh
.buildkite/scripts/steps/checks/test_hardening.sh
.buildkite/scripts/steps/checks/ftr_configs.sh
4 changes: 0 additions & 4 deletions .buildkite/scripts/steps/checks/bazel_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ set -euo pipefail

source .buildkite/scripts/common/util.sh

echo --- Check Bazel Packages Manifest
node scripts/generate packages_build_manifest
check_for_changed_files 'node scripts/generate packages_build_manifest' true

echo --- Check Codeowners Manifest
if [ -f ".github/CODEOWNERS" ]; then
node scripts/generate codeowners
Expand Down
10 changes: 8 additions & 2 deletions .buildkite/scripts/steps/checks/ts_projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ set -euo pipefail

source .buildkite/scripts/common/util.sh

echo --- Check TypeScript Projects
node scripts/check_ts_projects
echo --- Run TS Project Linter
cmd="node scripts/ts_project_linter"
if is_pr && ! is_auto_commit_disabled; then
cmd="$cmd --fix"
fi

eval "$cmd"
check_for_changed_files "$cmd" true
8 changes: 4 additions & 4 deletions .buildkite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"incremental": false,
"composite": false,
"emitDeclarationOnly": true,
"outDir": "./target/types",
"outDir": "target/types",
"types": ["node", "mocha"],
"paths": {
"#pipeline-utils": [".buildkite/pipeline-utils/index.ts"],
Expand All @@ -19,5 +16,8 @@
"scripts/**/*",
"pipelines/flaky_tests/groups.json",
"pull_requests.json"
],
"exclude": [
"target/**/*",
]
}
14 changes: 9 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
* Side Public License, v 1.
*/

require('@kbn/babel-register').install();

const Path = require('path');
const Fs = require('fs');

const normalizePath = require('normalize-path');
const { discoverPackageManifestPaths, Jsonc } = require('@kbn/bazel-packages');
const { REPO_ROOT } = require('@kbn/utils');
const { REPO_ROOT } = require('@kbn/repo-info');

const APACHE_2_0_LICENSE_HEADER = `
/*
Expand Down Expand Up @@ -137,6 +139,7 @@ const DEV_DIRECTORIES = [
'__mocks__',
'__stories__',
'e2e',
'cypress',
'fixtures',
'ftr_e2e',
'integration_tests',
Expand Down Expand Up @@ -165,7 +168,7 @@ const DEV_FILE_PATTERNS = [
'mock.{js,ts,tsx}',
'_stubs.{js,ts,tsx}',
'{testHelpers,test_helper,test_utils}.{js,ts,tsx}',
'{postcss,webpack}.config.js',
'{postcss,webpack,cypress}.config.{js,ts}',
];

/** Glob patterns which describe dev-only code. */
Expand All @@ -175,10 +178,10 @@ const DEV_PATTERNS = [
...DEV_FILE_PATTERNS.map((file) => `{packages,src,x-pack}/**/${file}`),
'packages/kbn-interpreter/tasks/**/*',
'src/dev/**/*',
'x-pack/{dev-tools,tasks,scripts,test,build_chromium}/**/*',
'x-pack/plugins/*/server/scripts/**/*',
'x-pack/plugins/fleet/cypress',
'x-pack/{dev-tools,tasks,test,build_chromium}/**/*',
'x-pack/performance/**/*',
'src/setup_node_env/index.js',
'src/cli/dev.js',
];

/** Restricted imports with suggested alternatives */
Expand Down Expand Up @@ -599,6 +602,7 @@ module.exports = {
'x-pack/test/saved_object_api_integration/*/apis/**/*',
'x-pack/test/ui_capabilities/*/tests/**/*',
'x-pack/test/performance/**/*.ts',
'**/cypress.config.{js,ts}',
],
rules: {
'import/no-default-export': 'off',
Expand Down
17 changes: 12 additions & 5 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -889,8 +889,10 @@ packages/kbn-apm-config-loader @elastic/kibana-core @vigneshshanmugam
packages/kbn-apm-synthtrace @elastic/apm-ui
packages/kbn-apm-utils @elastic/apm-ui
packages/kbn-axe-config @elastic/kibana-qa
packages/kbn-babel-plugin-synthetic-packages @elastic/kibana-operations
packages/kbn-babel-plugin-package-imports @elastic/kibana-operations
packages/kbn-babel-preset @elastic/kibana-operations
packages/kbn-babel-register @elastic/kibana-operations
packages/kbn-babel-transform @elastic/kibana-operations
packages/kbn-bazel-packages @elastic/kibana-operations
packages/kbn-bazel-runner @elastic/kibana-operations
packages/kbn-cases-components @elastic/response-ops
Expand All @@ -905,6 +907,7 @@ packages/kbn-config-mocks @elastic/kibana-core
packages/kbn-config-schema @elastic/kibana-core
packages/kbn-crypto @elastic/kibana-security
packages/kbn-crypto-browser @elastic/kibana-core
packages/kbn-cypress-config @elastic/kibana-operations
packages/kbn-datemath @elastic/kibana-app-services
packages/kbn-dev-cli-errors @elastic/kibana-operations
packages/kbn-dev-cli-runner @elastic/kibana-operations
Expand Down Expand Up @@ -954,13 +957,16 @@ packages/kbn-monaco @elastic/kibana-global-experience
packages/kbn-optimizer @elastic/kibana-operations
packages/kbn-optimizer-webpack-helpers @elastic/kibana-operations
packages/kbn-osquery-io-ts-types @elastic/security-asset-management
packages/kbn-package-map @elastic/kibana-operations
packages/kbn-peggy @elastic/kibana-operations
packages/kbn-peggy-loader @elastic/kibana-operations
packages/kbn-performance-testing-dataset-extractor @elastic/kibana-performance-testing
packages/kbn-plugin-discovery @elastic/kibana-operations
packages/kbn-plugin-generator @elastic/kibana-operations
packages/kbn-plugin-helpers @elastic/kibana-operations
packages/kbn-react-field @elastic/kibana-app-services
packages/kbn-repo-info @elastic/kibana-operations
packages/kbn-repo-path @elastic/kibana-operations
packages/kbn-repo-source-classifier @elastic/kibana-operations
packages/kbn-repo-source-classifier-cli @elastic/kibana-operations
packages/kbn-rison @elastic/kibana-operations
Expand Down Expand Up @@ -991,17 +997,17 @@ packages/kbn-spec-to-console @elastic/platform-deployment-management
packages/kbn-std @elastic/kibana-core
packages/kbn-stdio-dev-helpers @elastic/kibana-operations
packages/kbn-storybook @elastic/kibana-operations
packages/kbn-synthetic-package-map @elastic/kibana-operations
packages/kbn-telemetry-tools @elastic/kibana-core
packages/kbn-test @elastic/kibana-operations
packages/kbn-test-jest-helpers @elastic/kibana-operations
packages/kbn-test-subj-selector @elastic/kibana-operations
packages/kbn-timelion-grammar @elastic/kibana-visualizations
packages/kbn-tinymath @elastic/kibana-visualizations
packages/kbn-tooling-log @elastic/kibana-operations
packages/kbn-type-summarizer @elastic/kibana-operations
packages/kbn-type-summarizer-cli @elastic/kibana-operations
packages/kbn-type-summarizer-core @elastic/kibana-operations
packages/kbn-ts-project-linter @elastic/kibana-operations
packages/kbn-ts-project-linter-cli @elastic/kibana-operations
packages/kbn-ts-projects @elastic/kibana-operations
packages/kbn-ts-type-check-cli @elastic/kibana-operations
packages/kbn-typed-react-router-config @elastic/apm-ui
packages/kbn-ui-framework @elastic/kibana-design
packages/kbn-ui-shared-deps-npm @elastic/kibana-operations
Expand All @@ -1011,6 +1017,7 @@ packages/kbn-user-profile-components @elastic/kibana-security
packages/kbn-utility-types @elastic/kibana-core
packages/kbn-utility-types-jest @elastic/kibana-operations
packages/kbn-utils @elastic/kibana-operations
packages/kbn-web-worker-stub @elastic/kibana-operations
packages/kbn-yarn-lock-validator @elastic/kibana-operations
packages/shared-ux/avatar/solution @elastic/kibana-global-experience
packages/shared-ux/avatar/user_profile/impl @elastic/kibana-global-experience
Expand Down
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ report.asciidoc

# Automatically generated and user-modifiable
/tsconfig.refs.json
tsconfig.base.type_check.json
tsconfig.type_check.json
*.type_check.json

# Yarn local mirror content
.yarn-local-mirror
Expand All @@ -111,5 +110,5 @@ elastic-agent-*
fleet-server-*
elastic-agent.yml
fleet-server.yml
/packages/kbn-synthetic-package-map/synthetic-packages.json

/packages/kbn-package-map/package-map.json
/packages/kbn-synthetic-package-map/
11 changes: 9 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
exports_files(
[
"tsconfig.base.json",
"tsconfig.bazel.json",
"tsconfig.browser.json",
"tsconfig.browser_bazel.json",
"tsconfig.json",
"package.json"
"package.json",
".browserslistrc"
],
visibility = ["//visibility:public"]
)

config_setting(
name = "dist",
values = {
"define": "dist=true"
}
)
26 changes: 26 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,32 @@ THE SOFTWARE.
This product uses Noto fonts that are licensed under the SIL Open
Font License, Version 1.1.

---
This project includes code from the NX project, which is MIT licensed:

(The MIT License)

Copyright (c) 2017-2022 Narwhal Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---
Vendored copy of `strip-json-comments` so that we can use it when npm modules are not available.
https://github.com/sindresorhus/strip-json-comments/tree/34b79cb0f1129aa85ef4b5c3292e8bc546984ef9
Expand Down
2 changes: 1 addition & 1 deletion dev_docs/operations/operations_landing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ layout: landing
{ pageId: "kibDevDocsOpsOptimizer" },
{ pageId: "kibDevDocsOpsBabelPreset" },
{ pageId: "kibDevDocsOpsTypeSummarizer" },
{ pageId: "kibDevDocsOpsBabelPluginSyntheticPackages" },
{ pageId: "kibDevDocsOpsBabelPluginPackageImports" },
{ pageId: "kibDevDocsOpsUiSharedDepsNpm" },
{ pageId: "kibDevDocsOpsUiSharedDepsSrc" },
{ pageId: "kibDevDocsOpsPluginDiscovery" },
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ NOTE:

node scripts/build_plugin_list_docs

You can update the template within node_modules/@kbn/dev-utils/target_node/src/plugin_list/generate_plugin_list.js
You can update the template within packages/kbn-dev-utils/src/plugin_list/generate_plugin_list.ts

////
Expand Down
14 changes: 8 additions & 6 deletions examples/bfetch_explorer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target/types",
"outDir": "target/types",
},
"include": [
"index.ts",
Expand All @@ -10,11 +10,13 @@
"server/**/*.ts",
"../../typings/**/*",
],
"exclude": [],
"exclude": [
"target/**/*",
],
"kbn_references": [
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../developer_examples/tsconfig.json" },
{ "path": "../../src/plugins/bfetch/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
"@kbn/core",
"@kbn/developer-examples-plugin",
"@kbn/bfetch-plugin",
"@kbn/kibana-react-plugin",
]
}
22 changes: 14 additions & 8 deletions examples/controls_example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target/types"
"outDir": "target/types"
},
"include": [
"index.ts",
Expand All @@ -11,13 +11,19 @@
"server/**/*.ts",
"../../typings/**/*"
],
"exclude": [],
"exclude": [
"target/**/*",
],
"kbn_references": [
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../developer_examples/tsconfig.json" },
{ "path": "../../src/plugins/data/tsconfig.json" },
{ "path": "../../src/plugins/controls/tsconfig.json" },
{ "path": "../../src/plugins/navigation/tsconfig.json" },
{ "path": "../../src/plugins/presentation_util/tsconfig.json" }
"@kbn/core",
"@kbn/developer-examples-plugin",
"@kbn/data-plugin",
"@kbn/controls-plugin",
"@kbn/navigation-plugin",
"@kbn/presentation-util-plugin",
"@kbn/shared-ux-page-kibana-template",
"@kbn/embeddable-plugin",
"@kbn/data-views-plugin",
"@kbn/es-query",
]
}
Loading

0 comments on commit afb09cc

Please sign in to comment.