Skip to content

Commit

Permalink
Add TS projects for src/plugins & x-pack/plugins (elastic#78440)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mshustov committed Sep 30, 2020
1 parent c710567 commit 5104313
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 30 deletions.
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" },
]
}
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",
"storybook": "node scripts/storybook"
},
Expand Down
29 changes: 23 additions & 6 deletions src/dev/typescript/build_refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,37 @@
*/

import execa from 'execa';
import Path from 'path';
import { run, ToolingLog } from '@kbn/dev-utils';

export async function buildRefs(log: ToolingLog) {
export async function buildAllRefs(log: ToolingLog) {
await buildRefs(log, 'tsconfig.refs.json');
await buildRefs(log, Path.join('x-pack', 'tsconfig.refs.json'));
}

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]);
} 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
4 changes: 2 additions & 2 deletions src/dev/typescript/run_type_check_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import getopts from 'getopts';

import { execInProjects } from './exec_in_projects';
import { filterProjectsByFlag } from './projects';
import { buildRefs } from './build_refs';
import { buildAllRefs } from './build_refs';

export async function runTypeCheckCli() {
const extraFlags: string[] = [];
Expand Down Expand Up @@ -80,7 +80,7 @@ export async function runTypeCheckCli() {
process.exit();
}

await buildRefs(log);
await buildAllRefs(log);

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" }
]
}
7 changes: 6 additions & 1 deletion src/plugins/kibana_utils/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"id": "kibanaUtils",
"version": "kibana",
"ui": true,
"extraPublicDirs": ["common", "common/state_containers", "demos/state_containers/todomvc"]
"server": false,
"extraPublicDirs": [
"common",
"demos/state_containers/todomvc",
"common/state_containers"
]
}
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" }
]
}

0 comments on commit 5104313

Please sign in to comment.