Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Ensure `@tailwindcss/cli` in `--watch` mode doesn't crash on Windows when `@source` points to a directory that doesn't exist ([#20242](https://github.com/tailwindlabs/tailwindcss/pull/20242))

## [4.3.1] - 2026-06-12

Expand Down
29 changes: 29 additions & 0 deletions integrations/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,35 @@ describe.each([
},
)

test(
"watch mode with unknown @source paths shouldn't crash on Windows",
{
fs: {
'package.json': json`
{
"dependencies": {
"tailwindcss": "workspace:^",
"@tailwindcss/cli": "workspace:^"
}
}
`,
'index.html': html`
<div class="underline"></div>
`,
'src/index.css': css`
@import 'tailwindcss';
@source "unknown-folder/**/*";
`,
},
},
async ({ fs, spawn }) => {
let process = await spawn(`${command} --input src/index.css --output dist/out.css --watch`)
await process.onStderr((m) => m.includes('Done in'))

await fs.expectFileToContain('dist/out.css', [candidate`underline`])
},
)

test(
'production build (stdin)',
{
Expand Down
22 changes: 18 additions & 4 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {
if (args['--watch']) {
let cleanupWatchers: (() => Promise<void>)[] = []
cleanupWatchers.push(
await createWatchers(watchDirectories(scanner), async function handle(files) {
await createWatchers(await watchDirectories(scanner), async function handle(files) {
try {
// If the only change happened to the output file, then we don't want to
// trigger a rebuild because that will result in an infinite loop.
Expand Down Expand Up @@ -347,7 +347,7 @@ export async function handle(args: Result<ReturnType<typeof options>>) {

// Setup new watchers
DEBUG && I.start('Setup new watchers')
let newCleanupFunction = await createWatchers(watchDirectories(scanner), handle)
let newCleanupFunction = await createWatchers(await watchDirectories(scanner), handle)
DEBUG && I.end('Setup new watchers')

// Clear old watchers
Expand Down Expand Up @@ -586,8 +586,22 @@ async function createWatchers(dirs: string[], cb: (files: string[]) => void) {
}
}

function watchDirectories(scanner: Scanner) {
return [...new Set(scanner.normalizedSources.flatMap((globEntry) => globEntry.base))]
async function watchDirectories(scanner: Scanner) {
let directories = (
await Promise.all(
scanner.normalizedSources.map(async (globEntry) => {
let resolvedPath = path.resolve(globEntry.base)
let realPath = await fs.realpath(resolvedPath).catch(() => resolvedPath)

return fs
.stat(realPath)
.then((stat) => (stat.isDirectory() ? [realPath] : []))
.catch(() => [])
}),
)
).flat(1)

return Array.from(new Set(directories))
}

function dim(str: string) {
Expand Down
Loading