Skip to content

Commit 1603cec

Browse files
committed
Fix validation of source(…) paths
1 parent a241a7b commit 1603cec

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,9 @@ function createCompileOptions({
6363
}
6464
}
6565

66-
async function ensureSourceDetectionRootExists(
67-
compiler: { root: Awaited<ReturnType<typeof compile>>['root'] },
68-
base: string,
69-
) {
66+
async function ensureSourceDetectionRootExists(compiler: {
67+
root: Awaited<ReturnType<typeof compile>>['root']
68+
}) {
7069
// Verify if the `source(…)` path exists (until the glob pattern starts)
7170
if (compiler.root && compiler.root !== 'none') {
7271
let globSymbols = /[*{]/
@@ -80,25 +79,27 @@ async function ensureSourceDetectionRootExists(
8079
}
8180

8281
let exists = await fsPromises
83-
.stat(path.resolve(base, basePath.join('/')))
82+
.stat(path.resolve(compiler.root.base, basePath.join('/')))
8483
.then((stat) => stat.isDirectory())
8584
.catch(() => false)
8685

8786
if (!exists) {
88-
throw new Error(`The \`source(${compiler.root.pattern})\` does not exist`)
87+
throw new Error(
88+
`The \`source(${compiler.root.pattern})\` does not exist or is not a directory.`,
89+
)
8990
}
9091
}
9192
}
9293

9394
export async function compileAst(ast: AstNode[], options: CompileOptions) {
9495
let compiler = await _compileAst(ast, createCompileOptions(options))
95-
await ensureSourceDetectionRootExists(compiler, options.base)
96+
await ensureSourceDetectionRootExists(compiler)
9697
return compiler
9798
}
9899

99100
export async function compile(css: string, options: CompileOptions) {
100101
let compiler = await _compile(css, createCompileOptions(options))
101-
await ensureSourceDetectionRootExists(compiler, options.base)
102+
await ensureSourceDetectionRootExists(compiler)
102103
return compiler
103104
}
104105

0 commit comments

Comments
 (0)