镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Commit 182fa84

Browse files
committed
fix: ignore non-string safelist entries instead of crashing the build
A Tailwind-style { pattern: /.../ } safelist entry reached parseClass and threw 'className.startsWith is not a function', killing the whole build. Non-string entries are now skipped with a warning (build) or silently (plugin); pattern expansion remains unsupported.
1 parent 154b7c7 commit 182fa84

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎packages/crosswind/src/build.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,16 @@ export async function build(config: CrosswindConfig): Promise<BuildResult> {
3333
})
3434
const { classes, transformedFiles } = await scanner.scan()
3535

36-
// Add safelist classes
36+
// Add safelist classes. Only strings are supported — a Tailwind-style
37+
// { pattern: /.../ } entry previously reached parseClass and crashed the
38+
// whole build with 'className.startsWith is not a function'.
3739
for (const cls of config.safelist) {
38-
classes.add(cls)
40+
if (typeof cls === 'string') {
41+
classes.add(cls)
42+
}
43+
else {
44+
console.warn(`⚠️ Ignoring non-string safelist entry (patterns are not supported): ${JSON.stringify(cls)}`)
45+
}
3946
}
4047

4148
// Generate CSS

‎packages/crosswind/src/plugin.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ export function plugin(options: CrosswindPluginOptions = {}): BunPlugin {
105105
bracketSyntax: config.bracketSyntax,
106106
})
107107

108-
// Add safelist classes
108+
// Add safelist classes (strings only; pattern objects are ignored)
109109
for (const cls of config.safelist) {
110-
classes.add(cls)
110+
if (typeof cls === 'string') {
111+
classes.add(cls)
112+
}
111113
}
112114

113115
// Generate CSS

‎packages/crosswind/test/build.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ describe('build', () => {
2020
await rm(TEST_DIR, { recursive: true, force: true })
2121
})
2222

23+
it('ignores non-string safelist entries instead of crashing', async () => {
24+
const config = {
25+
...defaultConfig,
26+
content: [join(TEST_DIR, '*.html')],
27+
minify: false,
28+
safelist: ['bg-red-500', { pattern: /bg-(green|blue)-500/ } as any],
29+
}
30+
const result = await build(config)
31+
expect(result.css).toContain('.bg-red-500')
32+
})
33+
2334
it('should build CSS from files', async () => {
2435
const config = {
2536
...defaultConfig,

0 commit comments

Comments
 (0)