fix(cli): use content-based hashing for CSS module class names

Replace the default path-based CSS module hash with a content-based
hash derived from the CSS content. This prevents class name collisions
when multiple versions of packages are loaded simultaneously.

Uses 10 characters of hex-encoded MD5 hash for safe, readable class
name suffixes.

Signed-off-by: Johan Persson <johanopersson@gmail.com>
This commit is contained in:
Johan Persson
2026-01-20 11:06:23 +01:00
parent 3659aceaac
commit f6a5d2f07f
2 changed files with 19 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Fixed CSS module class name collisions when running multiple versions of packages simultaneously by using content-based hashing for class name generation.
@@ -16,7 +16,9 @@
import chalk from 'chalk';
import fs from 'fs-extra';
import { createHash } from 'crypto';
import {
basename,
extname,
relative as relativePath,
resolve as resolvePath,
@@ -239,7 +241,18 @@ export async function makeRollupConfigs(
include: /node_modules/,
exclude: [/\/[^/]+\.(?:stories|test)\.[^/]+$/],
}),
postcss(),
postcss({
modules: {
generateScopedName(name: string, filename: string, css: string) {
const hash = createHash('md5')
.update(css)
.digest('hex')
.slice(0, 10);
const file = basename(filename, '.module.css');
return `${file}_${name}__${hash}`;
},
},
}),
forwardFileImports({
exclude: /\.icon\.svg$/,
include: [