@zohodesk/client_build_tool 0.0.11-exp.16 → 0.0.11-exp.16.0

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 (226) hide show
  1. package/README.md +0 -204
  2. package/README_backup.md +0 -204
  3. package/docs/DYNAMIC_TEMPLATE_EXAMPLE.md +129 -0
  4. package/docs/I18N_NUMERIC_INDEXING_PLUGIN.md +225 -0
  5. package/docs/I18N_SINGLE_FILE_MODE.md +126 -0
  6. package/docs/client_build_tool_source_doc.md +390 -0
  7. package/example-single-file-config.js +59 -0
  8. package/lib/allCommandsConfigs.js +2 -7
  9. package/lib/commands/build/commandExecutor.js +1 -5
  10. package/lib/commands/build/config.js +2 -3
  11. package/lib/commands/build/optionsProcessor.js +2 -5
  12. package/lib/commands/build/preProcessor.js +0 -2
  13. package/lib/commands/buildEs/commandExecutor.js +0 -5
  14. package/lib/commands/buildEs/config.js +2 -3
  15. package/lib/commands/buildEs/preProcessor.js +0 -2
  16. package/lib/commands/buildLib/commandExecutor.js +0 -5
  17. package/lib/commands/buildLib/config.js +2 -3
  18. package/lib/commands/buildLib/preProcessor.js +0 -2
  19. package/lib/commands/mockserver/commandExecutor.js +2 -9
  20. package/lib/commands/mockserver/config.js +2 -3
  21. package/lib/commands/pre_process/commandExecutor.js +0 -2
  22. package/lib/commands/pre_process/config.js +2 -3
  23. package/lib/commands/start/commandExecutor.js +0 -2
  24. package/lib/commands/start/config.js +2 -3
  25. package/lib/commands/start/optionsProcessor.js +2 -4
  26. package/lib/commands/start/preProcessor.js +0 -2
  27. package/lib/commands/template/commandExecutor.js +0 -7
  28. package/lib/commands/template/config.js +2 -3
  29. package/lib/commands/version/commandExecutor.js +0 -3
  30. package/lib/commands/version/config.js +2 -3
  31. package/lib/commandsRouter.js +5 -21
  32. package/lib/index.js +0 -2
  33. package/lib/logger.js +0 -5
  34. package/lib/schemas/applyValuesToSchema/index.js +0 -8
  35. package/lib/schemas/applyValuesToSchema/isObject.js +0 -1
  36. package/lib/schemas/applyValuesToSchema/isValid.js +0 -2
  37. package/lib/schemas/cliArgsToObject.js +2 -6
  38. package/lib/schemas/defaultConfigValues.js +31 -7
  39. package/lib/schemas/defaultConfigValuesOnly.js +4 -7
  40. package/lib/schemas/deprecatedOptionsHandler.js +7 -16
  41. package/lib/schemas/getNpmVersion.js +0 -5
  42. package/lib/schemas/giveDefaultValue.js +0 -3
  43. package/lib/schemas/npmConfigToObject.js +2 -5
  44. package/lib/schemas/readOptions.js +10 -30
  45. package/lib/schemas/readOptionsForConfigFile.js +2 -12
  46. package/lib/shared/babel/addDefaultPlugins.js +0 -2
  47. package/lib/shared/babel/babelWebConfig.js +1 -10
  48. package/lib/shared/babel/babel_plugins/removeAttributesPlugin.js +0 -4
  49. package/lib/shared/babel/getBabelPlugin.js +2 -7
  50. package/lib/shared/babel/runBabelForJSFile.js +1 -4
  51. package/lib/shared/babel/runBabelForTsFile.js +1 -5
  52. package/lib/shared/bundler/webpack/common/decidePublicPath.js +0 -5
  53. package/lib/shared/bundler/webpack/common/libAlias.js +3 -3
  54. package/lib/shared/bundler/webpack/common/modeUtils.js +0 -5
  55. package/lib/shared/bundler/webpack/common/nameTemplates.js +11 -18
  56. package/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +2 -3
  57. package/lib/shared/bundler/webpack/configCustomLoaders.js +0 -1
  58. package/lib/shared/bundler/webpack/cssLoaders.js +0 -2
  59. package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +1 -20
  60. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/index.js +20 -25
  61. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +4 -9
  62. package/lib/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +3 -23
  63. package/lib/shared/bundler/webpack/custom_plugins/EFCTemplatePlugin.js +8 -19
  64. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +120 -0
  65. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +81 -0
  66. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +328 -0
  67. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +135 -0
  68. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +5 -26
  69. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +13 -16
  70. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +19 -53
  71. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/LocaleChunkAssetsStore.js +2 -17
  72. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ModulesI18nKeysStore.js +0 -13
  73. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +11 -21
  74. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +0 -4
  75. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +4 -14
  76. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +3 -13
  77. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/iterateModulesInChunk.js +3 -12
  78. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +2 -7
  79. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +0 -2
  80. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +2 -3
  81. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +2 -4
  82. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +8 -13
  83. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +2 -14
  84. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/getChunkModules.js +0 -1
  85. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +1 -3
  86. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +0 -4
  87. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -22
  88. package/lib/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +3 -10
  89. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/addFilesNamesToManifestJson.js +1 -6
  90. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createInitialEntries.js +1 -6
  91. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createManifestJson.js +0 -6
  92. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/findInitialFileNames.js +0 -1
  93. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +0 -7
  94. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/removeHashFromFileName.js +0 -1
  95. package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +13 -17
  96. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +6 -15
  97. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +4 -13
  98. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +4 -6
  99. package/lib/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +0 -10
  100. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/classHandling.js +0 -3
  101. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/index.js +4 -20
  102. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js +10 -12
  103. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/windowsModification.js +2 -3
  104. package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +7 -20
  105. package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPluginUtils.js +0 -1
  106. package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +7 -10
  107. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/addHashToFilePath.js +1 -6
  108. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +1 -16
  109. package/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin/index.js.js +4 -11
  110. package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js +3 -10
  111. package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/index.js +27 -62
  112. package/lib/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +3 -15
  113. package/lib/shared/bundler/webpack/custom_plugins/emitAsset.js +0 -1
  114. package/lib/shared/bundler/webpack/custom_plugins/getInitialAssetsFuncTemplate.js +2 -12
  115. package/lib/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +2 -7
  116. package/lib/shared/bundler/webpack/defaultVendorPatternList.js +2 -6
  117. package/lib/shared/bundler/webpack/devtoolConfig.js +0 -1
  118. package/lib/shared/bundler/webpack/entryConfig.js +0 -4
  119. package/lib/shared/bundler/webpack/externals.js +0 -1
  120. package/lib/shared/bundler/webpack/getCSSLoaders.js +1 -6
  121. package/lib/shared/bundler/webpack/getFilenameFromModule.js +1 -5
  122. package/lib/shared/bundler/webpack/jsLoaders.js +23 -4
  123. package/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +0 -2
  124. package/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +2 -3
  125. package/lib/shared/bundler/webpack/loaderConfigs/checkIsPatternsMatchFilename.js +3 -12
  126. package/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +0 -1
  127. package/lib/shared/bundler/webpack/loaderConfigs/configPostCssLoader.js +2 -10
  128. package/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +0 -2
  129. package/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +0 -12
  130. package/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +1 -15
  131. package/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +1 -4
  132. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +72 -0
  133. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +113 -0
  134. package/lib/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +2 -2
  135. package/lib/shared/bundler/webpack/loaders/workerLoader.js +8 -19
  136. package/lib/shared/bundler/webpack/optimizationConfig.js +5 -13
  137. package/lib/shared/bundler/webpack/outputConfig.js +1 -9
  138. package/lib/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +5 -9
  139. package/lib/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +0 -5
  140. package/lib/shared/bundler/webpack/pluginConfigs/configCSSMinifierPlugin.js +4 -9
  141. package/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +3 -8
  142. package/lib/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +1 -16
  143. package/lib/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +0 -4
  144. package/lib/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +0 -16
  145. package/lib/shared/bundler/webpack/pluginConfigs/configEFCTemplatePlugin.js +0 -5
  146. package/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +0 -5
  147. package/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +2 -8
  148. package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +38 -0
  149. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +86 -0
  150. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +92 -0
  151. package/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +3 -9
  152. package/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +0 -2
  153. package/lib/shared/bundler/webpack/pluginConfigs/configManifestJsonPlugin.js +0 -7
  154. package/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +3 -7
  155. package/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +1 -5
  156. package/lib/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +1 -4
  157. package/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +0 -4
  158. package/lib/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +3 -8
  159. package/lib/shared/bundler/webpack/pluginConfigs/configSelectorWeightPlugin.js +1 -6
  160. package/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +3 -8
  161. package/lib/shared/bundler/webpack/pluginConfigs/configSourceMapPlugin.js +0 -4
  162. package/lib/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +1 -8
  163. package/lib/shared/bundler/webpack/pluginConfigs/configVariableConversionPlugin.js +1 -6
  164. package/lib/shared/bundler/webpack/plugins.js +3 -24
  165. package/lib/shared/bundler/webpack/resolvers.js +3 -17
  166. package/lib/shared/bundler/webpack/splitChunksConfig.js +2 -15
  167. package/lib/shared/bundler/webpack/statsConfig.js +2 -5
  168. package/lib/shared/bundler/webpack/tsLoaders.js +2 -4
  169. package/lib/shared/bundler/webpack/utils/index.js +1 -12
  170. package/lib/shared/bundler/webpack/utils/object-manipulation.js +2 -16
  171. package/lib/shared/bundler/webpack/utils/updateArrayWithDefault.js +0 -7
  172. package/lib/shared/bundler/webpack/webpackBuild.js +1 -8
  173. package/lib/shared/bundler/webpack/webpackConfig.js +0 -17
  174. package/lib/shared/commands-utils/doBasicRequirementCheck.js +0 -3
  175. package/lib/shared/commands-utils/getCliPath.js +5 -9
  176. package/lib/shared/commands-utils/index.js +0 -3
  177. package/lib/shared/commands-utils/log.js +0 -2
  178. package/lib/shared/commands-utils/readArgsFormCommandLine.js +0 -1
  179. package/lib/shared/commands-utils/readOptionFormCommandLine.js +0 -1
  180. package/lib/shared/commands-utils/spawnSyncIO.js +5 -13
  181. package/lib/shared/constants.js +9 -29
  182. package/lib/shared/fileUtils/copyFile.js +1 -8
  183. package/lib/shared/fileUtils/directoryIterator.js +0 -4
  184. package/lib/shared/fileUtils/watchRun.js +3 -24
  185. package/lib/shared/postcss/custom_postcss_plugins/EmptyPlugin.js +1 -6
  186. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/constants.js +2 -3
  187. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js +6 -13
  188. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/index.js +6 -26
  189. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/insertBefore.js +6 -9
  190. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js +0 -3
  191. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js +2 -7
  192. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js +0 -2
  193. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/specialCases.js +4 -9
  194. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js +0 -10
  195. package/lib/shared/postcss/custom_postcss_plugins/RTLSplitPlugin.js +16 -29
  196. package/lib/shared/postcss/custom_postcss_plugins/SelectorReplace.js +0 -17
  197. package/lib/shared/postcss/custom_postcss_plugins/ValueReplacer.js +4 -9
  198. package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +28 -64
  199. package/lib/shared/postcss/filterPluginsAllowedForSpecficFile.js +5 -13
  200. package/lib/shared/postcss/getAllowedPostCssPlugins.js +0 -3
  201. package/lib/shared/postcss/getSpecificPostCssPlugin.js +7 -17
  202. package/lib/shared/postcss/runPostCssForCssFile.js +1 -9
  203. package/lib/shared/pre_process/runPreProcess.js +0 -11
  204. package/lib/shared/server/configWebpackDevMiddleware.js +1 -8
  205. package/lib/shared/server/corsHandling.js +2 -6
  206. package/lib/shared/server/getIp.js +1 -7
  207. package/lib/shared/server/getServerURL.js +0 -6
  208. package/lib/shared/server/httpsOptions.js +0 -11
  209. package/lib/shared/server/initExpressApp.js +1 -4
  210. package/lib/shared/server/initialHTMLHandling.js +7 -16
  211. package/lib/shared/server/mockApiHandler.js +8 -16
  212. package/lib/shared/server/mockServer.js +0 -7
  213. package/lib/shared/server/serveContextFiles.js +1 -5
  214. package/lib/shared/server/serverBywebpackDevMiddleware.js +4 -9
  215. package/lib/shared/server/startHttpServer.js +0 -3
  216. package/lib/shared/server/startHttpsServer.js +1 -9
  217. package/lib/shared/server/unwanted/addHttp2Server.js +2 -7
  218. package/lib/shared/server/unwanted/configWebpackDevMiddleware.js +1 -8
  219. package/lib/shared/server/unwanted/mockApiSupport.js +0 -2
  220. package/lib/shared/server/unwanted/websocketMockSetup.js +1 -7
  221. package/lib/shared/server/urlConcat.js +3 -8
  222. package/lib/shared/utils/requireLocalOrGlobal.js +10 -25
  223. package/lib/shared/utils/versionPrint.js +1 -6
  224. package/npm-shrinkwrap.json +2 -2
  225. package/package.json +1 -1
  226. package/packages/client_build_tool/test-i18n-config.js +22 -0
