@@ -41,18 +41,29 @@ const buildGlobalStyles = async (config: d.ValidatedConfig, compilerCtx: d.Compi
4141 const transformResults = await runPluginTransforms ( config , compilerCtx , buildCtx , globalStylePath ) ;
4242
4343 if ( transformResults ) {
44- const optimizedCss = await optimizeCss (
45- config ,
46- compilerCtx ,
47- buildCtx . diagnostics ,
48- transformResults . code ,
49- globalStylePath ,
50- ) ;
44+ let cssCode : string ;
45+ let dependencies : string [ ] | undefined ;
46+
47+ if ( typeof transformResults === 'string' ) {
48+ // Handle case where transformResults is a string (the CSS code directly)
49+ cssCode = transformResults ;
50+ dependencies = undefined ;
51+ } else if ( typeof transformResults === 'object' && transformResults . code ) {
52+ // Handle case where transformResults is a PluginTransformationDescriptor object
53+ cssCode = transformResults . code ;
54+ dependencies = transformResults . dependencies ;
55+ } else {
56+ // Invalid transformResults
57+ compilerCtx . cachedGlobalStyle = null ;
58+ return null ;
59+ }
60+
61+ const optimizedCss = await optimizeCss ( config , compilerCtx , buildCtx . diagnostics , cssCode , globalStylePath ) ;
5162 compilerCtx . cachedGlobalStyle = optimizedCss ;
5263
53- if ( Array . isArray ( transformResults . dependencies ) ) {
64+ if ( Array . isArray ( dependencies ) ) {
5465 const cssModuleImports = compilerCtx . cssModuleImports . get ( globalStylePath ) || [ ] ;
55- transformResults . dependencies . forEach ( ( dep ) => {
66+ dependencies . forEach ( ( dep : string ) => {
5667 compilerCtx . addWatchFile ( dep ) ;
5768 if ( ! cssModuleImports . includes ( dep ) ) {
5869 cssModuleImports . push ( dep ) ;
0 commit comments