Plugin-SDK: Varianten gegen CSS anderer Plugins absichern (0.39.1)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m15s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m19s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m3s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 10m46s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m11s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 16:32:48 +00:00
parent 93e83469f3
commit 326679b854
5 changed files with 49 additions and 4 deletions

View file

@ -10,6 +10,7 @@
"devDependencies": {
"@tailwindcss/vite": "{{v_tailwind_vite}}",
"@vitejs/plugin-vue": "{{v_plugin_vue}}",
"postcss": "^8.5.0",
"tailwindcss": "{{v_tailwind}}",
"vite": "{{v_vite}}",
"vue": "{{v_vue}}"

View file

@ -12,6 +12,7 @@
*/
import { existsSync, globSync } from 'node:fs';
import { resolve } from 'node:path';
import postcss from 'postcss';
import vue from '@vitejs/plugin-vue';
import tailwindcss from '@tailwindcss/vite';
@ -37,7 +38,7 @@ export function inhausPlugin({ root = process.cwd() } = {}) {
}
return {
plugins: [vue(), tailwindcss(), manifest(Object.keys(input))],
plugins: [vue(), tailwindcss(), manifest(Object.keys(input)), strongerVariants()],
// Plugins laufen unter /plugin-assets/<slug>/<version>/ – Pfade relativ halten
base: './',
build: {
@ -86,3 +87,41 @@ function manifest(entries) {
},
};
}
/**
* Mehrere Plugins bringen jeweils eigenes CSS mit, und dieselbe Hilfsklasse (z. B. ih:grid) kann in
* mehreren Dateien stehen. Lädt ein anderes Plugin sein CSS später, würde dessen „ih:grid“ sonst
* die Varianten dieses Plugins (ih:lg:hidden, ih:hover:…) überstimmen. Deshalb bekommen Regeln
* mit Variante (Media Query, :hover …) eine doppelte Klasse – sie gewinnen so immer gegen
* einfache Klassen, egal in welcher Reihenfolge die Dateien laden.
*/
export function strongerVariants() {
const pseudo = /(?<!\\):/;
const firstClass = /\.((?:\\.|[\w-])+)/;
return {
name: 'inhaus-stronger-variants',
enforce: 'post',
generateBundle(_, bundle) {
for (const file of Object.values(bundle)) {
if (file.type !== 'asset' || !file.fileName.endsWith('.css')) continue;
const root = postcss.parse(String(file.source));
root.walkRules((rule) => {
let conditional = false;
for (let parent = rule.parent; parent && parent.type !== 'root'; parent = parent.parent) {
if (parent.type === 'atrule' && parent.name !== 'layer') conditional = true;
}
rule.selectors = rule.selectors.map((selector) => (conditional || pseudo.test(selector.replace(/^[^.]*/, ''))) && firstClass.test(selector)
? selector.replace(firstClass, (match) => match + match)
: selector);
});
file.source = root.toString();
}
},
};
}