@@ -0,0 +1,328 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _fs = _interopRequireDefault(require("fs"));
8
+ var _path = _interopRequireDefault(require("path"));
9
+ var _webpack = require("webpack");
10
+ var _propertiesUtils = require("../I18nSplitPlugin/utils/propertiesUtils");
11
+ var _I18nGroupRuntimeModule = require("./I18nGroupRuntimeModule");
12
+ var _i18nDataLoader = require("./utils/i18nDataLoader");
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ const {
15
+ RawSource
16
+ } = _webpack.sources;
17
+ const pluginName = 'I18nNumericIndexPlugin';
18
+ class I18nNumericIndexPlugin {
19
+ constructor(options) {
20
+ this.options = {
21
+ ...options,
22
+ singleFile: options.singleFile || false,
23
+ singleFileTemplate: options.singleFileTemplate || '[locale].js',
24
+ includeContentHash: options.includeContentHash || false,
25
+ generateManifest: options.generateManifest || false,
26
+ outputFolder: options.outputFolder || 'i18n-chunk',
27
+ manifestPath: options.manifestPath || null
28
+ };
29
+ this.numericMap = {};
30
+ this.customGroups = {};
31
+ this.manifest = {};
32
+ }
33
+ apply(compiler) {
34
+ // Detect webpackI18nGroup comments in code
35
+ this.detectI18nGroupComments(compiler);
36
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
37
+ // Add runtime module for group-based loading
38
+ if (this.options.customGroups) {
39
+ compilation.hooks.runtimeRequirementInTree.for(_webpack.RuntimeGlobals.ensureChunk).tap(pluginName, chunk => {
40
+ compilation.addRuntimeModule(chunk, new _I18nGroupRuntimeModule.I18nGroupRuntimeModule({
41
+ customGroups: this.options.customGroups,
42
+ localeVarName: this.options.localeVarName,
43
+ jsonpFunc: this.options.jsonpFunc
44
+ }));
45
+ });
46
+ }
47
+ compilation.hooks.processAssets.tap({
48
+ name: pluginName,
49
+ stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
50
+ }, () => {
51
+ this.processI18nFiles(compilation);
52
+ });
53
+ });
54
+ }
55
+ detectI18nGroupComments(compiler) {
56
+ compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
57
+ factory.hooks.parser.for('javascript/auto').tap(pluginName, parser => {
58
+ parser.hooks.importCall.tap(pluginName, expr => {
59
+ // Check for webpackI18nGroup comment
60
+ const comments = expr.leadingComments || [];
61
+ comments.forEach(comment => {
62
+ if (comment.value && comment.value.includes('webpackI18nGroup')) {
63
+ const match = comment.value.match(/webpackI18nGroup:\s*["']([^"']+)["']/);
64
+ if (match) {
65
+ const groupName = match[1];
66
+ // Store this information for later use
67
+ if (!this.detectedGroups) {
68
+ this.detectedGroups = {};
69
+ }
70
+ // Extract chunk name from webpackChunkName comment
71
+ const chunkNameMatch = comment.value.match(/webpackChunkName:\s*["']([^"']+)["']/);
72
+ if (chunkNameMatch) {
73
+ const chunkName = chunkNameMatch[1];
74
+ this.detectedGroups[chunkName] = groupName;
75
+ }
76
+ }
77
+ }
78
+ });
79
+ });
80
+ });
81
+ });
82
+ }
83
+ processI18nFiles(compilation) {
84
+ const {
85
+ jsResourcePath,
86
+ propertiesFolderPath,
87
+ numericMapPath,
88
+ customGroups,
89
+ jsonpFunc,
90
+ numericFilenameTemplate,
91
+ dynamicFilenameTemplate
92
+ } = this.options;
93
+ if (!jsResourcePath || !propertiesFolderPath) {
94
+ return;
95
+ }
96
+
97
+ // Load existing numeric map if available
98
+ if (numericMapPath) {
99
+ const mapData = (0, _i18nDataLoader.loadNumericMap)(numericMapPath, compilation);
100
+ if (mapData && mapData.sortedKeys) {
101
+ // Initialize numericMap from existing data
102
+ mapData.sortedKeys.forEach((key, id) => {
103
+ if (key) {
104
+ this.numericMap[key] = id;
105
+ }
106
+ });
107
+ }
108
+ }
109
+
110
+ // Read JSResources.properties
111
+ const jsResourceKeys = (0, _propertiesUtils.getPropertiesAsJSON)(jsResourcePath);
112
+
113
+ // Parse custom groups from banner markers
114
+ if (customGroups) {
115
+ this.parseCustomGroups(jsResourcePath, customGroups);
116
+ }
117
+
118
+ // Get all locale translations
119
+ const allI18nObject = (0, _propertiesUtils.getAllI18n)({
120
+ folderPath: propertiesFolderPath,
121
+ disableDefault: false,
122
+ jsResourceI18nKeys: jsResourceKeys
123
+ });
124
+
125
+ // For en_US, use only JSResources (don't merge with ApplicationResources_en_US)
126
+ if (allI18nObject['en_US']) {
127
+ allI18nObject['en_US'] = jsResourceKeys;
128
+ } else {
129
+ // If en_US doesn't exist in the folder, create it from JSResources
130
+ allI18nObject['en_US'] = jsResourceKeys;
131
+ }
132
+ const locales = Object.keys(allI18nObject);
133
+
134
+ // Process each locale
135
+ locales.forEach(locale => {
136
+ const localeData = allI18nObject[locale];
137
+ const numericData = {};
138
+ const dynamicData = {};
139
+ const groupData = {};
140
+
141
+ // Initialize custom groups
142
+ Object.keys(customGroups || {}).forEach(groupName => {
143
+ groupData[groupName] = {};
144
+ });
145
+
146
+ // Process each key
147
+ Object.keys(localeData).forEach(key => {
148
+ const value = localeData[key];
149
+
150
+ // Simple logic: if has numeric ID use it, otherwise it's dynamic
151
+ if (this.numericMap[key]) {
152
+ const numericKey = String(this.numericMap[key]);
153
+
154
+ // Check if belongs to a custom group
155
+ const belongsToGroup = this.getKeyGroup(key);
156
+ if (belongsToGroup) {
157
+ groupData[belongsToGroup][numericKey] = value;
158
+ } else {
159
+ numericData[numericKey] = value;
160
+ }
161
+ } else {
162
+ // No numeric ID = dynamic key (regardless of placeholders)
163
+ dynamicData[key] = value;
164
+ }
165
+ });
166
+
167
+ // Handle single-file mode or separate files
168
+ if (this.options.singleFile) {
169
+ // Combine numeric and dynamic data into a single file
170
+ const combinedData = {
171
+ ...numericData,
172
+ ...dynamicData
173
+ };
174
+ if (Object.keys(combinedData).length > 0) {
175
+ // Use singleFileTemplate for combined file - no fileType suffix needed
176
+ const singleFileTemplate = this.options.singleFileTemplate || '[locale].js';
177
+ this.emitChunk(compilation, singleFileTemplate, locale, combinedData, jsonpFunc, null, null);
178
+ }
179
+ } else {
180
+ // Emit numeric chunk
181
+ if (Object.keys(numericData).length > 0) {
182
+ this.emitChunk(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc, null, 'numeric');
183
+ }
184
+
185
+ // Emit dynamic chunk
186
+ if (Object.keys(dynamicData).length > 0) {
187
+ this.emitChunk(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
188
+ }
189
+ }
190
+
191
+ // Emit custom group chunks (always separate)
192
+ Object.entries(groupData).forEach(([groupName, data]) => {
193
+ const groupConfig = customGroups[groupName];
194
+ if (groupConfig && Object.keys(data).length > 0) {
195
+ const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
196
+ this.emitChunk(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
197
+ }
198
+ });
199
+ });
200
+
201
+ // Generate manifest file if enabled
202
+ if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
203
+ const manifestPath = this.options.manifestPath || _path.default.join(this.options.outputFolder, 'manifest.json');
204
+ const manifestContent = JSON.stringify(this.manifest, null, 2);
205
+ compilation.emitAsset(manifestPath, new RawSource(manifestContent));
206
+ }
207
+
208
+ // Don't save numeric map - it should only be generated by the external script
209
+ }
210
+ parseCustomGroups(jsResourcePath, customGroups) {
211
+ const content = _fs.default.readFileSync(jsResourcePath, 'utf-8');
212
+ const lines = content.split('\n');
213
+ Object.entries(customGroups).forEach(([groupName, config]) => {
214
+ const {
215
+ bannerStart,
216
+ bannerEnd
217
+ } = config;
218
+ let inGroup = false;
219
+ const groupKeys = [];
220
+ lines.forEach(line => {
221
+ if (line.includes(bannerStart)) {
222
+ inGroup = true;
223
+ } else if (line.includes(bannerEnd)) {
224
+ inGroup = false;
225
+ } else if (inGroup && line.includes('=')) {
226
+ const key = line.split('=')[0].trim();
227
+ if (key && !key.startsWith('#')) {
228
+ groupKeys.push(key);
229
+ }
230
+ }
231
+ });
232
+ this.customGroups[groupName] = groupKeys;
233
+ });
234
+ }
235
+ getKeyGroup(key) {
236
+ for (const [groupName, keys] of Object.entries(this.customGroups)) {
237
+ if (keys.includes(key)) {
238
+ return groupName;
239
+ }
240
+ }
241
+ return null;
242
+ }
243
+ isDynamicKey(value) {
244
+ // Check if value contains placeholders like {0}, {1}, etc.
245
+ return /\{\d+\}/.test(value);
246
+ }
247
+ getNumericKey(key) {
248
+ // Return numeric ID if it exists, null otherwise
249
+ return this.numericMap[key] ? String(this.numericMap[key]) : null;
250
+ }
251
+ generateContentHash(content, compilation) {
252
+ const {
253
+ hashFunction,
254
+ hashDigest,
255
+ hashDigestLength
256
+ } = compilation.outputOptions;
257
+ const hash = _webpack.util.createHash(hashFunction || 'xxhash64');
258
+ hash.update(content);
259
+ return hash.digest(hashDigest || 'hex').substring(0, hashDigestLength || 8);
260
+ }
261
+ constructFilePath(template, locale) {
262
+ const {
263
+ outputFolder,
264
+ singleFile
265
+ } = this.options;
266
+
267
+ // Replace locale placeholder
268
+ let filePath = template.replace(/\[locale\]/g, locale);
269
+
270
+ // If template already contains outputFolder or starts with a path separator, use as-is
271
+ if (filePath.includes(outputFolder) || filePath.startsWith('/')) {
272
+ return filePath.replace(/\\/g, '/');
273
+ }
274
+
275
+ // For single-file mode with a simple template like '[locale].js',
276
+ // put it directly in outputFolder without subdirectories
277
+ if (singleFile && !filePath.includes('/')) {
278
+ return _path.default.join(outputFolder, filePath).replace(/\\/g, '/');
279
+ }
280
+
281
+ // For other cases, if template contains subdirectories, preserve them
282
+ return _path.default.join(outputFolder, filePath).replace(/\\/g, '/');
283
+ }
284
+ emitChunk(compilation, filenameTemplate, locale, data, jsonpFunc, groupName = null, fileType = null) {
285
+ if (!filenameTemplate || Object.keys(data).length === 0) {
286
+ return null;
287
+ }
288
+ const content = this.generateChunkContent(data, jsonpFunc, groupName);
289
+ let outputPath = this.constructFilePath(filenameTemplate, locale);
290
+
291
+ // Handle [contenthash] placeholder in template
292
+ if (outputPath.includes('[contenthash]')) {
293
+ const contentHash = this.generateContentHash(content, compilation);
294
+ outputPath = outputPath.replace(/\[contenthash\]/g, contentHash);
295
+ } else if (this.options.includeContentHash) {
296
+ // Legacy: Add content hash before .js extension if includeContentHash is true
297
+ const contentHash = this.generateContentHash(content, compilation);
298
+ outputPath = outputPath.replace(/\.js$/, `.${contentHash}.js`);
299
+ }
300
+
301
+ // Track in manifest if enabled
302
+ if (this.options.generateManifest) {
303
+ // For single-file mode, use clean locale.js format
304
+ let manifestKey;
305
+ if (this.options.singleFile) {
306
+ // Just use locale.js without path or type suffix
307
+ manifestKey = `${locale}.js`;
308
+ } else {
309
+ // For multi-file mode, include the full path
310
+ const cleanName = this.constructFilePath(filenameTemplate, locale);
311
+ manifestKey = fileType ? cleanName.replace(/\.js$/, `.${fileType}.js`) : cleanName;
312
+ }
313
+ this.manifest[manifestKey] = _path.default.basename(outputPath);
314
+ }
315
+ compilation.emitAsset(outputPath, new RawSource(content));
316
+ return outputPath;
317
+ }
318
+ generateChunkContent(data, jsonpFunc, groupName) {
319
+ // Decode Unicode escapes to convert \uXXXX to actual characters
320
+ const jsonString = (0, _propertiesUtils.decodeUnicodeEscapes)(JSON.stringify(data));
321
+ if (groupName) {
322
+ // Include group name for lazy loading identification
323
+ return `${jsonpFunc}(${jsonString}, "${groupName}");`;
324
+ }
325
+ return `${jsonpFunc}(${jsonString});`;
326
+ }
327
+ }
328
+ exports.default = I18nNumericIndexPlugin;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const {
6
+ getPropertiesAsJSON
7
+ } = require('../../I18nSplitPlugin/utils/propertiesUtils');
8
+
9
+ /**
10
+ * Load and parse a properties file
11
+ */
12
+ function loadPropertiesFile(filePath, compilation, description) {
13
+ try {
14
+ const parsed = getPropertiesAsJSON(filePath);
15
+ return parsed;
16
+ } catch (err) {
17
+ if (compilation) {
18
+ compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading ${description}: ${err.message}`));
19
+ }
20
+ return {};
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Load numeric mapping from JSON file
26
+ */
27
+ function loadNumericMap(numericMapPath, compilation) {
28
+ try {
29
+ const fileContent = fs.readFileSync(numericMapPath, 'utf-8');
30
+ const parsedData = JSON.parse(fileContent);
31
+ let numericMap;
32
+ let totalKeys;
33
+
34
+ // Handle both wrapped and flat formats
35
+ if (parsedData.originalKeyToNumericId) {
36
+ // New format with metadata
37
+ numericMap = parsedData.originalKeyToNumericId;
38
+ totalKeys = parsedData.totalKeysInMap || Object.keys(numericMap).length;
39
+ } else {
40
+ // Flat format - use directly
41
+ numericMap = parsedData;
42
+ totalKeys = Object.keys(numericMap).length;
43
+ }
44
+
45
+ // Create sorted array for numeric ID lookups
46
+ const maxId = Math.max(...Object.values(numericMap));
47
+ const sortedKeys = new Array(maxId + 1);
48
+ Object.entries(numericMap).forEach(([key, id]) => {
49
+ sortedKeys[id] = key;
50
+ });
51
+ return {
52
+ sortedKeys,
53
+ totalKeys
54
+ };
55
+ } catch (err) {
56
+ if (compilation) {
57
+ compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading numeric map: ${err.message}`));
58
+ }
59
+ return {
60
+ sortedKeys: [],
61
+ totalKeys: 0
62
+ };
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Load all locale files from properties directory
68
+ */
69
+ function loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase) {
70
+ const allI18n = {};
71
+ const locales = [];
72
+
73
+ // Start with English base
74
+ allI18n['en_US'] = jsResourceBase;
75
+ locales.push('en_US');
76
+ try {
77
+ const files = fs.readdirSync(propertiesPath);
78
+ files.forEach(file => {
79
+ if (!file.endsWith('.properties')) return;
80
+
81
+ // Match locale-specific property files
82
+ const match = file.match(/^ApplicationResources_([a-z]{2}_[A-Z]{2})\.properties$/);
83
+ if (match) {
84
+ const locale = match[1];
85
+ const filePath = path.join(propertiesPath, file);
86
+ const localeData = loadPropertiesFile(filePath, compilation, `locale ${locale}`);
87
+
88
+ // Merge with base resources
89
+ allI18n[locale] = {
90
+ ...jsResourceBase,
91
+ ...localeData
92
+ };
93
+ if (!locales.includes(locale)) {
94
+ locales.push(locale);
95
+ }
96
+ }
97
+ });
98
+ } catch (err) {
99
+ if (compilation) {
100
+ compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error reading properties folder: ${err.message}`));
101
+ }
102
+ }
103
+ return {
104
+ allI18n,
105
+ locales
106
+ };
107
+ }
108
+
109
+ /**
110
+ * Main loader function for i18n data
111
+ */
112
+ function loadI18nData(options, compilation) {
113
+ const jsResourcePath = path.resolve(compilation.compiler.context, options.jsResourcePath);
114
+ const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath);
115
+
116
+ // Load base JS resources
117
+ const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources');
118
+
119
+ // Load all locale files
120
+ const {
121
+ allI18n,
122
+ locales
123
+ } = loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase);
124
+ return {
125
+ jsResourceBase,
126
+ allI18n,
127
+ locales
128
+ };
129
+ }
130
+ module.exports = {
131
+ loadPropertiesFile,
132
+ loadNumericMap,
133
+ loadAllLocaleFiles,
134
+ loadI18nData
135
+ };
@@ -4,26 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.I18nFilesEmitPlugin = void 0;
7
-
8
7
  var _webpack = require("webpack");
9
-
10
8
  var _createHash = require("./createHash");
11
-
12
9
  var _pathCreator = require("./pathCreator");
13
-
14
10
  var _propertiesUtils = require("./utils/propertiesUtils");
15
-
16
11
  var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
17
-
18
12
  /* eslint-disable no-restricted-syntax */
13
+
19
14
  const pluginName = 'I18nFilesEmitPlugin';
20
15
  const {
21
16
  RawSource
22
17
  } = _webpack.sources;
23
-
24
18
  class I18nFilesEmitPlugin {
25
19
  constructor(options) {
26
- this.options = options; // this.options = {
20
+ this.options = options;
21
+ // this.options = {
27
22
  // locales: options.locales,
28
23
  // chunkFilename: options.chunkFilename,
29
24
  // filename: options.filename,
@@ -31,7 +26,6 @@ class I18nFilesEmitPlugin {
31
26
  // jsonpFunc: options.jsonpFunc
32
27
  // };
33
28
  }
34
-
35
29
  apply(compiler) {
36
30
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
37
31
  // Get store for cache
@@ -48,12 +42,10 @@ class I18nFilesEmitPlugin {
48
42
  if (!i18nStore.isChunkHasI18n(chunk.id)) {
49
43
  return;
50
44
  }
51
-
52
45
  this.emitI18nFileForEveryLocale(chunk, compilation);
53
46
  });
54
47
  });
55
48
  }
56
-
57
49
  createAndStoreFileContentForEveryChunkAndLocale(compilation) {
58
50
  const {
59
51
  chunks
@@ -62,15 +54,12 @@ class I18nFilesEmitPlugin {
62
54
  locales
63
55
  } = this.options;
64
56
  const i18nStore = this.store;
65
-
66
57
  for (const chunk of chunks) {
67
58
  const i18nKeys = i18nStore.getI18nKeysForChunk(chunk);
68
-
69
59
  if (!i18nKeys.length) {
70
60
  // eslint-disable-next-line no-continue
71
61
  continue;
72
62
  }
73
-
74
63
  for (const locale of locales) {
75
64
  const content = this.getI18nChunkFileContent(i18nKeys, locale);
76
65
  i18nStore.storeData(chunk.id, locale, {
@@ -79,13 +68,11 @@ class I18nFilesEmitPlugin {
79
68
  }
80
69
  }
81
70
  }
82
-
83
71
  updateChunkHashForEveryLocale(chunk, hash) {
84
72
  const {
85
73
  locales
86
74
  } = this.options;
87
75
  const i18nStore = this.store;
88
-
89
76
  if (i18nStore.isChunkHasI18n(chunk.id)) {
90
77
  for (const loc of locales) {
91
78
  const content = i18nStore.getContent(chunk.id, loc);
@@ -93,7 +80,6 @@ class I18nFilesEmitPlugin {
93
80
  }
94
81
  }
95
82
  }
96
-
97
83
  emitI18nFileForEveryLocale(chunk, compilation) {
98
84
  const i18nStore = this.store;
99
85
  const {
@@ -101,8 +87,8 @@ class I18nFilesEmitPlugin {
101
87
  chunkFilename,
102
88
  filename
103
89
  } = this.options;
104
- const fileNameTemplate = chunk.canBeInitial() ? filename : chunkFilename; // const { chunks } = compilation;
105
-
90
+ const fileNameTemplate = chunk.canBeInitial() ? filename : chunkFilename;
91
+ // const { chunks } = compilation;
106
92
  for (const locale of locales) {
107
93
  const content = i18nStore.getContent(chunk.id, locale);
108
94
  const contentHash = (0, _createHash.createHash)({
@@ -125,7 +111,6 @@ class I18nFilesEmitPlugin {
125
111
  compilation.emitAsset(filename, new RawSource(content));
126
112
  }
127
113
  }
128
-
129
114
  static createFilenameWithHash({
130
115
  compilation,
131
116
  fileNameTemplate,
@@ -147,20 +132,16 @@ class I18nFilesEmitPlugin {
147
132
  filename
148
133
  };
149
134
  }
150
-
151
135
  getI18nContentForkeys(i18nKeys, locale) {
152
136
  const {
153
137
  allI18nObject
154
138
  } = this.options;
155
139
  const data = {};
156
-
157
140
  for (const key of i18nKeys) {
158
141
  data[key] = allI18nObject[locale][key];
159
142
  }
160
-
161
143
  return data;
162
144
  }
163
-
164
145
  getI18nChunkFileContent(i18nKeys, loc) {
165
146
  const {
166
147
  jsonpFunc
@@ -168,7 +149,5 @@ class I18nFilesEmitPlugin {
168
149
  const data = this.getI18nContentForkeys(i18nKeys, loc);
169
150
  return `${jsonpFunc}(${(0, _propertiesUtils.jsonToString)(data)})`;
170
151
  }
171
-
172
152
  }
173
-
174
153
  exports.I18nFilesEmitPlugin = I18nFilesEmitPlugin;
@@ -4,13 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
11
-
12
9
  /* eslint-disable max-classes-per-file */
10
+
13
11
  const pluginName = 'I18nKeysIdentifier';
12
+
14
13
  /**
15
14
  * this plugin search the i18 keys and make it as I18nDependency.
16
15
  * how it works?
@@ -20,7 +19,6 @@ const pluginName = 'I18nKeysIdentifier';
20
19
  * after the walk of AST we get some I18n keys
21
20
  * then we make it as I18nDependency.
22
21
  */
23
-
24
22
  class I18nKeysIdentifer {
25
23
  constructor({
26
24
  jsResourceI18nKeys
@@ -28,9 +26,9 @@ class I18nKeysIdentifer {
28
26
  this.jsResourceI18nKeys = jsResourceI18nKeys;
29
27
  this.store = new _LocaleChunkAssetsStore.LocaleChunkAssetsStore();
30
28
  }
31
-
32
29
  apply(compiler) {
33
30
  // const { splitChunks } = compiler.options.optimization;
31
+
34
32
  // if (splitChunks) {
35
33
  // if (splitChunks.defaultSizeTypes.includes('...')) {
36
34
  // splitChunks.defaultSizeTypes.push(MODULE_TYPE);
@@ -46,31 +44,30 @@ class I18nKeysIdentifer {
46
44
  parser.hooks.program.tap(pluginName, (ast, comments) => {
47
45
  const {
48
46
  module
49
- } = parser.state; //
50
-
47
+ } = parser.state;
48
+ //
51
49
  if (!(module && /\.jsx?$/.test(module.resource))) {
52
50
  return;
53
- } // i18n grep proper contract regex
54
-
55
-
51
+ }
52
+ // i18n grep proper contract regex
56
53
  let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
57
- i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
54
+ i18nKeys = i18nKeys.concat(
55
+ // i18n grep proper contract regex
58
56
  (0, _utils.collectI18nKeysfromComments)(comments, this.jsResourceI18nKeys));
59
-
60
57
  if (i18nKeys.length) {
61
58
  // console.log('i18nKeys.length', module.resource, i18nKeys);
62
59
  this.store.updateModuleI18nKeys(module.resource, i18nKeys);
63
60
  }
64
61
  });
65
- }; // this below hook was tapped for collect I18n Key from files and add as Dependency
66
- // const factory = params.normalModuleFactory;
62
+ };
67
63
 
64
+ // this below hook was tapped for collect I18n Key from files and add as Dependency
65
+
66
+ // const factory = params.normalModuleFactory;
68
67
 
69
68
  factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
70
69
  factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
71
70
  });
72
71
  }
73
-
74
72
  }
75
-
76
73
  exports.default = I18nKeysIdentifer;