Skip to content

Commit 31913a5

Browse files
committed
validate that base paths of sources exist
1 parent be58a0e commit 31913a5

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

packages/@tailwindcss-node/src/compile.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
} from 'tailwindcss'
1111
import { getModuleDependencies } from './get-module-dependencies'
1212

13-
export function compile(
13+
export async function compile(
1414
css: string,
1515
{ base, onDependency }: { base: string; onDependency: (path: string) => void },
1616
) {
17-
return _compile(css, {
17+
let compiler = await _compile(css, {
1818
base,
1919
async loadModule(id, base) {
2020
return loadModule(id, base, onDependency)
@@ -23,6 +23,30 @@ export function compile(
2323
return loadStylesheet(id, base, onDependency)
2424
},
2525
})
26+
27+
// Verify if the `source(…)` path exists (until the glob pattern starts)
28+
if (compiler.root && compiler.root !== 'none') {
29+
let globSymbols = /[*{]/
30+
let basePath = []
31+
for (let segment of compiler.root.pattern.split('/')) {
32+
if (globSymbols.test(segment)) {
33+
break
34+
}
35+
36+
basePath.push(segment)
37+
}
38+
39+
let exists = await fsPromises
40+
.stat(path.resolve(base, basePath.join('/')))
41+
.then((stat) => stat.isDirectory())
42+
.catch(() => false)
43+
44+
if (!exists) {
45+
throw new Error(`The \`source(${compiler.root.pattern})\` does not exist`)
46+
}
47+
}
48+
49+
return compiler
2650
}
2751

2852
export async function __unstable__loadDesignSystem(css: string, { base }: { base: string }) {

0 commit comments

Comments
 (0)