@zohodesk/react-cli 1.1.29-exp.1 → 1.1.29-exp.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/lib/babel/babel-option-utils/babel-preset-react-option.js +0 -3
- package/lib/babel/cmjs-plugins-presets.js +1 -8
- package/lib/babel/es-plugins-presets.js +1 -8
- package/lib/common/buildEs.js +1 -0
- package/lib/common/getEntries.js +2 -13
- package/lib/common/getPublicPathConfig.js +0 -6
- package/lib/common/index.js +1 -6
- package/lib/common/runPreProcess.js +6 -15
- package/lib/common/splitChunks.js +2 -21
- package/lib/common/sslcertUpdater.js +7 -18
- package/lib/common/templateParameters.js +0 -2
- package/lib/common/testPattern.js +10 -21
- package/lib/common/valueReplacer.js +1 -16
- package/lib/configs/jest.config.js +1 -10
- package/lib/configs/libAlias.js +8 -14
- package/lib/configs/resolvers.js +4 -14
- package/lib/configs/webpack.component.umd.config.js +1 -6
- package/lib/configs/webpack.css.umd.config.js +6 -14
- package/lib/configs/webpack.dev.config.js +1 -14
- package/lib/configs/webpack.docs.config.js +1 -9
- package/lib/configs/webpack.impact.config.js +1 -8
- package/lib/configs/webpack.prod.config.js +4 -17
- package/lib/constants.js +9 -18
- package/lib/deprecationLogger.js +0 -7
- package/lib/hooks/docsProptypeHook.js +4 -8
- package/lib/jest/commitedFilesResult.js +4 -46
- package/lib/jest/coverageCollector.js +1 -12
- package/lib/jest/jsonMaker.js +0 -6
- package/lib/jest/preProcessors/cssPreprocessor.js +1 -9
- package/lib/jest/preProcessors/jsPreprocessor.js +1 -6
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +1 -4
- package/lib/jest/result.js +1 -23
- package/lib/jest/run.js +7 -18
- package/lib/jest/setup.js +8 -60
- package/lib/loaderUtils/configsAssetsLoaders.js +2 -12
- package/lib/loaderUtils/getCSSLoaders.js +10 -22
- package/lib/loaderUtils/getDevJsLoaders.js +4 -13
- package/lib/loaderUtils/index.js +1 -4
- package/lib/loaderUtils/tests/windowsModification.test.js +0 -1
- package/lib/loaderUtils/windowsModification.js +2 -3
- package/lib/loaders/__test__/markdownLoader.spec.js +0 -1
- package/lib/loaders/composeLoader.js +13 -37
- package/lib/loaders/docsLoader.js +1 -12
- package/lib/loaders/docsPropsLoader.js +4 -8
- package/lib/loaders/enhancedReactLiveConverter.js +2 -23
- package/lib/loaders/fileBountryLoader.js +1 -3
- package/lib/loaders/fileLoader.js +12 -23
- package/lib/loaders/markdownLoader.js +14 -19
- package/lib/loaders/reactLiveConvertor.js +5 -15
- package/lib/loaders/scriptInstrumentLoader.js +7 -16
- package/lib/loaders/selectorMappingLoader.js +7 -26
- package/lib/loaders/workerLoader.js +9 -24
- package/lib/logger.js +0 -4
- package/lib/middlewares/HMRMiddleware.js +13 -27
- package/lib/middlewares/SSTMiddleware.js +1 -5
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +1 -24
- package/lib/pluginUtils/getDevPlugins.js +9 -42
- package/lib/pluginUtils/getDocsPlugins.js +3 -13
- package/lib/pluginUtils/getLibraryImactPlugins.js +5 -6
- package/lib/pluginUtils/getLibraryPlugins.js +2 -8
- package/lib/pluginUtils/getProdPlugins.js +8 -47
- package/lib/pluginUtils/getServerPlugins.js +2 -8
- package/lib/pluginUtils/getUMDCSSPlugins.js +2 -10
- package/lib/pluginUtils/getUMDComponentPlugins.js +2 -10
- package/lib/pluginUtils/index.js +1 -9
- package/lib/plugins/CdnChangePlugin.js +2 -18
- package/lib/plugins/CleanupStatsPlugin.js +0 -5
- package/lib/plugins/CssOrderControlPlugin.js +3 -6
- package/lib/plugins/CustomAttributePlugin.js +14 -19
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +3 -23
- package/lib/plugins/EFCPlugin.js +20 -34
- package/lib/plugins/EFCTemplatePlugin.js +19 -30
- package/lib/plugins/EfcResourceCleanupPlugin.js +0 -3
- package/lib/plugins/EventsHandlingPlugin.js +2 -4
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +11 -37
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +10 -15
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +4 -10
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +12 -25
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +55 -133
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +12 -23
- package/lib/plugins/I18nSplitPlugin/index.js +13 -24
- package/lib/plugins/I18nSplitPlugin/utils/applyMetaManifest.js +64 -58
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +2 -12
- package/lib/plugins/I18nSplitPlugin/utils/createMetaManifest.js +10 -29
- package/lib/plugins/I18nSplitPlugin/utils/createRegularManifest.js +8 -19
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +0 -1
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +0 -5
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +1 -8
- package/lib/plugins/I18nSplitPlugin/utils/index.js +0 -4
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +0 -20
- package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +0 -1
- package/lib/plugins/ManifestPlugin.js +1 -18
- package/lib/plugins/MinifyPlugin.js +1 -10
- package/lib/plugins/ModuleStatsPlugin.js +1 -24
- package/lib/plugins/OptimizeJSPlugin.js +2 -10
- package/lib/plugins/PublicPathCallbackPlugin.js +1 -12
- package/lib/plugins/PublicPathChangePlugin.js +6 -39
- package/lib/plugins/ReportGeneratePlugin.js +5 -32
- package/lib/plugins/RequireVariablePublicPlugin.js +1 -8
- package/lib/plugins/ResourceHintsPlugin.js +4 -13
- package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +12 -17
- package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +10 -17
- package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +2 -5
- package/lib/plugins/ScriptInstrumentPlugin.js +1 -8
- package/lib/plugins/SelectorPlugin.js +6 -32
- package/lib/plugins/ServiceWorkerPlugin.js +5 -22
- package/lib/plugins/ShadowDOMSupportPlugin.js +4 -41
- package/lib/plugins/SourceMapHookPlugin.js +2 -12
- package/lib/plugins/StatsPlugin.js +0 -14
- package/lib/plugins/TPHashMappingPlugin.js +3 -18
- package/lib/plugins/UnusedFilesFindPlugin.js +4 -39
- package/lib/plugins/VariableConversionCollector.js +15 -42
- package/lib/plugins/index.js +1 -20
- package/lib/plugins/libraryImpactPlugin.js +1 -33
- package/lib/plugins/newi18nsplitplugin/18nPlugin1.js +306 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin2.js +363 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin3.js +694 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin_hashed.js +1258 -0
- package/lib/plugins/newi18nsplitplugin/18nPlugin_working.js +542 -0
- package/lib/plugins/newi18nsplitplugin/18nplugin.js +974 -0
- package/lib/plugins/newi18nsplitplugin/ChunkManager.js +131 -0
- package/lib/plugins/newi18nsplitplugin/GenerateModuleIdToKeysMapPlugin.js +59 -0
- package/lib/plugins/newi18nsplitplugin/I18nDiffPlugin.js +262 -0
- package/lib/plugins/newi18nsplitplugin/I18nDownloadLogic.js +166 -0
- package/lib/plugins/newi18nsplitplugin/I18nPropertiesPlugin.js +111 -0
- package/lib/plugins/newi18nsplitplugin/KeyCollector.js +163 -0
- package/lib/plugins/newi18nsplitplugin/ManifestGenerator.js +88 -0
- package/lib/plugins/newi18nsplitplugin/UnicodeConversionPlugin.js +101 -0
- package/lib/plugins/newi18nsplitplugin/constants.js +162 -0
- package/lib/plugins/newi18nsplitplugin/utils/I18nKeyHasher.js +78 -0
- package/lib/plugins/newi18nsplitplugin/utils/getJsResourceKeys.js +22 -0
- package/lib/plugins/newi18nsplitplugin/utils/i18nChunkUtils.js +18 -0
- package/lib/plugins/newi18nsplitplugin/utils/manifestGenerator.js +580 -0
- package/lib/plugins/newi18nsplitplugin/utils/propertiesUtils.js +54 -0
- package/lib/plugins/utils/classHandling.js +0 -6
- package/lib/plugins/utils/fileHandling.js +6 -15
- package/lib/plugins/utils/tests/fileHandling.test.js +0 -4
- package/lib/plugins/variableConvertorUtils.js +14 -29
- package/lib/plugins/webpackwatchrunplugin.js +0 -5
- package/lib/postcss-plugins/EmptyPlugin.js +3 -4
- package/lib/postcss-plugins/ExcludePlugin.js +1 -5
- package/lib/postcss-plugins/IncludePlugin.js +1 -5
- package/lib/postcss-plugins/RTLSplitPlugin.js +14 -27
- package/lib/postcss-plugins/SelectorReplace.js +1 -16
- package/lib/postcss-plugins/ValueReplacer.js +7 -6
- package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +0 -3
- package/lib/postcss-plugins/__test__/selectorReplace.test.js +6 -3
- package/lib/postcss-plugins/__test__/valueReplacer.spec.js +2 -5
- package/lib/postcss-plugins/hoverActivePlugin.js +31 -67
- package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +0 -7
- package/lib/postcss-plugins/variableModificationPlugin/index.js +28 -49
- package/lib/schemas/index.js +3 -9
- package/lib/servers/clusterHubServer.js +1 -11
- package/lib/servers/devBuild.js +14 -26
- package/lib/servers/docsServer.js +1 -3
- package/lib/servers/docsServerCore.js +1 -22
- package/lib/servers/getCliPath.js +0 -9
- package/lib/servers/helpServer.js +1 -6
- package/lib/servers/httpsOptions.js +2 -8
- package/lib/servers/impactServer.js +3 -35
- package/lib/servers/mockserver.js +1 -10
- package/lib/servers/nowatchserver.js +12 -37
- package/lib/servers/requireLocalOrGlobal.js +6 -17
- package/lib/servers/scrServer.js +14 -21
- package/lib/servers/server.js +6 -36
- package/lib/servers/ssServer.js +1 -17
- package/lib/templates/CoverageScriptTemplate.js +0 -14
- package/lib/templates/WMSTemplate.js +7 -13
- package/lib/templates/linterConstant.js +2 -4
- package/lib/utils/babelPresets.js +3 -7
- package/lib/utils/clean.js +3 -9
- package/lib/utils/copy.js +1 -7
- package/lib/utils/copyTimezones.js +1 -9
- package/lib/utils/createEventStream.js +1 -6
- package/lib/utils/cssClassNameGenerate.js +10 -30
- package/lib/utils/cssURLReplacer.js +1 -22
- package/lib/utils/dependencyPostPublish.js +1 -10
- package/lib/utils/deprecationSupport.js +7 -32
- package/lib/utils/fileUtils.js +1 -28
- package/lib/utils/folderIterator.js +2 -13
- package/lib/utils/getComponents.js +0 -21
- package/lib/utils/getCurrentBranch.js +0 -5
- package/lib/utils/getDependenciesImpactList.js +1 -22
- package/lib/utils/getFileType.js +2 -10
- package/lib/utils/getHash.js +1 -8
- package/lib/utils/getIp.js +0 -2
- package/lib/utils/getOptions.js +16 -53
- package/lib/utils/getServerURL.js +1 -10
- package/lib/utils/index.js +4 -51
- package/lib/utils/init.js +0 -1
- package/lib/utils/initPreCommitHook.js +7 -30
- package/lib/utils/jsonHelper.js +3 -22
- package/lib/utils/libraryImpactConfig.js +2 -5
- package/lib/utils/lint/addScripts.js +2 -5
- package/lib/utils/lint/checkExistingConfig.js +3 -12
- package/lib/utils/lint/copyConfigs.js +0 -3
- package/lib/utils/lint/index.js +0 -9
- package/lib/utils/lint/lintScripts.js +0 -1
- package/lib/utils/lint/lintSetup.js +3 -4
- package/lib/utils/lint/lintStagedPreCommitHook.js +0 -1
- package/lib/utils/lint/question.js +0 -7
- package/lib/utils/lintReporter.js +0 -20
- package/lib/utils/log.js +0 -1
- package/lib/utils/mailSender.js +1 -8
- package/lib/utils/object-manipulation.js +1 -17
- package/lib/utils/pullOrigin.js +0 -4
- package/lib/utils/reinstallDependencies.js +1 -29
- package/lib/utils/removeAttributes.js +1 -8
- package/lib/utils/repoClone.js +3 -28
- package/lib/utils/request.js +0 -12
- package/lib/utils/rtl.js +5 -17
- package/lib/utils/selectorReplacer.js +10 -16
- package/lib/utils/setEnvVariables.js +0 -2
- package/lib/utils/ssTestHack.js +1 -11
- package/lib/utils/switchBranch.js +0 -5
- package/lib/utils/typeCheck.js +0 -1
- package/lib/utils/urlConcat.js +0 -4
- package/lib/utils/useExitCleanup.js +9 -10
- package/lib/utils/variableConverter.js +22 -31
- package/{npm-shrinkwrap.json → package-lock.json} +2098 -1999
- package/package.json +1 -1
@@ -0,0 +1,694 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
var _collectI18nKeys = require("../I18nSplitPlugin/utils/collectI18nKeys");
|
8
|
+
var _I18nDependency = require("../I18nSplitPlugin/I18nDependency");
|
9
|
+
var _propertiesUtils = require("../I18nSplitPlugin/utils/propertiesUtils");
|
10
|
+
var _NullFactory = _interopRequireDefault(require("webpack/lib/NullFactory"));
|
11
|
+
var _webpackSources = require("webpack-sources");
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
13
|
+
var _fs = _interopRequireDefault(require("fs"));
|
14
|
+
function _interopRequireDefault(obj) {
|
15
|
+
return obj && obj.__esModule ? obj : {
|
16
|
+
default: obj
|
17
|
+
};
|
18
|
+
}
|
19
|
+
|
20
|
+
//import { RawSource } from 'webpack-sources';
|
21
|
+
const pluginName = 'I18nSplitPlugin';
|
22
|
+
const MODULE_TYPE = 'json/i18n'; // export default class I18nPlugin {
|
23
|
+
// constructor(options = {}) {
|
24
|
+
// const {
|
25
|
+
// jsResource,
|
26
|
+
// localeVarName = 'document.documentElement.lang',
|
27
|
+
// jsonpFunc = 'window.loadI18nChunk',
|
28
|
+
// propertiesFolder,
|
29
|
+
// disableDefault = false,
|
30
|
+
// filenameTemplate = 'i18n-chunk/[locale]/[name].[chunkhash].i18n.js',
|
31
|
+
// i18nManifestFileName = 'i18n-manifest.json',
|
32
|
+
// mainChunkName
|
33
|
+
// } = options;
|
34
|
+
// this.options = {
|
35
|
+
// localeVarName,
|
36
|
+
// jsonpFunc,
|
37
|
+
// filenameTemplate,
|
38
|
+
// i18nManifestFileName,
|
39
|
+
// mainChunkName
|
40
|
+
// };
|
41
|
+
// console.log('[I18N-BUILD] Loading resources from:', { jsResource, propertiesFolder });
|
42
|
+
// // Load and parse i18n resources
|
43
|
+
// this.jsResourceI18nKeys = jsResource ? getPropertiesAsJSON(jsResource) : {};
|
44
|
+
// this.allI18nData = getAllI18nGroupedBySection({
|
45
|
+
// folderPath: propertiesFolder,
|
46
|
+
// disableDefault,
|
47
|
+
// jsResourceI18nKeys: this.jsResourceI18nKeys
|
48
|
+
// });
|
49
|
+
// // Initialize tracking maps
|
50
|
+
// this.sectionToKeysMap = new Map();
|
51
|
+
// this.keyToSectionMap = new Map();
|
52
|
+
// this.moduleToKeysMap = new Map();
|
53
|
+
// this.moduleToSectionsMap = new Map();
|
54
|
+
// // Initialize section mapping
|
55
|
+
// this.initializeSectionMaps();
|
56
|
+
// }
|
57
|
+
// initializeSectionMaps() {
|
58
|
+
// const firstLocale = Object.keys(this.allI18nData)[0];
|
59
|
+
// if (!firstLocale) {
|
60
|
+
// console.warn('[I18N-BUILD] No locales found in i18n data');
|
61
|
+
// return;
|
62
|
+
// }
|
63
|
+
// const sections = this.allI18nData[firstLocale];
|
64
|
+
// console.log('[I18N-BUILD] Initializing sections:', Object.keys(sections));
|
65
|
+
// for (const [sectionName, sectionData] of Object.entries(sections)) {
|
66
|
+
// const keys = Object.keys(sectionData);
|
67
|
+
// this.sectionToKeysMap.set(sectionName, new Set(keys));
|
68
|
+
// keys.forEach(key => this.keyToSectionMap.set(key, sectionName));
|
69
|
+
// }
|
70
|
+
// }
|
71
|
+
// getSectionForKey(key) {
|
72
|
+
// const section = this.keyToSectionMap.get(key);
|
73
|
+
// if (section) return section;
|
74
|
+
// for (const [existingKey, section] of this.keyToSectionMap.entries()) {
|
75
|
+
// if (key.includes(existingKey) || existingKey.includes(key)) {
|
76
|
+
// return section;
|
77
|
+
// }
|
78
|
+
// }
|
79
|
+
// return 'common';
|
80
|
+
// }
|
81
|
+
// apply(compiler) {
|
82
|
+
// // Setup compilation hook
|
83
|
+
// compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
|
84
|
+
// // Set up dependencies
|
85
|
+
// this.setupDependencies(compilation);
|
86
|
+
// // Parse modules for i18n keys
|
87
|
+
// this.setupModuleParsing(compilation, params.normalModuleFactory);
|
88
|
+
// // Handle chunk optimization
|
89
|
+
// compilation.hooks.optimizeChunks.tap(pluginName, chunks => {
|
90
|
+
// console.log('[I18N-BUILD] Processing chunks:', chunks.length);
|
91
|
+
// this.processChunks(compilation, chunks);
|
92
|
+
// });
|
93
|
+
// });
|
94
|
+
// // Setup emit hook for Webpack 4
|
95
|
+
// compiler.hooks.emit.tap(pluginName, compilation => {
|
96
|
+
// this.emitAssets(compilation);
|
97
|
+
// });
|
98
|
+
// }
|
99
|
+
// setupDependencies(compilation) {
|
100
|
+
// compilation.dependencyFactories.set(I18nDependency, new NullFactory());
|
101
|
+
// compilation.dependencyTemplates.set(I18nDependency, new I18nDependencyTemplate());
|
102
|
+
// }
|
103
|
+
// setupModuleParsing(compilation, factory) {
|
104
|
+
// const handler = parser => {
|
105
|
+
// parser.hooks.program.tap(pluginName, (ast, comments) => {
|
106
|
+
// const { module } = parser.state;
|
107
|
+
// if (!(module && /\.jsx?$/.test(module.resource))) return;
|
108
|
+
// // Log for debugging
|
109
|
+
// console.log(`[I18N-BUILD] Processing module: ${module.resource}`);
|
110
|
+
// try {
|
111
|
+
// // Collect keys from all sources
|
112
|
+
// const codeKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
|
113
|
+
// const commentKeys = collectI18nKeysfromComments(comments, this.jsResourceI18nKeys);
|
114
|
+
// //const jsxKeys = collectI18nKeysFromJSX(ast, this.jsResourceI18nKeys);
|
115
|
+
// const moduleKeys = [...new Set([...codeKeys, ...commentKeys])];
|
116
|
+
// if (moduleKeys.length) {
|
117
|
+
// console.log('[I18N-BUILD] Found keys:', {
|
118
|
+
// module: module.resource,
|
119
|
+
// keyCount: moduleKeys.length,
|
120
|
+
// keys: moduleKeys
|
121
|
+
// });
|
122
|
+
// // Group keys by section
|
123
|
+
// const sections = new Set();
|
124
|
+
// moduleKeys.forEach(key => {
|
125
|
+
// const section = this.getSectionForKey(key);
|
126
|
+
// if (section) sections.add(section);
|
127
|
+
// });
|
128
|
+
// if (sections.size > 0) {
|
129
|
+
// console.log('[I18N-BUILD] Mapped to sections:', {
|
130
|
+
// module: module.resource,
|
131
|
+
// sections: Array.from(sections)
|
132
|
+
// });
|
133
|
+
// }
|
134
|
+
// this.moduleToKeysMap.set(module.resource, moduleKeys);
|
135
|
+
// this.moduleToSectionsMap.set(module.resource, Array.from(sections));
|
136
|
+
// this.addI18nDependency(module, moduleKeys);
|
137
|
+
// }
|
138
|
+
// } catch (error) {
|
139
|
+
// console.error('[I18N-BUILD] Error processing module:', {
|
140
|
+
// module: module.resource,
|
141
|
+
// error
|
142
|
+
// });
|
143
|
+
// }
|
144
|
+
// });
|
145
|
+
// };
|
146
|
+
// factory.hooks.parser
|
147
|
+
// .for('javascript/auto')
|
148
|
+
// .tap(pluginName, handler);
|
149
|
+
// factory.hooks.parser
|
150
|
+
// .for('javascript/dynamic')
|
151
|
+
// .tap(pluginName, handler);
|
152
|
+
// }
|
153
|
+
// addI18nDependency(module, keys) {
|
154
|
+
// const dep = new I18nDependency({
|
155
|
+
// identifier: `i18n ${module.resource}`,
|
156
|
+
// i18nKeys: keys
|
157
|
+
// }, module.context);
|
158
|
+
// module.addDependency(dep);
|
159
|
+
// }
|
160
|
+
// processChunks(compilation, chunks) {
|
161
|
+
// this.chunkToSectionsMap = new Map();
|
162
|
+
// chunks.forEach(chunk => {
|
163
|
+
// const sectionsInChunk = new Set();
|
164
|
+
// Array.from(chunk.modulesIterable).forEach(module => {
|
165
|
+
// if (!module.resource) return;
|
166
|
+
// const sections = this.moduleToSectionsMap.get(module.resource);
|
167
|
+
// if (sections) {
|
168
|
+
// sections.forEach(section => sectionsInChunk.add(section));
|
169
|
+
// }
|
170
|
+
// });
|
171
|
+
// if (sectionsInChunk.size > 0) {
|
172
|
+
// console.log('[I18N-BUILD] Chunk sections:', {
|
173
|
+
// chunk: chunk.id,
|
174
|
+
// sections: Array.from(sectionsInChunk)
|
175
|
+
// });
|
176
|
+
// this.chunkToSectionsMap.set(chunk.id, Array.from(sectionsInChunk));
|
177
|
+
// }
|
178
|
+
// });
|
179
|
+
// }
|
180
|
+
// emitAssets(compilation) {
|
181
|
+
// const manifest = {
|
182
|
+
// modules: {},
|
183
|
+
// chunks: {},
|
184
|
+
// locales: {}
|
185
|
+
// };
|
186
|
+
// // Add module mappings
|
187
|
+
// for (const [moduleResource, sections] of this.moduleToSectionsMap.entries()) {
|
188
|
+
// manifest.modules[moduleResource] = sections;
|
189
|
+
// }
|
190
|
+
// // Add chunk mappings
|
191
|
+
// for (const [chunkId, sections] of this.chunkToSectionsMap.entries()) {
|
192
|
+
// manifest.chunks[chunkId] = sections;
|
193
|
+
// }
|
194
|
+
// // Generate locale chunks
|
195
|
+
// for (const [locale, localeData] of Object.entries(this.allI18nData)) {
|
196
|
+
// manifest.locales[locale] = {};
|
197
|
+
// // For each chunk that needs i18n
|
198
|
+
// for (const [chunkId, sections] of this.chunkToSectionsMap.entries()) {
|
199
|
+
// const i18nData = {};
|
200
|
+
// // Collect all translations needed for this chunk
|
201
|
+
// sections.forEach(section => {
|
202
|
+
// const sectionData = localeData[section] || {};
|
203
|
+
// Object.assign(i18nData, sectionData);
|
204
|
+
// });
|
205
|
+
// if (Object.keys(i18nData).length > 0) {
|
206
|
+
// const fileName = this.getChunkFileName(chunkId, locale);
|
207
|
+
// const content = `${this.options.jsonpFunc}(${jsonToString(i18nData)});`;
|
208
|
+
// compilation.assets[fileName] = new RawSource(content);
|
209
|
+
// manifest.locales[locale][chunkId] = fileName;
|
210
|
+
// }
|
211
|
+
// }
|
212
|
+
// }
|
213
|
+
// // Emit manifest
|
214
|
+
// compilation.assets[this.options.i18nManifestFileName] = new RawSource(
|
215
|
+
// JSON.stringify(manifest, null, 2)
|
216
|
+
// );
|
217
|
+
// }
|
218
|
+
// getChunkFileName(chunkId, locale) {
|
219
|
+
// return this.options.filenameTemplate
|
220
|
+
// .replace('[locale]', locale)
|
221
|
+
// .replace('[name]', chunkId)
|
222
|
+
// .replace('[chunkhash]', this.getContentHash(chunkId, locale));
|
223
|
+
// }
|
224
|
+
// getContentHash(chunkId, locale) {
|
225
|
+
// const data = `${chunkId}_${locale}`;
|
226
|
+
// let hash = 0;
|
227
|
+
// for (let i = 0; i < data.length; i++) {
|
228
|
+
// hash = ((hash << 5) - hash) + data.charCodeAt(i);
|
229
|
+
// hash |= 0;
|
230
|
+
// }
|
231
|
+
// return hash.toString(36);
|
232
|
+
// }
|
233
|
+
// }
|
234
|
+
// export default class I18nPlugin {
|
235
|
+
// constructor(options = {}) {
|
236
|
+
// const {
|
237
|
+
// jsResource,
|
238
|
+
// localeVarName = 'document.documentElement.lang',
|
239
|
+
// jsonpFunc = 'window.loadI18nChunk',
|
240
|
+
// propertiesFolder,
|
241
|
+
// disableDefault = false,
|
242
|
+
// filenameTemplate = 'i18n-chunk/[locale]/[name].[chunkhash].i18n.js',
|
243
|
+
// i18nManifestFileName = 'i18n-manifest.json',
|
244
|
+
// mainChunkName
|
245
|
+
// } = options;
|
246
|
+
// this.options = {
|
247
|
+
// localeVarName,
|
248
|
+
// jsonpFunc,
|
249
|
+
// filenameTemplate,
|
250
|
+
// i18nManifestFileName,
|
251
|
+
// mainChunkName
|
252
|
+
// };
|
253
|
+
// console.log('[I18N-BUILD] Loading resources from:', { jsResource, propertiesFolder });
|
254
|
+
// // Load and parse i18n resources
|
255
|
+
// this.jsResourceI18nKeys = jsResource ? getPropertiesAsJSON(jsResource) : {};
|
256
|
+
// this.allI18nData = getAllI18nGroupedBySection({
|
257
|
+
// folderPath: propertiesFolder,
|
258
|
+
// disableDefault,
|
259
|
+
// jsResourceI18nKeys: this.jsResourceI18nKeys
|
260
|
+
// });
|
261
|
+
// // Initialize tracking maps
|
262
|
+
// this.moduleToKeysMap = new Map();
|
263
|
+
// this.chunkToKeysMap = new Map();
|
264
|
+
// this.keyToChunksMap = new Map();
|
265
|
+
// }
|
266
|
+
// apply(compiler) {
|
267
|
+
// compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
|
268
|
+
// // Set up dependencies
|
269
|
+
// compilation.dependencyFactories.set(I18nDependency, new NullFactory());
|
270
|
+
// compilation.dependencyTemplates.set(I18nDependency, new I18nDependencyTemplate());
|
271
|
+
// // Track module i18n keys
|
272
|
+
// this.setupModuleParsing(compilation, params.normalModuleFactory);
|
273
|
+
// // Map keys to chunks after optimization
|
274
|
+
// compilation.hooks.afterOptimizeChunks.tap(pluginName, (chunks) => {
|
275
|
+
// console.log('[I18N-BUILD] Processing chunks:', chunks.length);
|
276
|
+
// this.mapKeysToChunks(chunks);
|
277
|
+
// });
|
278
|
+
// // Emit assets during the emit phase
|
279
|
+
// compiler.hooks.emit.tap(pluginName, (compilation) => {
|
280
|
+
// this.emitAssets(compilation);
|
281
|
+
// });
|
282
|
+
// });
|
283
|
+
// }
|
284
|
+
// setupModuleParsing(compilation, factory) {
|
285
|
+
// const handler = parser => {
|
286
|
+
// parser.hooks.program.tap(pluginName, (ast, comments) => {
|
287
|
+
// const { module } = parser.state;
|
288
|
+
// if (!(module && /\.jsx?$/.test(module.resource))) return;
|
289
|
+
// // Collect keys from code and comments
|
290
|
+
// const codeKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
|
291
|
+
// const commentKeys = collectI18nKeysfromComments(comments, this.jsResourceI18nKeys);
|
292
|
+
// const moduleKeys = [...new Set([...codeKeys, ...commentKeys])];
|
293
|
+
// if (moduleKeys.length) {
|
294
|
+
// console.log('[I18N-BUILD] Found keys in module:', {
|
295
|
+
// module: module.resource,
|
296
|
+
// keyCount: moduleKeys.length,
|
297
|
+
// keys: moduleKeys
|
298
|
+
// });
|
299
|
+
// this.moduleToKeysMap.set(module.resource, moduleKeys);
|
300
|
+
// this.addI18nDependency(module, moduleKeys);
|
301
|
+
// }
|
302
|
+
// });
|
303
|
+
// };
|
304
|
+
// factory.hooks.parser
|
305
|
+
// .for('javascript/auto')
|
306
|
+
// .tap(pluginName, handler);
|
307
|
+
// factory.hooks.parser
|
308
|
+
// .for('javascript/dynamic')
|
309
|
+
// .tap(pluginName, handler);
|
310
|
+
// }
|
311
|
+
// mapKeysToChunks(chunks) {
|
312
|
+
// this.chunkToKeysMap.clear();
|
313
|
+
// this.keyToChunksMap.clear();
|
314
|
+
// chunks.forEach(chunk => {
|
315
|
+
// const chunkKeys = new Set();
|
316
|
+
// // Collect all i18n keys used in this chunk's modules
|
317
|
+
// for (const module of chunk.modulesIterable) {
|
318
|
+
// if (!module.resource) continue;
|
319
|
+
// const moduleKeys = this.moduleToKeysMap.get(module.resource);
|
320
|
+
// if (moduleKeys) {
|
321
|
+
// moduleKeys.forEach(key => {
|
322
|
+
// chunkKeys.add(key);
|
323
|
+
// // Map key back to chunk
|
324
|
+
// if (!this.keyToChunksMap.has(key)) {
|
325
|
+
// this.keyToChunksMap.set(key, new Set());
|
326
|
+
// }
|
327
|
+
// this.keyToChunksMap.get(key).add(chunk.name || chunk.id);
|
328
|
+
// });
|
329
|
+
// }
|
330
|
+
// }
|
331
|
+
// if (chunkKeys.size > 0) {
|
332
|
+
// console.log('[I18N-BUILD] Chunk keys:', {
|
333
|
+
// chunk: chunk.name || chunk.id,
|
334
|
+
// keyCount: chunkKeys.size,
|
335
|
+
// keys: Array.from(chunkKeys)
|
336
|
+
// });
|
337
|
+
// this.chunkToKeysMap.set(chunk.name || chunk.id, Array.from(chunkKeys));
|
338
|
+
// }
|
339
|
+
// });
|
340
|
+
// }
|
341
|
+
// emitAssets(compilation) {
|
342
|
+
// const manifest = {
|
343
|
+
// chunks: {},
|
344
|
+
// locales: {}
|
345
|
+
// };
|
346
|
+
// // Initialize locales
|
347
|
+
// Object.keys(this.allI18nData).forEach(locale => {
|
348
|
+
// manifest.locales[locale] = {};
|
349
|
+
// });
|
350
|
+
// // Generate i18n chunks
|
351
|
+
// for (const [chunkId, keys] of this.chunkToKeysMap.entries()) {
|
352
|
+
// if (keys.length === 0) continue;
|
353
|
+
// manifest.chunks[chunkId] = keys;
|
354
|
+
// // Generate locale-specific files for this chunk
|
355
|
+
// Object.entries(this.allI18nData).forEach(([locale, localeData]) => {
|
356
|
+
// // Collect translations for this chunk
|
357
|
+
// const translations = {};
|
358
|
+
// keys.forEach(key => {
|
359
|
+
// // Look up translation in the appropriate section
|
360
|
+
// for (const [section, sectionData] of Object.entries(localeData)) {
|
361
|
+
// if (key in sectionData) {
|
362
|
+
// translations[key] = sectionData[key];
|
363
|
+
// break;
|
364
|
+
// }
|
365
|
+
// }
|
366
|
+
// });
|
367
|
+
// if (Object.keys(translations).length > 0) {
|
368
|
+
// // Generate chunk file
|
369
|
+
// const fileName = this.options.filenameTemplate
|
370
|
+
// .replace('[locale]', locale)
|
371
|
+
// .replace('[name]', chunkId)
|
372
|
+
// .replace('[chunkhash]', this.getContentHash(chunkId, locale));
|
373
|
+
// const content = `${this.options.jsonpFunc}(${jsonToString(translations)});`;
|
374
|
+
// compilation.assets[fileName] = new RawSource(content);
|
375
|
+
// // Add to manifest
|
376
|
+
// manifest.locales[locale][chunkId] = fileName;
|
377
|
+
// }
|
378
|
+
// });
|
379
|
+
// }
|
380
|
+
// // Add metadata
|
381
|
+
// manifest.metadata = {
|
382
|
+
// generatedAt: new Date().toISOString(),
|
383
|
+
// totalChunks: manifest.chunks.length,
|
384
|
+
// totalKeys: Array.from(this.keyToChunksMap.keys()).length,
|
385
|
+
// totalLocales: Object.keys(this.allI18nData).length
|
386
|
+
// };
|
387
|
+
// // Emit manifest
|
388
|
+
// console.log('[I18N-BUILD] Emitting manifest with mappings:', {
|
389
|
+
// chunks: Object.keys(manifest.chunks).length,
|
390
|
+
// locales: Object.keys(manifest.locales).length,
|
391
|
+
// keys: manifest.metadata.totalKeys
|
392
|
+
// });
|
393
|
+
// compilation.assets[this.options.i18nManifestFileName] = new RawSource(
|
394
|
+
// JSON.stringify(manifest, null, 2)
|
395
|
+
// );
|
396
|
+
// }
|
397
|
+
// getContentHash(chunkId, locale) {
|
398
|
+
// let hash = 0;
|
399
|
+
// const str = `${chunkId}_${locale}`;
|
400
|
+
// for (let i = 0; i < str.length; i++) {
|
401
|
+
// const char = str.charCodeAt(i);
|
402
|
+
// hash = ((hash << 5) - hash) + char;
|
403
|
+
// hash = hash & hash; // Convert to 32-bit integer
|
404
|
+
// }
|
405
|
+
// return hash.toString(36);
|
406
|
+
// }
|
407
|
+
// addI18nDependency(module, keys) {
|
408
|
+
// const dep = new I18nDependency({
|
409
|
+
// identifier: `i18n ${module.resource}`,
|
410
|
+
// i18nKeys: keys
|
411
|
+
// }, module.context);
|
412
|
+
// module.addDependency(dep);
|
413
|
+
// }
|
414
|
+
// }
|
415
|
+
|
416
|
+
class I18nPlugin {
|
417
|
+
constructor(options = {}) {
|
418
|
+
const {
|
419
|
+
jsResource,
|
420
|
+
localeVarName = 'document.documentElement.lang',
|
421
|
+
jsonpFunc = 'window.loadI18nChunk',
|
422
|
+
propertiesFolder,
|
423
|
+
disableDefault = false,
|
424
|
+
filenameTemplate = 'i18n-chunk/[locale]/[name].[chunkhash].i18n.js',
|
425
|
+
i18nManifestFileName = 'i18n-manifest.json',
|
426
|
+
mainChunkName = 'main',
|
427
|
+
// Optimization options
|
428
|
+
minKeys = 5,
|
429
|
+
mainChunks = ['main', 'vendor'],
|
430
|
+
maxChunks = 20,
|
431
|
+
cacheFile = '.i18n-cache.json'
|
432
|
+
} = options;
|
433
|
+
this.options = {
|
434
|
+
localeVarName,
|
435
|
+
jsonpFunc,
|
436
|
+
filenameTemplate,
|
437
|
+
i18nManifestFileName,
|
438
|
+
mainChunkName,
|
439
|
+
optimization: {
|
440
|
+
minKeys,
|
441
|
+
mainChunks,
|
442
|
+
maxChunks
|
443
|
+
},
|
444
|
+
cacheFile
|
445
|
+
}; // Load and parse i18n resources
|
446
|
+
|
447
|
+
this.jsResourceI18nKeys = jsResource ? (0, _propertiesUtils.getPropertiesAsJSON)(jsResource) : {};
|
448
|
+
this.allI18nData = (0, _propertiesUtils.getAllI18nGroupedBySection)({
|
449
|
+
folderPath: propertiesFolder,
|
450
|
+
disableDefault,
|
451
|
+
jsResourceI18nKeys: this.jsResourceI18nKeys
|
452
|
+
}); // Initialize tracking maps
|
453
|
+
|
454
|
+
this.moduleToKeysMap = new Map();
|
455
|
+
this.chunkToKeysMap = new Map();
|
456
|
+
this.keyMovementHistory = new Map();
|
457
|
+
this.keyCache = this.loadKeyCache();
|
458
|
+
console.log('[I18N] Plugin initialized with:', {
|
459
|
+
totalKeys: Object.keys(this.jsResourceI18nKeys).length,
|
460
|
+
totalLocales: Object.keys(this.allI18nData).length,
|
461
|
+
mainChunks: this.options.optimization.mainChunks
|
462
|
+
});
|
463
|
+
}
|
464
|
+
loadKeyCache() {
|
465
|
+
try {
|
466
|
+
const cachePath = _path.default.join(process.cwd(), this.options.cacheFile);
|
467
|
+
if (_fs.default.existsSync(cachePath)) {
|
468
|
+
const cache = JSON.parse(_fs.default.readFileSync(cachePath, 'utf8'));
|
469
|
+
console.log('[I18N] Loaded key cache:', Object.keys(cache).length, 'entries');
|
470
|
+
return new Map(Object.entries(cache));
|
471
|
+
}
|
472
|
+
} catch (error) {
|
473
|
+
console.warn('[I18N] Failed to load key cache:', error);
|
474
|
+
}
|
475
|
+
return new Map();
|
476
|
+
}
|
477
|
+
saveKeyCache() {
|
478
|
+
try {
|
479
|
+
const cachePath = _path.default.join(process.cwd(), this.options.cacheFile);
|
480
|
+
const cache = Object.fromEntries(this.keyCache);
|
481
|
+
_fs.default.writeFileSync(cachePath, JSON.stringify(cache, null, 2));
|
482
|
+
console.log('[I18N] Saved key cache:', Object.keys(cache).length, 'entries');
|
483
|
+
} catch (error) {
|
484
|
+
console.warn('[I18N] Failed to save key cache:', error);
|
485
|
+
}
|
486
|
+
}
|
487
|
+
apply(compiler) {
|
488
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
|
489
|
+
// Setup dependencies
|
490
|
+
compilation.dependencyFactories.set(_I18nDependency.I18nDependency, new _NullFactory.default());
|
491
|
+
compilation.dependencyTemplates.set(_I18nDependency.I18nDependency, new _I18nDependency.I18nDependencyTemplate()); // Parse modules and collect i18n keys
|
492
|
+
|
493
|
+
this.setupModuleParsing(compilation, params.normalModuleFactory); // Map keys to chunks after optimization
|
494
|
+
|
495
|
+
compilation.hooks.afterOptimizeChunks.tap(pluginName, chunks => {
|
496
|
+
this.processChunks(compilation, chunks);
|
497
|
+
}); // Emit optimized assets
|
498
|
+
|
499
|
+
compiler.hooks.emit.tap(pluginName, compilation => {
|
500
|
+
this.emitAssets(compilation);
|
501
|
+
}); // Save cache after completion
|
502
|
+
|
503
|
+
compiler.hooks.done.tap(pluginName, () => {
|
504
|
+
this.saveKeyCache();
|
505
|
+
});
|
506
|
+
});
|
507
|
+
}
|
508
|
+
setupModuleParsing(compilation, factory) {
|
509
|
+
const handler = parser => {
|
510
|
+
parser.hooks.program.tap(pluginName, (ast, comments) => {
|
511
|
+
const {
|
512
|
+
module
|
513
|
+
} = parser.state;
|
514
|
+
if (!(module && /\.jsx?$/.test(module.resource))) return;
|
515
|
+
try {
|
516
|
+
// Collect keys from code and comments
|
517
|
+
const codeKeys = (0, _collectI18nKeys.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
|
518
|
+
const commentKeys = (0, _collectI18nKeys.collectI18nKeysfromComments)(comments, this.jsResourceI18nKeys);
|
519
|
+
const moduleKeys = [...new Set([...codeKeys, ...commentKeys])];
|
520
|
+
if (moduleKeys.length > 0) {
|
521
|
+
console.log('[I18N] Found keys in module:', {
|
522
|
+
module: module.resource,
|
523
|
+
keyCount: moduleKeys.length
|
524
|
+
}); // Track keys per module
|
525
|
+
|
526
|
+
this.moduleToKeysMap.set(module.resource, moduleKeys); // Update key cache with module association
|
527
|
+
|
528
|
+
moduleKeys.forEach(key => {
|
529
|
+
const modules = this.keyCache.get(key) || new Set();
|
530
|
+
modules.add(module.resource);
|
531
|
+
this.keyCache.set(key, modules);
|
532
|
+
}); // Add dependency for webpack
|
533
|
+
|
534
|
+
this.addI18nDependency(module, moduleKeys);
|
535
|
+
}
|
536
|
+
} catch (error) {
|
537
|
+
console.error('[I18N] Error processing module:', module.resource, error);
|
538
|
+
}
|
539
|
+
});
|
540
|
+
};
|
541
|
+
factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
|
542
|
+
factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
|
543
|
+
}
|
544
|
+
processChunks(compilation, chunks) {
|
545
|
+
console.log('[I18N] Processing', chunks.length, 'chunks');
|
546
|
+
const {
|
547
|
+
minKeys,
|
548
|
+
mainChunks,
|
549
|
+
maxChunks
|
550
|
+
} = this.options.optimization;
|
551
|
+
this.chunkToKeysMap.clear(); // First process main chunks
|
552
|
+
|
553
|
+
chunks.forEach(chunk => {
|
554
|
+
if (mainChunks.includes(chunk.name)) {
|
555
|
+
const keys = this.collectChunkKeys(chunk);
|
556
|
+
if (keys.size > 0) {
|
557
|
+
this.chunkToKeysMap.set(chunk.name || chunk.id, Array.from(keys));
|
558
|
+
}
|
559
|
+
}
|
560
|
+
}); // Then process other chunks by size
|
561
|
+
|
562
|
+
const otherChunks = chunks.filter(chunk => !mainChunks.includes(chunk.name)).map(chunk => ({
|
563
|
+
chunk,
|
564
|
+
keys: this.collectChunkKeys(chunk)
|
565
|
+
})).filter(({
|
566
|
+
keys
|
567
|
+
}) => keys.size >= minKeys).sort((a, b) => b.keys.size - a.keys.size); // Take only up to maxChunks - mainChunks.length chunks
|
568
|
+
|
569
|
+
const remainingSlots = maxChunks - this.chunkToKeysMap.size;
|
570
|
+
otherChunks.slice(0, remainingSlots).forEach(({
|
571
|
+
chunk,
|
572
|
+
keys
|
573
|
+
}) => {
|
574
|
+
this.chunkToKeysMap.set(chunk.name || chunk.id, Array.from(keys));
|
575
|
+
}); // Move remaining keys to most appropriate chunk
|
576
|
+
|
577
|
+
otherChunks.slice(remainingSlots).forEach(({
|
578
|
+
chunk,
|
579
|
+
keys
|
580
|
+
}) => {
|
581
|
+
keys.forEach(key => {
|
582
|
+
const bestChunk = this.findBestChunkForKey(key);
|
583
|
+
const chunkKeys = this.chunkToKeysMap.get(bestChunk) || [];
|
584
|
+
chunkKeys.push(key);
|
585
|
+
this.chunkToKeysMap.set(bestChunk, chunkKeys); // Track key movement
|
586
|
+
|
587
|
+
this.keyMovementHistory.set(key, {
|
588
|
+
from: chunk.name || chunk.id,
|
589
|
+
to: bestChunk
|
590
|
+
});
|
591
|
+
});
|
592
|
+
});
|
593
|
+
}
|
594
|
+
collectChunkKeys(chunk) {
|
595
|
+
const keys = new Set();
|
596
|
+
for (const module of chunk.modulesIterable) {
|
597
|
+
if (module.resource) {
|
598
|
+
const moduleKeys = this.moduleToKeysMap.get(module.resource);
|
599
|
+
if (moduleKeys) {
|
600
|
+
moduleKeys.forEach(key => keys.add(key));
|
601
|
+
}
|
602
|
+
}
|
603
|
+
}
|
604
|
+
return keys;
|
605
|
+
}
|
606
|
+
findBestChunkForKey(key) {
|
607
|
+
// First check history
|
608
|
+
const history = this.keyMovementHistory.get(key);
|
609
|
+
if (history && this.chunkToKeysMap.has(history.to)) {
|
610
|
+
return history.to;
|
611
|
+
} // Check key prefix matches
|
612
|
+
|
613
|
+
const keyPrefix = key.split('.')[0];
|
614
|
+
for (const [chunkId, chunkKeys] of this.chunkToKeysMap.entries()) {
|
615
|
+
if (chunkKeys.some(k => k.split('.')[0] === keyPrefix)) {
|
616
|
+
return chunkId;
|
617
|
+
}
|
618
|
+
} // Default to main chunk
|
619
|
+
|
620
|
+
return this.options.mainChunkName;
|
621
|
+
}
|
622
|
+
emitAssets(compilation) {
|
623
|
+
const manifest = {
|
624
|
+
chunks: {},
|
625
|
+
locales: {},
|
626
|
+
metadata: {
|
627
|
+
generatedAt: new Date().toISOString(),
|
628
|
+
totalChunks: this.chunkToKeysMap.size,
|
629
|
+
keyMovements: Array.from(this.keyMovementHistory.entries()).length
|
630
|
+
}
|
631
|
+
}; // Generate optimized chunks
|
632
|
+
|
633
|
+
for (const [chunkId, keys] of this.chunkToKeysMap.entries()) {
|
634
|
+
manifest.chunks[chunkId] = keys;
|
635
|
+
Object.keys(this.allI18nData).forEach(locale => {
|
636
|
+
if (!manifest.locales[locale]) {
|
637
|
+
manifest.locales[locale] = {};
|
638
|
+
}
|
639
|
+
const translations = this.collectTranslations(keys, locale);
|
640
|
+
if (Object.keys(translations).length > 0) {
|
641
|
+
const fileName = this.getChunkFileName(chunkId, locale);
|
642
|
+
const content = `${this.options.jsonpFunc}(${(0, _propertiesUtils.jsonToString)(translations)});`;
|
643
|
+
compilation.assets[fileName] = new _webpackSources.RawSource(content);
|
644
|
+
manifest.locales[locale][chunkId] = fileName;
|
645
|
+
}
|
646
|
+
});
|
647
|
+
} // Add key movements to manifest for development
|
648
|
+
|
649
|
+
if (process.env.NODE_ENV === 'development') {
|
650
|
+
manifest.keyMovements = Object.fromEntries(this.keyMovementHistory);
|
651
|
+
} // Emit manifest
|
652
|
+
|
653
|
+
const manifestContent = JSON.stringify(manifest, null, 2);
|
654
|
+
compilation.assets[this.options.i18nManifestFileName] = new _webpackSources.RawSource(manifestContent);
|
655
|
+
console.log('[I18N] Emitted manifest with:', {
|
656
|
+
chunks: Object.keys(manifest.chunks).length,
|
657
|
+
locales: Object.keys(manifest.locales).length,
|
658
|
+
totalKeys: Object.values(manifest.chunks).reduce((acc, keys) => acc + keys.length, 0)
|
659
|
+
});
|
660
|
+
}
|
661
|
+
collectTranslations(keys, locale) {
|
662
|
+
const translations = {};
|
663
|
+
const localeData = this.allI18nData[locale];
|
664
|
+
keys.forEach(key => {
|
665
|
+
for (const sectionData of Object.values(localeData)) {
|
666
|
+
if (key in sectionData) {
|
667
|
+
translations[key] = sectionData[key];
|
668
|
+
break;
|
669
|
+
}
|
670
|
+
}
|
671
|
+
});
|
672
|
+
return translations;
|
673
|
+
}
|
674
|
+
getChunkFileName(chunkId, locale) {
|
675
|
+
return this.options.filenameTemplate.replace('[locale]', locale).replace('[name]', chunkId).replace('[chunkhash]', this.getContentHash(chunkId, locale));
|
676
|
+
}
|
677
|
+
getContentHash(chunkId, locale) {
|
678
|
+
const data = `${chunkId}_${locale}`;
|
679
|
+
let hash = 0;
|
680
|
+
for (let i = 0; i < data.length; i++) {
|
681
|
+
hash = (hash << 5) - hash + data.charCodeAt(i);
|
682
|
+
hash = hash & hash;
|
683
|
+
}
|
684
|
+
return hash.toString(36);
|
685
|
+
}
|
686
|
+
addI18nDependency(module, keys) {
|
687
|
+
const dep = new _I18nDependency.I18nDependency({
|
688
|
+
identifier: `i18n ${module.resource}`,
|
689
|
+
i18nKeys: keys
|
690
|
+
}, module.context);
|
691
|
+
module.addDependency(dep);
|
692
|
+
}
|
693
|
+
}
|
694
|
+
exports.default = I18nPlugin;
|