@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.
Files changed (221) hide show
  1. package/lib/babel/babel-option-utils/babel-preset-react-option.js +0 -3
  2. package/lib/babel/cmjs-plugins-presets.js +1 -8
  3. package/lib/babel/es-plugins-presets.js +1 -8
  4. package/lib/common/buildEs.js +1 -0
  5. package/lib/common/getEntries.js +2 -13
  6. package/lib/common/getPublicPathConfig.js +0 -6
  7. package/lib/common/index.js +1 -6
  8. package/lib/common/runPreProcess.js +6 -15
  9. package/lib/common/splitChunks.js +2 -21
  10. package/lib/common/sslcertUpdater.js +7 -18
  11. package/lib/common/templateParameters.js +0 -2
  12. package/lib/common/testPattern.js +10 -21
  13. package/lib/common/valueReplacer.js +1 -16
  14. package/lib/configs/jest.config.js +1 -10
  15. package/lib/configs/libAlias.js +8 -14
  16. package/lib/configs/resolvers.js +4 -14
  17. package/lib/configs/webpack.component.umd.config.js +1 -6
  18. package/lib/configs/webpack.css.umd.config.js +6 -14
  19. package/lib/configs/webpack.dev.config.js +1 -14
  20. package/lib/configs/webpack.docs.config.js +1 -9
  21. package/lib/configs/webpack.impact.config.js +1 -8
  22. package/lib/configs/webpack.prod.config.js +4 -17
  23. package/lib/constants.js +9 -18
  24. package/lib/deprecationLogger.js +0 -7
  25. package/lib/hooks/docsProptypeHook.js +4 -8
  26. package/lib/jest/commitedFilesResult.js +4 -46
  27. package/lib/jest/coverageCollector.js +1 -12
  28. package/lib/jest/jsonMaker.js +0 -6
  29. package/lib/jest/preProcessors/cssPreprocessor.js +1 -9
  30. package/lib/jest/preProcessors/jsPreprocessor.js +1 -6
  31. package/lib/jest/preProcessors/otherFilesPreprocessor.js +1 -4
  32. package/lib/jest/result.js +1 -23
  33. package/lib/jest/run.js +7 -18
  34. package/lib/jest/setup.js +8 -60
  35. package/lib/loaderUtils/configsAssetsLoaders.js +2 -12
  36. package/lib/loaderUtils/getCSSLoaders.js +10 -22
  37. package/lib/loaderUtils/getDevJsLoaders.js +4 -13
  38. package/lib/loaderUtils/index.js +1 -4
  39. package/lib/loaderUtils/tests/windowsModification.test.js +0 -1
  40. package/lib/loaderUtils/windowsModification.js +2 -3
  41. package/lib/loaders/__test__/markdownLoader.spec.js +0 -1
  42. package/lib/loaders/composeLoader.js +13 -37
  43. package/lib/loaders/docsLoader.js +1 -12
  44. package/lib/loaders/docsPropsLoader.js +4 -8
  45. package/lib/loaders/enhancedReactLiveConverter.js +2 -23
  46. package/lib/loaders/fileBountryLoader.js +1 -3
  47. package/lib/loaders/fileLoader.js +12 -23
  48. package/lib/loaders/markdownLoader.js +14 -19
  49. package/lib/loaders/reactLiveConvertor.js +5 -15
  50. package/lib/loaders/scriptInstrumentLoader.js +7 -16
  51. package/lib/loaders/selectorMappingLoader.js +7 -26
  52. package/lib/loaders/workerLoader.js +9 -24
  53. package/lib/logger.js +0 -4
  54. package/lib/middlewares/HMRMiddleware.js +13 -27
  55. package/lib/middlewares/SSTMiddleware.js +1 -5
  56. package/lib/pluginUtils/configHtmlWebpackPlugins.js +1 -24
  57. package/lib/pluginUtils/getDevPlugins.js +9 -42
  58. package/lib/pluginUtils/getDocsPlugins.js +3 -13
  59. package/lib/pluginUtils/getLibraryImactPlugins.js +5 -6
  60. package/lib/pluginUtils/getLibraryPlugins.js +2 -8
  61. package/lib/pluginUtils/getProdPlugins.js +8 -47
  62. package/lib/pluginUtils/getServerPlugins.js +2 -8
  63. package/lib/pluginUtils/getUMDCSSPlugins.js +2 -10
  64. package/lib/pluginUtils/getUMDComponentPlugins.js +2 -10
  65. package/lib/pluginUtils/index.js +1 -9
  66. package/lib/plugins/CdnChangePlugin.js +2 -18
  67. package/lib/plugins/CleanupStatsPlugin.js +0 -5
  68. package/lib/plugins/CssOrderControlPlugin.js +3 -6
  69. package/lib/plugins/CustomAttributePlugin.js +14 -19
  70. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +3 -23
  71. package/lib/plugins/EFCPlugin.js +20 -34
  72. package/lib/plugins/EFCTemplatePlugin.js +19 -30
  73. package/lib/plugins/EfcResourceCleanupPlugin.js +0 -3
  74. package/lib/plugins/EventsHandlingPlugin.js +2 -4
  75. package/lib/plugins/I18NInjectIntoIndexPlugin.js +11 -37
  76. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +10 -15
  77. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +4 -10
  78. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +12 -25
  79. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +55 -133
  80. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +12 -23
  81. package/lib/plugins/I18nSplitPlugin/index.js +13 -24
  82. package/lib/plugins/I18nSplitPlugin/utils/applyMetaManifest.js +64 -58
  83. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +2 -12
  84. package/lib/plugins/I18nSplitPlugin/utils/createMetaManifest.js +10 -29
  85. package/lib/plugins/I18nSplitPlugin/utils/createRegularManifest.js +8 -19
  86. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +0 -1
  87. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +0 -5
  88. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +1 -8
  89. package/lib/plugins/I18nSplitPlugin/utils/index.js +0 -4
  90. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +0 -20
  91. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +0 -1
  92. package/lib/plugins/ManifestPlugin.js +1 -18
  93. package/lib/plugins/MinifyPlugin.js +1 -10
  94. package/lib/plugins/ModuleStatsPlugin.js +1 -24
  95. package/lib/plugins/OptimizeJSPlugin.js +2 -10
  96. package/lib/plugins/PublicPathCallbackPlugin.js +1 -12
  97. package/lib/plugins/PublicPathChangePlugin.js +6 -39
  98. package/lib/plugins/ReportGeneratePlugin.js +5 -32
  99. package/lib/plugins/RequireVariablePublicPlugin.js +1 -8
  100. package/lib/plugins/ResourceHintsPlugin.js +4 -13
  101. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +12 -17
  102. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +10 -17
  103. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +2 -5
  104. package/lib/plugins/ScriptInstrumentPlugin.js +1 -8
  105. package/lib/plugins/SelectorPlugin.js +6 -32
  106. package/lib/plugins/ServiceWorkerPlugin.js +5 -22
  107. package/lib/plugins/ShadowDOMSupportPlugin.js +4 -41
  108. package/lib/plugins/SourceMapHookPlugin.js +2 -12
  109. package/lib/plugins/StatsPlugin.js +0 -14
  110. package/lib/plugins/TPHashMappingPlugin.js +3 -18
  111. package/lib/plugins/UnusedFilesFindPlugin.js +4 -39
  112. package/lib/plugins/VariableConversionCollector.js +15 -42
  113. package/lib/plugins/index.js +1 -20
  114. package/lib/plugins/libraryImpactPlugin.js +1 -33
  115. package/lib/plugins/newi18nsplitplugin/18nPlugin1.js +306 -0
  116. package/lib/plugins/newi18nsplitplugin/18nPlugin2.js +363 -0
  117. package/lib/plugins/newi18nsplitplugin/18nPlugin3.js +694 -0
  118. package/lib/plugins/newi18nsplitplugin/18nPlugin_hashed.js +1258 -0
  119. package/lib/plugins/newi18nsplitplugin/18nPlugin_working.js +542 -0
  120. package/lib/plugins/newi18nsplitplugin/18nplugin.js +974 -0
  121. package/lib/plugins/newi18nsplitplugin/ChunkManager.js +131 -0
  122. package/lib/plugins/newi18nsplitplugin/GenerateModuleIdToKeysMapPlugin.js +59 -0
  123. package/lib/plugins/newi18nsplitplugin/I18nDiffPlugin.js +262 -0
  124. package/lib/plugins/newi18nsplitplugin/I18nDownloadLogic.js +166 -0
  125. package/lib/plugins/newi18nsplitplugin/I18nPropertiesPlugin.js +111 -0
  126. package/lib/plugins/newi18nsplitplugin/KeyCollector.js +163 -0
  127. package/lib/plugins/newi18nsplitplugin/ManifestGenerator.js +88 -0
  128. package/lib/plugins/newi18nsplitplugin/UnicodeConversionPlugin.js +101 -0
  129. package/lib/plugins/newi18nsplitplugin/constants.js +162 -0
  130. package/lib/plugins/newi18nsplitplugin/utils/I18nKeyHasher.js +78 -0
  131. package/lib/plugins/newi18nsplitplugin/utils/getJsResourceKeys.js +22 -0
  132. package/lib/plugins/newi18nsplitplugin/utils/i18nChunkUtils.js +18 -0
  133. package/lib/plugins/newi18nsplitplugin/utils/manifestGenerator.js +580 -0
  134. package/lib/plugins/newi18nsplitplugin/utils/propertiesUtils.js +54 -0
  135. package/lib/plugins/utils/classHandling.js +0 -6
  136. package/lib/plugins/utils/fileHandling.js +6 -15
  137. package/lib/plugins/utils/tests/fileHandling.test.js +0 -4
  138. package/lib/plugins/variableConvertorUtils.js +14 -29
  139. package/lib/plugins/webpackwatchrunplugin.js +0 -5
  140. package/lib/postcss-plugins/EmptyPlugin.js +3 -4
  141. package/lib/postcss-plugins/ExcludePlugin.js +1 -5
  142. package/lib/postcss-plugins/IncludePlugin.js +1 -5
  143. package/lib/postcss-plugins/RTLSplitPlugin.js +14 -27
  144. package/lib/postcss-plugins/SelectorReplace.js +1 -16
  145. package/lib/postcss-plugins/ValueReplacer.js +7 -6
  146. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +0 -3
  147. package/lib/postcss-plugins/__test__/selectorReplace.test.js +6 -3
  148. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +2 -5
  149. package/lib/postcss-plugins/hoverActivePlugin.js +31 -67
  150. package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +0 -7
  151. package/lib/postcss-plugins/variableModificationPlugin/index.js +28 -49
  152. package/lib/schemas/index.js +3 -9
  153. package/lib/servers/clusterHubServer.js +1 -11
  154. package/lib/servers/devBuild.js +14 -26
  155. package/lib/servers/docsServer.js +1 -3
  156. package/lib/servers/docsServerCore.js +1 -22
  157. package/lib/servers/getCliPath.js +0 -9
  158. package/lib/servers/helpServer.js +1 -6
  159. package/lib/servers/httpsOptions.js +2 -8
  160. package/lib/servers/impactServer.js +3 -35
  161. package/lib/servers/mockserver.js +1 -10
  162. package/lib/servers/nowatchserver.js +12 -37
  163. package/lib/servers/requireLocalOrGlobal.js +6 -17
  164. package/lib/servers/scrServer.js +14 -21
  165. package/lib/servers/server.js +6 -36
  166. package/lib/servers/ssServer.js +1 -17
  167. package/lib/templates/CoverageScriptTemplate.js +0 -14
  168. package/lib/templates/WMSTemplate.js +7 -13
  169. package/lib/templates/linterConstant.js +2 -4
  170. package/lib/utils/babelPresets.js +3 -7
  171. package/lib/utils/clean.js +3 -9
  172. package/lib/utils/copy.js +1 -7
  173. package/lib/utils/copyTimezones.js +1 -9
  174. package/lib/utils/createEventStream.js +1 -6
  175. package/lib/utils/cssClassNameGenerate.js +10 -30
  176. package/lib/utils/cssURLReplacer.js +1 -22
  177. package/lib/utils/dependencyPostPublish.js +1 -10
  178. package/lib/utils/deprecationSupport.js +7 -32
  179. package/lib/utils/fileUtils.js +1 -28
  180. package/lib/utils/folderIterator.js +2 -13
  181. package/lib/utils/getComponents.js +0 -21
  182. package/lib/utils/getCurrentBranch.js +0 -5
  183. package/lib/utils/getDependenciesImpactList.js +1 -22
  184. package/lib/utils/getFileType.js +2 -10
  185. package/lib/utils/getHash.js +1 -8
  186. package/lib/utils/getIp.js +0 -2
  187. package/lib/utils/getOptions.js +16 -53
  188. package/lib/utils/getServerURL.js +1 -10
  189. package/lib/utils/index.js +4 -51
  190. package/lib/utils/init.js +0 -1
  191. package/lib/utils/initPreCommitHook.js +7 -30
  192. package/lib/utils/jsonHelper.js +3 -22
  193. package/lib/utils/libraryImpactConfig.js +2 -5
  194. package/lib/utils/lint/addScripts.js +2 -5
  195. package/lib/utils/lint/checkExistingConfig.js +3 -12
  196. package/lib/utils/lint/copyConfigs.js +0 -3
  197. package/lib/utils/lint/index.js +0 -9
  198. package/lib/utils/lint/lintScripts.js +0 -1
  199. package/lib/utils/lint/lintSetup.js +3 -4
  200. package/lib/utils/lint/lintStagedPreCommitHook.js +0 -1
  201. package/lib/utils/lint/question.js +0 -7
  202. package/lib/utils/lintReporter.js +0 -20
  203. package/lib/utils/log.js +0 -1
  204. package/lib/utils/mailSender.js +1 -8
  205. package/lib/utils/object-manipulation.js +1 -17
  206. package/lib/utils/pullOrigin.js +0 -4
  207. package/lib/utils/reinstallDependencies.js +1 -29
  208. package/lib/utils/removeAttributes.js +1 -8
  209. package/lib/utils/repoClone.js +3 -28
  210. package/lib/utils/request.js +0 -12
  211. package/lib/utils/rtl.js +5 -17
  212. package/lib/utils/selectorReplacer.js +10 -16
  213. package/lib/utils/setEnvVariables.js +0 -2
  214. package/lib/utils/ssTestHack.js +1 -11
  215. package/lib/utils/switchBranch.js +0 -5
  216. package/lib/utils/typeCheck.js +0 -1
  217. package/lib/utils/urlConcat.js +0 -4
  218. package/lib/utils/useExitCleanup.js +9 -10
  219. package/lib/utils/variableConverter.js +22 -31
  220. package/{npm-shrinkwrap.json → package-lock.json} +2098 -1999
  221. package/package.json +1 -1
