Skip to content

Commit a9f7c57

Browse files
dgieselaarkibanamachine
authored andcommitted
[APM] Fix optimize-tsconfig script (#91487)
- Removes x-pack/plugins/apm/tsconfig.json file - Make optimisation opt-in for precommit script
1 parent f44a70f commit a9f7c57

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ npm-debug.log*
6161
.ci/bash_standard_lib.sh
6262
.gradle
6363

64-
# apm plugin
65-
/x-pack/plugins/apm/tsconfig.json
66-
apm.tsconfig.json
6764
## @cypress/snapshot from apm plugin
6865
snapshots.js
6966

x-pack/plugins/apm/scripts/optimize-tsconfig/optimize.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const { omit } = require('lodash');
1616

1717
const readFile = promisify(fs.readFile);
1818
const writeFile = promisify(fs.writeFile);
19+
const unlink = promisify(fs.unlink);
1920

2021
const {
2122
xpackRoot,
@@ -72,13 +73,19 @@ async function setIgnoreChanges() {
7273
}
7374
}
7475

76+
async function deleteApmTsConfig() {
77+
await unlink(path.resolve(kibanaRoot, 'x-pack/plugins/apm', 'tsconfig.json'));
78+
}
79+
7580
async function optimizeTsConfig() {
7681
await unoptimizeTsConfig();
7782

7883
await prepareParentTsConfigs();
7984

8085
await addApmFilesToXpackTsConfig();
8186

87+
await deleteApmTsConfig();
88+
8289
await setIgnoreChanges();
8390
// eslint-disable-next-line no-console
8491
console.log(

x-pack/plugins/apm/scripts/optimize-tsconfig/paths.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const filesToIgnore = [
1616
path.resolve(xpackRoot, 'tsconfig.json'),
1717
path.resolve(kibanaRoot, 'tsconfig.json'),
1818
path.resolve(kibanaRoot, 'tsconfig.base.json'),
19+
path.resolve(kibanaRoot, 'x-pack/plugins/apm', 'tsconfig.json'),
1920
];
2021

2122
module.exports = {

x-pack/plugins/apm/scripts/precommit.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,24 @@
1111
const execa = require('execa');
1212
const Listr = require('listr');
1313
const { resolve } = require('path');
14+
const { argv } = require('yargs');
1415

15-
const cwd = resolve(__dirname, '../../../..');
16+
const root = resolve(__dirname, '../../../..');
1617

17-
const execaOpts = { cwd, stderr: 'inherit' };
18+
const execaOpts = { cwd: root, stderr: 'pipe' };
19+
20+
const useOptimizedTsConfig = !!argv.optimizeTs;
21+
22+
const tsconfig = useOptimizedTsConfig
23+
? resolve(root, 'x-pack/tsconfig.json')
24+
: resolve(root, 'x-pack/plugins/apm/tsconfig.json');
25+
26+
console.log(
27+
resolve(
28+
__dirname,
29+
useOptimizedTsConfig ? './optimize-tsonfig.js' : './unoptimize-tsconfig.js'
30+
)
31+
);
1832

1933
const tasks = new Listr(
2034
[
@@ -37,17 +51,35 @@ const tasks = new Listr(
3751
title: 'Typescript',
3852
task: () =>
3953
execa(
40-
require.resolve('typescript/bin/tsc'),
41-
['--project', resolve(__dirname, '../tsconfig.json'), '--pretty'],
54+
'node',
55+
[
56+
resolve(
57+
__dirname,
58+
useOptimizedTsConfig
59+
? './optimize-tsconfig.js'
60+
: './unoptimize-tsconfig.js'
61+
),
62+
],
4263
execaOpts
64+
).then(() =>
65+
execa(
66+
require.resolve('typescript/bin/tsc'),
67+
[
68+
'--project',
69+
tsconfig,
70+
'--pretty',
71+
...(useOptimizedTsConfig ? ['--noEmit'] : []),
72+
],
73+
execaOpts
74+
)
4375
),
4476
},
4577
{
4678
title: 'Lint',
4779
task: () => execa('node', [resolve(__dirname, 'eslint.js')], execaOpts),
4880
},
4981
],
50-
{ exitOnError: false, concurrent: true }
82+
{ exitOnError: true, concurrent: true }
5183
);
5284

5385
tasks.run().catch((error) => {

0 commit comments

Comments
 (0)