Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-2037: Fix CssVarsDeclarationPlugin crashing dev server on missing files (#71139)

Stas Gavrylov91ca66121518
diff --git a/frontend/build/shared/rspack/plugins/CssVarsDeclarationPlugin/css-vars-declaration-plugin.js b/frontend/build/shared/rspack/plugins/CssVarsDeclarationPlugin/css-vars-declaration-plugin.js
index da47d2b3428..93b30e3e3cf 100644
--- a/frontend/build/shared/rspack/plugins/CssVarsDeclarationPlugin/css-vars-declaration-plugin.js
+++ b/frontend/build/shared/rspack/plugins/CssVarsDeclarationPlugin/css-vars-declaration-plugin.js
@@ -48,7 +48,7 @@ const CSS_VAR_CONFIGS = [
],
},
{
- path: "metabase/lib/colors/types/color-keys.ts",
+ path: "metabase/ui/colors/types/color-keys.ts",
sources: [
{
type: "unionType",
@@ -146,11 +146,21 @@ class CssVarsDeclarationPlugin {
}
}
+ if (cssVars.size === 0) {
+ this.#warn(`No CSS variables found for ${config.path}, skipping .d.css`);
+ return;
+ }
+
const outputPath = config.path.replace(/\.ts$/, ".d.css");
- this.#writeCssDeclarationFile(
- path.join(this.#frontendSrcPath, outputPath),
- cssVars,
- );
+ const fullOutputPath = path.join(this.#frontendSrcPath, outputPath);
+ const outputDir = path.dirname(fullOutputPath);
+
+ if (!fs.existsSync(outputDir)) {
+ this.#warn(`Output directory not found: ${outputDir}, skipping .d.css`);
+ return;
+ }
+
+ this.#writeCssDeclarationFile(fullOutputPath, cssVars);
}
/**
diff --git a/frontend/src/metabase/embedding-sdk/theme/css-vars-to-sdk-theme.ts b/frontend/src/metabase/embedding-sdk/theme/css-vars-to-sdk-theme.ts
index a29917c74b9..259bc87b1c3 100644
--- a/frontend/src/metabase/embedding-sdk/theme/css-vars-to-sdk-theme.ts
+++ b/frontend/src/metabase/embedding-sdk/theme/css-vars-to-sdk-theme.ts
@@ -1,3 +1,6 @@
+// WARNING: This file is referenced by CssVarsDeclarationPlugin.
+// If you move or rename it, update the path in css-vars-declaration-plugin.js.
+
import type { FlattenObjectKeys } from "../types/utils";
import type { MetabaseComponentTheme } from "./MetabaseTheme";
diff --git a/frontend/src/metabase/embedding-sdk/theme/dynamic-css-vars-config.ts b/frontend/src/metabase/embedding-sdk/theme/dynamic-css-vars-config.ts
index 2782c547470..db1cfa7b8a6 100644
--- a/frontend/src/metabase/embedding-sdk/theme/dynamic-css-vars-config.ts
+++ b/frontend/src/metabase/embedding-sdk/theme/dynamic-css-vars-config.ts
@@ -1,3 +1,6 @@
+// WARNING: This file is referenced by CssVarsDeclarationPlugin.
+// If you move or rename it, update the path in css-vars-declaration-plugin.js.
+
import type { DynamicCssVarConfig } from "../types/private/css-variables";
/**
diff --git a/frontend/src/metabase/styled-components/theme/css-variables.ts b/frontend/src/metabase/styled-components/theme/css-variables.ts
index 9f33fe0aa16..044ebfdc30d 100644
--- a/frontend/src/metabase/styled-components/theme/css-variables.ts
+++ b/frontend/src/metabase/styled-components/theme/css-variables.ts
@@ -1,3 +1,6 @@
+// WARNING: This file is referenced by CssVarsDeclarationPlugin.
+// If you move or rename it, update the path in css-vars-declaration-plugin.js.
+
// eslint-disable-next-line no-restricted-imports
import { css } from "@emotion/react";
import { getIn } from "icepick";
diff --git a/frontend/src/metabase/ui/colors/types/color-keys.ts b/frontend/src/metabase/ui/colors/types/color-keys.ts
index db1d571cf31..3c0ed897d9a 100644
--- a/frontend/src/metabase/ui/colors/types/color-keys.ts
+++ b/frontend/src/metabase/ui/colors/types/color-keys.ts
@@ -1,3 +1,6 @@
+// WARNING: This file is referenced by CssVarsDeclarationPlugin.
+// If you move or rename it, update the path in css-vars-declaration-plugin.js.
+
import type { ALL_ACCENT_COLOR_NAMES } from "../constants/accents";
/**