diff --git a/CHANGELOG.md b/CHANGELOG.md index 9edab04ed619..b6e8e5b878f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/integrations/cli/index.test.ts b/integrations/cli/index.test.ts index 75869ee32bd6..4be12d9a1a48 100644 --- a/integrations/cli/index.test.ts +++ b/integrations/cli/index.test.ts @@ -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` +
+ `, + '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)', { diff --git a/packages/@tailwindcss-cli/src/commands/build/index.ts b/packages/@tailwindcss-cli/src/commands/build/index.ts index 91365763392f..b8b11a6e45d9 100644 --- a/packages/@tailwindcss-cli/src/commands/build/index.ts +++ b/packages/@tailwindcss-cli/src/commands/build/index.ts @@ -272,7 +272,7 @@ export async function handle(args: Result>) { if (args['--watch']) { let cleanupWatchers: (() => Promise)[] = [] 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. @@ -347,7 +347,7 @@ export async function handle(args: Result>) { // 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 @@ -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) {