open-design/apps/web/tests/helpers/read-expanded-css.ts
Marc Chan 619087a6b4
refactor(web): split global CSS by ownership (#2609)
* refactor(web): split global CSS by ownership

* test(web): expand CSS imports in style checks

* fix(web): keep privacy consent banner above modals
2026-05-25 05:48:28 +00:00

23 lines
786 B
TypeScript

import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
function expandCssFile(filePath: string, seen = new Set<string>()): string {
const key = filePath;
if (seen.has(key)) {
return '';
}
seen.add(key);
const css = readFileSync(filePath, 'utf8');
return css.replace(/@import\s+(?:url\(([^)]+)\)|(['"])([^'"]+)\2);/g, (_match, urlImport, _quote, quotedImport) => {
const specifier = (quotedImport ?? urlImport ?? '').trim().replace(/^['"]|['"]$/g, '');
if (!specifier.startsWith('./') && !specifier.startsWith('../')) {
return '';
}
return expandCssFile(join(dirname(filePath), specifier), seen);
});
}
export function readExpandedIndexCss(): string {
return expandCssFile(join(process.cwd(), 'src/index.css'));
}