Skip to content

Commit

Permalink
fix(@formatjs/cli-lib): fix #4404
Browse files Browse the repository at this point in the history
  • Loading branch information
longlho committed May 5, 2024
1 parent 1693515 commit 2195fc0
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions packages/cli-lib/src/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,31 @@ export async function extract(
extractOpts: ExtractOpts
) {
const {throws, readFromStdin, flatten, ...opts} = extractOpts
let rawResults: Array<ExtractionResult | undefined>
if (readFromStdin) {
debug(`Reading input from stdin`)
// Read from stdin
if (process.stdin.isTTY) {
warn('Reading source file from TTY.')
}
const stdinSource = await getStdinAsString()
rawResults = [await processFile(stdinSource, 'dummy', opts)]
} else {
rawResults = await Promise.all(
files.map(async fn => {
debug('Extracting file:', fn)
try {
let rawResults: Array<ExtractionResult | undefined> = []
try {
if (readFromStdin) {
debug(`Reading input from stdin`)
// Read from stdin
if (process.stdin.isTTY) {
warn('Reading source file from TTY.')
}
const stdinSource = await getStdinAsString()
rawResults = [await processFile(stdinSource, 'dummy', opts)]
} else {
rawResults = await Promise.all(
files.map(async fn => {
debug('Extracting file:', fn)
const source = await readFile(fn, 'utf8')
return processFile(source, fn, opts)
} catch (e) {
if (throws) {
throw e
} else {
warn(String(e))
}
}
})
)
})
)
}
} catch (e) {
if (throws) {
throw e
} else {
warn(String(e))
}
}

const formatter: Formatter = await resolveBuiltinFormatter(opts.format)
Expand Down

0 comments on commit 2195fc0

Please sign in to comment.