Skip to content

Commit

Permalink
fix: extract-template async race issue (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
timofei-iatsenko authored Sep 12, 2022
1 parent be265ef commit a69ed8f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/cli/src/lingui-extract-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export type CliExtractTemplateOptions = {
files?: string[]
}

export default function command(
export default async function command(
config: LinguiConfig,
options: Partial<CliExtractTemplateOptions>
): boolean {
): Promise<boolean> {
// `react-app` babel plugin used by CRA requires either BABEL_ENV or NODE_ENV to be
// set. We're setting it here, because lingui macros are going to use them as well.
if (!process.env.BABEL_ENV && !process.env.NODE_ENV) {
Expand All @@ -32,15 +32,16 @@ export default function command(
options.verbose && console.error("Extracting messages from source files…")
const catalogs = getCatalogs(config)
const catalogStats: { [path: string]: Number } = {}
catalogs.forEach((catalog) => {
catalog.makeTemplate({

await Promise.all(catalogs.map(async (catalog) => {
await catalog.makeTemplate({
...options,
orderBy: config.orderBy,
projectType: detect(),
})

catalogStats[catalog.templateFile] = Object.keys(catalog.readTemplate()).length
})
}))

Object.entries(catalogStats).forEach(([key, value]) => {
console.log(
Expand All @@ -64,7 +65,8 @@ if (require.main === module) {
const result = command(config, {
verbose: program.verbose || false,
configPath: program.config || process.env.LINGUI_CONFIG,
}).then(() => {
if (!result) process.exit(1)
})

if (!result) process.exit(1)
}

0 comments on commit a69ed8f

Please sign in to comment.