From b1f924767c38abf4eee0c3bec185dc0a100a310d Mon Sep 17 00:00:00 2001 From: cpojer Date: Thu, 12 Dec 2024 22:39:02 +0900 Subject: [PATCH] Add the auto-import plugin to the default collector. --- package.json | 2 +- packages/babel-fbtee/package.json | 2 +- .../package.json | 2 +- .../babel-plugin-fbtee-runtime/package.json | 2 +- packages/babel-plugin-fbtee/package.json | 3 ++- .../src/bin/FbtCollector.tsx | 3 ++- .../babel-plugin-fbtee/src/bin/collect.tsx | 18 ++++++++---------- packages/fbtee/package.json | 2 +- pnpm-lock.yaml | 3 +++ 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index a0309301..4bb2bec3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nkzw/fbtee-internal", - "version": "0.0.3", + "version": "0.0.4", "private": true, "license": "MIT", "type": "module", diff --git a/packages/babel-fbtee/package.json b/packages/babel-fbtee/package.json index 7891b05c..29d16cb6 100644 --- a/packages/babel-fbtee/package.json +++ b/packages/babel-fbtee/package.json @@ -1,6 +1,6 @@ { "name": "@nkzw/babel-fbtee", - "version": "0.0.3", + "version": "0.0.4", "description": "The JavaScript & React Internationalization Framework.", "keywords": [ "fbt", diff --git a/packages/babel-plugin-fbtee-auto-import/package.json b/packages/babel-plugin-fbtee-auto-import/package.json index a1cfd2db..e7b46001 100644 --- a/packages/babel-plugin-fbtee-auto-import/package.json +++ b/packages/babel-plugin-fbtee-auto-import/package.json @@ -1,6 +1,6 @@ { "name": "@nkzw/babel-plugin-fbtee-auto-import", - "version": "0.0.3", + "version": "0.0.4", "description": "The JavaScript & React Internationalization Framework.", "keywords": [ "fbt", diff --git a/packages/babel-plugin-fbtee-runtime/package.json b/packages/babel-plugin-fbtee-runtime/package.json index afa9610c..4e2a0ea3 100644 --- a/packages/babel-plugin-fbtee-runtime/package.json +++ b/packages/babel-plugin-fbtee-runtime/package.json @@ -1,6 +1,6 @@ { "name": "@nkzw/babel-plugin-fbtee-runtime", - "version": "0.0.3", + "version": "0.0.4", "description": "The JavaScript & React Internationalization Framework.", "keywords": [ "fbt", diff --git a/packages/babel-plugin-fbtee/package.json b/packages/babel-plugin-fbtee/package.json index 7567988e..f04f8f81 100644 --- a/packages/babel-plugin-fbtee/package.json +++ b/packages/babel-plugin-fbtee/package.json @@ -1,6 +1,6 @@ { "name": "@nkzw/babel-plugin-fbtee", - "version": "0.0.3", + "version": "0.0.4", "description": "The JavaScript & React Internationalization Framework.", "keywords": [ "fbt", @@ -35,6 +35,7 @@ "@babel/preset-typescript": "^7.26.0", "@babel/traverse": "^7.26.4", "@babel/types": "^7.26.3", + "@nkzw/babel-plugin-fbtee-auto-import": "workspace:*", "glob": "^11.0.0", "invariant": "^2.2.4", "jest-docblock": "^30.0.0-alpha.6", diff --git a/packages/babel-plugin-fbtee/src/bin/FbtCollector.tsx b/packages/babel-plugin-fbtee/src/bin/FbtCollector.tsx index 2db091f3..c9f9d597 100644 --- a/packages/babel-plugin-fbtee/src/bin/FbtCollector.tsx +++ b/packages/babel-plugin-fbtee/src/bin/FbtCollector.tsx @@ -2,6 +2,7 @@ import type { PluginItem } from '@babel/core'; import { transformSync } from '@babel/core'; import presetReact from '@babel/preset-react'; import presetTypescript from '@babel/preset-typescript'; +import fbtAutoImport from '@nkzw/babel-plugin-fbtee-auto-import'; import type { PlainFbtNode } from '../fbt-nodes/FbtNode.tsx'; import { FbtCommonMap } from '../FbtCommon.tsx'; import type { FbtOptionConfig } from '../FbtConstants.tsx'; @@ -71,7 +72,7 @@ const transform = ( ast: false, code: false, filename: options.filename, - plugins: [[fbt, options], ...plugins], + plugins: [fbtAutoImport, [fbt, options], ...plugins], presets: [ presetTypescript, [ diff --git a/packages/babel-plugin-fbtee/src/bin/collect.tsx b/packages/babel-plugin-fbtee/src/bin/collect.tsx index a2a815c9..7c3b7eb1 100644 --- a/packages/babel-plugin-fbtee/src/bin/collect.tsx +++ b/packages/babel-plugin-fbtee/src/bin/collect.tsx @@ -240,17 +240,15 @@ if (argv.help) { ? (await import(transformPath)).default : null; - const commonFile = argv[args.COMMON_STRINGS]; + const commonFile = argv[args.COMMON_STRINGS]?.length + ? resolve(process.cwd(), argv[args.COMMON_STRINGS]) + : null; const fbtCommon = commonFile?.length - ? ( - await import( - resolve(process.cwd(), commonFile), - commonFile.endsWith('.json') - ? { - with: { type: 'json' }, - } - : {} - ) + ? (commonFile.endsWith('.json') + ? await import(commonFile, { + with: { type: 'json' }, + }) + : await import(commonFile) ).default : null; diff --git a/packages/fbtee/package.json b/packages/fbtee/package.json index ca15a37b..a847f6c3 100644 --- a/packages/fbtee/package.json +++ b/packages/fbtee/package.json @@ -1,6 +1,6 @@ { "name": "fbtee", - "version": "0.0.3", + "version": "0.0.4", "description": "The JavaScript & React Internationalization Framework.", "keywords": [ "fbt", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c3015c9..a2b1cdc2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -189,6 +189,9 @@ importers: '@babel/types': specifier: ^7.26.3 version: 7.26.3 + '@nkzw/babel-plugin-fbtee-auto-import': + specifier: workspace:* + version: link:../babel-plugin-fbtee-auto-import glob: specifier: ^11.0.0 version: 11.0.0