@zohodesk/client_build_tool 0.0.11-exp.15.4 → 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 (224) hide show
  1. package/README.md +102 -0
  2. package/README_backup.md +100 -0
  3. package/docs/DYNAMIC_TEMPLATE_EXAMPLE.md +129 -0
  4. package/docs/I18N_SINGLE_FILE_MODE.md +126 -0
  5. package/example-single-file-config.js +59 -0
  6. package/lib/allCommandsConfigs.js +2 -7
  7. package/lib/commands/build/commandExecutor.js +1 -5
  8. package/lib/commands/build/config.js +2 -3
  9. package/lib/commands/build/optionsProcessor.js +2 -5
  10. package/lib/commands/build/preProcessor.js +0 -2
  11. package/lib/commands/buildEs/commandExecutor.js +0 -5
  12. package/lib/commands/buildEs/config.js +2 -3
  13. package/lib/commands/buildEs/preProcessor.js +0 -2
  14. package/lib/commands/buildLib/commandExecutor.js +0 -5
  15. package/lib/commands/buildLib/config.js +2 -3
  16. package/lib/commands/buildLib/preProcessor.js +0 -2
  17. package/lib/commands/mockserver/commandExecutor.js +2 -9
  18. package/lib/commands/mockserver/config.js +2 -3
  19. package/lib/commands/pre_process/commandExecutor.js +0 -2
  20. package/lib/commands/pre_process/config.js +2 -3
  21. package/lib/commands/start/commandExecutor.js +0 -2
  22. package/lib/commands/start/config.js +2 -3
  23. package/lib/commands/start/optionsProcessor.js +2 -4
  24. package/lib/commands/start/preProcessor.js +0 -2
  25. package/lib/commands/template/commandExecutor.js +0 -7
  26. package/lib/commands/template/config.js +2 -3
  27. package/lib/commands/version/commandExecutor.js +0 -3
  28. package/lib/commands/version/config.js +2 -3
  29. package/lib/commandsRouter.js +5 -21
  30. package/lib/index.js +0 -2
  31. package/lib/logger.js +0 -5
  32. package/lib/schemas/applyValuesToSchema/index.js +0 -8
  33. package/lib/schemas/applyValuesToSchema/isObject.js +0 -1
  34. package/lib/schemas/applyValuesToSchema/isValid.js +0 -2
  35. package/lib/schemas/cliArgsToObject.js +2 -6
  36. package/lib/schemas/defaultConfigValues.js +21 -12
  37. package/lib/schemas/defaultConfigValuesOnly.js +4 -7
  38. package/lib/schemas/deprecatedOptionsHandler.js +7 -16
  39. package/lib/schemas/getNpmVersion.js +0 -5
  40. package/lib/schemas/giveDefaultValue.js +0 -3
  41. package/lib/schemas/npmConfigToObject.js +2 -5
  42. package/lib/schemas/readOptions.js +10 -30
  43. package/lib/schemas/readOptionsForConfigFile.js +2 -12
  44. package/lib/shared/babel/addDefaultPlugins.js +0 -2
  45. package/lib/shared/babel/babelWebConfig.js +1 -10
  46. package/lib/shared/babel/babel_plugins/removeAttributesPlugin.js +0 -4
  47. package/lib/shared/babel/getBabelPlugin.js +2 -7
  48. package/lib/shared/babel/runBabelForJSFile.js +1 -4
  49. package/lib/shared/babel/runBabelForTsFile.js +1 -5
  50. package/lib/shared/bundler/webpack/common/decidePublicPath.js +0 -5
  51. package/lib/shared/bundler/webpack/common/libAlias.js +3 -3
  52. package/lib/shared/bundler/webpack/common/modeUtils.js +0 -5
  53. package/lib/shared/bundler/webpack/common/nameTemplates.js +11 -18
  54. package/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +2 -3
  55. package/lib/shared/bundler/webpack/configCustomLoaders.js +0 -1
  56. package/lib/shared/bundler/webpack/cssLoaders.js +0 -2
  57. package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +1 -20
  58. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/index.js +20 -25
  59. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +4 -9
  60. package/lib/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +3 -23
  61. package/lib/shared/bundler/webpack/custom_plugins/EFCTemplatePlugin.js +8 -19
  62. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +2 -6
  63. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +81 -0
  64. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +135 -60
  65. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +20 -26
  66. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +5 -26
  67. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +13 -16
  68. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +19 -53
  69. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/LocaleChunkAssetsStore.js +2 -17
  70. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ModulesI18nKeysStore.js +0 -13
  71. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +11 -21
  72. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +0 -4
  73. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +4 -14
  74. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +3 -13
  75. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/iterateModulesInChunk.js +3 -12
  76. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +2 -7
  77. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +0 -2
  78. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +2 -3
  79. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +2 -4
  80. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +8 -13
  81. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +2 -14
  82. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/getChunkModules.js +0 -1
  83. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +1 -3
  84. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +0 -4
  85. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +5 -25
  86. package/lib/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +3 -10
  87. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/addFilesNamesToManifestJson.js +1 -6
  88. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createInitialEntries.js +1 -6
  89. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createManifestJson.js +0 -6
  90. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/findInitialFileNames.js +0 -1
  91. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +0 -7
  92. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/removeHashFromFileName.js +0 -1
  93. package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +13 -17
  94. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +6 -15
  95. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +4 -13
  96. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +4 -6
  97. package/lib/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +0 -10
  98. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/classHandling.js +0 -3
  99. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/index.js +4 -20
  100. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js +10 -12
  101. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/windowsModification.js +2 -3
  102. package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +7 -20
  103. package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPluginUtils.js +0 -1
  104. package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +7 -10
  105. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/addHashToFilePath.js +1 -6
  106. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +1 -16
  107. package/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin/index.js.js +4 -11
  108. package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js +3 -10
  109. package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/index.js +27 -62
  110. package/lib/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +3 -15
  111. package/lib/shared/bundler/webpack/custom_plugins/emitAsset.js +0 -1
  112. package/lib/shared/bundler/webpack/custom_plugins/getInitialAssetsFuncTemplate.js +2 -12
  113. package/lib/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +2 -7
  114. package/lib/shared/bundler/webpack/defaultVendorPatternList.js +2 -6
  115. package/lib/shared/bundler/webpack/devtoolConfig.js +0 -1
  116. package/lib/shared/bundler/webpack/entryConfig.js +0 -4
  117. package/lib/shared/bundler/webpack/externals.js +0 -1
  118. package/lib/shared/bundler/webpack/getCSSLoaders.js +1 -6
  119. package/lib/shared/bundler/webpack/getFilenameFromModule.js +1 -5
  120. package/lib/shared/bundler/webpack/jsLoaders.js +6 -10
  121. package/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +0 -2
  122. package/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +2 -3
  123. package/lib/shared/bundler/webpack/loaderConfigs/checkIsPatternsMatchFilename.js +3 -12
  124. package/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +0 -1
  125. package/lib/shared/bundler/webpack/loaderConfigs/configPostCssLoader.js +2 -10
  126. package/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +0 -2
  127. package/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +0 -12
  128. package/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +1 -15
  129. package/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +1 -4
  130. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +8 -16
  131. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +22 -29
  132. package/lib/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +2 -2
  133. package/lib/shared/bundler/webpack/loaders/workerLoader.js +8 -19
  134. package/lib/shared/bundler/webpack/optimizationConfig.js +5 -13
  135. package/lib/shared/bundler/webpack/outputConfig.js +1 -9
  136. package/lib/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +5 -9
  137. package/lib/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +0 -5
  138. package/lib/shared/bundler/webpack/pluginConfigs/configCSSMinifierPlugin.js +4 -9
  139. package/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +3 -8
  140. package/lib/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +1 -16
  141. package/lib/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +0 -4
  142. package/lib/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +0 -16
  143. package/lib/shared/bundler/webpack/pluginConfigs/configEFCTemplatePlugin.js +0 -5
  144. package/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +0 -5
  145. package/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +2 -8
  146. package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +5 -9
  147. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +19 -25
  148. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +92 -0
  149. package/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +3 -9
  150. package/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +0 -2
  151. package/lib/shared/bundler/webpack/pluginConfigs/configManifestJsonPlugin.js +0 -7
  152. package/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +3 -7
  153. package/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +1 -5
  154. package/lib/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +1 -4
  155. package/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +0 -4
  156. package/lib/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +3 -8
  157. package/lib/shared/bundler/webpack/pluginConfigs/configSelectorWeightPlugin.js +1 -6
  158. package/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +3 -8
  159. package/lib/shared/bundler/webpack/pluginConfigs/configSourceMapPlugin.js +0 -4
  160. package/lib/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +1 -8
  161. package/lib/shared/bundler/webpack/pluginConfigs/configVariableConversionPlugin.js +1 -6
  162. package/lib/shared/bundler/webpack/plugins.js +3 -30
  163. package/lib/shared/bundler/webpack/resolvers.js +3 -17
  164. package/lib/shared/bundler/webpack/splitChunksConfig.js +2 -15
  165. package/lib/shared/bundler/webpack/statsConfig.js +2 -5
  166. package/lib/shared/bundler/webpack/tsLoaders.js +2 -4
  167. package/lib/shared/bundler/webpack/utils/index.js +1 -12
  168. package/lib/shared/bundler/webpack/utils/object-manipulation.js +2 -16
  169. package/lib/shared/bundler/webpack/utils/updateArrayWithDefault.js +0 -7
  170. package/lib/shared/bundler/webpack/webpackBuild.js +1 -8
  171. package/lib/shared/bundler/webpack/webpackConfig.js +0 -17
  172. package/lib/shared/commands-utils/doBasicRequirementCheck.js +0 -3
  173. package/lib/shared/commands-utils/getCliPath.js +5 -9
  174. package/lib/shared/commands-utils/index.js +0 -3
  175. package/lib/shared/commands-utils/log.js +0 -2
  176. package/lib/shared/commands-utils/readArgsFormCommandLine.js +0 -1
  177. package/lib/shared/commands-utils/readOptionFormCommandLine.js +0 -1
  178. package/lib/shared/commands-utils/spawnSyncIO.js +5 -13
  179. package/lib/shared/constants.js +9 -29
  180. package/lib/shared/fileUtils/copyFile.js +1 -8
  181. package/lib/shared/fileUtils/directoryIterator.js +0 -4
  182. package/lib/shared/fileUtils/watchRun.js +3 -24
  183. package/lib/shared/postcss/custom_postcss_plugins/EmptyPlugin.js +1 -6
  184. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/constants.js +2 -3
  185. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js +6 -13
  186. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/index.js +6 -26
  187. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/insertBefore.js +6 -9
  188. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js +0 -3
  189. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js +2 -7
  190. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js +0 -2
  191. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/specialCases.js +4 -9
  192. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js +0 -10
  193. package/lib/shared/postcss/custom_postcss_plugins/RTLSplitPlugin.js +16 -29
  194. package/lib/shared/postcss/custom_postcss_plugins/SelectorReplace.js +0 -17
  195. package/lib/shared/postcss/custom_postcss_plugins/ValueReplacer.js +4 -9
  196. package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +27 -63
  197. package/lib/shared/postcss/filterPluginsAllowedForSpecficFile.js +5 -13
  198. package/lib/shared/postcss/getAllowedPostCssPlugins.js +0 -3
  199. package/lib/shared/postcss/getSpecificPostCssPlugin.js +7 -17
  200. package/lib/shared/postcss/runPostCssForCssFile.js +1 -9
  201. package/lib/shared/pre_process/runPreProcess.js +0 -11
  202. package/lib/shared/server/configWebpackDevMiddleware.js +1 -8
  203. package/lib/shared/server/corsHandling.js +2 -6
  204. package/lib/shared/server/getIp.js +1 -7
  205. package/lib/shared/server/getServerURL.js +0 -6
  206. package/lib/shared/server/httpsOptions.js +0 -11
  207. package/lib/shared/server/initExpressApp.js +1 -4
  208. package/lib/shared/server/initialHTMLHandling.js +7 -16
  209. package/lib/shared/server/mockApiHandler.js +8 -16
  210. package/lib/shared/server/mockServer.js +0 -7
  211. package/lib/shared/server/serveContextFiles.js +1 -5
  212. package/lib/shared/server/serverBywebpackDevMiddleware.js +4 -9
  213. package/lib/shared/server/startHttpServer.js +0 -3
  214. package/lib/shared/server/startHttpsServer.js +1 -9
  215. package/lib/shared/server/unwanted/addHttp2Server.js +2 -7
  216. package/lib/shared/server/unwanted/configWebpackDevMiddleware.js +1 -8
  217. package/lib/shared/server/unwanted/mockApiSupport.js +0 -2
  218. package/lib/shared/server/unwanted/websocketMockSetup.js +1 -7
  219. package/lib/shared/server/urlConcat.js +3 -8
  220. package/lib/shared/utils/requireLocalOrGlobal.js +10 -25
  221. package/lib/shared/utils/versionPrint.js +1 -6
  222. package/npm-shrinkwrap.json +2 -2
  223. package/package.json +1 -1
  224. package/packages/client_build_tool/test-i18n-config.js +22 -0
