Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Fix optimize-tsconfig script #91487

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all 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: 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