@intlayer/babel 8.12.1 → 8.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/babel-plugin-intlayer-usage-analyzer.cjs +293 -33
- package/dist/cjs/babel-plugin-intlayer-usage-analyzer.cjs.map +1 -1
- package/dist/cjs/index.cjs +3 -0
- package/dist/cjs/transformers.cjs +21 -7
- package/dist/cjs/transformers.cjs.map +1 -1
- package/dist/esm/babel-plugin-intlayer-usage-analyzer.mjs +293 -34
- package/dist/esm/babel-plugin-intlayer-usage-analyzer.mjs.map +1 -1
- package/dist/esm/index.mjs +3 -3
- package/dist/esm/transformers.mjs +20 -8
- package/dist/esm/transformers.mjs.map +1 -1
- package/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts +72 -4
- package/dist/types/babel-plugin-intlayer-usage-analyzer.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/transformers.d.ts +17 -5
- package/dist/types/transformers.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -28,11 +28,23 @@ const BABEL_PARSER_OPTIONS = {
|
|
|
28
28
|
]
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
* Fast pre-check: matches files that could contain intlayer calls
|
|
32
|
-
*
|
|
31
|
+
* Fast pre-check: matches files that could contain native intlayer calls
|
|
32
|
+
* (`useIntlayer` / `getIntlayer`). Used by the optimize/transform pass, which
|
|
33
|
+
* only rewrites native calls.
|
|
33
34
|
*/
|
|
34
35
|
const INTLAYER_USAGE_REGEX = /\b(use|get)Intlayer\b/;
|
|
35
36
|
/**
|
|
37
|
+
* Fast pre-check: matches files that could contain compat-adapter namespace
|
|
38
|
+
* callers (`useTranslation`, `useTranslations`, `getTranslations`, `getFixedT`,
|
|
39
|
+
* `useI18n`). These are analysed for field usage (pruning) but never rewritten.
|
|
40
|
+
*/
|
|
41
|
+
const COMPAT_USAGE_REGEX = /\b(useTranslation|useTranslations|getTranslations|getFixedT|useI18n)\b/;
|
|
42
|
+
/**
|
|
43
|
+
* Fast pre-check for the usage-analysis phase: matches files containing either
|
|
44
|
+
* native intlayer calls or compat-adapter namespace callers.
|
|
45
|
+
*/
|
|
46
|
+
const INTLAYER_OR_COMPAT_USAGE_REGEX = /\b(useIntlayer|getIntlayer|useTranslation|useTranslations|getTranslations|getFixedT|useI18n)\b/;
|
|
47
|
+
/**
|
|
36
48
|
* Matches source files that are valid targets for usage analysis and Babel
|
|
37
49
|
* transformation. Excludes sourcemap files, declaration files, and other
|
|
38
50
|
* non-source extensions.
|
|
@@ -44,10 +56,10 @@ const SOURCE_FILE_REGEX = /\.(tsx?|[mc]?jsx?|vue|svelte|astro)$/;
|
|
|
44
56
|
* This is analysis-only: the transformed code output is discarded.
|
|
45
57
|
* Throws if Babel cannot parse the content.
|
|
46
58
|
*/
|
|
47
|
-
const analyzeScriptContent = async (scriptContent, sourceFilePath, pruneContext) => {
|
|
59
|
+
const analyzeScriptContent = async (scriptContent, sourceFilePath, pruneContext, compatCallers) => {
|
|
48
60
|
await transformAsync(scriptContent, {
|
|
49
61
|
filename: sourceFilePath,
|
|
50
|
-
plugins: [makeUsageAnalyzerBabelPlugin(pruneContext)],
|
|
62
|
+
plugins: [makeUsageAnalyzerBabelPlugin(pruneContext, { compatCallers })],
|
|
51
63
|
parserOpts: BABEL_PARSER_OPTIONS,
|
|
52
64
|
ast: false,
|
|
53
65
|
code: false
|
|
@@ -65,11 +77,11 @@ const analyzeScriptContent = async (scriptContent, sourceFilePath, pruneContext)
|
|
|
65
77
|
* Throws if Babel cannot parse the file (caller should handle and flag
|
|
66
78
|
* `pruneContext.hasUnparsableSourceFiles`).
|
|
67
79
|
*/
|
|
68
|
-
const analyzeFieldUsageInFile = async (sourceFilePath, code, pruneContext) => {
|
|
80
|
+
const analyzeFieldUsageInFile = async (sourceFilePath, code, pruneContext, compatCallers) => {
|
|
69
81
|
const scriptBlocks = extractScriptBlocks(sourceFilePath, code);
|
|
70
82
|
for (const block of scriptBlocks) {
|
|
71
|
-
if (!
|
|
72
|
-
await analyzeScriptContent(block.content, sourceFilePath, pruneContext);
|
|
83
|
+
if (!INTLAYER_OR_COMPAT_USAGE_REGEX.test(block.content)) continue;
|
|
84
|
+
await analyzeScriptContent(block.content, sourceFilePath, pruneContext, compatCallers);
|
|
73
85
|
}
|
|
74
86
|
};
|
|
75
87
|
/**
|
|
@@ -138,5 +150,5 @@ const optimizeSourceFile = async (code, sourceFilePath, options) => {
|
|
|
138
150
|
};
|
|
139
151
|
|
|
140
152
|
//#endregion
|
|
141
|
-
export { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile };
|
|
153
|
+
export { BABEL_PARSER_OPTIONS, COMPAT_USAGE_REGEX, INTLAYER_OR_COMPAT_USAGE_REGEX, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile };
|
|
142
154
|
//# sourceMappingURL=transformers.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/transformers.ts"],"sourcesContent":["import { type TransformOptions, transformAsync } from '@babel/core';\nimport { makeFieldRenameBabelPlugin } from './babel-plugin-intlayer-field-rename';\nimport {\n intlayerOptimizeBabelPlugin,\n type OptimizePluginOptions,\n} from './babel-plugin-intlayer-optimize';\nimport {\n makeUsageAnalyzerBabelPlugin,\n type PruneContext,\n} from './babel-plugin-intlayer-usage-analyzer';\nimport { extractScriptBlocks, injectScriptBlocks } from './extractScriptBlocks';\n\n// ── Shared Babel parser configuration ─────────────────────────────────────────\n\n/**\n * Babel parser options covering the superset of syntaxes used across all\n * supported frameworks (React / Vue / Svelte / Angular / …).\n */\nexport const BABEL_PARSER_OPTIONS: NonNullable<TransformOptions['parserOpts']> =\n {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n };\n\n/**\n * Fast pre-check: matches files that could contain intlayer calls
|
|
1
|
+
{"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/transformers.ts"],"sourcesContent":["import { type TransformOptions, transformAsync } from '@babel/core';\nimport { makeFieldRenameBabelPlugin } from './babel-plugin-intlayer-field-rename';\nimport {\n intlayerOptimizeBabelPlugin,\n type OptimizePluginOptions,\n} from './babel-plugin-intlayer-optimize';\nimport {\n type CompatCallerConfig,\n makeUsageAnalyzerBabelPlugin,\n type PruneContext,\n} from './babel-plugin-intlayer-usage-analyzer';\nimport { extractScriptBlocks, injectScriptBlocks } from './extractScriptBlocks';\n\n// ── Shared Babel parser configuration ─────────────────────────────────────────\n\n/**\n * Babel parser options covering the superset of syntaxes used across all\n * supported frameworks (React / Vue / Svelte / Angular / …).\n */\nexport const BABEL_PARSER_OPTIONS: NonNullable<TransformOptions['parserOpts']> =\n {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'classProperties',\n 'objectRestSpread',\n 'asyncGenerators',\n 'functionBind',\n 'exportDefaultFrom',\n 'exportNamespaceFrom',\n 'dynamicImport',\n 'nullishCoalescingOperator',\n 'optionalChaining',\n ],\n };\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer`). Used by the optimize/transform pass, which\n * only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = /\\b(use|get)Intlayer\\b/;\n\n/**\n * Fast pre-check: matches files that could contain compat-adapter namespace\n * callers (`useTranslation`, `useTranslations`, `getTranslations`, `getFixedT`,\n * `useI18n`). These are analysed for field usage (pruning) but never rewritten.\n */\nexport const COMPAT_USAGE_REGEX =\n /\\b(useTranslation|useTranslations|getTranslations|getFixedT|useI18n)\\b/;\n\n/**\n * Fast pre-check for the usage-analysis phase: matches files containing either\n * native intlayer calls or compat-adapter namespace callers.\n */\nexport const INTLAYER_OR_COMPAT_USAGE_REGEX =\n /\\b(useIntlayer|getIntlayer|useTranslation|useTranslations|getTranslations|getFixedT|useI18n)\\b/;\n\n/**\n * Matches source files that are valid targets for usage analysis and Babel\n * transformation. Excludes sourcemap files, declaration files, and other\n * non-source extensions.\n */\nexport const SOURCE_FILE_REGEX = /\\.(tsx?|[mc]?jsx?|vue|svelte|astro)$/;\n\n// ── High-level transformer functions ──────────────────────────────────────────\n\n/**\n * Runs the usage-analysis Babel plugin on a single JS/TS code string.\n *\n * This is analysis-only: the transformed code output is discarded.\n * Throws if Babel cannot parse the content.\n */\nconst analyzeScriptContent = async (\n scriptContent: string,\n sourceFilePath: string,\n pruneContext: PruneContext,\n compatCallers?: CompatCallerConfig[]\n): Promise<void> => {\n await transformAsync(scriptContent, {\n filename: sourceFilePath,\n plugins: [makeUsageAnalyzerBabelPlugin(pruneContext, { compatCallers })],\n parserOpts: BABEL_PARSER_OPTIONS,\n ast: false,\n code: false, // analysis only – no output needed\n });\n};\n\n/**\n * Runs the usage-analysis Babel plugin on a source file, accumulating\n * field-usage data into `pruneContext`.\n *\n * For Vue / Svelte SFC files, script blocks are extracted before analysis so\n * Babel does not attempt to parse the full SFC syntax (templates, styles, …).\n * For plain JS/TS files, the whole file content is analysed directly.\n *\n * This is analysis-only: the transformed code output is discarded.\n * Throws if Babel cannot parse the file (caller should handle and flag\n * `pruneContext.hasUnparsableSourceFiles`).\n */\nexport const analyzeFieldUsageInFile = async (\n sourceFilePath: string,\n code: string,\n pruneContext: PruneContext,\n compatCallers?: CompatCallerConfig[]\n): Promise<void> => {\n const scriptBlocks = extractScriptBlocks(sourceFilePath, code);\n\n // For SFC files (Vue / Svelte): scriptBlocks[0].contentStartOffset > 0\n // means we extracted actual <script> tags from the file.\n // For plain JS/TS: extractScriptBlocks returns the whole file as a single\n // block with offset 0, so we fall through to the same path.\n for (const block of scriptBlocks) {\n if (!INTLAYER_OR_COMPAT_USAGE_REGEX.test(block.content)) continue;\n await analyzeScriptContent(\n block.content,\n sourceFilePath,\n pruneContext,\n compatCallers\n );\n }\n};\n\n/**\n * Applies field-renaming to a single JS/TS code string (not an SFC).\n *\n * Returns the renamed code string, or `null` if nothing changed or if\n * Babel failed to parse the input (caller should fall back to original code).\n */\nexport const renameFieldsInCode = async (\n code: string,\n sourceFilePath: string,\n pruneContext: PruneContext\n): Promise<string | null> => {\n try {\n const result = await transformAsync(code, {\n filename: sourceFilePath,\n plugins: [makeFieldRenameBabelPlugin(pruneContext)],\n parserOpts: BABEL_PARSER_OPTIONS,\n ast: false,\n });\n return result?.code ?? null;\n } catch {\n return null; // parse failure – caller falls back to original code\n }\n};\n\n/**\n * Applies field-renaming to a source file, correctly handling both plain\n * JS/TS files and SFC files (Vue / Svelte) by operating on each script block\n * individually and injecting the results back into the original source.\n *\n * Returns the renamed code string, or `null` if nothing changed.\n */\nexport const renameFieldsInSourceFile = async (\n sourceFilePath: string,\n code: string,\n pruneContext: PruneContext\n): Promise<string | null> => {\n if (pruneContext.dictionaryKeyToFieldRenameMap.size === 0) return null;\n if (!INTLAYER_USAGE_REGEX.test(code)) return null;\n\n const scriptBlocks = extractScriptBlocks(sourceFilePath, code);\n\n const isSFC =\n scriptBlocks.length > 0 &&\n ((scriptBlocks[0]?.contentStartOffset ?? 0) > 0 || scriptBlocks.length > 1);\n\n if (isSFC) {\n // Raw SFC: rename each script block individually and inject back.\n const modifications: Array<{\n block: (typeof scriptBlocks)[number];\n modifiedContent: string;\n }> = [];\n\n for (const block of scriptBlocks) {\n if (!INTLAYER_USAGE_REGEX.test(block.content)) continue;\n\n const renamedCode = await renameFieldsInCode(\n block.content,\n sourceFilePath,\n pruneContext\n );\n if (renamedCode && renamedCode !== block.content) {\n modifications.push({ block, modifiedContent: renamedCode });\n }\n }\n\n if (modifications.length === 0) return null;\n return injectScriptBlocks(code, modifications);\n }\n\n // Plain JS/TS or compiled SFC (no block delimiters) – rename the whole file.\n return renameFieldsInCode(code, sourceFilePath, pruneContext);\n};\n\n/**\n * Runs the intlayer optimize Babel plugin on a source file, transforming\n * `useIntlayer('key')` / `getIntlayer('key')` calls into `useDictionary(_hash)`\n * / `getDictionary(_hash)` and injecting the corresponding dictionary imports.\n *\n * Returns `{ code, map }` on success, or `null` if the transformation produced\n * no output.\n */\nexport const optimizeSourceFile = async (\n code: string,\n sourceFilePath: string,\n options: OptimizePluginOptions\n): Promise<{\n code: string;\n map: string | object | null | undefined;\n} | null> => {\n const result = await transformAsync(code, {\n filename: sourceFilePath,\n plugins: [[intlayerOptimizeBabelPlugin, options]],\n parserOpts: BABEL_PARSER_OPTIONS,\n });\n\n if (!result?.code) return null;\n\n return { code: result.code, map: result.map };\n};\n"],"mappings":";;;;;;;;;;;AAmBA,MAAa,uBACX;CACE,YAAY;CACZ,6BAA6B;CAC7B,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;AAOF,MAAa,uBAAuB;;;;;;AAOpC,MAAa,qBACX;;;;;AAMF,MAAa,iCACX;;;;;;AAOF,MAAa,oBAAoB;;;;;;;AAUjC,MAAM,uBAAuB,OAC3B,eACA,gBACA,cACA,kBACkB;CAClB,MAAM,eAAe,eAAe;EAClC,UAAU;EACV,SAAS,CAAC,6BAA6B,cAAc,EAAE,cAAc,CAAC,CAAC;EACvE,YAAY;EACZ,KAAK;EACL,MAAM;CACR,CAAC;AACH;;;;;;;;;;;;;AAcA,MAAa,0BAA0B,OACrC,gBACA,MACA,cACA,kBACkB;CAClB,MAAM,eAAe,oBAAoB,gBAAgB,IAAI;CAM7D,KAAK,MAAM,SAAS,cAAc;EAChC,IAAI,CAAC,+BAA+B,KAAK,MAAM,OAAO,GAAG;EACzD,MAAM,qBACJ,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
|
/** Canonical intlayer caller names that trigger usage analysis. */
|
|
102
102
|
declare const INTLAYER_CALLER_NAMES: readonly ["useIntlayer", "getIntlayer"];
|
|
103
103
|
type IntlayerCallerName = (typeof INTLAYER_CALLER_NAMES)[number];
|
|
104
|
+
/**
|
|
105
|
+
* Describes how a compat-adapter "namespace caller" exposes the dictionary key
|
|
106
|
+
* (namespace) and the translation function `t`.
|
|
107
|
+
*
|
|
108
|
+
* Compat adapters (`@intlayer/react-i18next`, `@intlayer/next-intl`, …) expose
|
|
109
|
+
* the original i18n library API while delegating to intlayer under the hood.
|
|
110
|
+
* Their call sites look like:
|
|
111
|
+
*
|
|
112
|
+
* const { t } = useTranslation('about'); t('counter.label')
|
|
113
|
+
* const t = useTranslations('about'); t('counter.label')
|
|
114
|
+
* const t = await getTranslations('about');
|
|
115
|
+
* const t = i18n.getFixedT(null, 'about', 'counter');
|
|
116
|
+
* const { t } = useI18n({ namespace: 'about' });
|
|
117
|
+
*
|
|
118
|
+
* The dictionary key is the *namespace* argument and the consumed top-level
|
|
119
|
+
* field is the **first segment** of every dot-path passed to `t()` (or the
|
|
120
|
+
* first segment of `keyPrefix` when one is supplied).
|
|
121
|
+
*/
|
|
122
|
+
type CompatNamespaceSource = /** Namespace is a positional argument (string literal or `{ namespace }`). */{
|
|
123
|
+
from: 'argument';
|
|
124
|
+
index: number;
|
|
125
|
+
} /** Namespace is a property of an options object argument. */ | {
|
|
126
|
+
from: 'option';
|
|
127
|
+
argumentIndex: number;
|
|
128
|
+
property: string;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Configuration entry for a single compat namespace caller.
|
|
132
|
+
*/
|
|
133
|
+
type CompatCallerConfig = {
|
|
134
|
+
/** The imported (or method) function name, e.g. `'useTranslation'`. */callerName: string;
|
|
135
|
+
/**
|
|
136
|
+
* Module specifiers from which `callerName` must be imported to be treated as
|
|
137
|
+
* a compat caller. Includes both the original library names and their
|
|
138
|
+
* `@intlayer/*` adapter equivalents, because the bundler aliases the former
|
|
139
|
+
* to the latter but user source code may import either.
|
|
140
|
+
*
|
|
141
|
+
* Ignored when `matchAsMethod` is `true`.
|
|
142
|
+
*/
|
|
143
|
+
importSources: string[];
|
|
144
|
+
/**
|
|
145
|
+
* When `true`, the caller is matched by method name on any object
|
|
146
|
+
* (`x.getFixedT(...)`) without an import check. Used for `i18next` instance
|
|
147
|
+
* methods that are never imported as named specifiers.
|
|
148
|
+
*/
|
|
149
|
+
matchAsMethod?: boolean; /** How the dictionary key (namespace) is read from the call arguments. */
|
|
150
|
+
namespace: CompatNamespaceSource;
|
|
151
|
+
/**
|
|
152
|
+
* Optional location of a `keyPrefix` that prefixes every `t()` path. When a
|
|
153
|
+
* static prefix is present, the only consumed top-level field is the first
|
|
154
|
+
* segment of the prefix.
|
|
155
|
+
*/
|
|
156
|
+
keyPrefix?: CompatNamespaceSource; /** How the translation function is obtained from the call result. */
|
|
157
|
+
translationFunction: 'return-value' | 'destructured-t';
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Default registry of compat namespace callers, covering every first-party
|
|
161
|
+
* `@intlayer/*` adapter package and its underlying i18n library.
|
|
162
|
+
*/
|
|
163
|
+
declare const DEFAULT_COMPAT_CALLERS: CompatCallerConfig[];
|
|
104
164
|
/**
|
|
105
165
|
* Creates a Babel plugin that traverses source files and records which
|
|
106
|
-
* top-level dictionary fields each `useIntlayer` / `getIntlayer` call-site
|
|
107
|
-
* accesses. Results are
|
|
166
|
+
* top-level dictionary fields each `useIntlayer` / `getIntlayer` call-site —
|
|
167
|
+
* and each configured compat namespace caller — accesses. Results are
|
|
168
|
+
* accumulated into `pruneContext`.
|
|
108
169
|
*
|
|
109
170
|
* This plugin is analysis-only: it does not transform the code (`code: false`
|
|
110
171
|
* should be passed to `transformAsync` when using it).
|
|
172
|
+
*
|
|
173
|
+
* @param pruneContext - Shared mutable state written by this plugin.
|
|
174
|
+
* @param options - Optional overrides. `compatCallers` defaults to
|
|
175
|
+
* {@link DEFAULT_COMPAT_CALLERS}; pass `[]` to disable
|
|
176
|
+
* compat-adapter analysis entirely.
|
|
111
177
|
*/
|
|
112
|
-
declare const makeUsageAnalyzerBabelPlugin: (pruneContext: PruneContext
|
|
178
|
+
declare const makeUsageAnalyzerBabelPlugin: (pruneContext: PruneContext, options?: {
|
|
179
|
+
compatCallers?: CompatCallerConfig[];
|
|
180
|
+
}) => ({
|
|
113
181
|
types: babelTypes
|
|
114
182
|
}: {
|
|
115
183
|
types: typeof BabelTypes;
|
|
116
184
|
}) => PluginObj;
|
|
117
185
|
//#endregion
|
|
118
|
-
export { DictionaryFieldUsage, INTLAYER_CALLER_NAMES, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, PruneContext, createPruneContext, makeUsageAnalyzerBabelPlugin };
|
|
186
|
+
export { CompatCallerConfig, CompatNamespaceSource, DEFAULT_COMPAT_CALLERS, DictionaryFieldUsage, INTLAYER_CALLER_NAMES, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, PruneContext, createPruneContext, makeUsageAnalyzerBabelPlugin };
|
|
119
187
|
//# sourceMappingURL=babel-plugin-intlayer-usage-analyzer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel-plugin-intlayer-usage-analyzer.d.ts","names":[],"sources":["../../src/babel-plugin-intlayer-usage-analyzer.ts"],"mappings":";;;;;;AAYA;;;;AAAsC;KAA1B,oBAAA,GAAuB,GAAG;;;;;;;;KAS1B,iBAAA;EACV,SAAA;EACA,QAAA,EAAU,eAAe;AAAA;;KAIf,eAAA,GAAkB,GAAG,SAAS,iBAAA;AAS1C;;;;;;;AAAA,KAAY,YAAA;EAiCqB;;;;;EA3B/B,4BAAA,EAA8B,GAAA,SAAY,oBAAA;EA+Db;;;;EAzD7B,yBAAA,EAA2B,GAAA;EAAA;;;;;EAO3B,wBAAA;EAc2C;;;;;EAP3C,mCAAA,EAAqC,GAAA;EA2CrC;;;;;EApCA,6BAAA,EAA+B,GAAA,SAAY,eAAA;E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;;cA2vB1C,4BAAA,GAET,YAAA,EAAc,YAAA,EACd,OAAA;EAAY,aAAA,GAAgB,kBAAA;AAAA;EAE7B,KAAA,EAAA;AAAA;EAAyB,KAAA,SAAc,UAAA;AAAA,MAAe,SAAA"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ATTRIBUTES_TO_EXTRACT, PackageName, SERVER_CAPABLE_PACKAGES, packageList } from "./extractContent/utils/constants.js";
|
|
2
2
|
import { ExtractPluginOptions, ExtractResult, intlayerExtractBabelPlugin } from "./babel-plugin-intlayer-extract.js";
|
|
3
|
-
import { DictionaryFieldUsage, INTLAYER_CALLER_NAMES, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, PruneContext, createPruneContext, makeUsageAnalyzerBabelPlugin } from "./babel-plugin-intlayer-usage-analyzer.js";
|
|
3
|
+
import { CompatCallerConfig, CompatNamespaceSource, DEFAULT_COMPAT_CALLERS, DictionaryFieldUsage, INTLAYER_CALLER_NAMES, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, PruneContext, createPruneContext, makeUsageAnalyzerBabelPlugin } from "./babel-plugin-intlayer-usage-analyzer.js";
|
|
4
4
|
import { buildNestedRenameMapFromContent, generateShortFieldName, makeFieldRenameBabelPlugin } from "./babel-plugin-intlayer-field-rename.js";
|
|
5
5
|
import { OptimizePluginOptions, intlayerOptimizeBabelPlugin } from "./babel-plugin-intlayer-optimize.js";
|
|
6
6
|
import { mergeWithExistingMultilingualDictionary, mergeWithExistingPerLocaleDictionary, writeContentHelper } from "./extractContent/contentWriter.js";
|
|
@@ -13,5 +13,5 @@ import { ExtractIntlayerOptions, extractContent, extractContentSync } from "./ex
|
|
|
13
13
|
import { ScriptBlock, extractScriptBlocks, injectScriptBlocks } from "./extractScriptBlocks.js";
|
|
14
14
|
import { CompilerMode, getExtractPluginOptions } from "./getExtractPluginOptions.js";
|
|
15
15
|
import { getOptimizePluginOptions } from "./getOptimizePluginOptions.js";
|
|
16
|
-
import { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile } from "./transformers.js";
|
|
17
|
-
export { ATTRIBUTES_TO_EXTRACT, BABEL_PARSER_OPTIONS, CompilerMode, DictionaryFieldUsage, ExtractDictionaryInfoOptions, ExtractIntlayerOptions, ExtractPluginOptions, ExtractResult, INTLAYER_CALLER_NAMES, INTLAYER_USAGE_REGEX, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, OptimizePluginOptions, PackageName, PruneContext, ResolveContentFilePaths, SERVER_CAPABLE_PACKAGES, SOURCE_FILE_REGEX, ScriptBlock, analyzeFieldUsageInFile, buildNestedRenameMapFromContent, createPruneContext, detectPackageName, extractContent, extractContentSync, extractDictionaryInfo, extractDictionaryKey, extractDictionaryKeyFromPath, extractScriptBlocks, generateKey, generateShortFieldName, getComponentName, getExtractPluginOptions, getOptimizePluginOptions, getOutput, injectScriptBlocks, intlayerExtractBabelPlugin, intlayerOptimizeBabelPlugin, makeFieldRenameBabelPlugin, makeUsageAnalyzerBabelPlugin, mergeWithExistingMultilingualDictionary, mergeWithExistingPerLocaleDictionary, optimizeSourceFile, packageList, renameFieldsInCode, renameFieldsInSourceFile, resolveContentFilePaths, writeContentHelper };
|
|
16
|
+
import { BABEL_PARSER_OPTIONS, COMPAT_USAGE_REGEX, INTLAYER_OR_COMPAT_USAGE_REGEX, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile } from "./transformers.js";
|
|
17
|
+
export { ATTRIBUTES_TO_EXTRACT, BABEL_PARSER_OPTIONS, COMPAT_USAGE_REGEX, CompatCallerConfig, CompatNamespaceSource, CompilerMode, DEFAULT_COMPAT_CALLERS, DictionaryFieldUsage, ExtractDictionaryInfoOptions, ExtractIntlayerOptions, ExtractPluginOptions, ExtractResult, INTLAYER_CALLER_NAMES, INTLAYER_OR_COMPAT_USAGE_REGEX, INTLAYER_USAGE_REGEX, IntlayerCallerName, NestedRenameEntry, NestedRenameMap, OptimizePluginOptions, PackageName, PruneContext, ResolveContentFilePaths, SERVER_CAPABLE_PACKAGES, SOURCE_FILE_REGEX, ScriptBlock, analyzeFieldUsageInFile, buildNestedRenameMapFromContent, createPruneContext, detectPackageName, extractContent, extractContentSync, extractDictionaryInfo, extractDictionaryKey, extractDictionaryKeyFromPath, extractScriptBlocks, generateKey, generateShortFieldName, getComponentName, getExtractPluginOptions, getOptimizePluginOptions, getOutput, injectScriptBlocks, intlayerExtractBabelPlugin, intlayerOptimizeBabelPlugin, makeFieldRenameBabelPlugin, makeUsageAnalyzerBabelPlugin, mergeWithExistingMultilingualDictionary, mergeWithExistingPerLocaleDictionary, optimizeSourceFile, packageList, renameFieldsInCode, renameFieldsInSourceFile, resolveContentFilePaths, writeContentHelper };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PruneContext } from "./babel-plugin-intlayer-usage-analyzer.js";
|
|
1
|
+
import { CompatCallerConfig, PruneContext } from "./babel-plugin-intlayer-usage-analyzer.js";
|
|
2
2
|
import { OptimizePluginOptions } from "./babel-plugin-intlayer-optimize.js";
|
|
3
3
|
import { TransformOptions } from "@babel/core";
|
|
4
4
|
|
|
@@ -9,10 +9,22 @@ import { TransformOptions } from "@babel/core";
|
|
|
9
9
|
*/
|
|
10
10
|
declare const BABEL_PARSER_OPTIONS: NonNullable<TransformOptions['parserOpts']>;
|
|
11
11
|
/**
|
|
12
|
-
* Fast pre-check: matches files that could contain intlayer calls
|
|
13
|
-
*
|
|
12
|
+
* Fast pre-check: matches files that could contain native intlayer calls
|
|
13
|
+
* (`useIntlayer` / `getIntlayer`). Used by the optimize/transform pass, which
|
|
14
|
+
* only rewrites native calls.
|
|
14
15
|
*/
|
|
15
16
|
declare const INTLAYER_USAGE_REGEX: RegExp;
|
|
17
|
+
/**
|
|
18
|
+
* Fast pre-check: matches files that could contain compat-adapter namespace
|
|
19
|
+
* callers (`useTranslation`, `useTranslations`, `getTranslations`, `getFixedT`,
|
|
20
|
+
* `useI18n`). These are analysed for field usage (pruning) but never rewritten.
|
|
21
|
+
*/
|
|
22
|
+
declare const COMPAT_USAGE_REGEX: RegExp;
|
|
23
|
+
/**
|
|
24
|
+
* Fast pre-check for the usage-analysis phase: matches files containing either
|
|
25
|
+
* native intlayer calls or compat-adapter namespace callers.
|
|
26
|
+
*/
|
|
27
|
+
declare const INTLAYER_OR_COMPAT_USAGE_REGEX: RegExp;
|
|
16
28
|
/**
|
|
17
29
|
* Matches source files that are valid targets for usage analysis and Babel
|
|
18
30
|
* transformation. Excludes sourcemap files, declaration files, and other
|
|
@@ -31,7 +43,7 @@ declare const SOURCE_FILE_REGEX: RegExp;
|
|
|
31
43
|
* Throws if Babel cannot parse the file (caller should handle and flag
|
|
32
44
|
* `pruneContext.hasUnparsableSourceFiles`).
|
|
33
45
|
*/
|
|
34
|
-
declare const analyzeFieldUsageInFile: (sourceFilePath: string, code: string, pruneContext: PruneContext) => Promise<void>;
|
|
46
|
+
declare const analyzeFieldUsageInFile: (sourceFilePath: string, code: string, pruneContext: PruneContext, compatCallers?: CompatCallerConfig[]) => Promise<void>;
|
|
35
47
|
/**
|
|
36
48
|
* Applies field-renaming to a single JS/TS code string (not an SFC).
|
|
37
49
|
*
|
|
@@ -60,5 +72,5 @@ declare const optimizeSourceFile: (code: string, sourceFilePath: string, options
|
|
|
60
72
|
map: string | object | null | undefined;
|
|
61
73
|
} | null>;
|
|
62
74
|
//#endregion
|
|
63
|
-
export { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile };
|
|
75
|
+
export { BABEL_PARSER_OPTIONS, COMPAT_USAGE_REGEX, INTLAYER_OR_COMPAT_USAGE_REGEX, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile };
|
|
64
76
|
//# sourceMappingURL=transformers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","names":[],"sources":["../../src/transformers.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","names":[],"sources":["../../src/transformers.ts"],"mappings":";;;;;;;AAmBA;;cAAa,oBAAA,EAAsB,WAAW,CAAC,gBAAA;;AAAgB;AAyB/D;;;cAAa,oBAAA,EAAoB,MAA0B;AAAA;AAO3D;;;;AAP2D,cAO9C,kBAAA,EAAkB,MAC2C;AAM1E;;;;AAAA,cAAa,8BAAA,EAA8B,MACuD;AAOlG;;;;AAAuE;AAAvE,cAAa,iBAAA,EAAiB,MAAyC;;;;;;;;;;;;;cAqC1D,uBAAA,GACX,cAAA,UACA,IAAA,UACA,YAAA,EAAc,YAAA,EACd,aAAA,GAAgB,kBAAA,OACf,OAAA;;;AAAO;AAwBV;;;cAAa,kBAAA,GACX,IAAA,UACA,cAAA,UACA,YAAA,EAAc,YAAA,KACb,OAAO;;;;;;;AAAA;cAqBG,wBAAA,GACX,cAAA,UACA,IAAA,UACA,YAAA,EAAc,YAAA,KACb,OAAO;;;;;;;;;cA8CG,kBAAA,GACX,IAAA,UACA,cAAA,UACA,OAAA,EAAS,qBAAA,KACR,OAAO;EACR,IAAA;EACA,GAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/babel",
|
|
3
|
-
"version": "8.12.
|
|
3
|
+
"version": "8.12.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Babel plugin for Intlayer that transforms declaration files and provides internationalization features during the build process according to the Intlayer configuration.",
|
|
6
6
|
"keywords": [
|
|
@@ -81,18 +81,18 @@
|
|
|
81
81
|
"@babel/plugin-syntax-jsx": "7.29.7",
|
|
82
82
|
"@babel/traverse": "7.29.7",
|
|
83
83
|
"@babel/types": "7.29.7",
|
|
84
|
-
"@intlayer/chokidar": "8.12.
|
|
85
|
-
"@intlayer/config": "8.12.
|
|
86
|
-
"@intlayer/core": "8.12.
|
|
87
|
-
"@intlayer/dictionaries-entry": "8.12.
|
|
88
|
-
"@intlayer/types": "8.12.
|
|
89
|
-
"@intlayer/unmerged-dictionaries-entry": "8.12.
|
|
84
|
+
"@intlayer/chokidar": "8.12.2",
|
|
85
|
+
"@intlayer/config": "8.12.2",
|
|
86
|
+
"@intlayer/core": "8.12.2",
|
|
87
|
+
"@intlayer/dictionaries-entry": "8.12.2",
|
|
88
|
+
"@intlayer/types": "8.12.2",
|
|
89
|
+
"@intlayer/unmerged-dictionaries-entry": "8.12.2",
|
|
90
90
|
"@types/babel__core": "7.20.5",
|
|
91
91
|
"@types/babel__generator": "7.27.0",
|
|
92
92
|
"@types/babel__traverse": "7.28.0"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
|
-
"@babel/plugin-syntax-jsx": "
|
|
95
|
+
"@babel/plugin-syntax-jsx": "7.29.7",
|
|
96
96
|
"@types/node": "25.9.1",
|
|
97
97
|
"@utils/ts-config": "1.0.4",
|
|
98
98
|
"@utils/ts-config-types": "1.0.4",
|
|
@@ -104,8 +104,8 @@
|
|
|
104
104
|
"vitest": "4.1.8"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
|
-
"@intlayer/svelte-compiler": "8.12.
|
|
108
|
-
"@intlayer/vue-compiler": "8.12.
|
|
107
|
+
"@intlayer/svelte-compiler": "8.12.2",
|
|
108
|
+
"@intlayer/vue-compiler": "8.12.2"
|
|
109
109
|
},
|
|
110
110
|
"peerDependenciesMeta": {
|
|
111
111
|
"@intlayer/svelte-compiler": {
|