Skip to content

Commit d251eaf

Browse files
committed
Fix type_check and check_ts_projects_cli
1 parent 79f56fd commit d251eaf

9 files changed

Lines changed: 43 additions & 51 deletions

File tree

src/dev/typescript/project.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import { basename, dirname, relative, resolve } from 'path';
2222

2323
import { IMinimatch, Minimatch } from 'minimatch';
2424
import { parseConfigFileTextToJson } from 'typescript';
25-
import deepMerge from 'deepmerge';
2625

2726
import { REPO_ROOT } from '../constants';
2827

@@ -36,17 +35,7 @@ function makeMatchers(directory: string, patterns: string[]) {
3635
}
3736

3837
function parseTsConfig(path: string) {
39-
// eslint-disable-next-line prefer-const
40-
let { error, config } = parseConfigFileTextToJson(path, readFileSync(path, 'utf8'));
41-
if (config.extends) {
42-
const extendsPath = resolve(dirname(path), config.extends);
43-
const extendSource = parseTsConfig(extendsPath);
44-
// This is a really rough approximation of Typescript's `extends`
45-
// behaviour and doesn't correctly include all files. But I couldn't find
46-
// a public API to read a fully extend config. Seems like
47-
// `getParsedCommandLine` might be what we want but unsure how to use it?
48-
config = deepMerge(config, extendSource);
49-
}
38+
const { error, config } = parseConfigFileTextToJson(path, readFileSync(path, 'utf8'));
5039

5140
if (error) {
5241
throw error;
@@ -81,7 +70,7 @@ export class Project {
8170
exclude?: string[];
8271
};
8372

84-
if (files || !include) {
73+
if ((files && files.length > 0) || !include) {
8574
throw new Error(
8675
'tsconfig.json files in the Kibana repo must use "include" keys and not "files"'
8776
);
@@ -91,7 +80,7 @@ export class Project {
9180
this.disableTypeCheck = options.disableTypeCheck || false;
9281
this.disableNoEmit = options.disableNoEmit || false;
9382
this.name = options.name || relative(REPO_ROOT, this.directory) || basename(this.directory);
94-
this.include = makeMatchers(this.directory, include);
83+
this.include = makeMatchers(this.directory, include || []);
9584
this.exclude = makeMatchers(this.directory, exclude);
9685
}
9786

src/dev/typescript/projects.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import { REPO_ROOT } from '../constants';
2323
import { Project } from './project';
2424

2525
export const PROJECTS = [
26-
new Project(resolve(REPO_ROOT, 'tsconfig.json'), {
26+
new Project(resolve(REPO_ROOT, 'tsconfig.oss.json'), {
27+
disableNoEmit: true,
28+
}),
29+
new Project(resolve(REPO_ROOT, 'tsconfig.test.json'), {
2730
disableNoEmit: true,
2831
}),
2932
new Project(resolve(REPO_ROOT, 'test/tsconfig.json'), { name: 'kibana/test' }),

src/dev/typescript/run_type_check_cli.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ export function runTypeCheckCli() {
9090
execInProjects(log, projects, process.execPath, (project) => [
9191
...(project.name.startsWith('x-pack') ? ['--max-old-space-size=4096'] : []),
9292
require.resolve('typescript/bin/tsc'),
93-
...['--project', project.tsConfigPath],
93+
...(project.config.compilerOptions?.composite
94+
? ['-b', project.tsConfigPath]
95+
: ['--noEmit', '--project', project.tsConfigPath]),
9496
...tscArgs,
95-
...(project.disableNoEmit ? [] : ['--noEmit']),
9697
]);
9798
}

test/tsconfig.base.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,5 @@
1010
"esnext",
1111
"dom"
1212
]
13-
},
14-
"include": [
15-
"**/*.ts",
16-
"**/*.tsx",
17-
"../typings/elastic__node_crypto.d.ts",
18-
"typings/**/*"
19-
],
20-
"exclude": [
21-
"plugin_functional/plugins/**/*",
22-
"interpreter_functional/plugins/**/*"
23-
]
13+
}
2414
}

test/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
{
22
"extends": "./tsconfig.base.json",
3+
"include": [
4+
"**/*.ts",
5+
"**/*.tsx",
6+
"../typings/elastic__node_crypto.d.ts",
7+
"typings/**/*"
8+
],
9+
"exclude": [
10+
"plugin_functional/plugins/**/*",
11+
"interpreter_functional/plugins/**/*"
12+
]
313
}

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"references": [
33
{"path": "./tsconfig.oss.json"},
4-
{"path": "./tsconfig.test.json"}, //TODO: Looks like tests weren't previously checked??
4+
{"path": "./tsconfig.test.json"},
55
{"path": "./examples/embeddable_examples"}
66
],
7-
"files": []
7+
"files": [],
8+
"include": []
89
}

tsconfig.test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
],
1919
"exclude": [
2020
"src/**/__fixtures__/**/*",
21-
"src/plugins/ui_actions/public/tests/**/*.test.ts",
21+
"src/plugins/ui_actions/public/**/*.test.ts",
2222
"src/plugins/embeddable/public/lib/panel/embeddable_panel.test.tsx",
2323
"src/plugins/dashboard/public/application/tests/dashboard_container.test.tsx",
2424
"src/core/server/utils/crypto/pkcs12.test.ts",

x-pack/tsconfig.base.json

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
11
{
22
"extends": "../tsconfig.base.json",
3-
"include": [
4-
"mocks.ts",
5-
"typings/**/*",
6-
"legacy/common/**/*",
7-
"legacy/server/**/*",
8-
"legacy/plugins/**/*",
9-
"plugins/**/*",
10-
"test_utils/**/*",
11-
"tasks/**/*"
12-
],
13-
"exclude": [
14-
"test/**/*",
15-
"plugins/security_solution/cypress/**/*",
16-
"plugins/apm/e2e/cypress/**/*",
17-
"plugins/apm/scripts/**/*",
18-
"**/typespec_tests.ts"
19-
],
203
"compilerOptions": {
214
"outDir": ".",
225
"paths": {

x-pack/tsconfig.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
{
2-
"extends": "../tsconfig.base.json",
3-
// "compilerOptions": {
4-
// }
2+
"extends": "./tsconfig.base.json",
3+
"include": [
4+
"mocks.ts",
5+
"typings/**/*",
6+
"legacy/common/**/*",
7+
"legacy/server/**/*",
8+
"legacy/plugins/**/*",
9+
"plugins/**/*",
10+
"test_utils/**/*",
11+
"tasks/**/*"
12+
],
13+
"exclude": [
14+
"test/**/*",
15+
"plugins/security_solution/cypress/**/*",
16+
"plugins/apm/e2e/cypress/**/*",
17+
"plugins/apm/scripts/**/*",
18+
"**/typespec_tests.ts"
19+
],
520
}

0 commit comments

Comments
 (0)