Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/bfetch_explorer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.

]
}
3 changes: 2 additions & 1 deletion examples/embeddable_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
],
"exclude": [],
"references": [
{ "path": "../../src/core/tsconfig.json" }
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
]
}
4 changes: 3 additions & 1 deletion examples/state_containers_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
],
"exclude": [],
"references": [
{ "path": "../../src/core/tsconfig.json" }
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
]
}
3 changes: 2 additions & 1 deletion examples/ui_action_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
],
"exclude": [],
"references": [
{ "path": "../../src/core/tsconfig.json" }
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
]
}
3 changes: 2 additions & 1 deletion examples/ui_actions_explorer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"exclude": [],
"references": [
{ "path": "../../src/core/tsconfig.json" }
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"kbn:watch": "node scripts/kibana --dev --logging.json=false",
"build:types": "rm -rf ./target/types && tsc --p tsconfig.types.json",
"docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"kbn:bootstrap": "node scripts/build_ts_refs && node scripts/register_git_hook",
"kbn:bootstrap": "node scripts/build_ts_refs --project tsconfig.refs.json && node scripts/register_git_hook",
"spec_to_console": "node scripts/spec_to_console",
"backport-skip-ci": "backport --prDescription \"[skip-ci]\"",
"storybook": "node scripts/storybook",
Expand Down
23 changes: 17 additions & 6 deletions src/dev/typescript/build_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
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

} 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
`,
},
}
);
}
10 changes: 8 additions & 2 deletions src/dev/typescript/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import { Project } from './project';

export const PROJECTS = [
new Project(resolve(REPO_ROOT, 'tsconfig.json')),
new Project(resolve(REPO_ROOT, 'src/test_utils/tsconfig.json')),
new Project(resolve(REPO_ROOT, 'src/core/tsconfig.json')),
new Project(resolve(REPO_ROOT, 'test/tsconfig.json'), { name: 'kibana/test' }),
new Project(resolve(REPO_ROOT, 'x-pack/tsconfig.json')),
new Project(resolve(REPO_ROOT, 'x-pack/test/tsconfig.json'), { name: 'x-pack/test' }),
new Project(resolve(REPO_ROOT, 'src/test_utils/tsconfig.json')),
new Project(resolve(REPO_ROOT, 'src/core/tsconfig.json')),
new Project(resolve(REPO_ROOT, 'x-pack/plugins/security_solution/cypress/tsconfig.json'), {
name: 'security_solution/cypress',
}),
Expand All @@ -47,6 +47,12 @@ export const PROJECTS = [
...glob
.sync('packages/*/tsconfig.json', { cwd: REPO_ROOT })
.map((path) => new Project(resolve(REPO_ROOT, path))),
...glob
.sync('src/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
.map((path) => new Project(resolve(REPO_ROOT, path))),
...glob
.sync('x-pack/plugins/*/tsconfig.json', { cwd: REPO_ROOT })
.map((path) => new Project(resolve(REPO_ROOT, path))),
...glob
.sync('examples/*/tsconfig.json', { cwd: REPO_ROOT })
.map((path) => new Project(resolve(REPO_ROOT, path))),
Expand Down
3 changes: 2 additions & 1 deletion src/dev/typescript/run_type_check_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?


const tscArgs = [
// composite project cannot be used with --noEmit
Expand Down
1 change: 1 addition & 0 deletions src/plugins/kibana_react/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"id": "kibanaReact",
"version": "kibana",
"ui": true,
"server": false,
"requiredBundles": ["kibanaUtils"]
}
17 changes: 17 additions & 0 deletions src/plugins/kibana_react/tsconfig.json
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" }
]
}
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"id": "kibanaUtils",
"version": "kibana",
"ui": true,
"server": false,
"extraPublicDirs": [
"common",
"demos/state_containers/todomvc",
Expand Down
22 changes: 22 additions & 0 deletions src/plugins/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" }
]
}
4 changes: 3 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"interpreter_functional/plugins/**/*"
],
"references": [
{ "path": "../src/core/tsconfig.json" }
{ "path": "../src/core/tsconfig.json" },
{ "path": "../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../src/plugins/kibana_react/tsconfig.json" }
]
}
8 changes: 6 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"exclude": [
"src/**/__fixtures__/**/*",
"src/test_utils/**/*",
"src/core/**/*"
"src/core/**/*",
"src/plugins/kibana_utils/**/*",
"src/plugins/kibana_react/**/*"
// In the build we actually exclude **/public/**/* from this config so that
// we can run the TSC on both this and the .browser version of this config
// file, but if we did it during development IDEs would not be able to find
Expand All @@ -21,6 +23,8 @@
],
"references": [
{ "path": "./src/test_utils/tsconfig.json" },
{ "path": "./src/core/tsconfig.json" }
{ "path": "./src/core/tsconfig.json" },
{ "path": "./src/plugins/kibana_utils/tsconfig.json" },
{ "path": "./src/plugins/kibana_react/tsconfig.json" }
]
}
6 changes: 4 additions & 2 deletions tsconfig.refs.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" },
]
}
4 changes: 3 additions & 1 deletion x-pack/examples/ui_actions_enhanced_examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
],
"exclude": [],
"references": [
{ "path": "../../../src/core/tsconfig.json" }
{ "path": "../../../src/core/tsconfig.json" },
{ "path": "../../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../../../src/plugins/kibana_react/tsconfig.json" },
]
}
2 changes: 1 addition & 1 deletion x-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Elastic-License",
"scripts": {
"kbn": "node ../scripts/kbn",
"kbn:bootstrap": "node plugins/canvas/scripts/storybook --clean",
"kbn:bootstrap": "node ../scripts/build_ts_refs --project tsconfig.refs.json && node plugins/canvas/scripts/storybook --clean",
"start": "node ../scripts/kibana --dev",
"build": "gulp build",
"testonly": "echo 'Deprecated, use `yarn test`' && gulp test",
Expand Down
20 changes: 20 additions & 0 deletions x-pack/plugins/licensing/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" }
]
}
3 changes: 0 additions & 3 deletions x-pack/plugins/transform/tsconfig.json

This file was deleted.

5 changes: 4 additions & 1 deletion x-pack/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"../typings/jest.d.ts"
],
"references": [
{ "path": "../../src/core/tsconfig.json" }
{ "path": "../../src/core/tsconfig.json" },
{ "path": "../../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../../src/plugins/kibana_react/tsconfig.json" },
{ "path": "../plugins/licensing/tsconfig.json" }
]
}
10 changes: 8 additions & 2 deletions x-pack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test/**/*",
"plugins/security_solution/cypress/**/*",
"plugins/apm/e2e/cypress/**/*",
"plugins/apm/scripts/**/*"
"plugins/apm/scripts/**/*",
"plugins/licensing/**/*"
],
"compilerOptions": {
"outDir": ".",
Expand All @@ -24,5 +25,10 @@
// overhead is too significant
"incremental": false
},
"references": [{ "path": "../src/core/tsconfig.json" }]
"references": [
{ "path": "../src/core/tsconfig.json" },
{ "path": "../src/plugins/kibana_utils/tsconfig.json" },
{ "path": "../src/plugins/kibana_react/tsconfig.json" },
{ "path": "./plugins/licensing/tsconfig.json" }
]
}
6 changes: 6 additions & 0 deletions x-pack/tsconfig.refs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"include": [],
"references": [
{ "path": "./plugins/licensing/tsconfig.json" }
]
}