Skip to content

The agent that grows with you

fix(web): isolate PostCSS discovery from ancestor config

Gilleb26b6c276924
diff --git a/web/src/postcss-build.test.ts b/web/src/postcss-build.test.ts
new file mode 100644
index 00000000000..63085677bbe
--- /dev/null
+++ b/web/src/postcss-build.test.ts
@@ -0,0 +1,51 @@
+import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import path from "node:path";
+import { afterEach, expect, test } from "vitest";
+import { build } from "vite";
+import dashboardConfig from "../vite.config";
+
+const fixtures: string[] = [];
+
+afterEach(() => {
+ for (const fixture of fixtures.splice(0)) {
+ rmSync(fixture, { recursive: true, force: true });
+ }
+});
+
+test.each(["package.json", ".postcssrc.json"])(
+ "dashboard CSS builds without loading an ancestor BOM-marked %s",
+ async (filename) => {
+ const fixture = mkdtempSync(path.join(tmpdir(), "hermes-web-postcss-"));
+ fixtures.push(fixture);
+ const root = path.join(fixture, "web");
+ mkdirSync(root);
+ const ambientConfig = path.join(fixture, filename);
+ const content = '\uFEFF{"name":"unrelated-parent","postcss":{}}';
+ writeFileSync(ambientConfig, content);
+ writeFileSync(path.join(root, "package.json"), '{"type":"module"}');
+ writeFileSync(path.join(root, "index.html"), '<script type="module" src="/main.js"></script>');
+ writeFileSync(path.join(root, "main.js"), 'import "./style.css";');
+ writeFileSync(path.join(root, "style.css"), "body { color: red; }");
+
+ const result = await build({
+ ...dashboardConfig,
+ root,
+ configFile: false,
+ publicDir: false,
+ logLevel: "silent",
+ build: { ...dashboardConfig.build, write: false, minify: false },
+ });
+
+ expect(result).toMatchObject({
+ output: expect.arrayContaining([
+ expect.objectContaining({
+ type: "asset",
+ fileName: expect.stringMatching(/\.css$/),
+ source: expect.stringMatching(/color:\s*red/),
+ }),
+ ]),
+ });
+ expect(readFileSync(ambientConfig, "utf8")).toBe(content);
+ },
+);
diff --git a/web/vite.config.ts b/web/vite.config.ts
index 4b7b8e317d7..81a86038566 100644
--- a/web/vite.config.ts
+++ b/web/vite.config.ts
@@ -77,6 +77,11 @@ function hermesDevToken(): Plugin {
}
export default defineConfig({
+ css: {
+ // Tailwind runs through its Vite plugin. Keep unrelated ancestor PostCSS
+ // configs (including BOM-marked JSON) out of this build.
+ postcss: { plugins: [] },
+ },
plugins: [
react(),
babel({ presets: [compilerPreset()] }),