Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TS projects for src/plugins & x-pack/plugins #78440

Merged
merged 16 commits into from
Sep 30, 2020

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Sep 24, 2020

Summary

Add TS projects for:

  • kibana_utils
  • kibana_react
  • x-pack/licensing

I'm going to document migration path in the following PR.
I'd appreciate if @elastic/kibana-app-arch tested the changes and how they impact IDE responsiveness when working inside kibana_utils & kibana_react plugins.

Results

OSS project

node --max-old-space-size=6144 ./node_modules/.bin/tsc -p tsconfig.json --extendedDiagnostics --noEmit
branch

Files:                         5196
Lines:                       693734
Nodes:                      2281721
Identifiers:                 776729

master

Files:                        5278
Lines:                      713209
Nodes:                     2354541
Identifiers:                801842

x-pack project

node --max-old-space-size=6144 ./node_modules/.bin/tsc -p x-pack/tsconfig.json --extendedDiagnostics --noEmit
branch

Files:                        17378
Lines:                      2021622
Nodes:                      7108433
Identifiers:                2367775

master

Files:                        17403
Lines:                      2024480
Nodes:                      7120542
Identifiers:                2371851

@mshustov mshustov added chore Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Sep 24, 2020
log.info('Building TypeScript projects refs...');
await execa(require.resolve('typescript/bin/tsc'), ['-b', 'tsconfig.refs.json']);
log.debug(`Building TypeScript projects refs for ${projectPath}...`);
await execa(require.resolve('typescript/bin/tsc'), ['-b', projectPath]);
Copy link
Contributor Author

@mshustov mshustov Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid hardcoding x-pack/tsconfig.refs.json

@@ -80,7 +80,8 @@ export async function runTypeCheckCli() {
process.exit();
}

await buildRefs(log);
await buildRefs(log, 'tsconfig.refs.json');
await buildRefs(log, 'x-pack/tsconfig.refs.json');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hardcoded the path here since this script is meant to be used in dev only. @elastic/kibana-operations any problems with this?

@@ -13,6 +13,7 @@
],
"exclude": [],
"references": [
{ "path": "../../src/core/tsconfig.json" }
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
Copy link
Contributor Author

@mshustov mshustov Sep 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not necessary, as we don't build the project with tsc, but it reduces the number of processed files:
with refs

Files:                         884
Lines:                      219774
Nodes:                      789226
Identifiers:                286286

without refs

Files:                        1214
Lines:                      271616
Nodes:                      928343
Identifiers:                333268

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What project did you build for these stats?

There are a lot of other example projects that import kibana_react types, should we add references from their tsconfig.json files too?
Screenshot 2020-09-25 at 00 35 32

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might become hard to maintain all the references if we start having many small projects. Maybe we can set composite: true in ./tsconfig.refs.json and then all other projects that might need these references just contain a single reference to ./tsconfig.refs.json instead of a reference for each project.

I didn't test this, but my understanding is that you can create such hierarchies of projects and TS will still be clever about what files it includes in the build instead of building the whole parent project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test this, but my understanding is that you can create such hierarchies of projects and TS will still be clever about what files it includes in the build instead of building the whole parent project.

Tested just to make sure it doesn't work: TS cannot build a DAG since a project references itself and other project dependent on it.

It might become hard to maintain all the references if we start having many small projects.

I declared the reference to kibana_react only for projects with an explicit dependency on kibanaReact plugin in kibana.json. Indeed, kibana_react might me compiled as a transitive dependency (you can run tsc with --traceResolution flag to learn how a file was included). But we will resolve the over-compilation problem when switching all the plugins to TypeScript project refs, so I think it's okay for now.

@mshustov mshustov marked this pull request as ready for review September 24, 2020 16:38
@mshustov mshustov requested review from a team as code owners September 24, 2020 16:38
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ML/Transform changes LGTM

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled and played with kibana_react, didn't notice any issues. Rebuild on changes works, node scrtips/type_check works, IDE is responsive with suggestions and errors. Hard to assess responsiveness improvements during such testing.

Copy link
Member

@mistic mistic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a suggestion @restrry : I would probably create a buildAllRefs function on src/dev/typescript/build_refs.ts which builds all the refs projects (even if hardcoded) and use it at src/dev/typescript/run_type_check_cli.ts instead

@mshustov
Copy link
Contributor Author

@mistic like in this commit 7c6a40e ?

@mshustov
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id value diff baseline
enterpriseSearch 430.1KB +29.0B 430.1KB

distributable file count

id value diff baseline
default 45806 +21 45785

page load bundle size

id value diff baseline
upgradeAssistant 64.8KB +29.0B 64.8KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@mistic
Copy link
Member

mistic commented Sep 30, 2020

@restrry yes, I think it's more manageable like this! We do something similar for kbn/pm projects

@mshustov mshustov merged commit ae8f8e1 into elastic:master Sep 30, 2020
@mshustov mshustov deleted the plugins-ts-projects branch September 30, 2020 13:02
mshustov added a commit to mshustov/kibana that referenced this pull request Sep 30, 2020
* bump query-string version to remove manual type definitions

* remove manual type declaration

* add kibana_utils tsconfig

* add refs to kibana_utils tsconfig

* add kibana_utils to the project list

* add kibana_react project

* add support for x-pack/tsconfig.refs.json

* add ts project for x-pack licensing plugins

* add glob for ts projects in src/plugins & x-pack/plugins

* add refs to projects in examples

* fix ref paths in x-pack/test

* address mistic comments

Co-authored-by: Elastic Machine <[email protected]>
# Conflicts:
#	src/plugins/kibana_utils/kibana.json
mshustov added a commit that referenced this pull request Sep 30, 2020
* bump query-string version to remove manual type definitions

* remove manual type declaration

* add kibana_utils tsconfig

* add refs to kibana_utils tsconfig

* add kibana_utils to the project list

* add kibana_react project

* add support for x-pack/tsconfig.refs.json

* add ts project for x-pack licensing plugins

* add glob for ts projects in src/plugins & x-pack/plugins

* add refs to projects in examples

* fix ref paths in x-pack/test

* address mistic comments

Co-authored-by: Elastic Machine <[email protected]>
# Conflicts:
#	src/plugins/kibana_utils/kibana.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants