Skip to content

Commit

Permalink
[APM] Fix optimize-tsconfig script
Browse files Browse the repository at this point in the history
- Removes x-pack/plugins/apm/tsconfig.json file
- Make optimisation opt-in for precommit script
  • Loading branch information
dgieselaar committed Feb 16, 2021
1 parent 7f10711 commit b9cc9cd
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ npm-debug.log*
.ci/bash_standard_lib.sh
.gradle

# apm plugin
/x-pack/plugins/apm/tsconfig.json
apm.tsconfig.json
## @cypress/snapshot from apm plugin
snapshots.js

Expand Down
7 changes: 7 additions & 0 deletions x-pack/plugins/apm/scripts/optimize-tsconfig/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const { omit } = require('lodash');

const readFile = promisify(fs.readFile);
const writeFile = promisify(fs.writeFile);
const unlink = promisify(fs.unlink);

const {
xpackRoot,
Expand Down Expand Up @@ -72,13 +73,19 @@ async function setIgnoreChanges() {
}
}

async function deleteApmTsConfig() {
await unlink(path.resolve(kibanaRoot, 'x-pack/plugins/apm', 'tsconfig.json'));
}

async function optimizeTsConfig() {
await unoptimizeTsConfig();

await prepareParentTsConfigs();

await addApmFilesToXpackTsConfig();

await deleteApmTsConfig();

await setIgnoreChanges();
// eslint-disable-next-line no-console
console.log(
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/scripts/optimize-tsconfig/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const filesToIgnore = [
path.resolve(xpackRoot, 'tsconfig.json'),
path.resolve(kibanaRoot, 'tsconfig.json'),
path.resolve(kibanaRoot, 'tsconfig.base.json'),
path.resolve(kibanaRoot, 'x-pack/plugins/apm', 'tsconfig.json'),
];

module.exports = {
Expand Down
42 changes: 37 additions & 5 deletions x-pack/plugins/apm/scripts/precommit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,24 @@
const execa = require('execa');
const Listr = require('listr');
const { resolve } = require('path');
const { argv } = require('yargs');

const cwd = resolve(__dirname, '../../../..');
const root = resolve(__dirname, '../../../..');

const execaOpts = { cwd, stderr: 'inherit' };
const execaOpts = { cwd: root, stderr: 'pipe' };

const useOptimizedTsConfig = !!argv.optimizeTs;

const tsconfig = useOptimizedTsConfig
? resolve(root, 'x-pack/tsconfig.json')
: resolve(root, 'x-pack/plugins/apm/tsconfig.json');

console.log(
resolve(
__dirname,
useOptimizedTsConfig ? './optimize-tsonfig.js' : './unoptimize-tsconfig.js'
)
);

const tasks = new Listr(
[
Expand All @@ -37,17 +51,35 @@ const tasks = new Listr(
title: 'Typescript',
task: () =>
execa(
require.resolve('typescript/bin/tsc'),
['--project', resolve(__dirname, '../tsconfig.json'), '--pretty'],
'node',
[
resolve(
__dirname,
useOptimizedTsConfig
? './optimize-tsconfig.js'
: './unoptimize-tsconfig.js'
),
],
execaOpts
).then(() =>
execa(
require.resolve('typescript/bin/tsc'),
[
'--project',
tsconfig,
'--pretty',
...(useOptimizedTsConfig ? ['--noEmit'] : []),
],
execaOpts
)
),
},
{
title: 'Lint',
task: () => execa('node', [resolve(__dirname, 'eslint.js')], execaOpts),
},
],
{ exitOnError: false, concurrent: true }
{ exitOnError: true, concurrent: true }
);

tasks.run().catch((error) => {
Expand Down

0 comments on commit b9cc9cd

Please sign in to comment.