@@ -4,33 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _fs = _interopRequireDefault(require("fs"));
9
-
10
8
  var _path = _interopRequireDefault(require("path"));
11
-
12
9
  var _webpack = require("webpack");
13
-
14
10
  var _propertiesUtils = require("../I18nSplitPlugin/utils/propertiesUtils");
15
-
16
11
  var _I18nGroupRuntimeModule = require("./I18nGroupRuntimeModule");
17
-
18
12
  var _i18nDataLoader = require("./utils/i18nDataLoader");
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
13
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
14
  const {
23
15
  RawSource
24
16
  } = _webpack.sources;
25
17
  const pluginName = 'I18nNumericIndexPlugin';
26
-
27
18
  class I18nNumericIndexPlugin {
28
19
  constructor(options) {
29
- this.options = 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
+ };
30
29
  this.numericMap = {};
31
30
  this.customGroups = {};
31
+ this.manifest = {};
32
32
  }
33
-
34
33
  apply(compiler) {
35
34
  // Detect webpackI18nGroup comments in code
36
35
  this.detectI18nGroupComments(compiler);
@@ -45,7 +44,6 @@ class I18nNumericIndexPlugin {
45
44
  }));
46
45
  });
47
46
  }
48
-
49
47
  compilation.hooks.processAssets.tap({
50
48
  name: pluginName,
51
49
  stage: compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
@@ -54,7 +52,6 @@ class I18nNumericIndexPlugin {
54
52
  });
55
53
  });
