Skip to content

Commit c937e69

Browse files
silverwindpull[bot]
authored andcommitted
Inline the css-variables-parser dependency (#29571)
Get rid of the `postcss@7` dependency by inlining this simple function.
1 parent dead19d commit c937e69

File tree

3 files changed

+24
-41
lines changed

3 files changed

+24
-41
lines changed

package-lock.json

-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"chartjs-plugin-zoom": "2.0.1",
2424
"clippie": "4.0.7",
2525
"css-loader": "6.10.0",
26-
"css-variables-parser": "1.0.1",
2726
"dayjs": "1.11.10",
2827
"dropzone": "6.0.0-beta.2",
2928
"easymde": "2.18.0",

tailwind.config.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import {readFileSync} from 'node:fs';
22
import {env} from 'node:process';
3-
import {parse} from 'css-variables-parser';
3+
import {parse} from 'postcss';
44

55
const isProduction = env.NODE_ENV !== 'development';
66

7+
function extractRootVars(css) {
8+
const root = parse(css);
9+
const vars = new Set();
10+
root.walkRules((rule) => {
11+
if (rule.selector !== ':root') return;
12+
rule.each((decl) => {
13+
if (decl.value && decl.prop.startsWith('--')) {
14+
vars.add(decl.prop.substring(2));
15+
}
16+
});
17+
});
18+
return Array.from(vars);
19+
}
20+
21+
const vars = extractRootVars([
22+
readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
23+
readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
24+
].join('\n'));
25+
726
export default {
827
prefix: 'tw-',
928
important: true, // the frameworks are mixed together, so tailwind needs to override other framework's styles
@@ -23,15 +42,10 @@ export default {
2342
theme: {
2443
colors: {
2544
// make `tw-bg-red` etc work with our CSS variables
26-
...Object.fromEntries(
27-
Object.keys(parse([
28-
readFileSync(new URL('web_src/css/themes/theme-gitea-light.css', import.meta.url), 'utf8'),
29-
readFileSync(new URL('web_src/css/themes/theme-gitea-dark.css', import.meta.url), 'utf8'),
30-
].join('\n'), {})).filter((prop) => prop.startsWith('color-')).map((prop) => {
31-
const color = prop.substring(6);
32-
return [color, `var(--color-${color})`];
33-
})
34-
),
45+
...Object.fromEntries(vars.filter((prop) => prop.startsWith('color-')).map((prop) => {
46+
const color = prop.substring(6);
47+
return [color, `var(--color-${color})`];
48+
})),
3549
inherit: 'inherit',
3650
current: 'currentcolor',
3751
transparent: 'transparent',

0 commit comments

Comments
 (0)