@ecopages/postcss-processor 0.2.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +136 -0
- package/package.json +82 -0
- package/src/index.ts +2 -0
- package/src/plugin.ts +354 -0
- package/src/postcss-processor.ts +157 -0
- package/src/presets/index.ts +7 -0
- package/src/presets/tailwind-v3.ts +61 -0
- package/src/presets/tailwind-v4.ts +113 -0
- package/src/runtime/css-loader-plugin.ts +37 -0
- package/src/runtime/css-loader.bun.ts +30 -0
- package/src/runtime/css-runtime-contract.ts +6 -0
- package/src/test/css/base.css +3 -0
- package/src/test/css/correct.css +3 -0
- package/src/test/css/error.css +3 -0
- package/src/test/css/external-plugins.css +13 -0
- package/src/test/css/import.css +4 -0
- package/src/test/plugin.test.ts +74 -0
- package/src/test/postcss-processor.test.ts +106 -0
- package/src/test/presets.test.ts +140 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { PostCssProcessor } from '../postcss-processor';
|
|
4
|
+
import { tailwindV3Preset } from '../presets/tailwind-v3';
|
|
5
|
+
import { tailwindV4Preset } from '../presets/tailwind-v4';
|
|
6
|
+
|
|
7
|
+
describe('Presets Verification', () => {
|
|
8
|
+
const cssToPrefix = `
|
|
9
|
+
.test-prefix {
|
|
10
|
+
user-select: none;
|
|
11
|
+
backdrop-filter: blur(10px);
|
|
12
|
+
appearance: none;
|
|
13
|
+
}
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
const cssWithImport = `
|
|
17
|
+
@import "base.css";
|
|
18
|
+
.main { background: blue; }
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
test('Tailwind v3 preset should add vendor prefixes', async () => {
|
|
22
|
+
const { plugins } = tailwindV3Preset();
|
|
23
|
+
/**
|
|
24
|
+
* Disable cssnano for readable output logic check, or just check content calls
|
|
25
|
+
* By default preset includes cssnano.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const result = await PostCssProcessor.processStringOrBuffer(cssToPrefix, {
|
|
29
|
+
plugins: plugins ? Object.values(plugins) : [],
|
|
30
|
+
filePath: path.resolve(__dirname, 'style.css'),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* cssnano will minify, so we check minified output
|
|
35
|
+
* user-select: none -> -webkit-user-select:none;user-select:none
|
|
36
|
+
* backdrop-filter: blur(10px) -> -webkit-backdrop-filter:blur(10px);backdrop-filter:blur(10px)
|
|
37
|
+
* appearance: none -> -webkit-appearance:none;-moz-appearance:none;appearance:none
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
expect(result).toContain('-webkit-user-select:none');
|
|
41
|
+
expect(result).toContain('user-select:none');
|
|
42
|
+
|
|
43
|
+
expect(result).toContain('-webkit-backdrop-filter:blur(10px)');
|
|
44
|
+
expect(result).toContain('backdrop-filter:blur(10px)');
|
|
45
|
+
|
|
46
|
+
expect(result).toContain('appearance:none');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('Tailwind v3 preset should support nesting', async () => {
|
|
50
|
+
const { plugins } = tailwindV3Preset();
|
|
51
|
+
const cssWithNesting = `
|
|
52
|
+
.parent {
|
|
53
|
+
& .child { color: blue; }
|
|
54
|
+
&__element { color: green; }
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
const result = await PostCssProcessor.processStringOrBuffer(cssWithNesting, {
|
|
59
|
+
plugins: plugins ? Object.values(plugins) : [],
|
|
60
|
+
filePath: path.resolve(__dirname, 'style.css'),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(result).toContain('.parent .child{color:blue}');
|
|
64
|
+
expect(result).toContain('.parent__element{color:green}');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('Tailwind v4 preset should add vendor prefixes (via Lightning CSS)', async () => {
|
|
68
|
+
const preset = tailwindV4Preset({
|
|
69
|
+
referencePath: path.resolve(__dirname, '../fixtures/tailwind.css'),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const result = await PostCssProcessor.processStringOrBuffer(cssToPrefix, {
|
|
73
|
+
plugins: preset.plugins ? Object.values(preset.plugins) : [],
|
|
74
|
+
filePath: path.resolve(__dirname, 'style.css'),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Lightning CSS used by @tailwindcss/postcss should verify this
|
|
79
|
+
* Note: The specific prefixes might depend on the browser targets configured in package.json or defaults
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
expect(result).toContain('-webkit-user-select:none');
|
|
83
|
+
expect(result).toContain('user-select:none');
|
|
84
|
+
|
|
85
|
+
expect(result).toContain('-webkit-backdrop-filter:blur(10px)');
|
|
86
|
+
expect(result).toContain('backdrop-filter:blur(10px)');
|
|
87
|
+
|
|
88
|
+
expect(result).toContain('appearance:none');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('Tailwind v4 preset should resolve @import', async () => {
|
|
92
|
+
const preset = tailwindV4Preset({
|
|
93
|
+
referencePath: path.resolve(__dirname, '../fixtures/tailwind.css'),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Provide a filePath that allows resolving sibling files (like base.css in existing tests/css dir)
|
|
98
|
+
* We'll leverage the existing test css files
|
|
99
|
+
*/
|
|
100
|
+
const filePath = path.resolve(__dirname, 'css/import.css');
|
|
101
|
+
|
|
102
|
+
const result = await PostCssProcessor.processStringOrBuffer(cssWithImport, {
|
|
103
|
+
plugins: preset.plugins ? Object.values(preset.plugins) : [],
|
|
104
|
+
filePath,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Expect content from base.css (.base { color: red }) + main css content
|
|
109
|
+
* Minified output expected
|
|
110
|
+
*/
|
|
111
|
+
expect(result).toContain('.base{color:red}');
|
|
112
|
+
expect(result).toContain('.main{background:blue}');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('Tailwind v4 preset should support nesting', async () => {
|
|
117
|
+
const preset = tailwindV4Preset({
|
|
118
|
+
referencePath: path.resolve(__dirname, '../fixtures/tailwind.css'),
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const cssWithNesting = `
|
|
122
|
+
.parent {
|
|
123
|
+
color: red;
|
|
124
|
+
& .child {
|
|
125
|
+
color: blue;
|
|
126
|
+
}
|
|
127
|
+
&__element {
|
|
128
|
+
color: green;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
|
|
133
|
+
const result = await PostCssProcessor.processStringOrBuffer(cssWithNesting, {
|
|
134
|
+
plugins: preset.plugins ? Object.values(preset.plugins) : [],
|
|
135
|
+
filePath: path.resolve(__dirname, 'style.css'),
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(result).toContain('.parent .child{color:blue}');
|
|
139
|
+
expect(result).toContain('.parent__element{color:green}');
|
|
140
|
+
});
|