56
54
  }
57
-
58
55
  detectI18nGroupComments(compiler) {
59
56
  compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
60
57
  factory.hooks.parser.for('javascript/auto').tap(pluginName, parser => {
@@ -64,17 +61,14 @@ class I18nNumericIndexPlugin {
64
61
  comments.forEach(comment => {
65
62
  if (comment.value && comment.value.includes('webpackI18nGroup')) {
66
63
  const match = comment.value.match(/webpackI18nGroup:\s*["']([^"']+)["']/);
67
-
68
64
  if (match) {
69
- const groupName = match[1]; // Store this information for later use
70
-
65
+ const groupName = match[1];
66
+ // Store this information for later use
71
67
  if (!this.detectedGroups) {
72
68
  this.detectedGroups = {};
73
- } // Extract chunk name from webpackChunkName comment
74
-
75
-
69
+ }
70
+ // Extract chunk name from webpackChunkName comment
76
71
  const chunkNameMatch = comment.value.match(/webpackChunkName:\s*["']([^"']+)["']/);
77
-
78
72
  if (chunkNameMatch) {
79
73
  const chunkName = chunkNameMatch[1];
80
74
  this.detectedGroups[chunkName] = groupName;
@@ -86,7 +80,6 @@ class I18nNumericIndexPlugin {
86
80
  });
87
81
  });
88
82
  }
89
-
90
83
  processI18nFiles(compilation) {
91
84
  const {
92
85
  jsResourcePath,
@@ -97,15 +90,13 @@ class I18nNumericIndexPlugin {
97
90
  numericFilenameTemplate,
98
91
  dynamicFilenameTemplate
99
92
  } = this.options;
100
-
101
93
  if (!jsResourcePath || !propertiesFolderPath) {
102
94
  return;
103
- } // Load existing numeric map if available
104
-
95
+ }
105
96
 
97
+ // Load existing numeric map if available
106
98
  if (numericMapPath) {
107
99
  const mapData = (0, _i18nDataLoader.loadNumericMap)(numericMapPath, compilation);
108
-
109
100
  if (mapData && mapData.sortedKeys) {
110
101
  // Initialize numericMap from existing data
111
102
  mapData.sortedKeys.forEach((key, id) => {
@@ -114,49 +105,54 @@ class I18nNumericIndexPlugin {
114
105
  }
115
106
  });
116
107
  }
117
- } // Read JSResources.properties
118
-
108
+ }
119
109
 
120
- const jsResourceKeys = (0, _propertiesUtils.getPropertiesAsJSON)(jsResourcePath); // Parse custom groups from banner markers
110
+ // Read JSResources.properties
111
+ const jsResourceKeys = (0, _propertiesUtils.getPropertiesAsJSON)(jsResourcePath);
121
112
 
113
+ // Parse custom groups from banner markers
122
114
  if (customGroups) {
123
115
  this.parseCustomGroups(jsResourcePath, customGroups);
124
- } // Get all locale translations
125
-
116
+ }
126
117
 
118
+ // Get all locale translations
127
119
  const allI18nObject = (0, _propertiesUtils.getAllI18n)({
128
120
  folderPath: propertiesFolderPath,
129
121
  disableDefault: false,
130
122
  jsResourceI18nKeys: jsResourceKeys
131
- }); // For en_US, use only JSResources (don't merge with ApplicationResources_en_US)
123
+ });
132
124
 
125
+ // For en_US, use only JSResources (don't merge with ApplicationResources_en_US)
133
126
  if (allI18nObject['en_US']) {
134
127
  allI18nObject['en_US'] = jsResourceKeys;
135
128
  } else {
136
129
  // If en_US doesn't exist in the folder, create it from JSResources
137
130
  allI18nObject['en_US'] = jsResourceKeys;
138
131
  }
132
+ const locales = Object.keys(allI18nObject);
139
133
 
140
- const locales = Object.keys(allI18nObject); // Process each locale
141
-
134
+ // Process each locale
142
135
  locales.forEach(locale => {
143
136
  const localeData = allI18nObject[locale];
144
137
  const numericData = {};
145
138
  const dynamicData = {};
146
- const groupData = {}; // Initialize custom groups
139
+ const groupData = {};
147
140
 
141
+ // Initialize custom groups
148
142
  Object.keys(customGroups || {}).forEach(groupName => {
149
143
  groupData[groupName] = {};
150
- }); // Process each key
144
+ });
151
145
 
146
+ // Process each key
152
147
  Object.keys(localeData).forEach(key => {
153
- const value = localeData[key]; // Simple logic: if has numeric ID use it, otherwise it's dynamic
148
+ const value = localeData[key];
154
149
 
150
+ // Simple logic: if has numeric ID use it, otherwise it's dynamic
155
151
  if (this.numericMap[key]) {
156
- const numericKey = String(this.numericMap[key]); // Check if belongs to a custom group
152
+ const numericKey = String(this.numericMap[key]);
157
153
 
154
+ // Check if belongs to a custom group
158
155
  const belongsToGroup = this.getKeyGroup(key);
159
-
160
156
  if (belongsToGroup) {
161
157
  groupData[belongsToGroup][numericKey] = value;
162
158
  } else {
@@ -166,25 +162,53 @@ class I18nNumericIndexPlugin {
166
162
  // No numeric ID = dynamic key (regardless of placeholders)
167
163
  dynamicData[key] = value;
168
164
  }
169
- }); // Emit numeric chunk
165
+ });
170
166
 
171
- this.emitChunk(compilation, numericFilenameTemplate, locale, numericData, jsonpFunc); // Emit dynamic chunk
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
+ }
172
184
 
