Skip to content

Commit 705493d

Browse files
authored
feat: adds globbing of input-files (#20)
1 parent 6e15ba8 commit 705493d

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
const postcss = require('postcss')
1515
const fs = require('fs');
16+
const glob = require('tiny-glob/sync');
1617

1718
const processed = Symbol('processed')
1819

@@ -38,7 +39,12 @@ module.exports = (UserProps) => {
3839
}
3940

4041
if (UserProps?.files?.length) {
41-
await Promise.all(UserProps.files.map(async file => {
42+
43+
const files = UserProps?.files
44+
.map((file) => glob(file))
45+
.reduce((flattenedFileList, files) => flattenedFileList.concat(files), [])
46+
47+
await Promise.all(files.map(async file => {
4248
let data = fs.readFileSync(file, 'utf8')
4349
let result = await postcss([(function(){})]).process(data, { from: undefined })
4450

index.test.js

+27
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,33 @@ it('Can jit props from a CSS file', async () => {
309309
)
310310
})
311311

312+
it('Can jit props from a CSS file via glob', async () => {
313+
await run(
314+
`@media (--dark) {
315+
a {
316+
color: var(--red);
317+
border-color: var( --pink );
318+
animation: var(--fade-in);
319+
}
320+
}`,
321+
`@custom-media --dark (prefers-color-scheme: dark);
322+
:root{
323+
--red: #f00;
324+
--pink: #ffc0cb;
325+
--fade-in: fade-in .5s ease;
326+
}
327+
@media (--dark) {
328+
a {
329+
color: var(--red);
330+
border-color: var( --pink );
331+
animation: var(--fade-in);
332+
}
333+
}
334+
@keyframes fade-in {to { opacity: 1 }}`,
335+
{ files: ['./*.test.css']}
336+
)
337+
})
338+
312339
it('Can fail without srcProps options gracefully', async () => {
313340
console.warn = jest.fn()
314341
await postcss([plugin({})]).process(``, { from: undefined })

package-lock.json

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

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,8 @@
6161
"statements": 90
6262
}
6363
}
64+
},
65+
"dependencies": {
66+
"tiny-glob": "^0.2.9"
6467
}
6568
}

0 commit comments

Comments
 (0)