Skip to content

Commit 6ff8075

Browse files
fix(declarations): update PluginTransformResults after Rollup update (#6232)
* fix(declarations): update PluginTransformResults after Rollup update * fix build * prettier
1 parent 7fe6372 commit 6ff8075

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/compiler/style/global-styles.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/declarations/stencil-private.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,10 +1299,12 @@ export interface Plugin {
12991299
sourceText: string,
13001300
id: string,
13011301
context: PluginCtx,
1302-
) => Promise<PluginTransformResults> | PluginTransformResults | string;
1302+
) => Promise<PluginTransformResults> | PluginTransformResults;
13031303
}
13041304

1305-
export interface PluginTransformResults {
1305+
export type PluginTransformResults = PluginTransformationDescriptor | string | null;
1306+
1307+
export interface PluginTransformationDescriptor {
13061308
code?: string;
13071309
map?: string;
13081310
id?: string;

0 commit comments

Comments
 (0)