-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Add TS projects for src/plugins & x-pack/plugins #78440
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
Changes from 13 commits
7463e15
4ab436d
e187e76
23bb02f
9be6fe2
7c9398b
7d4a0bf
40d95fd
b0d92f4
9df9ddf
014c4b4
8d41c8a
eaa507f
5b89668
7c6a40e
3e26554
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,18 +20,29 @@ | |
| import execa from 'execa'; | ||
| import { run, ToolingLog } from '@kbn/dev-utils'; | ||
|
|
||
| export async function buildRefs(log: ToolingLog) { | ||
| export async function buildRefs(log: ToolingLog, projectPath: string) { | ||
| try { | ||
| 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]); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to avoid hardcoding |
||
| } catch (e) { | ||
| log.error(e); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| export async function runBuildRefs() { | ||
| run(async ({ log }) => { | ||
| await buildRefs(log); | ||
| }); | ||
| run( | ||
| async ({ log, flags }) => { | ||
| await buildRefs(log, flags.project as string); | ||
| }, | ||
| { | ||
| description: 'Build TypeScript projects', | ||
| flags: { | ||
| string: ['project'], | ||
| help: ` | ||
| --project Required, path to the tsconfig.refs.file | ||
| `, | ||
| }, | ||
| } | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'); | ||
|
||
|
|
||
| const tscArgs = [ | ||
| // composite project cannot be used with --noEmit | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,5 +2,6 @@ | |
| "id": "kibanaReact", | ||
| "version": "kibana", | ||
| "ui": true, | ||
| "server": false, | ||
| "requiredBundles": ["kibanaUtils"] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| { | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "composite": true, | ||
| "outDir": "./target/types", | ||
| "emitDeclarationOnly": true, | ||
| "declaration": true, | ||
| "declarationMap": true | ||
| }, | ||
| "include": [ | ||
| "public/**/*", | ||
| "../../../typings/**/*" | ||
| ], | ||
| "references": [ | ||
| { "path": "../kibana_utils/tsconfig.json" } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "composite": true, | ||
| "outDir": "./target/types", | ||
| "emitDeclarationOnly": true, | ||
| "declaration": true, | ||
| "declarationMap": true | ||
| }, | ||
| "include": [ | ||
| "common/**/*", | ||
| "demos/**/*", | ||
| "public/**/*", | ||
| "server/**/*", | ||
| "index.ts", | ||
| "../../../typings/**/*" | ||
| ], | ||
| "references": [ | ||
| { "path": "../../test_utils/tsconfig.json" }, | ||
| { "path": "../../core/tsconfig.json" } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| { | ||
| "include": [], | ||
| "references": [ | ||
| { "path": "./src/test_utils" }, | ||
| { "path": "./src/core" }, | ||
| { "path": "./src/test_utils/tsconfig.json" }, | ||
| { "path": "./src/core/tsconfig.json" }, | ||
| { "path": "./src/plugins/kibana_utils/tsconfig.json" }, | ||
| { "path": "./src/plugins/kibana_react/tsconfig.json" }, | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "extends": "../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "composite": true, | ||
| "outDir": "./target/types", | ||
| "emitDeclarationOnly": true, | ||
| "declaration": true, | ||
| "declarationMap": true | ||
| }, | ||
| "include": [ | ||
| "public/**/*", | ||
| "server/**/*", | ||
| "common/**/*", | ||
| "../../../typings/**/*" | ||
| ], | ||
| "references": [ | ||
| { "path": "../../../src/core/tsconfig.json" }, | ||
| { "path": "../../../src/plugins/kibana_react/tsconfig.json" } | ||
| ] | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "include": [], | ||
| "references": [ | ||
| { "path": "./plugins/licensing/tsconfig.json" } | ||
| ] | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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
without refs
There was a problem hiding this comment.
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?

There was a problem hiding this comment.
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: truein./tsconfig.refs.jsonand then all other projects that might need these references just contain a single reference to./tsconfig.refs.jsoninstead 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
I declared the reference to
kibana_reactonly for projects with an explicit dependency onkibanaReactplugin inkibana.json. Indeed,kibana_reactmight me compiled as a transitive dependency (you can runtscwith--traceResolutionflag 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.