173
- this.emitChunk(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc); // Emit custom group chunks
185
+ // Emit dynamic chunk
186
+ if (Object.keys(dynamicData).length > 0) {
187
+ this.emitChunk(compilation, dynamicFilenameTemplate, locale, dynamicData, jsonpFunc, null, 'dynamic');
188
+ }
189
+ }
174
190
 
191
+ // Emit custom group chunks (always separate)
175
192
  Object.entries(groupData).forEach(([groupName, data]) => {
176
193
  const groupConfig = customGroups[groupName];
177
-
178
194
  if (groupConfig && Object.keys(data).length > 0) {
179
- this.emitChunk(compilation, groupConfig.filenameTemplate || `i18n-chunk/[locale]/${groupName}.i18n.js`, locale, data, jsonpFunc, groupName);
195
+ const groupTemplate = groupConfig.filenameTemplate || `[locale]/${groupName}.i18n.js`;
196
+ this.emitChunk(compilation, groupTemplate, locale, data, jsonpFunc, groupName, `group-${groupName}`);
180
197
  }
181
198
  });
182
- }); // Don't save numeric map - it should only be generated by the external script
183
- }
199
+ });
184
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
+ }
185
210
  parseCustomGroups(jsResourcePath, customGroups) {
186
211
  const content = _fs.default.readFileSync(jsResourcePath, 'utf-8');
187
-
188
212
  const lines = content.split('\n');
189
213
  Object.entries(customGroups).forEach(([groupName, config]) => {
190
214
  const {
@@ -200,7 +224,6 @@ class I18nNumericIndexPlugin {
200
224
  inGroup = false;
201
225
  } else if (inGroup && line.includes('=')) {
202
226
  const key = line.split('=')[0].trim();
203
-
204
227
  if (key && !key.startsWith('#')) {
205
228
  groupKeys.push(key);
206
229
  }
@@ -209,45 +232,97 @@ class I18nNumericIndexPlugin {
209
232
  this.customGroups[groupName] = groupKeys;
210
233
  });
211
234
  }
212
-
213
235
  getKeyGroup(key) {
214
236
  for (const [groupName, keys] of Object.entries(this.customGroups)) {
215
237
  if (keys.includes(key)) {
216
238
  return groupName;
217
239
  }
218
240
  }
219
-
220
241
  return null;
221
242
  }
222
-
223
243
  isDynamicKey(value) {
224
244
  // Check if value contains placeholders like {0}, {1}, etc.
225
245
  return /\{\d+\}/.test(value);
226
246
  }
227
-
228
247
  getNumericKey(key) {
229
248
  // Return numeric ID if it exists, null otherwise
230
249
  return this.numericMap[key] ? String(this.numericMap[key]) : null;
231
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;
232
266
 
233
- emitChunk(compilation, filenameTemplate, locale, data, jsonpFunc, groupName = null) {
234
- const filename = filenameTemplate.replace('[locale]', locale);
235
- const content = this.generateChunkContent(data, jsonpFunc, groupName);
236
- compilation.emitAsset(filename, new RawSource(content));
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, '/');
237
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
+ }
238
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
+ }
239
318
  generateChunkContent(data, jsonpFunc, groupName) {
240
319
  // Decode Unicode escapes to convert \uXXXX to actual characters
241
320
  const jsonString = (0, _propertiesUtils.decodeUnicodeEscapes)(JSON.stringify(data));
242
-
243
321
  if (groupName) {
244
322
  // Include group name for lazy loading identification
245
323
  return `${jsonpFunc}(${jsonString}, "${groupName}");`;
246
324
  }
247
-
248
325
  return `${jsonpFunc}(${jsonString});`;
249
326
  }
250
-
251
327
  }
252
-
253
328
  exports.default = I18nNumericIndexPlugin;
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require('fs');
4
-
5
4
  const path = require('path');
6
-
7
5
  const {
8
6
  getPropertiesAsJSON
9
7
  } = require('../../I18nSplitPlugin/utils/propertiesUtils');
8
+
10
9
  /**
11
10
  * Load and parse a properties file
12
11
  */
13
-
14
-
15
12
  function loadPropertiesFile(filePath, compilation, description) {
16
13
  try {
17
14
  const parsed = getPropertiesAsJSON(filePath);
@@ -20,22 +17,21 @@ function loadPropertiesFile(filePath, compilation, description) {
20
17
  if (compilation) {
21
18
  compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading ${description}: ${err.message}`));
22
19
  }
23
-
24
20
  return {};
25
21
  }
26
22
  }
23
+
27
24
  /**
28
25
  * Load numeric mapping from JSON file
29
26
  */
30
-
31
-
32
27
  function loadNumericMap(numericMapPath, compilation) {
33
28
  try {
34
29
  const fileContent = fs.readFileSync(numericMapPath, 'utf-8');
35
30
  const parsedData = JSON.parse(fileContent);
36
31
  let numericMap;
37
- let totalKeys; // Handle both wrapped and flat formats
32
+ let totalKeys;
38
33
 
34
+ // Handle both wrapped and flat formats
39
35
  if (parsedData.originalKeyToNumericId) {
40
36
  // New format with metadata
41
37
  numericMap = parsedData.originalKeyToNumericId;
@@ -44,9 +40,9 @@ function loadNumericMap(numericMapPath, compilation) {
44
40
  // Flat format - use directly
45
41
  numericMap = parsedData;
46
42
  totalKeys = Object.keys(numericMap).length;
47
- } // Create sorted array for numeric ID lookups
48
-
43
+ }
49
44
 
45
+ // Create sorted array for numeric ID lookups
50
46
  const maxId = Math.max(...Object.values(numericMap));
51
47
  const sortedKeys = new Array(maxId + 1);
52
48
  Object.entries(numericMap).forEach(([key, id]) => {
@@ -60,41 +56,40 @@ function loadNumericMap(numericMapPath, compilation) {
60
56
  if (compilation) {
61
57
  compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error loading numeric map: ${err.message}`));
62
58
  }
63
-
64
59
  return {
65
60
  sortedKeys: [],
66
61
  totalKeys: 0
67
62
  };
68
63
  }
69
64
  }
