Skip to content

Commit

Permalink
build(cdk-build): Include lint commands in build timing info. (#27326)
Browse files Browse the repository at this point in the history
Includes individual lint commands (eslint, pkglint, markdownlint, awslint) in the build timing info emitted by `cdk-build`.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
mikewrighton authored Sep 28, 2023
1 parent 735b786 commit 7df11f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tools/@aws-cdk/cdk-build-tools/bin/cdk-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function main() {
const overrides: CompilerOverrides = { eslint: args.eslint, jsii: args.jsii, tsc: args.tsc };
await compileCurrentPackage(options, timers, overrides);
if (!args['skip-lint']) {
await lintCurrentPackage(options, { ...overrides, fix: args.fix });
await lintCurrentPackage(options, timers, { ...overrides, fix: args.fix });
}

if (options.post) {
Expand Down
11 changes: 9 additions & 2 deletions tools/@aws-cdk/cdk-build-tools/bin/cdk-lint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as yargs from 'yargs';
import { lintCurrentPackage } from '../lib/lint';
import { cdkBuildOptions } from '../lib/package-info';
import { cdkBuildOptions, currentPackageJson } from '../lib/package-info';
import { Timers } from '../lib/timer';

async function main() {
const args = yargs
Expand All @@ -19,11 +20,17 @@ async function main() {

const options = cdkBuildOptions();

await lintCurrentPackage(options, { eslint: args.eslint, fix: args.fix });
await lintCurrentPackage(options, timers, { eslint: args.eslint, fix: args.fix });
}

const timers = new Timers();
const buildTimer = timers.start('Total time');

main().catch(e => {
process.stderr.write(`${e.toString()}\n`);
process.stderr.write('Linting failed.\n');
process.exit(1);
}).finally(() => {
buildTimer.end();
process.stdout.write(`Lint times for ${currentPackageJson().name}: ${timers.display()}\n`);
});
14 changes: 9 additions & 5 deletions tools/@aws-cdk/cdk-build-tools/lib/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import * as process from 'process';
import * as fs from 'fs-extra';
import { shell, escape } from './os';
import { CDKBuildOptions, CompilerOverrides } from './package-info';
import { Timers } from './timer';

export async function lintCurrentPackage(options: CDKBuildOptions, compilers: CompilerOverrides & { fix?: boolean } = {}): Promise<void> {
export async function lintCurrentPackage(
options: CDKBuildOptions,
timers: Timers,
compilers: CompilerOverrides & { fix?: boolean } = {}): Promise<void> {
const env = options.env;
const fixOption = compilers.fix ? ['--fix'] : [];

Expand All @@ -15,14 +19,14 @@ export async function lintCurrentPackage(options: CDKBuildOptions, compilers: Co
'--ext=.ts',
`--resolve-plugins-relative-to=${__dirname}`,
...fixOption,
], { env });
], { timers, env });
}

if (!options.pkglint?.disable) {
await shell([
'pkglint',
...fixOption,
], { env });
], { timers, env });
}

if (await fs.pathExists('README.md')) {
Expand All @@ -34,8 +38,8 @@ export async function lintCurrentPackage(options: CDKBuildOptions, compilers: Co
'--config', path.resolve(__dirname, '..', 'config', 'markdownlint.json'),
...fixOption,
'README.md',
]);
], { timers });
}

await shell([path.join(__dirname, '..', 'bin', 'cdk-awslint')], { env });
await shell([path.join(__dirname, '..', 'bin', 'cdk-awslint')], { timers, env });
}

0 comments on commit 7df11f4

Please sign in to comment.