Skip to content

Commit 164194d

Browse files
Don’t try reading from pipes or special file descriptors (#19421)
Fixes #19420
1 parent cdc851d commit 164194d

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Canonicalization: combine `text-*` and `leading-*` classes ([#19396](https://github.com/tailwindlabs/tailwindcss/pull/19396))
2525
- Correctly handle duplicate CLI arguments ([#19416](https://github.com/tailwindlabs/tailwindcss/pull/19416))
2626
- Don’t emit color-mix fallback rules inside `@keyframes` ([#19419](https://github.com/tailwindlabs/tailwindcss/pull/19419))
27+
- CLI: Don't hang when output is `/dev/stdout` ([#19421](https://github.com/tailwindlabs/tailwindcss/pull/19421))
2728

2829
### Added
2930

packages/@tailwindcss-cli/src/commands/build/utils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@ export function drainStdin() {
1313
}
1414

1515
export async function outputFile(file: string, contents: string) {
16-
try {
17-
let currentContents = await fs.readFile(file, 'utf8')
18-
if (currentContents === contents) return // Skip writing the file
19-
} catch {}
16+
// Check for special files like `/dev/stdout` or pipes. We don't want to read from these as that
17+
// will hang the process until the file descriptors are closed.
18+
let isSpecialFile = await fs
19+
.stat(file)
20+
.then((stats) => stats.isCharacterDevice() || stats.isFIFO())
21+
.catch(() => false)
22+
23+
if (!isSpecialFile) {
24+
try {
25+
let currentContents = await fs.readFile(file, 'utf8')
26+
if (currentContents === contents) return // Skip writing the file
27+
} catch {}
28+
}
2029

2130
// Ensure the parent directories exist
2231
await fs.mkdir(path.dirname(file), { recursive: true })

0 commit comments

Comments
 (0)