From 696e852465a8d4074148605d0e00eeec608f8eba Mon Sep 17 00:00:00 2001 From: Timofei Iatsenko Date: Wed, 16 Oct 2024 16:45:58 +0200 Subject: [PATCH] refactor: remove strings support from `LinguiConfig.extractors` --- packages/cli/src/api/extractors/index.ts | 11 +---------- packages/conf/__typetests__/index.test-d.tsx | 1 - packages/conf/src/types.ts | 2 +- website/docs/releases/migration-5.md | 1 + 4 files changed, 3 insertions(+), 12 deletions(-) diff --git a/packages/cli/src/api/extractors/index.ts b/packages/cli/src/api/extractors/index.ts index 8eaa773cd..fa82c0fc8 100644 --- a/packages/cli/src/api/extractors/index.ts +++ b/packages/cli/src/api/extractors/index.ts @@ -20,16 +20,7 @@ export default async function extract( ): Promise { const extractorsToExtract = options.extractors ?? DEFAULT_EXTRACTORS - for (let e of extractorsToExtract) { - let ext: ExtractorType = e - if (typeof e === "string") { - // in case of the user using require.resolve in their extractors, we require that module - ext = require(e) - } - if ((ext as any).default) { - ext = (ext as any).default - } - + for (let ext of extractorsToExtract) { if (!ext.match(filename)) continue try { diff --git a/packages/conf/__typetests__/index.test-d.tsx b/packages/conf/__typetests__/index.test-d.tsx index 1f582b46e..00ca4aa2b 100644 --- a/packages/conf/__typetests__/index.test-d.tsx +++ b/packages/conf/__typetests__/index.test-d.tsx @@ -48,7 +48,6 @@ expectAssignable({ expectAssignable({ locales: ["en", "pl"], extractors: [ - "babel", { match: (fileName: string) => false, extract: ( diff --git a/packages/conf/src/types.ts b/packages/conf/src/types.ts index e814c3fd3..29c2d658f 100644 --- a/packages/conf/src/types.ts +++ b/packages/conf/src/types.ts @@ -199,7 +199,7 @@ export type LinguiConfig = { } compilerBabelOptions?: any fallbackLocales?: FallbackLocales | false - extractors?: (string | ExtractorType)[] + extractors?: ExtractorType[] prevFormat?: CatalogFormat localeDir?: string format?: CatalogFormat | CatalogFormatter diff --git a/website/docs/releases/migration-5.md b/website/docs/releases/migration-5.md index beabcc8d9..c14df30c5 100644 --- a/website/docs/releases/migration-5.md +++ b/website/docs/releases/migration-5.md @@ -203,3 +203,4 @@ You'll need to [re-compile](/docs/ref/cli.md#compile) your messages in the new f ## Deprecations and Removals - Removed the deprecated `isTranslated` prop from the React `Trans` component. +- Removed support of the module path strings in `LinguiConfig.extractors` property. Please pass extractor object directly.