Files
wehub-resource-sync 070959e133
landing-page-staging / Deploy landing page to staging (push) Has been skipped
landing-page-ci / Validate landing page (push) Failing after 4s
visual-baseline / Capture visual baselines (push) Has been cancelled
bake-plugin-previews / Bake plugin previews (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:00:47 +08:00

29 lines
1.0 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
const packageCssImports = new Map([
['@open-design/components/styles.css', join(process.cwd(), '../../packages/components/src/styles.css')],
]);
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('../')) {
const packageCssPath = packageCssImports.get(specifier);
return packageCssPath == null ? '' : expandCssFile(packageCssPath, seen);
}
return expandCssFile(join(dirname(filePath), specifier), seen);
});
}
export function readExpandedIndexCss(): string {
return expandCssFile(join(process.cwd(), 'src/index.css'));
}