Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | 7x 7x 7x 9x 6x 4x 4x 9x 9x 7x 3x 4x 1x | /**
* postcss-reject-theme-layer
*
* Fails the build if any `@layer theme { ... }` block is found in the output.
*
* Standard (non-theme-layer) CSS must not contain @layer theme — that content
* belongs exclusively in the theme-layer dist path. This plugin acts as a gate
* to prevent accidental bleed during the theme-layer migration.
*
* Collects all violations and reports them as a single error at OnceExit.
*/
/**
* @type {import('postcss').PluginCreator}
*/
const postcssRejectThemeLayer = () => ({
postcssPlugin: 'postcss-reject-theme-layer',
OnceExit(root) {
const violations = [];
root.walkAtRules('layer', (atRule) => {
if (!atRule.nodes || atRule.nodes.length === 0) return;
if (atRule.params.trim() !== 'theme') return;
const source = atRule.source;
const file = source?.input?.file || source?.input?.from || 'unknown file';
const line = source?.start?.line ?? '?';
violations.push(`${file}:${line}`);
});
if (violations.length > 0) {
throw root.error(
`@layer theme is not allowed in standard CSS outputs. ` +
`Found ${violations.length} occurrence(s):\n` +
violations.map((v) => ` - ${v}`).join('\n') +
`\nTheme layer content must only appear in theme-layer dist builds.`,
);
}
},
});
postcssRejectThemeLayer.postcss = true;
export default postcssRejectThemeLayer;
|