@@ -0,0 +1,974 @@
1
+ "use strict";
2
+
3
+ // // // //section based approch
4
+ // // // const path = require('path');
5
+ // // // const fs = require('fs');
6
+ // // // const {
7
+ // // // getAllI18nGroupedBySection,
8
+ // // // getPropertiesAsJSON,
9
+ // // // } = require('../I18nSplitPlugin/utils/propertiesUtils');
10
+ // // // const {
11
+ // // // collectI18nKeysfromAST,
12
+ // // // collectI18nKeysfromComments,
13
+ // // // } = require('../I18nSplitPlugin/utils/collectI18nKeys');
14
+ // // // const NullFactory = require('webpack/lib/NullFactory');
15
+ // // // const {
16
+ // // // I18nDependency,
17
+ // // // I18nDependencyTemplate,
18
+ // // // } = require('../I18nSplitPlugin/I18nDependency');
19
+ // // // const webpack = require('webpack');
20
+ // // // const { RawSource } = require('webpack-sources'); // Import RawSource from webpack-sources
21
+ // // // const { generateManifests } = require('./utils/manifestGenerator');
22
+ // // // const pluginName = 'I18nPlugin';
23
+ // // // class I18nPlugin {
24
+ // // // constructor(options = {}) {
25
+ // // // const {
26
+ // // // jsResourcePath,
27
+ // // // mainChunkName,
28
+ // // // propertiesFolder,
29
+ // // // disableDefault,
30
+ // // // jsResource,
31
+ // // // } = options;
32
+ // // // if (!jsResourcePath) {
33
+ // // // throw new Error('I18nPlugin: "jsResourcePath" option is required.');
34
+ // // // }
35
+ // // // if (!mainChunkName) {
36
+ // // // throw new Error('I18nPlugin: "mainChunkName" option is required.');
37
+ // // // }
38
+ // // // this.jsResourcePath = jsResourcePath;
39
+ // // // this.entryPointName = mainChunkName;
40
+ // // // this.jsResourceI18nKeys = jsResource
41
+ // // // ? getPropertiesAsJSON(jsResource)
42
+ // // // : {};
43
+ // // // // Get all i18n keys grouped by sections
44
+ // // // this.allI18nKeys = getAllI18nGroupedBySection({
45
+ // // // folderPath: propertiesFolder,
46
+ // // // disableDefault,
47
+ // // // jsResourceI18nKeys: this.jsResourceI18nKeys,
48
+ // // // });
49
+ // // // console.log('All locales:', Object.keys(this.allI18nKeys));
50
+ // // // this.moduleToKeysMap = new Map();
51
+ // // // this.keyToModulesMap = new Map();
52
+ // // // this.keyToI18nChunkIdMap = {};
53
+ // // // }
54
+ // // // defineI18nDependency(compilation) {
55
+ // // // compilation.dependencyFactories.set(I18nDependency, new NullFactory());
56
+ // // // compilation.dependencyTemplates.set(
57
+ // // // I18nDependency,
58
+ // // // new I18nDependencyTemplate()
59
+ // // // );
60
+ // // // }
61
+ // // // addI18nDependency(module, i18nKeys) {
62
+ // // // const identifier = `i18n ${module.resource}`;
63
+ // // // const dep = new I18nDependency({ identifier, i18nKeys }, module.context, 0);
64
+ // // // module.addDependency(dep);
65
+ // // // }
66
+ // // // apply(compiler) {
67
+ // // // compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
68
+ // // // this.defineI18nDependency(compilation);
69
+ // // // // Handler for parser
70
+ // // // const handler = (parser) => {
71
+ // // // parser.hooks.program.tap(pluginName, (ast, comments) => {
72
+ // // // const { module } = parser.state;
73
+ // // // if (!(module && /\.jsx?$/.test(module.resource))) {
74
+ // // // return;
75
+ // // // }
76
+ // // // // Collect i18n keys
77
+ // // // let i18nKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
78
+ // // // let commentKeys = collectI18nKeysfromComments(
79
+ // // // comments,
80
+ // // // this.jsResourceI18nKeys
81
+ // // // );
82
+ // // // i18nKeys = i18nKeys.concat(commentKeys);
83
+ // // // if (i18nKeys.length) {
84
+ // // // // Store the keys for this module
85
+ // // // this.moduleToKeysMap.set(module.resource, i18nKeys);
86
+ // // // // Map keys to modules
87
+ // // // for (const key of i18nKeys) {
88
+ // // // if (!this.keyToModulesMap.has(key)) {
89
+ // // // this.keyToModulesMap.set(key, new Set());
90
+ // // // }
91
+ // // // this.keyToModulesMap.get(key).add(module.resource);
92
+ // // // }
93
+ // // // // Add I18nDependency to the module (optional, if needed)
94
+ // // // // this.addI18nDependency(module, i18nKeys);
95
+ // // // }
96
+ // // // });
97
+ // // // };
98
+ // // // // Tap into parser hooks
99
+ // // // const factory = params.normalModuleFactory;
100
+ // // // factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
101
+ // // // factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
102
+ // // // // After optimizing chunks, process collected keys
103
+ // // // compilation.hooks.afterOptimizeChunks.tap(pluginName, () => {
104
+ // // // this.processCollectedKeys(compilation);
105
+ // // // });
106
+ // // // });
107
+ // // // }
108
+ // // // processCollectedKeys(compilation) {
109
+ // // // console.log('Starting processCollectedKeys...');
110
+ // // // // Initialize mappings
111
+ // // // this.chunkIdToKeysMap = {};
112
+ // // // this.moduleChunkIdToModulesMap = {};
113
+ // // // // Iterate over all chunks in the compilation
114
+ // // // for (const chunk of compilation.chunks) {
115
+ // // // const chunkId = chunk.name || chunk.id;
116
+ // // // const chunkIdString = String(chunkId);
117
+ // // // console.log(`Processing chunk with ID: ${chunkIdString}`);
118
+ // // // // Collect all modules in the chunk
119
+ // // // const modules = chunk.getModules();
120
+ // // // let chunkKeys = new Set();
121
+ // // // let moduleResources = [];
122
+ // // // for (const module of modules) {
123
+ // // // const moduleResource = module.resource;
124
+ // // // if (moduleResource) {
125
+ // // // moduleResources.push(moduleResource);
126
+ // // // const keys = this.moduleToKeysMap.get(moduleResource);
127
+ // // // if (keys) {
128
+ // // // for (const key of keys) {
129
+ // // // chunkKeys.add(key);
130
+ // // // }
131
+ // // // }
132
+ // // // }
133
+ // // // }
134
+ // // // // Store in the map if there are keys
135
+ // // // chunkKeys = Array.from(chunkKeys);
136
+ // // // if (chunkKeys.length > 0) {
137
+ // // // this.chunkIdToKeysMap[chunkIdString] = chunkKeys;
138
+ // // // }
139
+ // // // // Map chunkId to module resources
140
+ // // // if (moduleResources.length > 0) {
141
+ // // // this.moduleChunkIdToModulesMap[chunkIdString] = moduleResources;
142
+ // // // }
143
+ // // // }
144
+ // // // // Emit the i18n chunks
145
+ // // // this.emitI18nChunks(compilation);
146
+ // // // }
147
+ // // // emitI18nChunks(compilation) {
148
+ // // // const manifest = {
149
+ // // // moduleToI18nChunkMap: {},
150
+ // // // locales: {},
151
+ // // // };
152
+ // // // // Get the list of locales
153
+ // // // const locales = Object.keys(this.allI18nKeys);
154
+ // // // // Initialize i18nChunkId counter
155
+ // // // let i18nChunkIdCounter = 0;
156
+ // // // const sectionToI18nChunkIdMap = {};
157
+ // // // // Assign each section to an i18n chunk
158
+ // // // // Assuming all locales have the same sections as the first locale
159
+ // // // const firstLocale = locales[0];
160
+ // // // const sections = Object.keys(this.allI18nKeys[firstLocale]);
161
+ // // // for (const sectionName of sections) {
162
+ // // // const i18nChunkId = i18nChunkIdCounter++;
163
+ // // // sectionToI18nChunkIdMap[sectionName] = i18nChunkId;
164
+ // // // // Collect keys for this section from the first locale
165
+ // // // const keys = Object.keys(this.allI18nKeys[firstLocale][sectionName] || {});
166
+ // // // // Map keys to i18nChunkId
167
+ // // // for (const key of keys) {
168
+ // // // this.keyToI18nChunkIdMap[key] = i18nChunkId;
169
+ // // // }
170
+ // // // // Generate the i18n chunk for each locale
171
+ // // // for (const locale of locales) {
172
+ // // // manifest.locales[locale] = manifest.locales[locale] || {};
173
+ // // // const i18nData = {};
174
+ // // // const localeSectionKeys = this.allI18nKeys[locale][sectionName] || {};
175
+ // // // for (const key of keys) {
176
+ // // // const value = localeSectionKeys[key];
177
+ // // // if (value !== undefined) {
178
+ // // // i18nData[key] = value;
179
+ // // // }
180
+ // // // }
181
+ // // // if (Object.keys(i18nData).length > 0) {
182
+ // // // const moduleSource = `window.loadI18nChunk(${JSON.stringify(i18nData, null, 2)});`;
183
+ // // // const filename = `i18n-chunks/${locale}/${sectionName}chunk-${i18nChunkId}.js`;
184
+ // // // compilation.emitAsset(filename, new RawSource(moduleSource));
185
+ // // // manifest.locales[locale][i18nChunkId] = filename;
186
+ // // // }
187
+ // // // }
188
+ // // // }
189
+ // // // // Now, create moduleToI18nChunkMap
190
+ // // // for (const [moduleChunkId, moduleResources] of Object.entries(
191
+ // // // this.moduleChunkIdToModulesMap
192
+ // // // )) {
193
+ // // // const requiredI18nChunkIds = new Set();
194
+ // // // for (const moduleResource of moduleResources) {
195
+ // // // const keys = this.moduleToKeysMap.get(moduleResource);
196
+ // // // if (keys) {
197
+ // // // for (const key of keys) {
198
+ // // // const i18nChunkId = this.keyToI18nChunkIdMap[key];
199
+ // // // if (i18nChunkId !== undefined) {
200
+ // // // requiredI18nChunkIds.add(i18nChunkId);
201
+ // // // }
202
+ // // // }
203
+ // // // }
204
+ // // // }
205
+ // // // if (requiredI18nChunkIds.size > 0) {
206
+ // // // manifest.moduleToI18nChunkMap[moduleChunkId] = Array.from(
207
+ // // // requiredI18nChunkIds
208
+ // // // );
209
+ // // // } else {
210
+ // // // console.log(
211
+ // // // `No required i18n chunks for module chunk ID ${moduleChunkId}`
212
+ // // // );
213
+ // // // }
214
+ // // // }
215
+ // // // // Emit the manifest file
216
+ // // // // const manifestSource = new RawSource(
217
+ // // // // `window.i18n = window.i18n || {}; window.i18n.manifest = ${JSON.stringify(
218
+ // // // // manifest,
219
+ // // // // null,
220
+ // // // // 2
221
+ // // // // )};`
222
+ // // // // );
223
+ // // // // const manifestFilename = 'i18n-chunks/manifest.js';
224
+ // // // // compilation.emitAsset(manifestFilename, manifestSource);
225
+ // // // // console.log(`Emitted i18n manifest: ${manifestFilename}`);
226
+ // // // // Generate the manifests using the external module
227
+ // // // generateManifests({
228
+ // // // compilation,
229
+ // // // allI18nKeys: this.allI18nKeys,
230
+ // // // moduleToKeysMap: this.moduleToKeysMap,
231
+ // // // keyToModulesMap: this.keyToModulesMap,
232
+ // // // moduleChunkIdToModulesMap: this.moduleChunkIdToModulesMap,
233
+ // // // keyToI18nChunkIdMap: this.keyToI18nChunkIdMap, // Pass this map
234
+ // // // sectionToI18nChunkIdMap: sectionToI18nChunkIdMap, // Pass if needed
235
+ // // // // Remove NUMBER_OF_CHUNKS and entryPointKeys if not used
236
+ // // // });
237
+ // // // }
238
+ // // // }
239
+ // // // I18nPlugin.isChunkHasI18n = function (chunk) {
240
+ // // // for (const module of chunk.modulesIterable) {
241
+ // // // for (const dep of module.dependencies) {
242
+ // // // if (dep instanceof I18nDependency) {
243
+ // // // return true;
244
+ // // // }
245
+ // // // }
246
+ // // // }
247
+ // // // return false;
248
+ // // // };
249
+ // // // module.exports = I18nPlugin;
250
+ // // //working size based approch
251
+ // // const path = require('path');
252
+ // // const fs = require('fs');
253
+ // // const { getAllI18nGroupedBySection, getPropertiesAsJSON } = require('../I18nSplitPlugin/utils/propertiesUtils');
254
+ // // const { collectI18nKeysfromAST, collectI18nKeysfromComments } = require('../I18nSplitPlugin/utils/collectI18nKeys');
255
+ // // const NullFactory = require('webpack/lib/NullFactory');
256
+ // // const { I18nDependency, I18nDependencyTemplate } = require('../I18nSplitPlugin/I18nDependency');
257
+ // // const { RawSource } = require('webpack-sources');
258
+ // // const { generateManifests } = require('./utils/manifestGenerator');
259
+ // // const pluginName = 'I18nPlugin';
260
+ // // class I18nPlugin {
261
+ // // constructor(options = {}) {
262
+ // // const { jsResourcePath, mainChunkName, propertiesFolder, disableDefault, jsResource } = options;
263
+ // // if (!jsResourcePath) {
264
+ // // throw new Error('I18nPlugin: "jsResourcePath" option is required.');
265
+ // // }
266
+ // // if (!mainChunkName) {
267
+ // // throw new Error('I18nPlugin: "mainChunkName" option is required.');
268
+ // // }
269
+ // // this.jsResourcePath = jsResourcePath;
270
+ // // this.entryPointName = mainChunkName;
271
+ // // this.jsResourceI18nKeys = jsResource ? getPropertiesAsJSON(jsResource) : {};
272
+ // // // Use getAllI18nGroupedBySection to group keys by sections
273
+ // // this.allI18nKeys = getAllI18nGroupedBySection({
274
+ // // folderPath: propertiesFolder,
275
+ // // disableDefault,
276
+ // // jsResourceI18nKeys: this.jsResourceI18nKeys,
277
+ // // });
278
+ // // console.log('Locales found:', Object.keys(this.allI18nKeys));
279
+ // // // Build keyToSectionMap
280
+ // // this.keyToSectionMap = {};
281
+ // // const locales = Object.keys(this.allI18nKeys);
282
+ // // if (locales.length > 0) {
283
+ // // // Use the first locale to build keyToSectionMap
284
+ // // const firstLocale = locales[0];
285
+ // // const sections = this.allI18nKeys[firstLocale];
286
+ // // console.log(`Sections found in properties files: ${Object.keys(sections).join(', ')}`);
287
+ // // for (const sectionName of Object.keys(sections)) {
288
+ // // const keysInSection = sections[sectionName];
289
+ // // for (const key of Object.keys(keysInSection)) {
290
+ // // this.keyToSectionMap[key] = sectionName;
291
+ // // }
292
+ // // }
293
+ // // }
294
+ // // this.moduleToKeysMap = new Map();
295
+ // // this.keyToModulesMap = new Map();
296
+ // // this.keyToI18nChunkIdMap = {};
297
+ // // }
298
+ // // defineI18nDependency(compilation) {
299
+ // // compilation.dependencyFactories.set(I18nDependency, new NullFactory());
300
+ // // compilation.dependencyTemplates.set(I18nDependency, new I18nDependencyTemplate());
301
+ // // }
302
+ // // apply(compiler) {
303
+ // // compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
304
+ // // this.defineI18nDependency(compilation);
305
+ // // // Handler for parser
306
+ // // const handler = parser => {
307
+ // // parser.hooks.program.tap(pluginName, (ast, comments) => {
308
+ // // const { module } = parser.state;
309
+ // // if (!(module && /\.jsx?$/.test(module.resource))) {
310
+ // // return;
311
+ // // }
312
+ // // // Collect i18n keys
313
+ // // let i18nKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
314
+ // // let commentKeys = collectI18nKeysfromComments(comments, this.jsResourceI18nKeys);
315
+ // // i18nKeys = i18nKeys.concat(commentKeys);
316
+ // // if (i18nKeys.length) {
317
+ // // // Store the keys for this module
318
+ // // this.moduleToKeysMap.set(module.resource, i18nKeys);
319
+ // // // Map keys to modules
320
+ // // for (const key of i18nKeys) {
321
+ // // if (!this.keyToModulesMap.has(key)) {
322
+ // // this.keyToModulesMap.set(key, new Set());
323
+ // // }
324
+ // // this.keyToModulesMap.get(key).add(module.resource);
325
+ // // }
326
+ // // }
327
+ // // });
328
+ // // };
329
+ // // const factory = params.normalModuleFactory;
330
+ // // factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
331
+ // // factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
332
+ // // compilation.hooks.afterOptimizeChunks.tap(pluginName, () => {
333
+ // // this.processCollectedKeys(compilation);
334
+ // // });
335
+ // // });
336
+ // // }
337
+ // // processCollectedKeys(compilation) {
338
+ // // // Map to store chunkId to required sections
339
+ // // this.chunkIdToSectionsMap = {};
340
+ // // this.moduleChunkIdToModulesMap = {};
341
+ // // // Map module resource to chunk IDs
342
+ // // this.moduleResourceToChunkIds = new Map();
343
+ // // // Collect modules for the entry point
344
+ // // const entryPointChunk = compilation.namedChunks.get(this.entryPointName);
345
+ // // const entryPointModules = new Set();
346
+ // // if (entryPointChunk) {
347
+ // // for (const module of entryPointChunk.getModules()) {
348
+ // // if (module.resource) {
349
+ // // entryPointModules.add(module.resource);
350
+ // // }
351
+ // // }
352
+ // // }
353
+ // // // Iterate over all chunks in the compilation
354
+ // // for (const chunk of compilation.chunks) {
355
+ // // const chunkId = chunk.name || chunk.id;
356
+ // // const chunkIdString = String(chunkId);
357
+ // // // Collect all modules in the chunk
358
+ // // const modules = chunk.getModules();
359
+ // // let requiredSections = new Set();
360
+ // // let moduleResources = [];
361
+ // // for (const module of modules) {
362
+ // // const moduleResource = module.resource;
363
+ // // if (moduleResource) {
364
+ // // moduleResources.push(moduleResource);
365
+ // // const keys = this.moduleToKeysMap.get(moduleResource);
366
+ // // if (keys) {
367
+ // // for (const key of keys) {
368
+ // // const section = this.keyToSectionMap[key];
369
+ // // if (section) {
370
+ // // requiredSections.add(section);
371
+ // // }
372
+ // // }
373
+ // // }
374
+ // // // Map module resource to chunk IDs
375
+ // // if (!this.moduleResourceToChunkIds.has(moduleResource)) {
376
+ // // this.moduleResourceToChunkIds.set(moduleResource, new Set());
377
+ // // }
378
+ // // this.moduleResourceToChunkIds.get(moduleResource).add(chunkIdString);
379
+ // // }
380
+ // // }
381
+ // // // Store in the map if there are required sections
382
+ // // if (requiredSections.size > 0) {
383
+ // // this.chunkIdToSectionsMap[chunkIdString] = Array.from(requiredSections);
384
+ // // }
385
+ // // // Map chunkId to module resources
386
+ // // if (moduleResources.length > 0) {
387
+ // // this.moduleChunkIdToModulesMap[chunkIdString] = moduleResources;
388
+ // // }
389
+ // // }
390
+ // // // Collect all used keys
391
+ // // this.allUsedKeys = new Set();
392
+ // // for (const keys of this.moduleToKeysMap.values()) {
393
+ // // for (const key of keys) {
394
+ // // this.allUsedKeys.add(key);
395
+ // // }
396
+ // // }
397
+ // // // Collect entry point keys
398
+ // // this.entryPointKeys = new Set();
399
+ // // for (const moduleResource of entryPointModules) {
400
+ // // const keys = this.moduleToKeysMap.get(moduleResource);
401
+ // // if (keys) {
402
+ // // for (const key of keys) {
403
+ // // this.entryPointKeys.add(key);
404
+ // // }
405
+ // // }
406
+ // // }
407
+ // // // Collect unused keys
408
+ // // this.allKeysInProperties = new Set();
409
+ // // const firstLocale = Object.keys(this.allI18nKeys)[0];
410
+ // // const sections = this.allI18nKeys[firstLocale];
411
+ // // for (const section of Object.values(sections)) {
412
+ // // for (const key of Object.keys(section)) {
413
+ // // this.allKeysInProperties.add(key);
414
+ // // }
415
+ // // }
416
+ // // this.unusedKeys = new Set([...this.allKeysInProperties].filter(key => !this.allUsedKeys.has(key)));
417
+ // // // Remove entry point keys from allUsedKeys
418
+ // // this.remainingKeys = new Set([...this.allUsedKeys].filter(key => !this.entryPointKeys.has(key)));
419
+ // // // Emit the i18n chunks
420
+ // // this.emitI18nChunks(compilation);
421
+ // // }
422
+ // // getValueForKeyInLocale(key, locale) {
423
+ // // const sections = this.allI18nKeys[locale];
424
+ // // for (const sectionName in sections) {
425
+ // // const section = sections[sectionName];
426
+ // // if (key in section) {
427
+ // // return section[key];
428
+ // // }
429
+ // // }
430
+ // // return undefined;
431
+ // // }
432
+ // // emitI18nChunks(compilation) {
433
+ // // const manifest = {
434
+ // // moduleToI18nChunkMap: {},
435
+ // // locales: {},
436
+ // // };
437
+ // // // Get the list of locales
438
+ // // const locales = Object.keys(this.allI18nKeys);
439
+ // // // Initialize i18nChunkId counter
440
+ // // let i18nChunkIdCounter = 0;
441
+ // // const sectionToI18nChunkIdMap = {};
442
+ // // // Assign each section to an i18n chunk
443
+ // // // Assuming all locales have the same sections as the first locale
444
+ // // const firstLocale = locales[0];
445
+ // // const sections = Object.keys(this.allI18nKeys[firstLocale]);
446
+ // // for (const sectionName of sections) {
447
+ // // const i18nChunkId = i18nChunkIdCounter++;
448
+ // // sectionToI18nChunkIdMap[sectionName] = i18nChunkId;
449
+ // // // Collect keys for this section from the first locale
450
+ // // const keys = Object.keys(this.allI18nKeys[firstLocale][sectionName] || {});
451
+ // // // Map keys to i18nChunkId
452
+ // // for (const key of keys) {
453
+ // // this.keyToI18nChunkIdMap[key] = i18nChunkId;
454
+ // // }
455
+ // // // Generate the i18n chunk for each locale
456
+ // // for (const locale of locales) {
457
+ // // manifest.locales[locale] = manifest.locales[locale] || {};
458
+ // // const i18nData = {};
459
+ // // const localeSectionKeys = this.allI18nKeys[locale][sectionName] || {};
460
+ // // for (const key of keys) {
461
+ // // const value = localeSectionKeys[key];
462
+ // // if (value !== undefined) {
463
+ // // i18nData[key] = value;
464
+ // // }
465
+ // // }
466
+ // // if (Object.keys(i18nData).length > 0) {
467
+ // // const moduleSource = `window.loadI18nChunk(${JSON.stringify(i18nData, null, 2)});`;
468
+ // // const filename = `i18n-chunks/${locale}/${sectionName}chunk-${i18nChunkId}.js`;
469
+ // // compilation.emitAsset(filename, new RawSource(moduleSource));
470
+ // // manifest.locales[locale][i18nChunkId] = filename;
471
+ // // }
472
+ // // }
473
+ // // }
474
+ // // // Now, create moduleToI18nChunkMap
475
+ // // for (const [moduleChunkId, moduleResources] of Object.entries(
476
+ // // this.moduleChunkIdToModulesMap
477
+ // // )) {
478
+ // // const requiredI18nChunkIds = new Set();
479
+ // // for (const moduleResource of moduleResources) {
480
+ // // const keys = this.moduleToKeysMap.get(moduleResource);
481
+ // // if (keys) {
482
+ // // for (const key of keys) {
483
+ // // const i18nChunkId = this.keyToI18nChunkIdMap[key];
484
+ // // if (i18nChunkId !== undefined) {
485
+ // // requiredI18nChunkIds.add(i18nChunkId);
486
+ // // }
487
+ // // }
488
+ // // }
489
+ // // }
490
+ // // if (requiredI18nChunkIds.size > 0) {
491
+ // // manifest.moduleToI18nChunkMap[moduleChunkId] = Array.from(
492
+ // // requiredI18nChunkIds
493
+ // // );
494
+ // // } else {
495
+ // // console.log(
496
+ // // `No required i18n chunks for module chunk ID ${moduleChunkId}`
497
+ // // );
498
+ // // }
499
+ // // }
500
+ // // // Emit the manifest file
501
+ // // // const manifestSource = new RawSource(
502
+ // // // `window.i18n = window.i18n || {}; window.i18n.manifest = ${JSON.stringify(
503
+ // // // manifest,
504
+ // // // null,
505
+ // // // 2
506
+ // // // )};`
507
+ // // // );
508
+ // // // const manifestFilename = 'i18n-chunks/manifest.js';
509
+ // // // compilation.emitAsset(manifestFilename, manifestSource);
510
+ // // // console.log(`Emitted i18n manifest: ${manifestFilename}`);
511
+ // // // Generate the manifests using the external module
512
+ // // generateManifests({
513
+ // // compilation,
514
+ // // allI18nKeys: this.allI18nKeys,
515
+ // // moduleToKeysMap: this.moduleToKeysMap,
516
+ // // keyToModulesMap: this.keyToModulesMap,
517
+ // // moduleChunkIdToModulesMap: this.moduleChunkIdToModulesMap,
518
+ // // keyToI18nChunkIdMap: this.keyToI18nChunkIdMap, // Pass this map
519
+ // // sectionToI18nChunkIdMap: sectionToI18nChunkIdMap, // Pass if needed
520
+ // // // Remove NUMBER_OF_CHUNKS and entryPointKeys if not used
521
+ // // });
522
+ // // }
523
+ // // }
524
+ // // module.exports = I18nPlugin;
525
+ // // const path = require('path');
526
+ // // const fs = require('fs');
527
+ // // const {
528
+ // // getAllI18nGroupedBySection,
529
+ // // getPropertiesAsJSON,
530
+ // // } = require('../I18nSplitPlugin/utils/propertiesUtils');
531
+ // // const {
532
+ // // collectI18nKeysfromAST,
533
+ // // collectI18nKeysfromComments,
534
+ // // } = require('../I18nSplitPlugin/utils/collectI18nKeys');
535
+ // // const NullFactory = require('webpack/lib/NullFactory');
536
+ // // const {
537
+ // // I18nDependency,
538
+ // // I18nDependencyTemplate,
539
+ // // } = require('../I18nSplitPlugin/I18nDependency');
540
+ // // const { generateManifests } = require('./utils/manifestGenerator');
541
+ // // const pluginName = 'I18nPlugin';
542
+ // // class I18nPlugin {
543
+ // // constructor(options = {}) {
544
+ // // const {
545
+ // // jsResourcePath,
546
+ // // mainChunkName,
547
+ // // propertiesFolder,
548
+ // // disableDefault,
549
+ // // jsResource,
550
+ // // } = options;
551
+ // // if (!jsResourcePath) {
552
+ // // throw new Error('I18nPlugin: "jsResourcePath" option is required.');
553
+ // // }
554
+ // // if (!mainChunkName) {
555
+ // // throw new Error('I18nPlugin: "mainChunkName" option is required.');
556
+ // // }
557
+ // // this.jsResourcePath = jsResourcePath;
558
+ // // this.entryPointName = mainChunkName;
559
+ // // this.jsResourceI18nKeys = jsResource ? getPropertiesAsJSON(jsResource) : {};
560
+ // // // Group keys by sections
561
+ // // this.allI18nKeys = getAllI18nGroupedBySection({
562
+ // // folderPath: propertiesFolder,
563
+ // // disableDefault,
564
+ // // jsResourceI18nKeys: this.jsResourceI18nKeys,
565
+ // // });
566
+ // // console.log('Locales found:', Object.keys(this.allI18nKeys));
567
+ // // // Build keyToSectionMap
568
+ // // this.keyToSectionMap = {};
569
+ // // const locales = Object.keys(this.allI18nKeys);
570
+ // // if (locales.length > 0) {
571
+ // // const firstLocale = locales[0];
572
+ // // const sections = this.allI18nKeys[firstLocale];
573
+ // // console.log(
574
+ // // `Sections found in properties files: ${Object.keys(sections).join(
575
+ // // ', '
576
+ // // )}`
577
+ // // );
578
+ // // for (const sectionName of Object.keys(sections)) {
579
+ // // const keysInSection = sections[sectionName];
580
+ // // for (const key of Object.keys(keysInSection)) {
581
+ // // if (this.jsResourceI18nKeys.hasOwnProperty(key)) {
582
+ // // this.keyToSectionMap[key] = sectionName;
583
+ // // }
584
+ // // }
585
+ // // }
586
+ // // }
587
+ // // this.moduleToKeysMap = new Map();
588
+ // // this.keyToModulesMap = new Map();
589
+ // // }
590
+ // // defineI18nDependency(compilation) {
591
+ // // compilation.dependencyFactories.set(I18nDependency, new NullFactory());
592
+ // // compilation.dependencyTemplates.set(
593
+ // // I18nDependency,
594
+ // // new I18nDependencyTemplate()
595
+ // // );
596
+ // // }
597
+ // // apply(compiler) {
598
+ // // compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
599
+ // // this.defineI18nDependency(compilation);
600
+ // // const handler = (parser) => {
601
+ // // parser.hooks.program.tap(pluginName, (ast, comments) => {
602
+ // // const { module } = parser.state;
603
+ // // if (!(module && /\.jsx?$/.test(module.resource))) {
604
+ // // return;
605
+ // // }
606
+ // // // Collect i18n keys
607
+ // // let i18nKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
608
+ // // let commentKeys = collectI18nKeysfromComments(
609
+ // // comments,
610
+ // // this.jsResourceI18nKeys
611
+ // // );
612
+ // // i18nKeys = i18nKeys.concat(commentKeys);
613
+ // // if (i18nKeys.length) {
614
+ // // // Store the keys for this module
615
+ // // this.moduleToKeysMap.set(module.resource, i18nKeys);
616
+ // // // Map keys to modules
617
+ // // for (const key of i18nKeys) {
618
+ // // if (!this.keyToModulesMap.has(key)) {
619
+ // // this.keyToModulesMap.set(key, new Set());
620
+ // // }
621
+ // // this.keyToModulesMap.get(key).add(module.resource);
622
+ // // }
623
+ // // }
624
+ // // });
625
+ // // };
626
+ // // const factory = params.normalModuleFactory;
627
+ // // factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
628
+ // // factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
629
+ // // compilation.hooks.afterOptimizeChunks.tap(pluginName, () => {
630
+ // // this.processCollectedKeys(compilation);
631
+ // // });
632
+ // // });
633
+ // // }
634
+ // // processCollectedKeys(compilation) {
635
+ // // this.chunkIdToSectionsMap = {};
636
+ // // this.moduleChunkIdToModulesMap = {};
637
+ // // this.moduleResourceToChunkIds = new Map();
638
+ // // const entryPointChunk = compilation.namedChunks.get(this.entryPointName);
639
+ // // const entryPointModules = new Set();
640
+ // // if (entryPointChunk) {
641
+ // // for (const module of entryPointChunk.getModules()) {
642
+ // // if (module.resource) {
643
+ // // entryPointModules.add(module.resource);
644
+ // // }
645
+ // // }
646
+ // // }
647
+ // // for (const chunk of compilation.chunks) {
648
+ // // const chunkId = chunk.name || chunk.id;
649
+ // // const chunkIdString = String(chunkId);
650
+ // // const modules = chunk.getModules();
651
+ // // let requiredSections = new Set();
652
+ // // let moduleResources = [];
653
+ // // for (const module of modules) {
654
+ // // const moduleResource = module.resource;
655
+ // // if (moduleResource) {
656
+ // // moduleResources.push(moduleResource);
657
+ // // const keys = this.moduleToKeysMap.get(moduleResource);
658
+ // // if (keys) {
659
+ // // for (const key of keys) {
660
+ // // const section = this.keyToSectionMap[key];
661
+ // // if (section) {
662
+ // // requiredSections.add(section);
663
+ // // }
664
+ // // }
665
+ // // }
666
+ // // if (!this.moduleResourceToChunkIds.has(moduleResource)) {
667
+ // // this.moduleResourceToChunkIds.set(moduleResource, new Set());
668
+ // // }
669
+ // // this.moduleResourceToChunkIds
670
+ // // .get(moduleResource)
671
+ // // .add(chunkIdString);
672
+ // // }
673
+ // // }
674
+ // // if (requiredSections.size > 0) {
675
+ // // this.chunkIdToSectionsMap[chunkIdString] = Array.from(
676
+ // // requiredSections
677
+ // // );
678
+ // // }
679
+ // // if (moduleResources.length > 0) {
680
+ // // this.moduleChunkIdToModulesMap[chunkIdString] = moduleResources;
681
+ // // }
682
+ // // }
683
+ // // // Collect all used keys
684
+ // // this.allUsedKeys = new Set();
685
+ // // for (const keys of this.moduleToKeysMap.values()) {
686
+ // // for (const key of keys) {
687
+ // // this.allUsedKeys.add(key);
688
+ // // }
689
+ // // }
690
+ // // // Collect entry point keys
691
+ // // this.entryPointKeys = new Set();
692
+ // // for (const moduleResource of entryPointModules) {
693
+ // // const keys = this.moduleToKeysMap.get(moduleResource);
694
+ // // if (keys) {
695
+ // // for (const key of keys) {
696
+ // // this.entryPointKeys.add(key);
697
+ // // }
698
+ // // }
699
+ // // }
700
+ // // // Collect unused keys
701
+ // // this.allKeysInProperties = new Set();
702
+ // // const firstLocale = Object.keys(this.allI18nKeys)[0];
703
+ // // const sections = this.allI18nKeys[firstLocale];
704
+ // // for (const section of Object.values(sections)) {
705
+ // // for (const key of Object.keys(section)) {
706
+ // // this.allKeysInProperties.add(key);
707
+ // // }
708
+ // // }
709
+ // // this.unusedKeys = new Set(
710
+ // // [...this.allKeysInProperties].filter((key) => !this.allUsedKeys.has(key))
711
+ // // );
712
+ // // // Remove entry point keys from allUsedKeys
713
+ // // this.remainingKeys = new Set(
714
+ // // [...this.allUsedKeys].filter((key) => !this.entryPointKeys.has(key))
715
+ // // );
716
+ // // // Emit the i18n chunks
717
+ // // this.emitI18nChunks(compilation);
718
+ // // }
719
+ // // emitI18nChunks(compilation) {
720
+ // // generateManifests({
721
+ // // compilation,
722
+ // // allI18nKeys: this.allI18nKeys,
723
+ // // moduleToKeysMap: this.moduleToKeysMap,
724
+ // // keyToModulesMap: this.keyToModulesMap,
725
+ // // moduleChunkIdToModulesMap: this.moduleChunkIdToModulesMap,
726
+ // // jsResourceI18nKeys: this.jsResourceI18nKeys,
727
+ // // });
728
+ // // }
729
+ // // }
730
+ // // module.exports = I18nPlugin;
731
+ // const {
732
+ // getAllI18nGroupedBySection,
733
+ // getPropertiesAsJSON,
734
+ // } = require('../I18nSplitPlugin/utils/propertiesUtils');
735
+ // const {
736
+ // collectI18nKeysfromAST,
737
+ // collectI18nKeysfromComments,
738
+ // } = require('../I18nSplitPlugin/utils/collectI18nKeys');
739
+ // const NullFactory = require('webpack/lib/NullFactory');
740
+ // const {
741
+ // I18nDependency,
742
+ // I18nDependencyTemplate,
743
+ // } = require('../I18nSplitPlugin/I18nDependency');
744
+ // const { generateManifests } = require('./utils/manifestGenerator');
745
+ // const pluginName = 'I18nPlugin';
746
+ // class I18nPlugin {
747
+ // constructor(options = {}) {
748
+ // const {
749
+ // jsResourcePath,
750
+ // mainChunkName,
751
+ // propertiesFolder,
752
+ // disableDefault,
753
+ // jsResource,
754
+ // } = options;
755
+ // if (!jsResourcePath) {
756
+ // throw new Error('I18nPlugin: "jsResourcePath" option is required.');
757
+ // }
758
+ // if (!mainChunkName) {
759
+ // throw new Error('I18nPlugin: "mainChunkName" option is required.');
760
+ // }
761
+ // this.jsResourcePath = jsResourcePath;
762
+ // this.entryPointName = mainChunkName;
763
+ // this.jsResourceI18nKeys = jsResource ? getPropertiesAsJSON(jsResource) : {};
764
+ // // Group keys by locales
765
+ // this.allI18nKeys = getAllI18nGroupedBySection({
766
+ // folderPath: propertiesFolder,
767
+ // disableDefault,
768
+ // jsResourceI18nKeys: this.jsResourceI18nKeys,
769
+ // });
770
+ // console.log('Locales found:', Object.keys(this.allI18nKeys));
771
+ // this.moduleToKeysMap = new Map();
772
+ // this.keyToModulesMap = new Map();
773
+ // }
774
+ // defineI18nDependency(compilation) {
775
+ // compilation.dependencyFactories.set(I18nDependency, new NullFactory());
776
+ // compilation.dependencyTemplates.set(
777
+ // I18nDependency,
778
+ // new I18nDependencyTemplate()
779
+ // );
780
+ // }
781
+ // apply(compiler) {
782
+ // compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
783
+ // this.defineI18nDependency(compilation);
784
+ // const handler = (parser) => {
785
+ // parser.hooks.program.tap(pluginName, (ast, comments) => {
786
+ // const { module } = parser.state;
787
+ // if (!(module && /\.jsx?$/.test(module.resource))) {
788
+ // return;
789
+ // }
790
+ // // Collect i18n keys
791
+ // let i18nKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
792
+ // let commentKeys = collectI18nKeysfromComments(
793
+ // comments,
794
+ // this.jsResourceI18nKeys
795
+ // );
796
+ // i18nKeys = i18nKeys.concat(commentKeys);
797
+ // if (i18nKeys.length) {
798
+ // // Store the keys for this module
799
+ // this.moduleToKeysMap.set(module.resource, i18nKeys);
800
+ // // Map keys to modules
801
+ // for (const key of i18nKeys) {
802
+ // if (!this.keyToModulesMap.has(key)) {
803
+ // this.keyToModulesMap.set(key, new Set());
804
+ // }
805
+ // this.keyToModulesMap.get(key).add(module.resource);
806
+ // }
807
+ // }
808
+ // });
809
+ // };
810
+ // const factory = params.normalModuleFactory;
811
+ // factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
812
+ // factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
813
+ // compilation.hooks.afterOptimizeChunks.tap(pluginName, () => {
814
+ // this.processCollectedKeys(compilation);
815
+ // });
816
+ // });
817
+ // }
818
+ // processCollectedKeys(compilation) {
819
+ // this.chunkToModulesMap = new Map();
820
+ // for (const chunk of compilation.chunks) {
821
+ // const chunkId = chunk.name || chunk.id;
822
+ // const chunkIdString = String(chunkId);
823
+ // const modules = chunk.getModules();
824
+ // const moduleResources = [];
825
+ // for (const module of modules) {
826
+ // const moduleResource = module.resource;
827
+ // if (moduleResource) {
828
+ // moduleResources.push(moduleResource);
829
+ // }
830
+ // }
831
+ // if (moduleResources.length > 0) {
832
+ // this.chunkToModulesMap.set(chunkIdString, moduleResources);
833
+ // }
834
+ // }
835
+ // // Emit the i18n chunks
836
+ // this.emitI18nChunks(compilation);
837
+ // }
838
+ // emitI18nChunks(compilation) {
839
+ // generateManifests({
840
+ // compilation,
841
+ // allI18nKeys: this.allI18nKeys,
842
+ // moduleToKeysMap: this.moduleToKeysMap,
843
+ // chunkToModulesMap: this.chunkToModulesMap,
844
+ // jsResourceI18nKeys: this.jsResourceI18nKeys,
845
+ // });
846
+ // }
847
+ // }
848
+ // module.exports = I18nPlugin;
849
+ const {
850
+ getAllI18nGroupedBySection,
851
+ getPropertiesAsJSON
852
+ } = require('../I18nSplitPlugin/utils/propertiesUtils');
853
+ const {
854
+ collectI18nKeysfromAST,
855
+ collectI18nKeysfromComments
856
+ } = require('../I18nSplitPlugin/utils/collectI18nKeys');
857
+ const NullFactory = require('webpack/lib/NullFactory');
858
+ const {
859
+ I18nDependency,
860
+ I18nDependencyTemplate
861
+ } = require('../I18nSplitPlugin/I18nDependency');
862
+ const {
863
+ generateManifests
864
+ } = require('./utils/manifestGenerator');
865
+ const pluginName = 'I18nPlugin';
866
+ class I18nPlugin {
867
+ constructor(options = {}) {
868
+ const {
869
+ jsResourcePath,
870
+ mainChunkName,
871
+ propertiesFolder,
872
+ disableDefault,
873
+ jsResource
874
+ } = options;
875
+ if (!jsResourcePath) {
876
+ throw new Error('I18nPlugin: "jsResourcePath" option is required.');
877
+ }
878
+ if (!mainChunkName) {
879
+ throw new Error('I18nPlugin: "mainChunkName" option is required.');
880
+ }
881
+ this.jsResourcePath = jsResourcePath;
882
+ this.entryPointName = mainChunkName;
883
+ this.jsResourceI18nKeys = jsResource ? getPropertiesAsJSON(jsResource) : {}; // Group keys by locales
884
+
885
+ this.allI18nKeys = getAllI18nGroupedBySection({
886
+ folderPath: propertiesFolder,
887
+ disableDefault,
888
+ jsResourceI18nKeys: this.jsResourceI18nKeys
889
+ });
890
+ console.log('Locales found:', Object.keys(this.allI18nKeys));
891
+ this.moduleToKeysMap = new Map();
892
+ this.keyToModulesMap = new Map();
893
+ }
894
+ defineI18nDependency(compilation) {
895
+ compilation.dependencyFactories.set(I18nDependency, new NullFactory());
896
+ compilation.dependencyTemplates.set(I18nDependency, new I18nDependencyTemplate());
897
+ }
898
+ apply(compiler) {
899
+ compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
900
+ this.defineI18nDependency(compilation);
901
+ const handler = parser => {
902
+ parser.hooks.program.tap(pluginName, (ast, comments) => {
903
+ const {
904
+ module
905
+ } = parser.state;
906
+ if (!(module && /\.jsx?$/.test(module.resource))) {
907
+ return;
908
+ } // Collect i18n keys
909
+
910
+ let i18nKeys = collectI18nKeysfromAST(ast, this.jsResourceI18nKeys);
911
+ let commentKeys = collectI18nKeysfromComments(comments, this.jsResourceI18nKeys);
912
+ i18nKeys = i18nKeys.concat(commentKeys);
913
+ if (i18nKeys.length) {
914
+ // Store the keys for this module
915
+ this.moduleToKeysMap.set(module.resource, i18nKeys); // Map keys to modules
916
+
917
+ for (const key of i18nKeys) {
918
+ if (!this.keyToModulesMap.has(key)) {
919
+ this.keyToModulesMap.set(key, new Set());
920
+ }
921
+ this.keyToModulesMap.get(key).add(module.resource);
922
+ }
923
+ }
924
+ });
925
+ };
926
+ const factory = params.normalModuleFactory;
927
+ factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
928
+ factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
929
+ compilation.hooks.afterOptimizeChunks.tap(pluginName, () => {
930
+ this.processCollectedKeys(compilation);
931
+ });
932
+ });
933
+ }
934
+ processCollectedKeys(compilation) {
935
+ this.cacheGroupToModulesMap = new Map();
936
+ for (const chunk of compilation.chunks) {
937
+ const chunkName = chunk.name || chunk.id;
938
+ const modules = chunk.getModules ? chunk.getModules() : chunk.modulesIterable;
939
+ for (const module of modules) {
940
+ const moduleResource = module.resource;
941
+ if (moduleResource) {
942
+ // Get the cache group name for the chunk
943
+ const cacheGroupName = this.getCacheGroupName(chunk);
944
+ if (!cacheGroupName) continue;
945
+ if (!this.cacheGroupToModulesMap.has(cacheGroupName)) {
946
+ this.cacheGroupToModulesMap.set(cacheGroupName, new Set());
947
+ }
948
+ this.cacheGroupToModulesMap.get(cacheGroupName).add(moduleResource);
949
+ }
950
+ }
951
+ } // Emit the i18n chunks
952
+
953
+ this.emitI18nChunks(compilation);
954
+ }
955
+ getCacheGroupName(chunk) {
956
+ // This function attempts to retrieve the cache group name for a chunk.
957
+ // Since Webpack doesn't expose cache group names directly, we may need to use chunk names or IDs.
958
+ // If you're using named chunks and cache groups, you can map chunk names to cache group names.
959
+ // For example, if your cache groups assign names to chunks, you can use chunk.name.
960
+ // In this example, we'll assume chunk.name corresponds to the cache group name.
961
+ // You may need to adjust this based on your configuration.
962
+ return chunk.name;
963
+ }
964
+ emitI18nChunks(compilation) {
965
+ generateManifests({
966
+ compilation,
967
+ allI18nKeys: this.allI18nKeys,
968
+ moduleToKeysMap: this.moduleToKeysMap,
969
+ cacheGroupToModulesMap: this.cacheGroupToModulesMap,
970
+ jsResourceI18nKeys: this.jsResourceI18nKeys
971
+ });
972
+ }
973
+ }
974
+ module.exports = I18nPlugin;