Skip to content

Commit 618b64d

Browse files
committed
[code-infra] Add command run duration measurement
to each relevant sub-command. Removed markFn and measureFn functions and wrapped their functionality in a single HOC `withPerformanceMeasurement`.
1 parent 347db03 commit 618b64d

File tree

7 files changed

+160
-332
lines changed

7 files changed

+160
-332
lines changed

package.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,15 @@
3434
"dependencies": {
3535
"@actions/core": "^1.11.1",
3636
"@actions/github": "^6.0.1",
37-
"@eslint/compat": "^1.3.2",
3837
"@mui/internal-bundle-size-checker": "workspace:*",
3938
"@mui/internal-code-infra": "workspace:*",
4039
"@octokit/rest": "^22.0.0",
4140
"@tsconfig/node22": "^22.0.2",
4241
"@types/node": "^24.3.1",
43-
"@types/semver": "^7.7.1",
44-
"@typescript-eslint/eslint-plugin": "8.42.0",
45-
"@typescript-eslint/parser": "^8.42.0",
4642
"eslint": "^9.35.0",
47-
"execa": "^9.6.0",
4843
"lerna": "^8.2.3",
4944
"prettier": "^3.6.2",
5045
"pretty-quick": "^4.2.2",
51-
"semver": "^7.7.2",
52-
"tsx": "^4.20.5",
5346
"typescript": "^5.9.2",
5447
"vitest": "^3.2.4"
5548
},

packages/code-infra/src/cli/cmdBuild.mjs

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import * as fs from 'node:fs/promises';
77
import * as path from 'node:path';
88
import { sep as posixSep } from 'node:path/posix';
99

10-
import { getOutExtension, isMjsBuild, mapConcurrently, validatePkgJson } from '../utils/build.mjs';
10+
import {
11+
getOutExtension,
12+
isMjsBuild,
13+
mapConcurrently,
14+
validatePkgJson,
15+
withPerformanceMeasurement,
16+
} from '../utils/build.mjs';
1117

1218
/**
1319
* @typedef {Object} Args
@@ -238,7 +244,7 @@ async function writePackageJson({ packageJson, bundles, outputDir, cwd, addTypes
238244
);
239245
}
240246

241-
export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
247+
const command = /** @type {import('yargs').CommandModule<{}, Args>} */ ({
242248
command: 'build',
243249
describe: 'Builds the package for publishing.',
244250
builder(yargs) {
@@ -375,24 +381,29 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
375381

376382
const promises = [];
377383

378-
promises.push(
379-
babelMod.babelBuild({
380-
cwd,
381-
sourceDir,
382-
outDir: outputDir,
383-
babelRuntimeVersion,
384-
hasLargeFiles,
385-
bundle,
386-
verbose,
387-
optimizeClsx:
388-
packageJson.dependencies.clsx !== undefined ||
389-
packageJson.dependencies.classnames !== undefined,
390-
removePropTypes: packageJson.dependencies['prop-types'] !== undefined,
391-
pkgVersion: packageJson.version,
392-
ignores: extraIgnores,
393-
outExtension,
394-
}),
384+
const markLabel = `build:babel:${bundle}`;
385+
const runBabel = withPerformanceMeasurement(
386+
markLabel,
387+
async () =>
388+
babelMod.babelBuild({
389+
cwd,
390+
sourceDir,
391+
outDir: outputDir,
392+
babelRuntimeVersion,
393+
hasLargeFiles,
394+
bundle,
395+
verbose,
396+
optimizeClsx:
397+
packageJson.dependencies.clsx !== undefined ||
398+
packageJson.dependencies.classnames !== undefined,
399+
removePropTypes: packageJson.dependencies['prop-types'] !== undefined,
400+
pkgVersion: packageJson.version,
401+
ignores: extraIgnores,
402+
outExtension,
403+
}),
404+
{ shouldLog: true },
395405
);
406+
promises.push(runBabel());
396407

397408
if (buildDir !== outputDir && !skipBundlePackageJson && !isMjsBuild) {
398409
// @TODO - Not needed if the output extension is .mjs. Remove this before PR merge.
@@ -420,23 +431,31 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
420431
// js build end
421432

422433
if (buildTypes) {
423-
const tsMod = await import('./typescript.mjs');
424-
/**
425-
* @type {{type: import('../utils/build.mjs').BundleType, dir: string}[]};
426-
*/
427-
const bundleMap = bundles.map((type) => ({
428-
type,
429-
dir: relativeOutDirs[type],
430-
}));
431-
432-
await tsMod.createTypes({
433-
bundles: bundleMap,
434-
srcDir: sourceDir,
435-
cwd,
436-
skipTsc,
437-
isMjsBuild,
438-
buildDir,
439-
});
434+
const tsMarkLabel = 'build:typescript';
435+
const runTsc = withPerformanceMeasurement(
436+
tsMarkLabel,
437+
async () => {
438+
const tsMod = await import('./typescript.mjs');
439+
/**
440+
* @type {{type: import('../utils/build.mjs').BundleType, dir: string}[]};
441+
*/
442+
const bundleMap = bundles.map((type) => ({
443+
type,
444+
dir: relativeOutDirs[type],
445+
}));
446+
447+
await tsMod.createTypes({
448+
bundles: bundleMap,
449+
srcDir: sourceDir,
450+
cwd,
451+
skipTsc,
452+
isMjsBuild,
453+
buildDir,
454+
});
455+
},
456+
{ shouldLog: true },
457+
);
458+
await runTsc();
440459
}
441460
if (skipPackageJson) {
442461
console.log('Skipping package.json generation in the output directory.');
@@ -464,6 +483,14 @@ export default /** @type {import('yargs').CommandModule<{}, Args>} */ ({
464483
},
465484
});
466485

486+
command.handler = withPerformanceMeasurement(
487+
/** @type {string} */ (command.command),
488+
command.handler,
489+
{ shouldLog: true },
490+
);
491+
492+
export default command;
493+
467494
/**
468495
* @param {Object} param0
469496
* @param {string} param0.cwd - The current working directory.

packages/code-infra/src/cli/cmdCopyFiles.mjs

Lines changed: 0 additions & 208 deletions
This file was deleted.

0 commit comments

Comments
 (0)