import type * as d from '../../declarations' ; import { optimizeCssId } from '../../version' ; import { hasError , normalizePath } from '@utils' ; export const optimizeCss = async ( config , compilerCtx , diagnostics , styleText , filePath ) => { if ( typeof styleText !== 'string' || ! styleText . length ) { return styleText ; } if ( ( config . autoprefixCss === false || config . autoprefixCss === null ) && ! config . minifyCss ) { return styleText ; } if ( typeof filePath === 'string' ) { filePath = normalizePath ( filePath ) ; } const opts = { input : styleText , filePath : filePath , autoprefixer : config . autoprefixCss , minify : config . minifyCss , } ; const cacheKey = await compilerCtx . cache . createKey ( 'optimizeCss' , optimizeCssId , opts ) ; const cachedContent = await compilerCtx . cache . get ( cacheKey ) ; if ( cachedContent != null ) { return cachedContent ; } const minifyResults = await compilerCtx . worker . optimizeCss ( opts ) ; minifyResults . diagnostics . forEach ( ( d ) => { diagnostics . push ( d ) ; } ) ; if ( typeof minifyResults . output === 'string' && ! hasError ( diagnostics ) ) { await compilerCtx . cache . put ( cacheKey , minifyResults . output ) ; return minifyResults . output ; } return styleText ; } ;