import Path from 'path' ; import { REPO_ROOT } from '@kbn/utils' ; import { lastValueFrom } from '@kbn/std' ; import { CiStatsMetric } from '@kbn/dev-utils' ; import { runOptimizer , OptimizerConfig , logOptimizerState , reportOptimizerTimings , } from '@kbn/optimizer' ; import { Task , deleteAll , write , read } from '../lib' ; export const BuildKibanaPlatformPlugins = { description : 'Building distributable versions of Kibana platform plugins' , async run ( buildConfig , log , build ) { const config = OptimizerConfig . create ( { repoRoot : REPO_ROOT , outputRoot : build . resolvePath ( ) , cache : false , examples : false , watch : false , dist : true , includeCoreBundle : true , limitsPath : Path . resolve ( REPO_ROOT , 'packages/kbn-optimizer/limits.yml' ) , } ) ; await lastValueFrom ( runOptimizer ( config ) . pipe ( logOptimizerState ( log , config ) , reportOptimizerTimings ( log , config ) ) ) ; const combinedMetrics = [ ] ; const metricFilePaths = [ ] ; for ( const bundle of config . bundles ) { const path = Path . resolve ( bundle . outputDir , 'metrics.json' ) ; const metrics = JSON . parse ( await read ( path ) ) ; combinedMetrics . push ( ... metrics ) ; metricFilePaths . push ( path ) ; } await write ( buildConfig . resolveFromTarget ( 'optimizer_bundle_metrics.json' ) , JSON . stringify ( combinedMetrics , null , 2 ) ) ; await deleteAll ( metricFilePaths , log ) ; await Promise . all ( config . bundles . map ( ( b ) => b . cache . clear ( ) ) ) ; } , } ;