/
githubmirror
/
tailwindcss
Обзор
Документация
Войти
/
githubmirror
/
tailwindcss
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/@tailwindcss-cli/src/commands/build/utils.ts
35 строк
1 KB
Jordan Pittman
Don’t try reading from pipes or special file descriptors (#19421)
09 дек 2025, 01:04
Не верифицирован
09 дек 2025, 01:04
164194d
Код
Авторство
О чём код?
import fs from 'node:fs/promises' import path from 'node:path' export function drainStdin() { return new Promise<string>((resolve, reject) => { let result = '' process.stdin.on('data', (chunk) => { result += chunk }) process.stdin.on('end', () => resolve(result)) process.stdin.on('error', (err) => reject(err)) }) } export async function outputFile(file: string, contents: string) { // Check for special files like `/dev/stdout` or pipes. We don't want to read from these as that // will hang the process until the file descriptors are closed. let isSpecialFile = await fs .stat(file) .then((stats) => stats.isCharacterDevice() || stats.isFIFO()) .catch(() => false) if (!isSpecialFile) { try { let currentContents = await fs.readFile(file, 'utf8') if (currentContents === contents) return // Skip writing the file } catch {} } // Ensure the parent directories exist await fs.mkdir(path.dirname(file), { recursive: true }) // Write the file await fs.writeFile(file, contents, 'utf8') }