Skip to content

Commit 1d7090a

Browse files
committed
return globs from compile()
1 parent a165644 commit 1d7090a

File tree

2 files changed

+15
-32
lines changed

2 files changed

+15
-32
lines changed

packages/tailwindcss/src/index.test.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3-
import { describe, expect, it, test, vi } from 'vitest'
3+
import { describe, expect, it, test } from 'vitest'
44
import { compile } from '.'
55
import { compileCss, optimizeCss, run } from './test-utils/run'
66

@@ -1346,35 +1346,20 @@ describe('plugins', () => {
13461346

13471347
describe('@content', () => {
13481348
test('emits @content files', () => {
1349-
const onContentPath = vi.fn()
1350-
compile(
1351-
css`
1352-
@content "./foo/bar/*.ts";
1353-
`,
1354-
{
1355-
loadPlugin: () => () => {},
1356-
onContentPath,
1357-
},
1358-
)
1349+
let { globs } = compile(css`
1350+
@content "./foo/bar/*.ts";
1351+
`)
13591352

1360-
expect(onContentPath).toHaveBeenCalledWith('./foo/bar/*.ts')
1353+
expect(globs).toEqual(['./foo/bar/*.ts'])
13611354
})
13621355

13631356
test('emits multiple @content files', () => {
1364-
const onContentPath = vi.fn()
1365-
compile(
1366-
css`
1367-
@content "./foo/**/*.ts";
1368-
@content "./php/secr3t/smarty.php";
1369-
`,
1370-
{
1371-
loadPlugin: () => () => {},
1372-
onContentPath,
1373-
},
1374-
)
1357+
let { globs } = compile(css`
1358+
@content "./foo/**/*.ts";
1359+
@content "./php/secr3t/smarty.php";
1360+
`)
13751361

1376-
expect(onContentPath).toHaveBeenNthCalledWith(1, './foo/**/*.ts')
1377-
expect(onContentPath).toHaveBeenNthCalledWith(2, './php/secr3t/smarty.php')
1362+
expect(globs).toEqual(['./foo/**/*.ts', './php/secr3t/smarty.php'])
13781363
})
13791364
})
13801365

packages/tailwindcss/src/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,17 @@ type Plugin = (api: PluginAPI) => void
2727

2828
type CompileOptions = {
2929
loadPlugin?: (path: string) => Plugin
30-
onContentPath?: (path: string) => void
3130
}
3231

3332
function throwOnPlugin(): never {
3433
throw new Error('No `loadPlugin` function provided to `compile`')
3534
}
3635

37-
function throwOnContentPath(): never {
38-
throw new Error('No `onContentPath` function provided to `compile`')
39-
}
40-
4136
export function compile(
4237
css: string,
43-
{ loadPlugin = throwOnPlugin, onContentPath = throwOnContentPath }: CompileOptions = {},
38+
{ loadPlugin = throwOnPlugin }: CompileOptions = {},
4439
): {
40+
globs: string[]
4541
build(candidates: string[]): string
4642
} {
4743
let ast = CSS.parse(css)
@@ -63,6 +59,7 @@ export function compile(
6359
let customUtilities: ((designSystem: DesignSystem) => void)[] = []
6460
let firstThemeRule: Rule | null = null
6561
let keyframesRules: Rule[] = []
62+
let globs: string[] = []
6663

6764
walk(ast, (node, { parent, replaceWith }) => {
6865
if (node.kind !== 'rule') return
@@ -119,7 +116,7 @@ export function compile(
119116
) {
120117
throw new Error('`@content` paths must be quoted.')
121118
}
122-
onContentPath(path.slice(1, -1))
119+
globs.push(path.slice(1, -1))
123120
replaceWith([])
124121
return
125122
}
@@ -375,6 +372,7 @@ export function compile(
375372
let previousAstNodeCount = 0
376373

377374
return {
375+
globs,
378376
build(newRawCandidates: string[]) {
379377
let didChange = false
380378

0 commit comments

Comments
 (0)