Skip to content

Commit

Permalink
fix(#1137): configPath is passed through babel-plugin-extract-messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Moreno committed Sep 28, 2021
1 parent 5cad96f commit a029774
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/babel-plugin-extract-messages/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default function ({ types: t }) {
// Config was already validated in CLI.
file.set(
CONFIG,
getConfig({ cwd: file.opts.filename, skipValidation: true })
getConfig({ cwd: file.opts.filename, skipValidation: true, configPath: this.opts.configPath })
)

// Ignore else path for now. Collision is possible if other plugin is
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export class Catalog {
paths.forEach((filename) =>
extract(filename, tmpDir, {
verbose: options.verbose,
configPath: options.configPath,
babelOptions: this.config.extractBabelOptions,
// @ts-ignore
extractors: options.extractors,
projectType: options.projectType,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/api/extract.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fs from "fs"
import path from "path"
import chalk from "chalk"
import ora from "ora"
import * as R from "ramda"

import { prettyOrigin } from "./utils"
Expand All @@ -11,6 +10,7 @@ import cliExtractor, { ExtractorType } from "./extractors"
type ExtractOptions = {
ignore?: Array<string>
verbose?: boolean
configPath?: string
extractors?: ExtractorType[]
projectType?: string
babelOptions?: Object
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/api/extractors/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const extractor: ExtractorType = {
},

extract(filename, localeDir, options = {}) {
const { babelOptions: _babelOptions = {} } = options
const { babelOptions: _babelOptions = {}, configPath } = options
const { plugins = [], ...babelOptions } = _babelOptions
const frameworkOptions: BabelOptions = {}

Expand All @@ -30,7 +30,7 @@ const extractor: ExtractorType = {
// we override envName to avoid issues with NODE_ENV=production
// https://github.com/lingui/js-lingui/issues/952
envName: "development",
plugins: ["macros", [linguiExtractMessages, { localeDir }], ...plugins],
plugins: ["macros", [linguiExtractMessages, { localeDir, configPath }], ...plugins],
})
},
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/api/extractors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type BabelOptions = {
export type ExtractOptions = {
verbose?: boolean
projectType?: string
configPath?: string
extractors?: ExtractorType[]
babelOptions?: BabelOptions
}
Expand All @@ -36,7 +37,7 @@ export default function extract(
if ((ext as any).default) {
ext = (ext as any).default
}

if (!ext.match(filename)) return false

let spinner
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/api/extractors/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ const extractor: ExtractorType = {
frameworkOptions.presets = ["react-app"]
}

const { babelOptions = {} } = options
const { babelOptions = {}, configPath } = options
const plugins = [
"macros",
[linguiExtractMessages, { localeDir }],
[linguiExtractMessages, { localeDir, configPath }],
...(babelOptions.plugins || []),
]

Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/lingui-extract-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { getConfig, LinguiConfig } from "@lingui/conf"

import { getCatalogs } from "./api/catalog"
import { detect } from "./api/detect"
import { ExtractorType } from "./api/extractors"

export type CliExtractTemplateOptions = {
verbose: boolean
configPath: string
extractors?: ExtractorType[]
files?: string[]
}

Expand Down Expand Up @@ -56,10 +59,11 @@ if (require.main === module) {
.option("--verbose", "Verbose output")
.parse(process.argv)

const config = getConfig({ configPath: program.config })
const config = getConfig({ configPath: program.config || process.env.LINGUI_CONFIG })

const result = command(config, {
verbose: program.verbose || false,
configPath: program.config || process.env.LINGUI_CONFIG,
})

if (!result) process.exit(1)
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/lingui-extract.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk"
import chokidar, { watch } from "chokidar"
import chokidar from "chokidar"
import program from "commander"

import { getConfig, LinguiConfig } from "@lingui/conf"
Expand All @@ -8,11 +8,14 @@ import { AllCatalogsType, getCatalogs } from "./api/catalog"
import { printStats } from "./api/stats"
import { detect } from "./api/detect"
import { helpRun } from "./api/help"
import { ExtractorType } from "./api/extractors"

export type CliExtractOptions = {
verbose: boolean
files?: string[]
clean: boolean
extractors?: ExtractorType[]
configPath: string
overwrite: boolean
locale: string
prevFormat: string | null
Expand Down Expand Up @@ -153,6 +156,7 @@ if (require.main === module) {
clean: program.watch ? false : program.clean || false,
overwrite: program.watch || program.overwrite || false,
locale: program.locale,
configPath: program.config || process.env.LINGUI_CONFIG,
watch: program.watch || false,
files: filePath?.length ? filePath : undefined,
prevFormat,
Expand Down

0 comments on commit a029774

Please sign in to comment.