@intlayer/babel 9.5.9-canary.0 → 9.5.10
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/analyzeContentUsage.cjs +1 -1
- package/dist/cjs/babel-plugin-intlayer-extract.cjs +2 -2
- package/dist/cjs/babel-plugin-intlayer-field-rename.cjs +1 -1
- package/dist/cjs/babel-plugin-intlayer-optimize.cjs +1 -1
- package/dist/cjs/babel-plugin-intlayer-purge.cjs +4 -4
- package/dist/cjs/babel-plugin-intlayer-usage-analyzer.cjs +1 -1
- package/dist/cjs/babelParser.cjs +0 -1
- package/dist/cjs/babelParser.cjs.map +1 -1
- package/dist/cjs/compat/usageAnalysis.cjs +1 -1
- package/dist/cjs/extractContent/contentWriter.cjs +1 -1
- package/dist/cjs/extractContent/extractContent.cjs +2 -2
- package/dist/cjs/extractContent/processTsxFile.cjs +1 -1
- package/dist/cjs/extractContent/utils/detectPackageName.cjs +1 -1
- package/dist/cjs/extractContent/utils/extractDictionaryInfo.cjs +1 -1
- package/dist/cjs/extractContent/utils/extractDictionaryKey.cjs +1 -1
- package/dist/cjs/extractContent/utils/resolveDictionaryKey.cjs +1 -1
- package/dist/cjs/getExtractPluginOptions.cjs +1 -1
- package/dist/cjs/getOptimizePluginOptions.cjs +1 -1
- package/dist/cjs/getPurgePluginOptions.cjs +1 -1
- package/dist/cjs/index.cjs +11 -11
- package/dist/cjs/transformers.cjs +2 -9
- package/dist/cjs/transformers.cjs.map +1 -1
- package/dist/esm/analyzeContentUsage.mjs +1 -1
- package/dist/esm/babel-plugin-intlayer-extract.mjs +2 -2
- package/dist/esm/babel-plugin-intlayer-field-rename.mjs +1 -1
- package/dist/esm/babel-plugin-intlayer-optimize.mjs +1 -1
- package/dist/esm/babel-plugin-intlayer-purge.mjs +4 -4
- package/dist/esm/babel-plugin-intlayer-usage-analyzer.mjs +1 -1
- package/dist/esm/babelParser.mjs +0 -1
- package/dist/esm/babelParser.mjs.map +1 -1
- package/dist/esm/compat/usageAnalysis.mjs +1 -1
- package/dist/esm/extractContent/contentWriter.mjs +1 -1
- package/dist/esm/extractContent/extractContent.mjs +2 -2
- package/dist/esm/extractContent/processTsxFile.mjs +1 -1
- package/dist/esm/extractContent/utils/detectPackageName.mjs +1 -1
- package/dist/esm/extractContent/utils/extractDictionaryInfo.mjs +1 -1
- package/dist/esm/extractContent/utils/extractDictionaryKey.mjs +1 -1
- package/dist/esm/extractContent/utils/resolveDictionaryKey.mjs +1 -1
- package/dist/esm/getExtractPluginOptions.mjs +1 -1
- package/dist/esm/getOptimizePluginOptions.mjs +1 -1
- package/dist/esm/getPurgePluginOptions.mjs +1 -1
- package/dist/esm/index.mjs +11 -11
- package/dist/esm/transformers.mjs +2 -9
- package/dist/esm/transformers.mjs.map +1 -1
- package/dist/types/babelParser.d.ts.map +1 -1
- package/dist/types/transformers.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
2
3
|
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
3
4
|
const require_pruneContext = require('./pruneContext.cjs');
|
|
4
|
-
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/analyzeContentUsage.ts
|
|
7
7
|
/**
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_normalizedFilesList = require('./normalizedFilesList.cjs');
|
|
3
4
|
const require_extractContent_utils_detectPackageName = require('./extractContent/utils/detectPackageName.cjs');
|
|
4
5
|
const require_extractContent_extractContent = require('./extractContent/extractContent.cjs');
|
|
5
|
-
const require_normalizedFilesList = require('./normalizedFilesList.cjs');
|
|
6
6
|
let node_path = require("node:path");
|
|
7
|
-
let _babel_parser = require("@babel/parser");
|
|
8
7
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
9
8
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
10
9
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
11
10
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
11
|
+
let _babel_parser = require("@babel/parser");
|
|
12
12
|
|
|
13
13
|
//#region src/babel-plugin-intlayer-extract.ts
|
|
14
14
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
3
2
|
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
3
|
+
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/babel-plugin-intlayer-field-rename.ts
|
|
6
6
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_normalizedFilesList = require('./normalizedFilesList.cjs');
|
|
3
2
|
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
4
3
|
const require_compat_optimizePass = require('./compat/optimizePass.cjs');
|
|
5
4
|
const require_dictionaryImports = require('./dictionaryImports.cjs');
|
|
5
|
+
const require_normalizedFilesList = require('./normalizedFilesList.cjs');
|
|
6
6
|
let node_path = require("node:path");
|
|
7
7
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
8
8
|
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_extractScriptBlocks = require('./extractScriptBlocks.cjs');
|
|
4
3
|
const require_pruneContext = require('./pruneContext.cjs');
|
|
5
4
|
const require_babel_plugin_intlayer_usage_analyzer = require('./babel-plugin-intlayer-usage-analyzer.cjs');
|
|
6
5
|
const require_babel_plugin_intlayer_field_rename = require('./babel-plugin-intlayer-field-rename.cjs');
|
|
6
|
+
const require_extractScriptBlocks = require('./extractScriptBlocks.cjs');
|
|
7
7
|
const require_transformers = require('./transformers.cjs');
|
|
8
|
-
let node_path = require("node:path");
|
|
9
8
|
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
let node_path = require("node:path");
|
|
11
|
+
let _babel_core = require("@babel/core");
|
|
10
12
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
11
13
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
12
14
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
13
|
-
let node_fs = require("node:fs");
|
|
14
|
-
let _babel_core = require("@babel/core");
|
|
15
15
|
|
|
16
16
|
//#region src/babel-plugin-intlayer-purge.ts
|
|
17
17
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
2
3
|
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
3
4
|
const require_pruneContext = require('./pruneContext.cjs');
|
|
4
|
-
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
5
5
|
const require_analyzeContentUsage = require('./analyzeContentUsage.cjs');
|
|
6
6
|
const require_compat_usageAnalysis = require('./compat/usageAnalysis.cjs');
|
|
7
7
|
|
package/dist/cjs/babelParser.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babelParser.cjs","names":["babelParse"],"sources":["../../src/babelParser.ts"],"sourcesContent":["import { parse as babelParse, type ParserOptions } from '@babel/parser';\n\n/**\n * Recast-compatible parsers backed by the `@babel/parser` version owned by\n * `@intlayer/babel`.\n *\n * All Babel operations are centralized in this package so that consumers such\n * as `@intlayer/engine` never need to depend on (or resolve) `@babel/parser`\n * themselves. `@intlayer/engine` loads these parsers lazily, which keeps\n * `@babel/parser` off the hot path until an AST transform is actually run.\n *\n * Recast's own `recast/parsers/typescript` / `recast/parsers/babel-ts` modules\n * resolve `@babel/parser` from the hoisted dependency tree, which can pick up\n * an incompatible major. Exposing the parser here resolves it against this\n * package's own pinned dependency, keeping the `intlayer init` AST transforms\n * working regardless of hoisting.\n *\n * The plugin list mirrors `recast/parsers/_babel_options.js`, adapted to the\n * Babel 8 parser. Only the still-optional plugins are listed here: the many\n * proposals that shipped as language features (e.g. class fields, private\n * methods, static blocks, optional chaining, nullish coalescing, numeric\n * separators, object rest/spread, dynamic import, top-level await, import\n * attributes) are enabled by default in Babel 8 and no longer accepted as\n * explicit plugins. Compared to the Babel 7 list, `decimal` and `recordAndTuple`\n * were removed with their proposals, `importAssertions` became the default\n * import-attributes syntax, and `pipelineOperator` uses the `fsharp` proposal\n * (the `minimal` proposal was removed, and `hack` conflicts with `v8intrinsic`).\n *\n * The goal is still to tolerate as much syntax as possible, since these\n * transforms run on arbitrary user code.\n */\nconst buildBabelOptions = (\n extraPlugins: NonNullable<ParserOptions['plugins']>\n): ParserOptions => ({\n sourceType: 'module',\n strictMode: false,\n allowImportExportEverywhere: true,\n allowReturnOutsideFunction: true,\n startLine: 1,\n tokens: true,\n plugins: [\n 'decorators-legacy',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n
|
|
1
|
+
{"version":3,"file":"babelParser.cjs","names":["babelParse"],"sources":["../../src/babelParser.ts"],"sourcesContent":["import { parse as babelParse, type ParserOptions } from '@babel/parser';\n\n/**\n * Recast-compatible parsers backed by the `@babel/parser` version owned by\n * `@intlayer/babel`.\n *\n * All Babel operations are centralized in this package so that consumers such\n * as `@intlayer/engine` never need to depend on (or resolve) `@babel/parser`\n * themselves. `@intlayer/engine` loads these parsers lazily, which keeps\n * `@babel/parser` off the hot path until an AST transform is actually run.\n *\n * Recast's own `recast/parsers/typescript` / `recast/parsers/babel-ts` modules\n * resolve `@babel/parser` from the hoisted dependency tree, which can pick up\n * an incompatible major. Exposing the parser here resolves it against this\n * package's own pinned dependency, keeping the `intlayer init` AST transforms\n * working regardless of hoisting.\n *\n * The plugin list mirrors `recast/parsers/_babel_options.js`, adapted to the\n * Babel 8 parser. Only the still-optional plugins are listed here: the many\n * proposals that shipped as language features (e.g. class fields, private\n * methods, static blocks, optional chaining, nullish coalescing, numeric\n * separators, object rest/spread, dynamic import, top-level await, import\n * attributes) are enabled by default in Babel 8 and no longer accepted as\n * explicit plugins. Compared to the Babel 7 list, `decimal` and `recordAndTuple`\n * were removed with their proposals, `importAssertions` became the default\n * import-attributes syntax, and `pipelineOperator` uses the `fsharp` proposal\n * (the `minimal` proposal was removed, and `hack` conflicts with `v8intrinsic`).\n *\n * The goal is still to tolerate as much syntax as possible, since these\n * transforms run on arbitrary user code.\n */\nconst buildBabelOptions = (\n extraPlugins: NonNullable<ParserOptions['plugins']>\n): ParserOptions => ({\n sourceType: 'module',\n strictMode: false,\n allowImportExportEverywhere: true,\n allowReturnOutsideFunction: true,\n startLine: 1,\n tokens: true,\n plugins: [\n 'decorators-legacy',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n ['pipelineOperator', { proposal: 'fsharp' }],\n 'throwExpressions',\n 'v8intrinsic',\n ...extraPlugins,\n ],\n});\n\n/** A parser object accepted by `recast.parse`'s `parser` option. */\nexport type RecastParser = {\n parse: (source: string) => unknown;\n};\n\n/** Drop-in replacement for `recast/parsers/typescript` (TS without JSX). */\nexport const typescriptParser: RecastParser = {\n parse: (source: string) =>\n babelParse(source, buildBabelOptions(['typescript'])),\n};\n\n/** Drop-in replacement for `recast/parsers/babel-ts` (TS *and* JSX). */\nexport const babelTsParser: RecastParser = {\n parse: (source: string) =>\n babelParse(source, buildBabelOptions(['jsx', 'typescript'])),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAM,qBACJ,kBACmB;CACnB,YAAY;CACZ,YAAY;CACZ,6BAA6B;CAC7B,4BAA4B;CAC5B,WAAW;CACX,QAAQ;CACR,SAAS;EACP;EACA;EACA;EACA;EACA;EACA,CAAC,oBAAoB,EAAE,UAAU,SAAS,CAAC;EAC3C;EACA;EACA,GAAG;CACL;AACF;;AAQA,MAAa,mBAAiC,EAC5C,QAAQ,eACNA,qBAAW,QAAQ,kBAAkB,CAAC,YAAY,CAAC,CAAC,EACxD;;AAGA,MAAa,gBAA8B,EACzC,QAAQ,eACNA,qBAAW,QAAQ,kBAAkB,CAAC,OAAO,YAAY,CAAC,CAAC,EAC/D"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_pruneContext = require('../pruneContext.cjs');
|
|
3
2
|
const require_staticAstReaders = require('../staticAstReaders.cjs');
|
|
3
|
+
const require_pruneContext = require('../pruneContext.cjs');
|
|
4
4
|
const require_analyzeContentUsage = require('../analyzeContentUsage.cjs');
|
|
5
5
|
const require_compat_namespaceResolution = require('./namespaceResolution.cjs');
|
|
6
6
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_extractContent_utils_extractDictionaryInfo = require('./utils/extractDictionaryInfo.cjs');
|
|
4
|
-
let node_path = require("node:path");
|
|
5
4
|
let node_fs = require("node:fs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
6
|
let node_fs_promises = require("node:fs/promises");
|
|
7
7
|
let _intlayer_core_plugins = require("@intlayer/core/plugins");
|
|
8
8
|
let _intlayer_engine_build = require("@intlayer/engine/build");
|
|
@@ -5,14 +5,14 @@ const require_extractContent_utils_generateKey = require('./utils/generateKey.cj
|
|
|
5
5
|
const require_extractContent_babelProcessor = require('./babelProcessor.cjs');
|
|
6
6
|
const require_extractContent_contentWriter = require('./contentWriter.cjs');
|
|
7
7
|
const require_extractContent_processTsxFile = require('./processTsxFile.cjs');
|
|
8
|
-
let node_path = require("node:path");
|
|
9
8
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
9
|
+
let node_fs = require("node:fs");
|
|
10
|
+
let node_path = require("node:path");
|
|
10
11
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
11
12
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
12
13
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
13
14
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
14
15
|
let node_child_process = require("node:child_process");
|
|
15
|
-
let node_fs = require("node:fs");
|
|
16
16
|
let _intlayer_config_extract = require("@intlayer/config/extract");
|
|
17
17
|
let _intlayer_dictionaries_entry_unmerged = require("@intlayer/dictionaries-entry/unmerged");
|
|
18
18
|
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
|
@@ -2,9 +2,9 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_extractContent_utils_constants = require('./utils/constants.cjs');
|
|
4
4
|
const require_extractContent_babelProcessor = require('./babelProcessor.cjs');
|
|
5
|
+
let node_fs = require("node:fs");
|
|
5
6
|
let _babel_parser = require("@babel/parser");
|
|
6
7
|
let node_child_process = require("node:child_process");
|
|
7
|
-
let node_fs = require("node:fs");
|
|
8
8
|
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
|
9
9
|
let _babel_traverse = require("@babel/traverse");
|
|
10
10
|
_babel_traverse = require_runtime.__toESM(_babel_traverse);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_extractContent_utils_constants = require('./constants.cjs');
|
|
3
|
-
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
4
3
|
let node_fs = require("node:fs");
|
|
4
|
+
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
5
5
|
|
|
6
6
|
//#region src/extractContent/utils/detectPackageName.ts
|
|
7
7
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_extractContent_utils_extractDictionaryKey = require('./extractDictionaryKey.cjs');
|
|
4
|
-
let node_path = require("node:path");
|
|
5
4
|
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
6
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
7
7
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
8
8
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
2
3
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
3
4
|
let _intlayer_engine_cli = require("@intlayer/engine/cli");
|
|
4
|
-
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
5
5
|
|
|
6
6
|
//#region src/extractContent/utils/extractDictionaryKey.ts
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let node_fs = require("node:fs");
|
|
2
3
|
let node_path = require("node:path");
|
|
3
4
|
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
4
|
-
let node_fs = require("node:fs");
|
|
5
5
|
let _intlayer_dictionaries_entry_unmerged = require("@intlayer/dictionaries-entry/unmerged");
|
|
6
6
|
|
|
7
7
|
//#region src/extractContent/utils/resolveDictionaryKey.ts
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
3
|
const require_extractContent_contentWriter = require('./extractContent/contentWriter.cjs');
|
|
4
|
+
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
4
5
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
5
6
|
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
6
7
|
let _intlayer_config_colors = require("@intlayer/config/colors");
|
|
7
8
|
_intlayer_config_colors = require_runtime.__toESM(_intlayer_config_colors);
|
|
8
9
|
let _intlayer_config_logger = require("@intlayer/config/logger");
|
|
9
|
-
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
10
10
|
|
|
11
11
|
//#region src/getExtractPluginOptions.ts
|
|
12
12
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let node_path = require("node:path");
|
|
3
2
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
4
3
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
5
4
|
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
6
|
|
|
7
7
|
//#region src/getOptimizePluginOptions.ts
|
|
8
8
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
2
3
|
let _intlayer_config_node = require("@intlayer/config/node");
|
|
3
4
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
4
5
|
let _intlayer_engine_utils = require("@intlayer/engine/utils");
|
|
5
|
-
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
6
6
|
|
|
7
7
|
//#region src/getPurgePluginOptions.ts
|
|
8
8
|
/**
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
3
|
+
const require_getPurgePluginOptions = require('./getPurgePluginOptions.cjs');
|
|
4
|
+
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
5
|
+
const require_pruneContext = require('./pruneContext.cjs');
|
|
6
|
+
const require_babel_plugin_intlayer_usage_analyzer = require('./babel-plugin-intlayer-usage-analyzer.cjs');
|
|
7
|
+
const require_babel_plugin_intlayer_field_rename = require('./babel-plugin-intlayer-field-rename.cjs');
|
|
2
8
|
const require_extractScriptBlocks = require('./extractScriptBlocks.cjs');
|
|
3
|
-
const
|
|
9
|
+
const require_babel_plugin_intlayer_optimize = require('./babel-plugin-intlayer-optimize.cjs');
|
|
10
|
+
const require_transformers = require('./transformers.cjs');
|
|
11
|
+
const require_babel_plugin_intlayer_purge = require('./babel-plugin-intlayer-purge.cjs');
|
|
12
|
+
const require_babel_plugin_intlayer_minify = require('./babel-plugin-intlayer-minify.cjs');
|
|
4
13
|
const require_extractContent_utils_constants = require('./extractContent/utils/constants.cjs');
|
|
5
14
|
const require_extractContent_utils_detectPackageName = require('./extractContent/utils/detectPackageName.cjs');
|
|
6
15
|
const require_extractContent_utils_extractDictionaryKey = require('./extractContent/utils/extractDictionaryKey.cjs');
|
|
@@ -10,17 +19,8 @@ const require_extractContent_utils_getComponentName = require('./extractContent/
|
|
|
10
19
|
const require_extractContent_contentWriter = require('./extractContent/contentWriter.cjs');
|
|
11
20
|
const require_extractContent_extractContent = require('./extractContent/extractContent.cjs');
|
|
12
21
|
const require_babel_plugin_intlayer_extract = require('./babel-plugin-intlayer-extract.cjs');
|
|
13
|
-
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
14
|
-
const require_pruneContext = require('./pruneContext.cjs');
|
|
15
|
-
const require_staticAstReaders = require('./staticAstReaders.cjs');
|
|
16
|
-
const require_babel_plugin_intlayer_usage_analyzer = require('./babel-plugin-intlayer-usage-analyzer.cjs');
|
|
17
|
-
const require_babel_plugin_intlayer_field_rename = require('./babel-plugin-intlayer-field-rename.cjs');
|
|
18
|
-
const require_babel_plugin_intlayer_optimize = require('./babel-plugin-intlayer-optimize.cjs');
|
|
19
|
-
const require_transformers = require('./transformers.cjs');
|
|
20
|
-
const require_babel_plugin_intlayer_purge = require('./babel-plugin-intlayer-purge.cjs');
|
|
21
|
-
const require_babel_plugin_intlayer_minify = require('./babel-plugin-intlayer-minify.cjs');
|
|
22
22
|
const require_getExtractPluginOptions = require('./getExtractPluginOptions.cjs');
|
|
23
|
-
const
|
|
23
|
+
const require_getOptimizePluginOptions = require('./getOptimizePluginOptions.cjs');
|
|
24
24
|
|
|
25
25
|
exports.BABEL_PARSER_OPTIONS = require_transformers.BABEL_PARSER_OPTIONS;
|
|
26
26
|
exports.CHAINABLE_RUNTIME_METHOD_NAMES = require_nativeCallers.CHAINABLE_RUNTIME_METHOD_NAMES;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_extractScriptBlocks = require('./extractScriptBlocks.cjs');
|
|
3
2
|
const require_nativeCallers = require('./nativeCallers.cjs');
|
|
4
3
|
const require_babel_plugin_intlayer_usage_analyzer = require('./babel-plugin-intlayer-usage-analyzer.cjs');
|
|
5
4
|
const require_babel_plugin_intlayer_field_rename = require('./babel-plugin-intlayer-field-rename.cjs');
|
|
5
|
+
const require_extractScriptBlocks = require('./extractScriptBlocks.cjs');
|
|
6
6
|
const require_babel_plugin_intlayer_optimize = require('./babel-plugin-intlayer-optimize.cjs');
|
|
7
7
|
let _babel_core = require("@babel/core");
|
|
8
8
|
|
|
@@ -19,15 +19,8 @@ const BABEL_PARSER_OPTIONS = {
|
|
|
19
19
|
"typescript",
|
|
20
20
|
"jsx",
|
|
21
21
|
"decorators-legacy",
|
|
22
|
-
"classProperties",
|
|
23
|
-
"objectRestSpread",
|
|
24
|
-
"asyncGenerators",
|
|
25
22
|
"functionBind",
|
|
26
|
-
"exportDefaultFrom"
|
|
27
|
-
"exportNamespaceFrom",
|
|
28
|
-
"dynamicImport",
|
|
29
|
-
"nullishCoalescingOperator",
|
|
30
|
-
"optionalChaining"
|
|
23
|
+
"exportDefaultFrom"
|
|
31
24
|
]
|
|
32
25
|
};
|
|
33
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.cjs","names":["INTLAYER_CALLER_NAMES","transformAsync","makeUsageAnalyzerBabelPlugin","extractScriptBlocks","makeFieldRenameBabelPlugin","injectScriptBlocks","intlayerOptimizeBabelPlugin"],"sources":["../../src/transformers.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\n// Typed from `@babel/parser` rather than `@babel/core`'s\n// `InputOptions['parserOpts']` (Babel 8's rename of `TransformOptions`): the\n// two describe the same shape, but naming `@babel/core` in an exported type\n// pulls its declaration file into every consumer's type-check, and that file\n// needs `@types/convert-source-map` to resolve.\nimport type { ParserOptions } from '@babel/parser';\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 INTLAYER_CALLER_NAMES,\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: ParserOptions = {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n // Astro frontmatter may `return new Response(...)` at the top level.\n allowReturnOutsideFunction: 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 * Builds a fast pre-check regex that matches files potentially containing\n * native intlayer calls and/or the given compat namespace caller names.\n *\n * The result is used to skip files that definitely contain none of the\n * relevant function names, avoiding unnecessary Babel parsing.\n *\n * The native names come from {@link INTLAYER_CALLER_NAMES} rather than being\n * spelled out here: a name missing from this regex silently opts every file\n * using it out of the optimize, purge and minify passes, leaving its calls to\n * resolve through the dictionary registry — empty in browser bundles.\n *\n * Compat caller names are NOT hardcoded here — they are provided at runtime by\n * the compat adapter packages that configure the usage-analysis pipeline.\n *\n * @param extraCallerNames - Additional caller function names to match\n * (e.g. `['useTranslation', 'getFixedT']` from `@intlayer/react-i18next`).\n * @returns A `RegExp` matching any of the native or provided caller names.\n */\nexport const buildUsageCheckRegex = (extraCallerNames?: string[]): RegExp => {\n const callerNames = [...INTLAYER_CALLER_NAMES, ...(extraCallerNames ?? [])];\n const uniqueNames = [...new Set(callerNames)];\n return new RegExp(`\\\\b(${uniqueNames.join('|')})\\\\b`);\n};\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer` / `getIntlayerAsync`). Used by the\n * optimize/transform pass, which only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = buildUsageCheckRegex();\n\n/** Usage-check regex covering only the native callers (no compat callers). */\nconst NATIVE_USAGE_CHECK_REGEX = INTLAYER_USAGE_REGEX;\n\n/** Cache of usage-check regexes, keyed by the compat-caller array reference. */\nconst usageCheckRegexCache = new WeakMap<\n readonly CompatCallerConfig[],\n RegExp\n>();\n\n/**\n * Returns the usage-check regex for the given compat callers, memoised by the\n * array reference. Plugins pass the same options array for every analysed\n * file, so the regex is built once per build instead of once per file.\n */\nexport const getUsageCheckRegex = (\n compatCallers?: readonly CompatCallerConfig[]\n): RegExp => {\n if (!compatCallers || compatCallers.length === 0) {\n return NATIVE_USAGE_CHECK_REGEX;\n }\n\n let usageCheckRegex = usageCheckRegexCache.get(compatCallers);\n if (!usageCheckRegex) {\n usageCheckRegex = buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n );\n usageCheckRegexCache.set(compatCallers, usageCheckRegex);\n }\n return usageCheckRegex;\n};\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 usageCheckRegex = getUsageCheckRegex(compatCallers);\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 (!usageCheckRegex.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":"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"}
|
|
1
|
+
{"version":3,"file":"transformers.cjs","names":["INTLAYER_CALLER_NAMES","transformAsync","makeUsageAnalyzerBabelPlugin","extractScriptBlocks","makeFieldRenameBabelPlugin","injectScriptBlocks","intlayerOptimizeBabelPlugin"],"sources":["../../src/transformers.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\n// Typed from `@babel/parser` rather than `@babel/core`'s\n// `InputOptions['parserOpts']` (Babel 8's rename of `TransformOptions`): the\n// two describe the same shape, but naming `@babel/core` in an exported type\n// pulls its declaration file into every consumer's type-check, and that file\n// needs `@types/convert-source-map` to resolve.\nimport type { ParserOptions } from '@babel/parser';\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 INTLAYER_CALLER_NAMES,\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: ParserOptions = {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n // Astro frontmatter may `return new Response(...)` at the top level.\n allowReturnOutsideFunction: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'functionBind',\n 'exportDefaultFrom',\n ],\n};\n\n/**\n * Builds a fast pre-check regex that matches files potentially containing\n * native intlayer calls and/or the given compat namespace caller names.\n *\n * The result is used to skip files that definitely contain none of the\n * relevant function names, avoiding unnecessary Babel parsing.\n *\n * The native names come from {@link INTLAYER_CALLER_NAMES} rather than being\n * spelled out here: a name missing from this regex silently opts every file\n * using it out of the optimize, purge and minify passes, leaving its calls to\n * resolve through the dictionary registry — empty in browser bundles.\n *\n * Compat caller names are NOT hardcoded here — they are provided at runtime by\n * the compat adapter packages that configure the usage-analysis pipeline.\n *\n * @param extraCallerNames - Additional caller function names to match\n * (e.g. `['useTranslation', 'getFixedT']` from `@intlayer/react-i18next`).\n * @returns A `RegExp` matching any of the native or provided caller names.\n */\nexport const buildUsageCheckRegex = (extraCallerNames?: string[]): RegExp => {\n const callerNames = [...INTLAYER_CALLER_NAMES, ...(extraCallerNames ?? [])];\n const uniqueNames = [...new Set(callerNames)];\n return new RegExp(`\\\\b(${uniqueNames.join('|')})\\\\b`);\n};\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer` / `getIntlayerAsync`). Used by the\n * optimize/transform pass, which only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = buildUsageCheckRegex();\n\n/** Usage-check regex covering only the native callers (no compat callers). */\nconst NATIVE_USAGE_CHECK_REGEX = INTLAYER_USAGE_REGEX;\n\n/** Cache of usage-check regexes, keyed by the compat-caller array reference. */\nconst usageCheckRegexCache = new WeakMap<\n readonly CompatCallerConfig[],\n RegExp\n>();\n\n/**\n * Returns the usage-check regex for the given compat callers, memoised by the\n * array reference. Plugins pass the same options array for every analysed\n * file, so the regex is built once per build instead of once per file.\n */\nexport const getUsageCheckRegex = (\n compatCallers?: readonly CompatCallerConfig[]\n): RegExp => {\n if (!compatCallers || compatCallers.length === 0) {\n return NATIVE_USAGE_CHECK_REGEX;\n }\n\n let usageCheckRegex = usageCheckRegexCache.get(compatCallers);\n if (!usageCheckRegex) {\n usageCheckRegex = buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n );\n usageCheckRegexCache.set(compatCallers, usageCheckRegex);\n }\n return usageCheckRegex;\n};\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 usageCheckRegex = getUsageCheckRegex(compatCallers);\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 (!usageCheckRegex.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":"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"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { unwrapAwait } from "./staticAstReaders.mjs";
|
|
1
2
|
import { CHAINABLE_RUNTIME_METHOD_NAMES } from "./nativeCallers.mjs";
|
|
2
3
|
import { recordFieldUsage } from "./pruneContext.mjs";
|
|
3
|
-
import { unwrapAwait } from "./staticAstReaders.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/analyzeContentUsage.ts
|
|
6
6
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { getNormalizedFilesListSet } from "./normalizedFilesList.mjs";
|
|
1
2
|
import { detectPackageName } from "./extractContent/utils/detectPackageName.mjs";
|
|
2
3
|
import { extractContentSync } from "./extractContent/extractContent.mjs";
|
|
3
|
-
import { getNormalizedFilesListSet } from "./normalizedFilesList.mjs";
|
|
4
4
|
import { relative } from "node:path";
|
|
5
|
-
import { parse } from "@babel/parser";
|
|
6
5
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
7
6
|
import { colorize, colorizePath, getAppLogger } from "@intlayer/config/logger";
|
|
8
7
|
import { normalizePath } from "@intlayer/config/utils";
|
|
8
|
+
import { parse } from "@babel/parser";
|
|
9
9
|
|
|
10
10
|
//#region src/babel-plugin-intlayer-extract.ts
|
|
11
11
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CHAINABLE_RUNTIME_METHOD_NAMES, NATIVE_CALLER_NAME_SET } from "./nativeCallers.mjs";
|
|
2
1
|
import { unwrapAwait } from "./staticAstReaders.mjs";
|
|
2
|
+
import { CHAINABLE_RUNTIME_METHOD_NAMES, NATIVE_CALLER_NAME_SET } from "./nativeCallers.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/babel-plugin-intlayer-field-rename.ts
|
|
5
5
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { getNormalizedFilesListSet } from "./normalizedFilesList.mjs";
|
|
2
1
|
import { readStaticString } from "./staticAstReaders.mjs";
|
|
3
2
|
import { createCompatOptimizePass } from "./compat/optimizePass.mjs";
|
|
4
3
|
import { createDictionaryImportRegistry } from "./dictionaryImports.mjs";
|
|
4
|
+
import { getNormalizedFilesListSet } from "./normalizedFilesList.mjs";
|
|
5
5
|
import { dirname, join, relative } from "node:path";
|
|
6
6
|
import { normalizePath } from "@intlayer/config/utils";
|
|
7
7
|
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { extractScriptBlocks } from "./extractScriptBlocks.mjs";
|
|
2
1
|
import { createPruneContext, preserveNestedDictionaryFields } from "./pruneContext.mjs";
|
|
3
2
|
import { makeUsageAnalyzerBabelPlugin } from "./babel-plugin-intlayer-usage-analyzer.mjs";
|
|
4
3
|
import { buildNestedRenameMapFromContent, getNestedRenameEntryAtPath } from "./babel-plugin-intlayer-field-rename.mjs";
|
|
4
|
+
import { extractScriptBlocks } from "./extractScriptBlocks.mjs";
|
|
5
5
|
import { BABEL_PARSER_OPTIONS, SOURCE_FILE_REGEX, getUsageCheckRegex } from "./transformers.mjs";
|
|
6
|
-
import { join } from "node:path";
|
|
7
6
|
import { formatPath } from "@intlayer/engine/utils";
|
|
8
|
-
import * as ANSIColors from "@intlayer/config/colors";
|
|
9
|
-
import { colorize, colorizeKey, colorizeNumber, getAppLogger } from "@intlayer/config/logger";
|
|
10
7
|
import { existsSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
11
9
|
import { transformSync } from "@babel/core";
|
|
10
|
+
import * as ANSIColors from "@intlayer/config/colors";
|
|
11
|
+
import { colorize, colorizeKey, colorizeNumber, getAppLogger } from "@intlayer/config/logger";
|
|
12
12
|
|
|
13
13
|
//#region src/babel-plugin-intlayer-purge.ts
|
|
14
14
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { readStaticString, unwrapAwait } from "./staticAstReaders.mjs";
|
|
1
2
|
import { CHAINABLE_RUNTIME_METHOD_NAMES, INTLAYER_CALLER_NAMES, NATIVE_CALLER_NAME_SET } from "./nativeCallers.mjs";
|
|
2
3
|
import { createPruneContext, preserveNestedDictionaryFields } from "./pruneContext.mjs";
|
|
3
|
-
import { readStaticString, unwrapAwait } from "./staticAstReaders.mjs";
|
|
4
4
|
import { analyzeCallExpressionUsage } from "./analyzeContentUsage.mjs";
|
|
5
5
|
import { createCompatUsageAnalyzer } from "./compat/usageAnalysis.mjs";
|
|
6
6
|
|
package/dist/esm/babelParser.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babelParser.mjs","names":["babelParse"],"sources":["../../src/babelParser.ts"],"sourcesContent":["import { parse as babelParse, type ParserOptions } from '@babel/parser';\n\n/**\n * Recast-compatible parsers backed by the `@babel/parser` version owned by\n * `@intlayer/babel`.\n *\n * All Babel operations are centralized in this package so that consumers such\n * as `@intlayer/engine` never need to depend on (or resolve) `@babel/parser`\n * themselves. `@intlayer/engine` loads these parsers lazily, which keeps\n * `@babel/parser` off the hot path until an AST transform is actually run.\n *\n * Recast's own `recast/parsers/typescript` / `recast/parsers/babel-ts` modules\n * resolve `@babel/parser` from the hoisted dependency tree, which can pick up\n * an incompatible major. Exposing the parser here resolves it against this\n * package's own pinned dependency, keeping the `intlayer init` AST transforms\n * working regardless of hoisting.\n *\n * The plugin list mirrors `recast/parsers/_babel_options.js`, adapted to the\n * Babel 8 parser. Only the still-optional plugins are listed here: the many\n * proposals that shipped as language features (e.g. class fields, private\n * methods, static blocks, optional chaining, nullish coalescing, numeric\n * separators, object rest/spread, dynamic import, top-level await, import\n * attributes) are enabled by default in Babel 8 and no longer accepted as\n * explicit plugins. Compared to the Babel 7 list, `decimal` and `recordAndTuple`\n * were removed with their proposals, `importAssertions` became the default\n * import-attributes syntax, and `pipelineOperator` uses the `fsharp` proposal\n * (the `minimal` proposal was removed, and `hack` conflicts with `v8intrinsic`).\n *\n * The goal is still to tolerate as much syntax as possible, since these\n * transforms run on arbitrary user code.\n */\nconst buildBabelOptions = (\n extraPlugins: NonNullable<ParserOptions['plugins']>\n): ParserOptions => ({\n sourceType: 'module',\n strictMode: false,\n allowImportExportEverywhere: true,\n allowReturnOutsideFunction: true,\n startLine: 1,\n tokens: true,\n plugins: [\n 'decorators-legacy',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n
|
|
1
|
+
{"version":3,"file":"babelParser.mjs","names":["babelParse"],"sources":["../../src/babelParser.ts"],"sourcesContent":["import { parse as babelParse, type ParserOptions } from '@babel/parser';\n\n/**\n * Recast-compatible parsers backed by the `@babel/parser` version owned by\n * `@intlayer/babel`.\n *\n * All Babel operations are centralized in this package so that consumers such\n * as `@intlayer/engine` never need to depend on (or resolve) `@babel/parser`\n * themselves. `@intlayer/engine` loads these parsers lazily, which keeps\n * `@babel/parser` off the hot path until an AST transform is actually run.\n *\n * Recast's own `recast/parsers/typescript` / `recast/parsers/babel-ts` modules\n * resolve `@babel/parser` from the hoisted dependency tree, which can pick up\n * an incompatible major. Exposing the parser here resolves it against this\n * package's own pinned dependency, keeping the `intlayer init` AST transforms\n * working regardless of hoisting.\n *\n * The plugin list mirrors `recast/parsers/_babel_options.js`, adapted to the\n * Babel 8 parser. Only the still-optional plugins are listed here: the many\n * proposals that shipped as language features (e.g. class fields, private\n * methods, static blocks, optional chaining, nullish coalescing, numeric\n * separators, object rest/spread, dynamic import, top-level await, import\n * attributes) are enabled by default in Babel 8 and no longer accepted as\n * explicit plugins. Compared to the Babel 7 list, `decimal` and `recordAndTuple`\n * were removed with their proposals, `importAssertions` became the default\n * import-attributes syntax, and `pipelineOperator` uses the `fsharp` proposal\n * (the `minimal` proposal was removed, and `hack` conflicts with `v8intrinsic`).\n *\n * The goal is still to tolerate as much syntax as possible, since these\n * transforms run on arbitrary user code.\n */\nconst buildBabelOptions = (\n extraPlugins: NonNullable<ParserOptions['plugins']>\n): ParserOptions => ({\n sourceType: 'module',\n strictMode: false,\n allowImportExportEverywhere: true,\n allowReturnOutsideFunction: true,\n startLine: 1,\n tokens: true,\n plugins: [\n 'decorators-legacy',\n 'doExpressions',\n 'exportDefaultFrom',\n 'functionBind',\n 'functionSent',\n ['pipelineOperator', { proposal: 'fsharp' }],\n 'throwExpressions',\n 'v8intrinsic',\n ...extraPlugins,\n ],\n});\n\n/** A parser object accepted by `recast.parse`'s `parser` option. */\nexport type RecastParser = {\n parse: (source: string) => unknown;\n};\n\n/** Drop-in replacement for `recast/parsers/typescript` (TS without JSX). */\nexport const typescriptParser: RecastParser = {\n parse: (source: string) =>\n babelParse(source, buildBabelOptions(['typescript'])),\n};\n\n/** Drop-in replacement for `recast/parsers/babel-ts` (TS *and* JSX). */\nexport const babelTsParser: RecastParser = {\n parse: (source: string) =>\n babelParse(source, buildBabelOptions(['jsx', 'typescript'])),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAM,qBACJ,kBACmB;CACnB,YAAY;CACZ,YAAY;CACZ,6BAA6B;CAC7B,4BAA4B;CAC5B,WAAW;CACX,QAAQ;CACR,SAAS;EACP;EACA;EACA;EACA;EACA;EACA,CAAC,oBAAoB,EAAE,UAAU,SAAS,CAAC;EAC3C;EACA;EACA,GAAG;CACL;AACF;;AAQA,MAAa,mBAAiC,EAC5C,QAAQ,WACNA,MAAW,QAAQ,kBAAkB,CAAC,YAAY,CAAC,CAAC,EACxD;;AAGA,MAAa,gBAA8B,EACzC,QAAQ,WACNA,MAAW,QAAQ,kBAAkB,CAAC,OAAO,YAAY,CAAC,CAAC,EAC/D"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { recordFieldUsage } from "../pruneContext.mjs";
|
|
2
1
|
import { ABSENT_VALUE, firstPathSegment, readJsxAttributeString, readObjectProperty, readStaticFirstSegment, readStaticString, unwrapAwait } from "../staticAstReaders.mjs";
|
|
2
|
+
import { recordFieldUsage } from "../pruneContext.mjs";
|
|
3
3
|
import { analyzeCallExpressionUsage } from "../analyzeContentUsage.mjs";
|
|
4
4
|
import { DEFAULT_COMPAT_NAMESPACE, resolveKeyPrefixForAnalysis, resolveNamespaceForAnalysis } from "./namespaceResolution.mjs";
|
|
5
5
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveContentFilePaths } from "./utils/extractDictionaryInfo.mjs";
|
|
2
|
-
import { dirname, relative } from "node:path";
|
|
3
2
|
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, relative } from "node:path";
|
|
4
4
|
import { mkdir } from "node:fs/promises";
|
|
5
5
|
import { insertContentInDictionary } from "@intlayer/core/plugins";
|
|
6
6
|
import { buildDictionary, ensureIntlayerBundle, loadContentDeclaration, writeContentDeclaration } from "@intlayer/engine/build";
|
|
@@ -3,13 +3,13 @@ import { generateKey } from "./utils/generateKey.mjs";
|
|
|
3
3
|
import { extractTsContent } from "./babelProcessor.mjs";
|
|
4
4
|
import { writeContentHelper } from "./contentWriter.mjs";
|
|
5
5
|
import { processTsxFile } from "./processTsxFile.mjs";
|
|
6
|
-
import { extname, relative } from "node:path";
|
|
7
6
|
import { getConfiguration } from "@intlayer/config/node";
|
|
7
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { extname, relative } from "node:path";
|
|
8
9
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
9
10
|
import { colorize, colorizePath, getAppLogger } from "@intlayer/config/logger";
|
|
10
11
|
import { getProjectRequire } from "@intlayer/config/utils";
|
|
11
12
|
import { execSync } from "node:child_process";
|
|
12
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { ATTRIBUTES_TO_EXTRACT, shouldExtract } from "@intlayer/config/extract";
|
|
14
14
|
import { getUnmergedDictionaries } from "@intlayer/dictionaries-entry/unmerged";
|
|
15
15
|
import { detectFormatCommand } from "@intlayer/engine/cli";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SERVER_CAPABLE_PACKAGES } from "./utils/constants.mjs";
|
|
2
2
|
import { extractBabelContentForComponents } from "./babelProcessor.mjs";
|
|
3
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
3
4
|
import { parse } from "@babel/parser";
|
|
4
5
|
import { execSync } from "node:child_process";
|
|
5
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { detectFormatCommand } from "@intlayer/engine/cli";
|
|
7
7
|
import _traverse from "@babel/traverse";
|
|
8
8
|
import * as t from "@babel/types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { packageList } from "./constants.mjs";
|
|
2
|
-
import { getPackageJsonPath } from "@intlayer/config/utils";
|
|
3
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { getPackageJsonPath } from "@intlayer/config/utils";
|
|
4
4
|
|
|
5
5
|
//#region src/extractContent/utils/detectPackageName.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extractDictionaryKey } from "./extractDictionaryKey.mjs";
|
|
2
|
-
import { basename, dirname, extname, relative, resolve } from "node:path";
|
|
3
2
|
import { getFormatFromExtension, resolveRelativePath } from "@intlayer/engine/utils";
|
|
3
|
+
import { basename, dirname, extname, relative, resolve } from "node:path";
|
|
4
4
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
5
5
|
import { colorize } from "@intlayer/config/logger";
|
|
6
6
|
import { assertPathWithin, parseStringPattern } from "@intlayer/config/utils";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { COMPILER_DICTIONARY_KEY_PREFIX } from "@intlayer/config/defaultValues";
|
|
1
2
|
import { camelCaseToKebabCase } from "@intlayer/config/utils";
|
|
2
3
|
import { detectExportedComponentName } from "@intlayer/engine/cli";
|
|
3
|
-
import { COMPILER_DICTIONARY_KEY_PREFIX } from "@intlayer/config/defaultValues";
|
|
4
4
|
|
|
5
5
|
//#region src/extractContent/utils/extractDictionaryKey.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { dirname, join, resolve } from "node:path";
|
|
2
3
|
import { assertPathWithin } from "@intlayer/config/utils";
|
|
3
|
-
import { existsSync } from "node:fs";
|
|
4
4
|
import { getUnmergedDictionaries } from "@intlayer/dictionaries-entry/unmerged";
|
|
5
5
|
|
|
6
6
|
//#region src/extractContent/utils/resolveDictionaryKey.ts
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { writeContentHelper } from "./extractContent/contentWriter.mjs";
|
|
2
|
+
import { COMPILER_ENABLED } from "@intlayer/config/defaultValues";
|
|
2
3
|
import { getConfiguration } from "@intlayer/config/node";
|
|
3
4
|
import { buildComponentFilesList } from "@intlayer/engine/utils";
|
|
4
5
|
import * as ANSIColors from "@intlayer/config/colors";
|
|
5
6
|
import { colorize, colorizeKey, getAppLogger } from "@intlayer/config/logger";
|
|
6
|
-
import { COMPILER_ENABLED } from "@intlayer/config/defaultValues";
|
|
7
7
|
|
|
8
8
|
//#region src/getExtractPluginOptions.ts
|
|
9
9
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __require } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import { getConfiguration } from "@intlayer/config/node";
|
|
4
3
|
import { getNestedDictionaryGraph } from "@intlayer/core/dictionaryManipulator";
|
|
5
4
|
import { buildComponentFilesList } from "@intlayer/engine/utils";
|
|
5
|
+
import { join } from "node:path";
|
|
6
6
|
|
|
7
7
|
//#region src/getOptimizePluginOptions.ts
|
|
8
8
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __require } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { IMPORT_MODE } from "@intlayer/config/defaultValues";
|
|
2
3
|
import { getConfiguration } from "@intlayer/config/node";
|
|
3
4
|
import { getNestedDictionaryReferences } from "@intlayer/core/dictionaryManipulator";
|
|
4
5
|
import { buildComponentFilesList } from "@intlayer/engine/utils";
|
|
5
|
-
import { IMPORT_MODE } from "@intlayer/config/defaultValues";
|
|
6
6
|
|
|
7
7
|
//#region src/getPurgePluginOptions.ts
|
|
8
8
|
/**
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import { unwrapAwait } from "./staticAstReaders.mjs";
|
|
2
|
+
import { getMinifyPluginOptions, getPurgePluginOptions } from "./getPurgePluginOptions.mjs";
|
|
3
|
+
import { CHAINABLE_RUNTIME_METHOD_NAMES, INTLAYER_CALLER_NAMES, NATIVE_CALLER_NAME_SET } from "./nativeCallers.mjs";
|
|
4
|
+
import { createPruneContext, preserveNestedDictionaryFields } from "./pruneContext.mjs";
|
|
5
|
+
import { DEFAULT_COMPAT_CALLERS, makeUsageAnalyzerBabelPlugin } from "./babel-plugin-intlayer-usage-analyzer.mjs";
|
|
6
|
+
import { buildNestedRenameMapFromContent, generateShortFieldName, getNestedRenameEntryAtPath, makeFieldRenameBabelPlugin, renameIntlayerFieldAccesses, serializeFieldRenameMap } from "./babel-plugin-intlayer-field-rename.mjs";
|
|
1
7
|
import { extractScriptBlocks, injectScriptBlocks } from "./extractScriptBlocks.mjs";
|
|
2
|
-
import {
|
|
8
|
+
import { intlayerOptimizeBabelPlugin } from "./babel-plugin-intlayer-optimize.mjs";
|
|
9
|
+
import { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, buildUsageCheckRegex, getUsageCheckRegex, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile } from "./transformers.mjs";
|
|
10
|
+
import { getSharedPruneContext, intlayerPurgeBabelPlugin, runIntlayerPurgePipeline } from "./babel-plugin-intlayer-purge.mjs";
|
|
11
|
+
import { intlayerMinifyBabelPlugin } from "./babel-plugin-intlayer-minify.mjs";
|
|
3
12
|
import { SERVER_CAPABLE_PACKAGES, packageList } from "./extractContent/utils/constants.mjs";
|
|
4
13
|
import { detectPackageName } from "./extractContent/utils/detectPackageName.mjs";
|
|
5
14
|
import { extractDictionaryKey, extractDictionaryKeyFromPath } from "./extractContent/utils/extractDictionaryKey.mjs";
|
|
@@ -9,16 +18,7 @@ import { getComponentName } from "./extractContent/utils/getComponentName.mjs";
|
|
|
9
18
|
import { mergeWithExistingMultilingualDictionary, mergeWithExistingPerLocaleDictionary, writeContentHelper } from "./extractContent/contentWriter.mjs";
|
|
10
19
|
import { extractContent, extractContentSync } from "./extractContent/extractContent.mjs";
|
|
11
20
|
import { intlayerExtractBabelPlugin } from "./babel-plugin-intlayer-extract.mjs";
|
|
12
|
-
import { CHAINABLE_RUNTIME_METHOD_NAMES, INTLAYER_CALLER_NAMES, NATIVE_CALLER_NAME_SET } from "./nativeCallers.mjs";
|
|
13
|
-
import { createPruneContext, preserveNestedDictionaryFields } from "./pruneContext.mjs";
|
|
14
|
-
import { unwrapAwait } from "./staticAstReaders.mjs";
|
|
15
|
-
import { DEFAULT_COMPAT_CALLERS, makeUsageAnalyzerBabelPlugin } from "./babel-plugin-intlayer-usage-analyzer.mjs";
|
|
16
|
-
import { buildNestedRenameMapFromContent, generateShortFieldName, getNestedRenameEntryAtPath, makeFieldRenameBabelPlugin, renameIntlayerFieldAccesses, serializeFieldRenameMap } from "./babel-plugin-intlayer-field-rename.mjs";
|
|
17
|
-
import { intlayerOptimizeBabelPlugin } from "./babel-plugin-intlayer-optimize.mjs";
|
|
18
|
-
import { BABEL_PARSER_OPTIONS, INTLAYER_USAGE_REGEX, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, buildUsageCheckRegex, getUsageCheckRegex, optimizeSourceFile, renameFieldsInCode, renameFieldsInSourceFile } from "./transformers.mjs";
|
|
19
|
-
import { getSharedPruneContext, intlayerPurgeBabelPlugin, runIntlayerPurgePipeline } from "./babel-plugin-intlayer-purge.mjs";
|
|
20
|
-
import { intlayerMinifyBabelPlugin } from "./babel-plugin-intlayer-minify.mjs";
|
|
21
21
|
import { getExtractPluginOptions } from "./getExtractPluginOptions.mjs";
|
|
22
|
-
import {
|
|
22
|
+
import { getOptimizePluginOptions } from "./getOptimizePluginOptions.mjs";
|
|
23
23
|
|
|
24
24
|
export { BABEL_PARSER_OPTIONS, CHAINABLE_RUNTIME_METHOD_NAMES, DEFAULT_COMPAT_CALLERS, INTLAYER_CALLER_NAMES, INTLAYER_USAGE_REGEX, NATIVE_CALLER_NAME_SET, SERVER_CAPABLE_PACKAGES, SOURCE_FILE_REGEX, analyzeFieldUsageInFile, buildNestedRenameMapFromContent, buildUsageCheckRegex, createPruneContext, detectPackageName, extractContent, extractContentSync, extractDictionaryInfo, extractDictionaryKey, extractDictionaryKeyFromPath, extractScriptBlocks, generateKey, generateShortFieldName, getComponentName, getExtractPluginOptions, getMinifyPluginOptions, getNestedRenameEntryAtPath, getOptimizePluginOptions, getOutput, getPurgePluginOptions, getSharedPruneContext, getUsageCheckRegex, injectScriptBlocks, intlayerExtractBabelPlugin, intlayerMinifyBabelPlugin, intlayerOptimizeBabelPlugin, intlayerPurgeBabelPlugin, makeFieldRenameBabelPlugin, makeUsageAnalyzerBabelPlugin, mergeWithExistingMultilingualDictionary, mergeWithExistingPerLocaleDictionary, optimizeSourceFile, packageList, preserveNestedDictionaryFields, renameFieldsInCode, renameFieldsInSourceFile, renameIntlayerFieldAccesses, resolveContentFilePaths, runIntlayerPurgePipeline, serializeFieldRenameMap, unwrapAwait, writeContentHelper };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { extractScriptBlocks, injectScriptBlocks } from "./extractScriptBlocks.mjs";
|
|
2
1
|
import { INTLAYER_CALLER_NAMES } from "./nativeCallers.mjs";
|
|
3
2
|
import { makeUsageAnalyzerBabelPlugin } from "./babel-plugin-intlayer-usage-analyzer.mjs";
|
|
4
3
|
import { makeFieldRenameBabelPlugin } from "./babel-plugin-intlayer-field-rename.mjs";
|
|
4
|
+
import { extractScriptBlocks, injectScriptBlocks } from "./extractScriptBlocks.mjs";
|
|
5
5
|
import { intlayerOptimizeBabelPlugin } from "./babel-plugin-intlayer-optimize.mjs";
|
|
6
6
|
import { transformAsync } from "@babel/core";
|
|
7
7
|
|
|
@@ -18,15 +18,8 @@ const BABEL_PARSER_OPTIONS = {
|
|
|
18
18
|
"typescript",
|
|
19
19
|
"jsx",
|
|
20
20
|
"decorators-legacy",
|
|
21
|
-
"classProperties",
|
|
22
|
-
"objectRestSpread",
|
|
23
|
-
"asyncGenerators",
|
|
24
21
|
"functionBind",
|
|
25
|
-
"exportDefaultFrom"
|
|
26
|
-
"exportNamespaceFrom",
|
|
27
|
-
"dynamicImport",
|
|
28
|
-
"nullishCoalescingOperator",
|
|
29
|
-
"optionalChaining"
|
|
22
|
+
"exportDefaultFrom"
|
|
30
23
|
]
|
|
31
24
|
};
|
|
32
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/transformers.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\n// Typed from `@babel/parser` rather than `@babel/core`'s\n// `InputOptions['parserOpts']` (Babel 8's rename of `TransformOptions`): the\n// two describe the same shape, but naming `@babel/core` in an exported type\n// pulls its declaration file into every consumer's type-check, and that file\n// needs `@types/convert-source-map` to resolve.\nimport type { ParserOptions } from '@babel/parser';\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 INTLAYER_CALLER_NAMES,\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: ParserOptions = {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n // Astro frontmatter may `return new Response(...)` at the top level.\n allowReturnOutsideFunction: 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 * Builds a fast pre-check regex that matches files potentially containing\n * native intlayer calls and/or the given compat namespace caller names.\n *\n * The result is used to skip files that definitely contain none of the\n * relevant function names, avoiding unnecessary Babel parsing.\n *\n * The native names come from {@link INTLAYER_CALLER_NAMES} rather than being\n * spelled out here: a name missing from this regex silently opts every file\n * using it out of the optimize, purge and minify passes, leaving its calls to\n * resolve through the dictionary registry — empty in browser bundles.\n *\n * Compat caller names are NOT hardcoded here — they are provided at runtime by\n * the compat adapter packages that configure the usage-analysis pipeline.\n *\n * @param extraCallerNames - Additional caller function names to match\n * (e.g. `['useTranslation', 'getFixedT']` from `@intlayer/react-i18next`).\n * @returns A `RegExp` matching any of the native or provided caller names.\n */\nexport const buildUsageCheckRegex = (extraCallerNames?: string[]): RegExp => {\n const callerNames = [...INTLAYER_CALLER_NAMES, ...(extraCallerNames ?? [])];\n const uniqueNames = [...new Set(callerNames)];\n return new RegExp(`\\\\b(${uniqueNames.join('|')})\\\\b`);\n};\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer` / `getIntlayerAsync`). Used by the\n * optimize/transform pass, which only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = buildUsageCheckRegex();\n\n/** Usage-check regex covering only the native callers (no compat callers). */\nconst NATIVE_USAGE_CHECK_REGEX = INTLAYER_USAGE_REGEX;\n\n/** Cache of usage-check regexes, keyed by the compat-caller array reference. */\nconst usageCheckRegexCache = new WeakMap<\n readonly CompatCallerConfig[],\n RegExp\n>();\n\n/**\n * Returns the usage-check regex for the given compat callers, memoised by the\n * array reference. Plugins pass the same options array for every analysed\n * file, so the regex is built once per build instead of once per file.\n */\nexport const getUsageCheckRegex = (\n compatCallers?: readonly CompatCallerConfig[]\n): RegExp => {\n if (!compatCallers || compatCallers.length === 0) {\n return NATIVE_USAGE_CHECK_REGEX;\n }\n\n let usageCheckRegex = usageCheckRegexCache.get(compatCallers);\n if (!usageCheckRegex) {\n usageCheckRegex = buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n );\n usageCheckRegexCache.set(compatCallers, usageCheckRegex);\n }\n return usageCheckRegex;\n};\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 usageCheckRegex = getUsageCheckRegex(compatCallers);\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 (!usageCheckRegex.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":";;;;;;;;;;;;AA0BA,MAAa,uBAAsC;CACjD,YAAY;CACZ,6BAA6B;CAE7B,4BAA4B;CAC5B,SAAS;EACP;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,wBAAwB,qBAAwC;CAC3E,MAAM,cAAc,CAAC,GAAG,uBAAuB,GAAI,oBAAoB,CAAC,CAAE;CAC1E,MAAM,cAAc,CAAC,GAAG,IAAI,IAAI,WAAW,CAAC;CAC5C,OAAO,IAAI,OAAO,OAAO,YAAY,KAAK,GAAG,EAAE,KAAK;AACtD;;;;;;AAOA,MAAa,uBAAuB,qBAAqB;;AAGzD,MAAM,2BAA2B;;AAGjC,MAAM,uCAAuB,IAAI,QAG/B;;;;;;AAOF,MAAa,sBACX,kBACW;CACX,IAAI,CAAC,iBAAiB,cAAc,WAAW,GAC7C,OAAO;CAGT,IAAI,kBAAkB,qBAAqB,IAAI,aAAa;CAC5D,IAAI,CAAC,iBAAiB;EACpB,kBAAkB,qBAChB,cAAc,KAAK,WAAW,OAAO,UAAU,CACjD;EACA,qBAAqB,IAAI,eAAe,eAAe;CACzD;CACA,OAAO;AACT;;;;;;AAOA,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,kBAAkB,mBAAmB,aAAa;CACxD,MAAM,eAAe,oBAAoB,gBAAgB,IAAI;CAM7D,KAAK,MAAM,SAAS,cAAc;EAChC,IAAI,CAAC,gBAAgB,KAAK,MAAM,OAAO,GAAG;EAC1C,MAAM,qBACJ,MAAM,SACN,gBACA,cACA,aACF;CACF;AACF;;;;;;;AAQA,MAAa,qBAAqB,OAChC,MACA,gBACA,iBAC2B;CAC3B,IAAI;EAOF,QAAO,MANc,eAAe,MAAM;GACxC,UAAU;GACV,SAAS,CAAC,2BAA2B,YAAY,CAAC;GAClD,YAAY;GACZ,KAAK;EACP,CAAC,EACY,EAAE,QAAQ;CACzB,QAAQ;EACN,OAAO;CACT;AACF;;;;;;;;AASA,MAAa,2BAA2B,OACtC,gBACA,MACA,iBAC2B;CAC3B,IAAI,aAAa,8BAA8B,SAAS,GAAG,OAAO;CAClE,IAAI,CAAC,qBAAqB,KAAK,IAAI,GAAG,OAAO;CAE7C,MAAM,eAAe,oBAAoB,gBAAgB,IAAI;CAM7D,IAHE,aAAa,SAAS,OACpB,aAAa,EAAE,EAAE,sBAAsB,KAAK,KAAK,aAAa,SAAS,IAEhE;EAET,MAAM,gBAGD,CAAC;EAEN,KAAK,MAAM,SAAS,cAAc;GAChC,IAAI,CAAC,qBAAqB,KAAK,MAAM,OAAO,GAAG;GAE/C,MAAM,cAAc,MAAM,mBACxB,MAAM,SACN,gBACA,YACF;GACA,IAAI,eAAe,gBAAgB,MAAM,SACvC,cAAc,KAAK;IAAE;IAAO,iBAAiB;GAAY,CAAC;EAE9D;EAEA,IAAI,cAAc,WAAW,GAAG,OAAO;EACvC,OAAO,mBAAmB,MAAM,aAAa;CAC/C;CAGA,OAAO,mBAAmB,MAAM,gBAAgB,YAAY;AAC9D;;;;;;;;;AAUA,MAAa,qBAAqB,OAChC,MACA,gBACA,YAIW;CACX,MAAM,SAAS,MAAM,eAAe,MAAM;EACxC,UAAU;EACV,SAAS,CAAC,CAAC,6BAA6B,OAAO,CAAC;EAChD,YAAY;CACd,CAAC;CAED,IAAI,CAAC,QAAQ,MAAM,OAAO;CAE1B,OAAO;EAAE,MAAM,OAAO;EAAM,KAAK,OAAO;CAAI;AAC9C"}
|
|
1
|
+
{"version":3,"file":"transformers.mjs","names":[],"sources":["../../src/transformers.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\n// Typed from `@babel/parser` rather than `@babel/core`'s\n// `InputOptions['parserOpts']` (Babel 8's rename of `TransformOptions`): the\n// two describe the same shape, but naming `@babel/core` in an exported type\n// pulls its declaration file into every consumer's type-check, and that file\n// needs `@types/convert-source-map` to resolve.\nimport type { ParserOptions } from '@babel/parser';\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 INTLAYER_CALLER_NAMES,\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: ParserOptions = {\n sourceType: 'module',\n allowImportExportEverywhere: true,\n // Astro frontmatter may `return new Response(...)` at the top level.\n allowReturnOutsideFunction: true,\n plugins: [\n 'typescript',\n 'jsx',\n 'decorators-legacy',\n 'functionBind',\n 'exportDefaultFrom',\n ],\n};\n\n/**\n * Builds a fast pre-check regex that matches files potentially containing\n * native intlayer calls and/or the given compat namespace caller names.\n *\n * The result is used to skip files that definitely contain none of the\n * relevant function names, avoiding unnecessary Babel parsing.\n *\n * The native names come from {@link INTLAYER_CALLER_NAMES} rather than being\n * spelled out here: a name missing from this regex silently opts every file\n * using it out of the optimize, purge and minify passes, leaving its calls to\n * resolve through the dictionary registry — empty in browser bundles.\n *\n * Compat caller names are NOT hardcoded here — they are provided at runtime by\n * the compat adapter packages that configure the usage-analysis pipeline.\n *\n * @param extraCallerNames - Additional caller function names to match\n * (e.g. `['useTranslation', 'getFixedT']` from `@intlayer/react-i18next`).\n * @returns A `RegExp` matching any of the native or provided caller names.\n */\nexport const buildUsageCheckRegex = (extraCallerNames?: string[]): RegExp => {\n const callerNames = [...INTLAYER_CALLER_NAMES, ...(extraCallerNames ?? [])];\n const uniqueNames = [...new Set(callerNames)];\n return new RegExp(`\\\\b(${uniqueNames.join('|')})\\\\b`);\n};\n\n/**\n * Fast pre-check: matches files that could contain native intlayer calls\n * (`useIntlayer` / `getIntlayer` / `getIntlayerAsync`). Used by the\n * optimize/transform pass, which only rewrites native calls.\n */\nexport const INTLAYER_USAGE_REGEX = buildUsageCheckRegex();\n\n/** Usage-check regex covering only the native callers (no compat callers). */\nconst NATIVE_USAGE_CHECK_REGEX = INTLAYER_USAGE_REGEX;\n\n/** Cache of usage-check regexes, keyed by the compat-caller array reference. */\nconst usageCheckRegexCache = new WeakMap<\n readonly CompatCallerConfig[],\n RegExp\n>();\n\n/**\n * Returns the usage-check regex for the given compat callers, memoised by the\n * array reference. Plugins pass the same options array for every analysed\n * file, so the regex is built once per build instead of once per file.\n */\nexport const getUsageCheckRegex = (\n compatCallers?: readonly CompatCallerConfig[]\n): RegExp => {\n if (!compatCallers || compatCallers.length === 0) {\n return NATIVE_USAGE_CHECK_REGEX;\n }\n\n let usageCheckRegex = usageCheckRegexCache.get(compatCallers);\n if (!usageCheckRegex) {\n usageCheckRegex = buildUsageCheckRegex(\n compatCallers.map((caller) => caller.callerName)\n );\n usageCheckRegexCache.set(compatCallers, usageCheckRegex);\n }\n return usageCheckRegex;\n};\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 usageCheckRegex = getUsageCheckRegex(compatCallers);\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 (!usageCheckRegex.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":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babelParser.d.ts","names":[],"sources":["../../src/babelParser.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"babelParser.d.ts","names":[],"sources":["../../src/babelParser.ts"],"mappings":";;YAsDY;EACV,QAAQ;;;qBAIG,kBAAkB;;qBAMlB,eAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","names":[],"sources":["../../src/transformers.ts"],"mappings":";;;;;;;;;qBA0Ba,sBAAsB;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","names":[],"sources":["../../src/transformers.ts"],"mappings":";;;;;;;;;qBA0Ba,sBAAsB;;;;;;;;;;;;;;;;;;;;qBAiCtB,uBAAoB,gCAAkC;;;;;;qBAWtD,sBAAoB;;;;;;qBAgBpB,qBAAkB,yBACJ,yBACxB;;;;;;qBAoBU,mBAAiB;;;;;;;;;;;;;qBAqCjB,0BAAuB,wBACZ,cACV,cACE,cAAY,gBACV,yBACf;;;;;;;qBAyBU,qBAAkB,cACjB,wBACU,cACR,iBACb;;;;;;;;qBAqBU,2BAAwB,wBACb,cACV,cACE,iBACb;;;;;;;;;qBA8CU,qBAAkB,cACjB,wBACU,SACb,0BACR;EACD;EACA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/babel",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.10",
|
|
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": [
|
|
@@ -90,11 +90,11 @@
|
|
|
90
90
|
"@babel/plugin-syntax-jsx": "8.0.1",
|
|
91
91
|
"@babel/traverse": "8.0.5",
|
|
92
92
|
"@babel/types": "8.0.5",
|
|
93
|
-
"@intlayer/config": "9.5.
|
|
94
|
-
"@intlayer/core": "9.5.
|
|
95
|
-
"@intlayer/dictionaries-entry": "9.5.
|
|
96
|
-
"@intlayer/engine": "9.5.
|
|
97
|
-
"@intlayer/types": "9.5.
|
|
93
|
+
"@intlayer/config": "9.5.10",
|
|
94
|
+
"@intlayer/core": "9.5.10",
|
|
95
|
+
"@intlayer/dictionaries-entry": "9.5.10",
|
|
96
|
+
"@intlayer/engine": "9.5.10",
|
|
97
|
+
"@intlayer/types": "9.5.10"
|
|
98
98
|
},
|
|
99
99
|
"devDependencies": {
|
|
100
100
|
"@babel/plugin-syntax-jsx": "8.0.1",
|
|
@@ -109,11 +109,11 @@
|
|
|
109
109
|
"rimraf": "6.1.3",
|
|
110
110
|
"tsdown": "0.23.0",
|
|
111
111
|
"typescript": "7.0.2",
|
|
112
|
-
"vitest": "5.0.
|
|
112
|
+
"vitest": "5.0.2"
|
|
113
113
|
},
|
|
114
114
|
"peerDependencies": {
|
|
115
|
-
"@intlayer/svelte-compiler": "9.5.
|
|
116
|
-
"@intlayer/vue-compiler": "9.5.
|
|
115
|
+
"@intlayer/svelte-compiler": "9.5.10",
|
|
116
|
+
"@intlayer/vue-compiler": "9.5.10"
|
|
117
117
|
},
|
|
118
118
|
"peerDependenciesMeta": {
|
|
119
119
|
"@intlayer/svelte-compiler": {
|