mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[APM] Script optimization of APM-specific tsconfig (#49868)
* [APM] Script optimization of APM-specific tsconfig * Don't break bootstrap process * Document TS optimizations
This commit is contained in:
parent
8f6c41f268
commit
15f2ebcdb8
9 changed files with 192 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -44,3 +44,5 @@ package-lock.json
|
|||
*.sublime-*
|
||||
npm-debug.log*
|
||||
.tern-project
|
||||
x-pack/legacy/plugins/apm/tsconfig.json
|
||||
apm.tsconfig.json
|
||||
|
|
11
x-pack/legacy/plugins/apm/dev_docs/typescript.md
Normal file
11
x-pack/legacy/plugins/apm/dev_docs/typescript.md
Normal file
|
@ -0,0 +1,11 @@
|
|||
#### Optimizing TypeScript
|
||||
|
||||
Kibana and X-Pack are very large TypeScript projects, and it comes at a cost. Editor responsiveness is not great, and the CLI type check for X-Pack takes about a minute. To get faster feedback, we create a smaller APM TypeScript project that only type checks the APM project and the files it uses. This optimization consists of creating a `tsconfig.json` in APM that includes the Kibana/X-Pack typings, and editing the Kibana/X-Pack configurations to not include any files, or removing the configurations altogether. The script configures git to ignore any changes in these files, and has an undo script as well.
|
||||
|
||||
To run the optimization:
|
||||
|
||||
`$ node x-pack/legacy/plugins/apm/scripts/optimize-tsconfig`
|
||||
|
||||
To undo the optimization:
|
||||
|
||||
`$ node x-pack/legacy/plugins/apm/scripts/unoptimize-tsconfig`
|
9
x-pack/legacy/plugins/apm/scripts/optimize-tsconfig.js
Normal file
9
x-pack/legacy/plugins/apm/scripts/optimize-tsconfig.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
const { optimizeTsConfig } = require('./optimize-tsconfig/optimize');
|
||||
|
||||
optimizeTsConfig();
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
|
||||
const fs = require('fs');
|
||||
const promisify = require('util').promisify;
|
||||
const path = require('path');
|
||||
const json5 = require('json5');
|
||||
const execa = require('execa');
|
||||
|
||||
const copyFile = promisify(fs.copyFile);
|
||||
const rename = promisify(fs.rename);
|
||||
const readFile = promisify(fs.readFile);
|
||||
const writeFile = promisify(fs.writeFile);
|
||||
|
||||
const {
|
||||
xpackRoot,
|
||||
kibanaRoot,
|
||||
apmRoot,
|
||||
tsconfigTpl,
|
||||
filesToIgnore
|
||||
} = require('./paths');
|
||||
const { unoptimizeTsConfig } = require('./unoptimize');
|
||||
|
||||
function updateParentTsConfigs() {
|
||||
return Promise.all(
|
||||
[
|
||||
path.resolve(xpackRoot, 'apm.tsconfig.json'),
|
||||
path.resolve(kibanaRoot, 'tsconfig.json')
|
||||
].map(async filename => {
|
||||
const config = json5.parse(await readFile(filename, 'utf-8'));
|
||||
|
||||
await writeFile(
|
||||
filename,
|
||||
JSON.stringify(
|
||||
{
|
||||
...config,
|
||||
include: []
|
||||
},
|
||||
null,
|
||||
2
|
||||
),
|
||||
{ encoding: 'utf-8' }
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async function setIgnoreChanges() {
|
||||
for (const filename of filesToIgnore) {
|
||||
await execa('git', ['update-index', '--skip-worktree', filename]);
|
||||
}
|
||||
}
|
||||
|
||||
const optimizeTsConfig = () => {
|
||||
return unoptimizeTsConfig()
|
||||
.then(() =>
|
||||
Promise.all([
|
||||
copyFile(tsconfigTpl, path.resolve(apmRoot, './tsconfig.json')),
|
||||
rename(
|
||||
path.resolve(xpackRoot, 'tsconfig.json'),
|
||||
path.resolve(xpackRoot, 'apm.tsconfig.json')
|
||||
)
|
||||
])
|
||||
)
|
||||
.then(() => updateParentTsConfigs())
|
||||
.then(() => setIgnoreChanges())
|
||||
.then(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(
|
||||
'Created an optimized tsconfig.json for APM. To undo these changes, run `./scripts/unoptimize-tsconfig.js`'
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
optimizeTsConfig
|
||||
};
|
25
x-pack/legacy/plugins/apm/scripts/optimize-tsconfig/paths.js
Normal file
25
x-pack/legacy/plugins/apm/scripts/optimize-tsconfig/paths.js
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
const path = require('path');
|
||||
|
||||
const apmRoot = path.resolve(__dirname, '../..');
|
||||
const xpackRoot = path.resolve(apmRoot, '../../..');
|
||||
const kibanaRoot = path.resolve(xpackRoot, '..');
|
||||
|
||||
const tsconfigTpl = path.resolve(__dirname, './tsconfig.json');
|
||||
|
||||
const filesToIgnore = [
|
||||
path.resolve(xpackRoot, 'tsconfig.json'),
|
||||
path.resolve(kibanaRoot, 'tsconfig.json')
|
||||
];
|
||||
|
||||
module.exports = {
|
||||
apmRoot,
|
||||
xpackRoot,
|
||||
kibanaRoot,
|
||||
tsconfigTpl,
|
||||
filesToIgnore
|
||||
};
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"extends": "../../../apm.tsconfig.json",
|
||||
"include": [
|
||||
"./**/*",
|
||||
"../../../typings/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"**/__fixtures__/**/*",
|
||||
"./cypress/**/*"
|
||||
]
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
|
||||
const path = require('path');
|
||||
const execa = require('execa');
|
||||
const fs = require('fs');
|
||||
const promisify = require('util').promisify;
|
||||
const removeFile = promisify(fs.unlink);
|
||||
const exists = promisify(fs.exists);
|
||||
|
||||
const { apmRoot, filesToIgnore } = require('./paths');
|
||||
|
||||
async function unoptimizeTsConfig() {
|
||||
for (const filename of filesToIgnore) {
|
||||
await execa('git', ['update-index', '--no-skip-worktree', filename]);
|
||||
await execa('git', ['checkout', filename]);
|
||||
}
|
||||
|
||||
const apmTsConfig = path.join(apmRoot, 'tsconfig.json');
|
||||
if (await exists(apmTsConfig)) {
|
||||
await removeFile(apmTsConfig);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
unoptimizeTsConfig: () => {
|
||||
return unoptimizeTsConfig().then(() => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Removed APM TypeScript optimizations');
|
||||
});
|
||||
}
|
||||
};
|
9
x-pack/legacy/plugins/apm/scripts/unoptimize-tsconfig.js
Normal file
9
x-pack/legacy/plugins/apm/scripts/unoptimize-tsconfig.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
const { unoptimizeTsConfig } = require('./optimize-tsconfig/unoptimize');
|
||||
|
||||
unoptimizeTsConfig();
|
|
@ -4,6 +4,13 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import '../../infra/types/rison_node';
|
||||
import '../../infra/types/eui';
|
||||
// EUIBasicTable
|
||||
import {} from '../../reporting/public/components/report_listing';
|
||||
// .svg
|
||||
import '../../canvas/types/webpack';
|
||||
|
||||
// Allow unknown properties in an object
|
||||
export type AllowUnknownProperties<T> = T extends Array<infer X>
|
||||
? Array<AllowUnknownObjectProperties<X>>
|
Loading…
Add table
Add a link
Reference in a new issue