65
+
70
66
  /**
71
67
  * Load all locale files from properties directory
72
68
  */
73
-
74
-
75
69
  function loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase) {
76
70
  const allI18n = {};
77
- const locales = []; // Start with English base
71
+ const locales = [];
78
72
 
73
+ // Start with English base
79
74
  allI18n['en_US'] = jsResourceBase;
80
75
  locales.push('en_US');
81
-
82
76
  try {
83
77
  const files = fs.readdirSync(propertiesPath);
84
78
  files.forEach(file => {
85
- if (!file.endsWith('.properties')) return; // Match locale-specific property files
79
+ if (!file.endsWith('.properties')) return;
86
80
 
81
+ // Match locale-specific property files
87
82
  const match = file.match(/^ApplicationResources_([a-z]{2}_[A-Z]{2})\.properties$/);
88
-
89
83
  if (match) {
90
84
  const locale = match[1];
91
85
  const filePath = path.join(propertiesPath, file);
92
- const localeData = loadPropertiesFile(filePath, compilation, `locale ${locale}`); // Merge with base resources
86
+ const localeData = loadPropertiesFile(filePath, compilation, `locale ${locale}`);
93
87
 
94
- allI18n[locale] = { ...jsResourceBase,
88
+ // Merge with base resources
89
+ allI18n[locale] = {
90
+ ...jsResourceBase,
95
91
  ...localeData
96
92
  };
97
-
98
93
  if (!locales.includes(locale)) {
99
94
  locales.push(locale);
100
95
  }
@@ -105,23 +100,23 @@ function loadAllLocaleFiles(propertiesPath, compilation, jsResourceBase) {
105
100
  compilation.errors.push(new Error(`I18nNumericIndexPlugin: Error reading properties folder: ${err.message}`));
106
101
  }
107
102
  }
108
-
109
103
  return {
110
104
  allI18n,
111
105
  locales
112
106
  };
113
107
  }
108
+
114
109
  /**
115
110
  * Main loader function for i18n data
116
111
  */
117
-
118
-
119
112
  function loadI18nData(options, compilation) {
120
113
  const jsResourcePath = path.resolve(compilation.compiler.context, options.jsResourcePath);
121
- const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath); // Load base JS resources
114
+ const propertiesPath = path.resolve(compilation.compiler.context, options.propertiesFolderPath);
122
115
 
123
- const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources'); // Load all locale files
116
+ // Load base JS resources
117
+ const jsResourceBase = loadPropertiesFile(jsResourcePath, compilation, 'JS resources');
124
118
 
119
+ // Load all locale files
125
120
  const {
126
121
  allI18n,
127
122
  locales
@@ -132,7 +127,6 @@ function loadI18nData(options, compilation) {
132
127
  locales
133
128
  };
134
129
  }
135
-
136
130
  module.exports = {
137
131
  loadPropertiesFile,
138
132
  loadNumericMap,
@@ -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;