diff --git a/packages/cli/src/api/compile.ts b/packages/cli/src/api/compile.ts index de37bfde0..a4babd72d 100644 --- a/packages/cli/src/api/compile.ts +++ b/packages/cli/src/api/compile.ts @@ -1,5 +1,5 @@ import * as t from "@babel/types" -import generate from "@babel/generator" +import generate, { GeneratorOptions } from "@babel/generator" import { parse } from "messageformat-parser" import * as R from "ramda" @@ -15,7 +15,7 @@ export type CreateCompileCatalogOptions = { strict?: boolean namespace?: CompiledCatalogNamespace pseudoLocale?: string - compilerBabelOptions?: Record + compilerBabelOptions?: GeneratorOptions } export function createCompiledCatalog( diff --git a/packages/conf/index.d.ts b/packages/conf/index.d.ts index 02606c5cd..0b49e5112 100644 --- a/packages/conf/index.d.ts +++ b/packages/conf/index.d.ts @@ -1,3 +1,5 @@ +import type { GeneratorOptions } from "@babel/core"; + export declare type CatalogFormat = "lingui" | "minimal" | "po" | "csv" | "po-gettext"; export type CatalogFormatOptions = { origins?: boolean; @@ -24,7 +26,7 @@ export declare type LinguiConfig = { catalogs: CatalogConfig[]; compileNamespace: string; extractBabelOptions: Record; - compilerBabelOptions: Record; + compilerBabelOptions: GeneratorOptions; fallbackLocales: FallbackLocales; format: CatalogFormat; prevFormat: CatalogFormat; @@ -52,7 +54,7 @@ export declare const configValidation: { plugins: string[]; presets: string[]; }; - compilerBabelOptions: Record; + compilerBabelOptions: GeneratorOptions; catalogs: CatalogConfig[]; compileNamespace: string; fallbackLocales: FallbackLocales; diff --git a/packages/conf/src/__snapshots__/index.test.ts.snap b/packages/conf/src/__snapshots__/index.test.ts.snap index 08b1bd90f..56fcc5244 100644 --- a/packages/conf/src/__snapshots__/index.test.ts.snap +++ b/packages/conf/src/__snapshots__/index.test.ts.snap @@ -110,7 +110,12 @@ Object { ], catalogsMergePath: , compileNamespace: cjs, - compilerBabelOptions: Object {}, + compilerBabelOptions: Object { + jsescOption: Object { + minimal: true, + }, + minified: true, + }, extractBabelOptions: Object { plugins: Array [], presets: Array [], diff --git a/packages/conf/src/index.ts b/packages/conf/src/index.ts index 152147eab..29af12712 100644 --- a/packages/conf/src/index.ts +++ b/packages/conf/src/index.ts @@ -1,3 +1,4 @@ +import type { GeneratorOptions } from "@babel/core" import path from "path" import fs from "fs" import chalk from "chalk" @@ -34,7 +35,7 @@ export type LinguiConfig = { catalogs: CatalogConfig[] compileNamespace: string extractBabelOptions: Record - compilerBabelOptions: Record + compilerBabelOptions: GeneratorOptions fallbackLocales?: FallbackLocales format: CatalogFormat formatOptions: CatalogFormatOptions @@ -66,7 +67,12 @@ export const defaultConfig: LinguiConfig = { ], catalogsMergePath: "", compileNamespace: "cjs", - compilerBabelOptions: {}, + compilerBabelOptions: { + minified: true, + jsescOption: { + minimal: true, + } + }, extractBabelOptions: { plugins: [], presets: [] }, fallbackLocales: {}, format: "po", @@ -266,7 +272,7 @@ export function replaceRootDir( } else if (typeof value === "string") { return replace(value) } else if (Array.isArray(value)) { - return value.map((item) => replaceDeep(item, rootDir)) as any + return (value as any).map((item) => replaceDeep(item, rootDir)) } else if (typeof value === "object") { Object.keys(value).forEach((key) => { const newKey = replaceDeep(key, rootDir)