@zohodesk/react-cli 1.1.29-exp.2 → 1.1.29-exp.3

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 (222) hide show
  1. package/README.md +18 -0
  2. package/lib/babel/babel-option-utils/babel-preset-react-option.js +3 -0
  3. package/lib/babel/cmjs-plugins-presets.js +13 -2
  4. package/lib/babel/es-plugins-presets.js +14 -3
  5. package/lib/common/buildEs.js +0 -1
  6. package/lib/common/getEntries.js +13 -2
  7. package/lib/common/getPublicPathConfig.js +6 -0
  8. package/lib/common/index.js +6 -1
  9. package/lib/common/runPreProcess.js +15 -6
  10. package/lib/common/splitChunks.js +21 -2
  11. package/lib/common/sslcertUpdater.js +18 -7
  12. package/lib/common/templateParameters.js +2 -0
  13. package/lib/common/testPattern.js +21 -10
  14. package/lib/common/valueReplacer.js +16 -1
  15. package/lib/configs/jest.config.js +11 -2
  16. package/lib/configs/libAlias.js +16 -10
  17. package/lib/configs/resolvers.js +16 -6
  18. package/lib/configs/webpack.component.umd.config.js +6 -1
  19. package/lib/configs/webpack.css.umd.config.js +14 -6
  20. package/lib/configs/webpack.dev.config.js +14 -1
  21. package/lib/configs/webpack.docs.config.js +9 -1
  22. package/lib/configs/webpack.impact.config.js +8 -1
  23. package/lib/configs/webpack.prod.config.js +17 -4
  24. package/lib/constants.js +18 -9
  25. package/lib/deprecationLogger.js +7 -0
  26. package/lib/hooks/docsProptypeHook.js +8 -4
  27. package/lib/jest/commitedFilesResult.js +46 -4
  28. package/lib/jest/coverageCollector.js +12 -1
  29. package/lib/jest/jsonMaker.js +6 -0
  30. package/lib/jest/preProcessors/cssPreprocessor.js +9 -1
  31. package/lib/jest/preProcessors/jsPreprocessor.js +11 -2
  32. package/lib/jest/preProcessors/otherFilesPreprocessor.js +4 -1
  33. package/lib/jest/result.js +23 -1
  34. package/lib/jest/run.js +18 -7
  35. package/lib/jest/setup.js +60 -8
  36. package/lib/loaderUtils/configsAssetsLoaders.js +12 -2
  37. package/lib/loaderUtils/getCSSLoaders.js +22 -10
  38. package/lib/loaderUtils/getDevJsLoaders.js +13 -4
  39. package/lib/loaderUtils/index.js +4 -1
  40. package/lib/loaderUtils/tests/windowsModification.test.js +1 -0
  41. package/lib/loaderUtils/windowsModification.js +3 -2
  42. package/lib/loaders/__test__/markdownLoader.spec.js +1 -0
  43. package/lib/loaders/composeLoader.js +37 -13
  44. package/lib/loaders/docsLoader.js +12 -1
  45. package/lib/loaders/docsPropsLoader.js +8 -4
  46. package/lib/loaders/enhancedReactLiveConverter.js +23 -2
  47. package/lib/loaders/fileBountryLoader.js +3 -1
  48. package/lib/loaders/fileLoader.js +23 -12
  49. package/lib/loaders/markdownLoader.js +19 -14
  50. package/lib/loaders/reactLiveConvertor.js +15 -5
  51. package/lib/loaders/scriptInstrumentLoader.js +16 -7
  52. package/lib/loaders/selectorMappingLoader.js +26 -7
  53. package/lib/loaders/workerLoader.js +24 -9
  54. package/lib/logger.js +4 -0
  55. package/lib/middlewares/HMRMiddleware.js +27 -13
  56. package/lib/middlewares/SSTMiddleware.js +5 -1
  57. package/lib/pluginUtils/configHtmlWebpackPlugins.js +24 -1
  58. package/lib/pluginUtils/getDevPlugins.js +42 -9
  59. package/lib/pluginUtils/getDocsPlugins.js +13 -3
  60. package/lib/pluginUtils/getLibraryImactPlugins.js +6 -5
  61. package/lib/pluginUtils/getLibraryPlugins.js +8 -2
  62. package/lib/pluginUtils/getProdPlugins.js +47 -8
  63. package/lib/pluginUtils/getServerPlugins.js +8 -2
  64. package/lib/pluginUtils/getUMDCSSPlugins.js +10 -2
  65. package/lib/pluginUtils/getUMDComponentPlugins.js +10 -2
  66. package/lib/pluginUtils/index.js +9 -1
  67. package/lib/plugins/CdnChangePlugin.js +18 -2
  68. package/lib/plugins/CleanupStatsPlugin.js +5 -0
  69. package/lib/plugins/CssOrderControlPlugin.js +6 -3
  70. package/lib/plugins/CustomAttributePlugin.js +19 -14
  71. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +23 -3
  72. package/lib/plugins/EFCPlugin.js +34 -20
  73. package/lib/plugins/EFCTemplatePlugin.js +30 -19
  74. package/lib/plugins/EfcResourceCleanupPlugin.js +3 -0
  75. package/lib/plugins/EventsHandlingPlugin.js +4 -2
  76. package/lib/plugins/I18NInjectIntoIndexPlugin.js +37 -14
  77. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +15 -10
  78. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +10 -4
  79. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +155 -78
  80. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +81 -198
  81. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +23 -12
  82. package/lib/plugins/I18nSplitPlugin/index.js +24 -13
  83. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +12 -2
  84. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +1 -0
  85. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +5 -0
  86. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +8 -1
  87. package/lib/plugins/I18nSplitPlugin/utils/index.js +4 -0
  88. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -0
  89. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +1 -0
  90. package/lib/plugins/ManifestPlugin.js +18 -1
  91. package/lib/plugins/MinifyPlugin.js +10 -1
  92. package/lib/plugins/ModuleStatsPlugin.js +24 -1
  93. package/lib/plugins/OptimizeJSPlugin.js +10 -2
  94. package/lib/plugins/PublicPathCallbackPlugin.js +12 -1
  95. package/lib/plugins/PublicPathChangePlugin.js +39 -6
  96. package/lib/plugins/ReportGeneratePlugin.js +32 -5
  97. package/lib/plugins/RequireVariablePublicPlugin.js +8 -1
  98. package/lib/plugins/ResourceHintsPlugin.js +13 -4
  99. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +17 -12
  100. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +17 -10
  101. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +5 -2
  102. package/lib/plugins/ScriptInstrumentPlugin.js +8 -1
  103. package/lib/plugins/SelectorPlugin.js +32 -6
  104. package/lib/plugins/ServiceWorkerPlugin.js +22 -5
  105. package/lib/plugins/ShadowDOMSupportPlugin.js +41 -4
  106. package/lib/plugins/SourceMapHookPlugin.js +12 -2
  107. package/lib/plugins/StatsPlugin.js +14 -0
  108. package/lib/plugins/TPHashMappingPlugin.js +18 -3
  109. package/lib/plugins/UnusedFilesFindPlugin.js +39 -4
  110. package/lib/plugins/VariableConversionCollector.js +42 -15
  111. package/lib/plugins/index.js +20 -1
  112. package/lib/plugins/libraryImpactPlugin.js +33 -1
  113. package/lib/plugins/utils/classHandling.js +6 -0
  114. package/lib/plugins/utils/fileHandling.js +15 -6
  115. package/lib/plugins/utils/tests/fileHandling.test.js +4 -0
  116. package/lib/plugins/variableConvertorUtils.js +29 -14
  117. package/lib/plugins/webpackwatchrunplugin.js +5 -0
  118. package/lib/postcss-plugins/EmptyPlugin.js +4 -3
  119. package/lib/postcss-plugins/ExcludePlugin.js +5 -1
  120. package/lib/postcss-plugins/IncludePlugin.js +5 -1
  121. package/lib/postcss-plugins/RTLSplitPlugin.js +27 -14
  122. package/lib/postcss-plugins/SelectorReplace.js +16 -1
  123. package/lib/postcss-plugins/ValueReplacer.js +6 -7
  124. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +3 -0
  125. package/lib/postcss-plugins/__test__/selectorReplace.test.js +3 -6
  126. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +5 -2
  127. package/lib/postcss-plugins/hoverActivePlugin.js +67 -31
  128. package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +7 -0
  129. package/lib/postcss-plugins/variableModificationPlugin/index.js +49 -28
  130. package/lib/schemas/index.js +10 -3
  131. package/lib/servers/clusterHubServer.js +11 -1
  132. package/lib/servers/devBuild.js +26 -14
  133. package/lib/servers/docsServer.js +3 -1
  134. package/lib/servers/docsServerCore.js +22 -1
  135. package/lib/servers/getCliPath.js +9 -0
  136. package/lib/servers/helpServer.js +6 -1
  137. package/lib/servers/httpsOptions.js +8 -2
  138. package/lib/servers/impactServer.js +35 -3
  139. package/lib/servers/mockserver.js +10 -1
  140. package/lib/servers/nowatchserver.js +37 -12
  141. package/lib/servers/requireLocalOrGlobal.js +17 -6
  142. package/lib/servers/scrServer.js +21 -14
  143. package/lib/servers/server.js +36 -6
  144. package/lib/servers/ssServer.js +17 -1
  145. package/lib/templates/CoverageScriptTemplate.js +14 -0
  146. package/lib/templates/WMSTemplate.js +13 -7
  147. package/lib/templates/linterConstant.js +4 -2
  148. package/lib/utils/babelPresets.js +7 -3
  149. package/lib/utils/clean.js +9 -3
  150. package/lib/utils/copy.js +7 -1
  151. package/lib/utils/copyTimezones.js +9 -1
  152. package/lib/utils/createEventStream.js +6 -1
  153. package/lib/utils/cssClassNameGenerate.js +30 -10
  154. package/lib/utils/cssURLReplacer.js +22 -1
  155. package/lib/utils/dependencyPostPublish.js +10 -1
  156. package/lib/utils/deprecationSupport.js +32 -7
  157. package/lib/utils/fileUtils.js +28 -1
  158. package/lib/utils/folderIterator.js +13 -2
  159. package/lib/utils/getComponents.js +21 -0
  160. package/lib/utils/getCurrentBranch.js +5 -0
  161. package/lib/utils/getDependenciesImpactList.js +22 -1
  162. package/lib/utils/getFileType.js +10 -2
  163. package/lib/utils/getHash.js +8 -1
  164. package/lib/utils/getIp.js +2 -0
  165. package/lib/utils/getOptions.js +53 -16
  166. package/lib/utils/getServerURL.js +10 -1
  167. package/lib/utils/index.js +51 -4
  168. package/lib/utils/init.js +1 -0
  169. package/lib/utils/initPreCommitHook.js +30 -7
  170. package/lib/utils/jsonHelper.js +22 -3
  171. package/lib/utils/libraryImpactConfig.js +5 -2
  172. package/lib/utils/lint/addScripts.js +5 -2
  173. package/lib/utils/lint/checkExistingConfig.js +12 -3
  174. package/lib/utils/lint/copyConfigs.js +3 -0
  175. package/lib/utils/lint/index.js +9 -0
  176. package/lib/utils/lint/lintScripts.js +1 -0
  177. package/lib/utils/lint/lintSetup.js +4 -3
  178. package/lib/utils/lint/lintStagedPreCommitHook.js +1 -0
  179. package/lib/utils/lint/question.js +7 -0
  180. package/lib/utils/lintReporter.js +20 -0
  181. package/lib/utils/log.js +1 -0
  182. package/lib/utils/mailSender.js +8 -1
  183. package/lib/utils/object-manipulation.js +17 -1
  184. package/lib/utils/pullOrigin.js +4 -0
  185. package/lib/utils/reinstallDependencies.js +29 -1
  186. package/lib/utils/removeAttributes.js +8 -1
  187. package/lib/utils/repoClone.js +28 -3
  188. package/lib/utils/request.js +12 -0
  189. package/lib/utils/rtl.js +17 -5
  190. package/lib/utils/selectorReplacer.js +16 -10
  191. package/lib/utils/setEnvVariables.js +2 -0
  192. package/lib/utils/ssTestHack.js +11 -1
  193. package/lib/utils/switchBranch.js +5 -0
  194. package/lib/utils/typeCheck.js +1 -0
  195. package/lib/utils/urlConcat.js +4 -0
  196. package/lib/utils/useExitCleanup.js +10 -9
  197. package/lib/utils/variableConverter.js +31 -22
  198. package/{package-lock.json → npm-shrinkwrap.json} +2333 -2101
  199. package/package.json +3 -2
  200. package/lib/plugins/I18nSplitPlugin/utils/applyMetaManifest.js +0 -279
  201. package/lib/plugins/I18nSplitPlugin/utils/createMetaManifest.js +0 -51
  202. package/lib/plugins/I18nSplitPlugin/utils/createRegularManifest.js +0 -48
  203. package/lib/plugins/newi18nsplitplugin/18nPlugin1.js +0 -306
  204. package/lib/plugins/newi18nsplitplugin/18nPlugin2.js +0 -363
  205. package/lib/plugins/newi18nsplitplugin/18nPlugin3.js +0 -694
  206. package/lib/plugins/newi18nsplitplugin/18nPlugin_hashed.js +0 -1258
  207. package/lib/plugins/newi18nsplitplugin/18nPlugin_working.js +0 -542
  208. package/lib/plugins/newi18nsplitplugin/18nplugin.js +0 -974
  209. package/lib/plugins/newi18nsplitplugin/ChunkManager.js +0 -131
  210. package/lib/plugins/newi18nsplitplugin/GenerateModuleIdToKeysMapPlugin.js +0 -59
  211. package/lib/plugins/newi18nsplitplugin/I18nDiffPlugin.js +0 -262
  212. package/lib/plugins/newi18nsplitplugin/I18nDownloadLogic.js +0 -166
  213. package/lib/plugins/newi18nsplitplugin/I18nPropertiesPlugin.js +0 -111
  214. package/lib/plugins/newi18nsplitplugin/KeyCollector.js +0 -163
  215. package/lib/plugins/newi18nsplitplugin/ManifestGenerator.js +0 -88
  216. package/lib/plugins/newi18nsplitplugin/UnicodeConversionPlugin.js +0 -101
  217. package/lib/plugins/newi18nsplitplugin/constants.js +0 -162
  218. package/lib/plugins/newi18nsplitplugin/utils/I18nKeyHasher.js +0 -78
  219. package/lib/plugins/newi18nsplitplugin/utils/getJsResourceKeys.js +0 -22
  220. package/lib/plugins/newi18nsplitplugin/utils/i18nChunkUtils.js +0 -18
  221. package/lib/plugins/newi18nsplitplugin/utils/manifestGenerator.js +0 -580
  222. package/lib/plugins/newi18nsplitplugin/utils/propertiesUtils.js +0 -54
@@ -4,75 +4,66 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _webpackSources = require("webpack-sources");
9
+
8
10
  var _utils = require("./utils");
11
+
9
12
  var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKeysFormModules"));
10
- var _createRegularManifest = require("./utils/createRegularManifest");
11
- var _createMetaManifest = require("./utils/createMetaManifest");
12
- var _applyMetaManifest = require("./utils/applyMetaManifest");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
14
16
  /**
15
17
  * this plugin was creating the chunk specific i18n chunk's.
16
18
  */
17
-
19
+ // this plugin's kick starter is apply method
18
20
  const pluginName = 'I18nFilesEmitter';
19
21
  const MODULE_TYPE = 'json/i18n';
22
+
20
23
  const i18ntype = locale => `${MODULE_TYPE}/${locale}`;
24
+
21
25
  class I18nFilesEmitter {
22
26
  constructor({
23
27
  allI18nObject,
24
28
  i18nManifestFileName,
25
29
  filenameTemplate,
26
30
  locales,
27
- jsonpFunc,
28
- i18nMetaManifestFileName,
29
- entryPointNames = ['main'],
30
- masterChunkFileName = 'master.i18n.js'
31
+ jsonpFunc
31
32
  }) {
32
33
  this.locales = locales;
33
34
  this.allI18nObject = allI18nObject;
34
- this.filenameTemplate = filenameTemplate;
35
+ this.filenameTemplate = filenameTemplate; // this.filenameTemplate = "i18n-chunk/[locale]/[name].js"
36
+
35
37
  this.jsonpFunc = jsonpFunc;
36
38
  this.prevHashes = {};
37
39
  this.i18nManifestFileName = i18nManifestFileName;
38
- this.i18nMetaManifestFileName = i18nMetaManifestFileName || 'i18n-chunk/metaManifest.json';
39
- this.regularManifest = {};
40
- this.detailedManifest = {};
41
- this.entryPointNames = Array.isArray(entryPointNames) ? entryPointNames : [entryPointNames];
42
- this.masterChunkFileName = masterChunkFileName;
43
- this.generatedMetaManifest = {
44
- modules: {},
45
- masterKeys: []
46
- };
47
- this.extraKeys = new Set();
48
- this.movedKeys = new Set();
49
- this.entryPointKeys = new Set();
50
- this.combinedChunks = {};
51
- this.moduleIdMap = new Map();
52
- this.moduleToChunks = new Map();
53
- this.resourceToModule = new Map();
54
40
  }
41
+
55
42
  emitAsset(compilation, filename, source, info) {
43
+ // NOTE: info support available since webpack v4.40.0 https://webpack.js.org/api/stats/#asset-objects
56
44
  if (!compilation.emitAsset) {
57
45
  compilation.assets[filename] = source;
58
46
  } else {
59
47
  compilation.emitAsset(filename, source, info);
60
48
  }
61
- }
49
+ } // this method for create object and assign value for i18nkeys
50
+
51
+
62
52
  getI18nObjectByLocale(i18nKeys, locale) {
63
53
  const data = {};
64
54
  i18nKeys.forEach(key => {
65
- if (this.allI18nObject[locale] && this.allI18nObject[locale][key] !== undefined) {
66
- data[key] = this.allI18nObject[locale][key];
67
- }
55
+ data[key] = this.allI18nObject[locale][key];
68
56
  });
69
57
  return data;
70
58
  }
59
+
71
60
  getTemplateString(i18nKeys, locale) {
72
- const i18nObject = this.getI18nObjectByLocale(i18nKeys, locale);
73
- return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`;
61
+ let i18nObject = this.getI18nObjectByLocale(i18nKeys, locale);
62
+ return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`; // return `${this.jsonpFunc}(JSON.parse(${JSON.stringify(jsonToString(i18nObject))}));`;
74
63
  }
64
+
75
65
  renderI18nLocaleChunk(chunk, locale, i18nKeys) {
66
+ // renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation) {
76
67
  const filenameTemplate = this.filenameTemplate.replace(/\[locale\]/g, locale);
77
68
  const pathOptions = {
78
69
  chunk,
@@ -86,48 +77,7 @@ class I18nFilesEmitter {
86
77
  hash: chunk.contentHash[i18ntype(locale)]
87
78
  };
88
79
  }
89
- captureModuleIds(compilation) {
90
- console.log('Capturing final module IDs from compilation...');
91
- this.moduleIdMap.clear();
92
- this.resourceToModule.clear();
93
- this.moduleToChunks.clear();
94
-
95
- // Process all modules to build our mapping
96
- compilation.modules.forEach(module => {
97
- // Skip modules without resources
98
- if (!module.resource) return;
99
- const originalId = module.resource;
100
- const finalId = module.id;
101
80
 
102
- // Map resource path to final module ID
103
- this.moduleIdMap.set(originalId, finalId);
104
- // Map resource path to module object
105
- this.resourceToModule.set(originalId, module);
106
-
107
- // Build chunk membership for each module
108
- const chunkIds = Array.from(module.chunksIterable || []).map(chunk => chunk.id).filter(Boolean);
109
- if (chunkIds.length > 0) {
110
- this.moduleToChunks.set(originalId, chunkIds);
111
- }
112
- });
113
-
114
- // console.log(`Captured ${this.moduleIdMap.size} module ID mappings`);
115
- }
116
- gatherModuleDetails(chunk, i18nKeys) {
117
- if (!i18nKeys.length) return;
118
- const stableModuleIds = Array.from(chunk.modulesIterable).map(module => module.resource).filter(Boolean);
119
- const moduleKey = stableModuleIds.length ? stableModuleIds[0] : `chunk_${chunk.id}`;
120
- if (!this.detailedManifest[moduleKey]) {
121
- this.detailedManifest[moduleKey] = {
122
- chunkId: chunk.id,
123
- chunkName: chunk.name || `chunk_${chunk.id}`,
124
- keysUsed: new Set()
125
- };
126
- }
127
- i18nKeys.forEach(key => {
128
- this.detailedManifest[moduleKey].keysUsed.add(key);
129
- });
130
- }
131
81
  emitI18nFilesForChunk(chunk, compilation) {
132
82
  const i18nKeys = (0, _getI18nKeysFormModules.default)(chunk.modulesIterable);
133
83
  const manifestForChunk = {
@@ -135,17 +85,16 @@ class I18nFilesEmitter {
135
85
  hasI18n: false,
136
86
  hasChanges: false
137
87
  };
88
+
138
89
  if (!i18nKeys.length) {
90
+ // why it is not checked as 0
139
91
  return manifestForChunk;
140
92
  }
141
- this.gatherModuleDetails(chunk, i18nKeys);
142
- manifestForChunk.hasI18n = true;
143
- const isEntryPoint = this.isPartOfEntryPoint(chunk, compilation);
144
- if (isEntryPoint) {
145
- i18nKeys.forEach(key => this.entryPointKeys.add(key));
146
- }
93
+
94
+ manifestForChunk.hasI18n = true; // const locales = ['en_US'];
95
+
147
96
  this.locales.forEach(locale => {
148
- const result = this.renderI18nLocaleChunk(chunk, locale, i18nKeys);
97
+ const result = this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation);
149
98
  const {
150
99
  filenameTemplate,
151
100
  pathOptions,
@@ -155,146 +104,80 @@ class I18nFilesEmitter {
155
104
  } = result;
156
105
  const filePath = compilation.getPath(filenameTemplate, pathOptions);
157
106
  manifestForChunk.assets[locale] = filePath;
107
+
158
108
  if (this.prevHashes[identifier] === hash) {
159
109
  return;
160
110
  }
111
+
161
112
  manifestForChunk.hasChanges = true;
162
113
  this.prevHashes[identifier] = hash;
163
- const renderedContent = render().source();
164
- this.emitAsset(compilation, filePath, new _webpackSources.RawSource(renderedContent), {
114
+ this.emitAsset(compilation, filePath, render(), {
165
115
  locale,
166
116
  chunkId: chunk.id,
167
117
  chunkName: chunk.name
168
- });
169
- if (!this.combinedChunks[locale]) {
170
- this.combinedChunks[locale] = [];
171
- }
172
- this.combinedChunks[locale].push({
173
- path: filePath,
174
- content: renderedContent,
175
- data: this.getI18nObjectByLocale(i18nKeys, locale),
176
- isEntryPoint: isEntryPoint
177
- });
118
+ }); // compilation.assets[filePath] = render();
178
119
  });
179
120
  return manifestForChunk;
180
121
  }
181
- isPartOfEntryPoint(chunk, compilation) {
182
- let isEntryChunk = false;
183
- this.entryPointNames.forEach(entryName => {
184
- const entryPoint = compilation.entrypoints.get(entryName);
185
- if (entryPoint && entryPoint.chunks.includes(chunk)) {
186
- isEntryChunk = true;
187
- }
188
- });
189
- return isEntryChunk;
190
- }
191
- createMetaManifestWithFinalIds(compilation) {
192
- console.log('Creating meta manifest with final module IDs...');
193
- const finalMetaManifest = {
194
- modules: {},
195
- masterKeys: []
196
- };
197
- for (const [resourcePath, moduleData] of Object.entries(this.detailedManifest)) {
198
- const finalId = this.moduleIdMap.get(resourcePath) || resourcePath;
199
- const chunkName = moduleData.chunkName || `chunk_${finalId}`;
200
- const keysArray = Array.isArray(moduleData.keysUsed) ? moduleData.keysUsed : Array.from(moduleData.keysUsed);
201
- if (keysArray.length > 0) {
202
- finalMetaManifest.modules[chunkName] = {
203
- id: moduleData.chunkId,
204
- finalId: finalId,
205
- resourcePath: resourcePath,
206
- keys: keysArray
207
- };
208
- }
209
- }
210
- this.generatedMetaManifest = finalMetaManifest;
211
- console.log(`Created meta manifest with ${Object.keys(finalMetaManifest.modules).length} modules`);
212
- }
213
- compareWithRemoteManifest(compilation) {
214
- (0, _applyMetaManifest.applyMetaManifest)(compilation, this);
215
- }
216
- emitMasterChunks(compilation) {
217
- const combinedKeys = new Set([...this.extraKeys, ...this.movedKeys, ...(this.generatedMetaManifest.masterKeys || [])]);
218
122
 
219
- // console.log(`Extra and moved keys to add to master chunk: ${combinedKeys.size}`);
220
- // console.log(`Entry point keys: ${this.entryPointKeys.size}`);
221
-
222
- // Add entry point keys to the master keys in meta manifest
223
- if (this.generatedMetaManifest) {
224
- this.generatedMetaManifest.masterKeys = [...this.generatedMetaManifest.masterKeys, ...Array.from(this.entryPointKeys)];
225
- }
226
-
227
- // Create a master object that contains all needed keys
228
- const allMasterKeys = new Set([...combinedKeys, ...this.entryPointKeys]);
229
-
230
- // console.log(`Creating master chunks with ${allMasterKeys.size} total keys`);
231
-
232
- for (const locale of this.locales) {
233
- try {
234
- const masterI18nObject = this.getI18nObjectByLocale([...allMasterKeys], locale);
235
- console.log(`Master i18n object has ${Object.keys(masterI18nObject).length} keys`);
236
- const finalContent = `${this.jsonpFunc}(${(0, _utils.jsonToString)(masterI18nObject)});`;
237
- const outputPath = `i18n-chunk/${locale}/${this.masterChunkFileName}`;
238
- this.emitAsset(compilation, outputPath, new _webpackSources.RawSource(finalContent), {
239
- locale,
240
- chunkName: 'master',
241
- desc: 'Combined master i18n chunk'
242
- });
243
- if (!this.regularManifest.master) {
244
- this.regularManifest.master = {};
245
- }
246
- this.regularManifest.master[locale] = outputPath;
247
- } catch (error) {
248
- console.error(`ERROR processing master chunk for locale ${locale}:`, error.message);
249
- try {
250
- console.log(`Attempting to emit a fallback master chunk for locale ${locale}`);
251
- const fallbackI18nObject = this.getI18nObjectByLocale([...combinedKeys], locale);
252
- const fallbackContent = `${this.jsonpFunc}(${(0, _utils.jsonToString)(fallbackI18nObject)});`;
253
- const outputPath = `i18n-chunk/${locale}/${this.masterChunkFileName}`;
254
- this.emitAsset(compilation, outputPath, new _webpackSources.RawSource(fallbackContent), {
255
- locale,
256
- chunkName: 'master',
257
- desc: 'Fallback master i18n chunk (only moved/extra keys)'
258
- });
259
- if (!this.regularManifest.master) {
260
- this.regularManifest.master = {};
261
- }
262
- this.regularManifest.master[locale] = outputPath;
263
- console.log(`Emitted fallback master chunk for locale ${locale}: ${outputPath}`);
264
- } catch (fallbackError) {
265
- console.error(`Failed to emit fallback master chunk for locale ${locale}:`, fallbackError.message);
266
- }
267
- }
268
- }
269
- }
270
123
  emitI18nAssert(compilation) {
271
- console.log('Starting I18n asset emission process...');
272
- this.captureModuleIds(compilation);
273
- this.entryPointKeys = new Set();
124
+ let manifest = {};
125
+ let needEmitManifest = false;
274
126
  compilation.chunks.forEach(chunk => {
275
127
  const manifestForChunk = this.emitI18nFilesForChunk(chunk, compilation);
128
+
276
129
  if (manifestForChunk.hasI18n) {
277
- this.regularManifest[chunk.id] = manifestForChunk.assets;
130
+ manifest[chunk.id] = manifestForChunk.assets;
131
+ needEmitManifest = needEmitManifest || manifestForChunk.hasChanges;
278
132
  }
279
133
  });
280
- this.createMetaManifestWithFinalIds(compilation);
281
- this.compareWithRemoteManifest(compilation);
282
- this.emitMasterChunks(compilation);
283
- (0, _createRegularManifest.createRegularManifest)(compilation, this);
284
- const metaManifestSource = new _webpackSources.RawSource(JSON.stringify(this.generatedMetaManifest, null, 2));
285
- this.emitAsset(compilation, this.i18nMetaManifestFileName, metaManifestSource, {
286
- desc: 'Updated meta manifest with master keys'
287
- });
288
- console.log('Completed I18n asset emission process');
134
+
135
+ if (needEmitManifest) {
136
+ const manifestSource = new _webpackSources.RawSource(JSON.stringify(manifest));
137
+ this.emitAsset(compilation, this.i18nManifestFileName, manifestSource, {
138
+ desc: 'this file is has chunks-locales-assets mapping'
139
+ });
140
+ }
289
141
  }
142
+
290
143
  apply(compiler) {
291
- compiler.hooks.afterCompile.tap(pluginName, compilation => {
292
- this.compilation = compilation;
293
- });
294
- compiler.hooks.emit.tapAsync(pluginName, (compilation, callback) => {
144
+ /*
145
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
146
+ compilation.mainTemplate.hooks.renderManifest.tap(
147
+ pluginName,
148
+ (result, { chunk }) => {
149
+ this.renderChunk(result, compilation, chunk);
150
+ }
151
+ );
152
+ compilation.chunkTemplate.hooks.renderManifest.tap(
153
+ pluginName,
154
+ (result, { chunk }) => {
155
+ this.renderChunk(result, compilation, chunk);
156
+ }
157
+ );
158
+ });
159
+ */
160
+ // this below hook was tapped for create asssets(file) for chunk specific i18nChunk Files
161
+ compiler.hooks.emit.tap(pluginName, compilation => {
295
162
  this.emitI18nAssert(compilation);
296
- callback();
297
163
  });
298
164
  }
165
+ /*
166
+ renderChunk(result, compilation, chunk) {
167
+ const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
168
+ // TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
169
+ // IDEA: we chose this place for add i18n locale files ????
170
+ if (i18nKeys.length > 0) {
171
+ Object.keys(this.allI18nObject).forEach(locale => {
172
+ result.push(
173
+ this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
174
+ );
175
+ });
176
+ }
177
+ }
178
+ */
179
+
180
+
299
181
  }
182
+
300
183
  exports.default = I18nFilesEmitter;
@@ -4,12 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _utils = require("./utils");
9
+
8
10
  var _I18nDependency = require("./I18nDependency");
11
+
9
12
  var _NullFactory = _interopRequireDefault(require("webpack/lib/NullFactory"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const pluginName = 'I18nKeysIdentifer';
12
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const pluginName = 'I18nKeysIdentifer';
13
17
  /**
14
18
  * this plugin search the i18 keys and make it as I18nDependency.
15
19
  * how it works?
@@ -19,14 +23,17 @@ const pluginName = 'I18nKeysIdentifer';
19
23
  * after the walk of AST we get some I18n keys
20
24
  * then we make it as I18nDependency.
21
25
  */
26
+
22
27
  class I18nKeysIdentifer {
23
28
  constructor(jsResourceI18nKeys) {
24
29
  this.jsResourceI18nKeys = jsResourceI18nKeys;
25
30
  }
31
+
26
32
  defineConfigarationForI18nDependency(compilation) {
27
33
  compilation.dependencyFactories.set(_I18nDependency.I18nDependency, new _NullFactory.default());
28
34
  compilation.dependencyTemplates.set(_I18nDependency.I18nDependency, new _I18nDependency.I18nDependencyTemplate());
29
35
  }
36
+
30
37
  addI18nDependency(module, i18nKeys) {
31
38
  const identifier = `i18n ${module.resource}`;
32
39
  const dep = new _I18nDependency.I18nDependency({
@@ -35,43 +42,46 @@ class I18nKeysIdentifer {
35
42
  }, module.context, 0);
36
43
  module.addDependency(dep);
37
44
  }
45
+
38
46
  apply(compiler) {
39
47
  compiler.hooks.thisCompilation.tap(pluginName, (compilation, params) => {
40
48
  // this below hook was tapped for we use I18nDependency
41
49
  // so we must define module factory for I18nDependency
42
50
  // and we must define how it import statement look like I18nDependencyTemplate
43
- this.defineConfigarationForI18nDependency(compilation);
51
+ this.defineConfigarationForI18nDependency(compilation); // handler for parser
44
52
 
45
- // handler for parser
46
53
  const handler = parser => {
47
54
  parser.hooks.program.tap(pluginName, (ast, commmets) => {
48
55
  const {
49
56
  module
50
- } = parser.state;
51
- //
57
+ } = parser.state; //
58
+
52
59
  if (!(module && /\.jsx?$/.test(module.resource))) {
53
60
  return;
54
- }
55
- // i18n grep proper contract regex
61
+ } // i18n grep proper contract regex
62
+
63
+
56
64
  let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
57
- i18nKeys = i18nKeys.concat(
58
- // i18n grep proper contract regex
65
+ i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
59
66
  (0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
67
+
60
68
  if (i18nKeys.length) {
61
69
  this.addI18nDependency(module, i18nKeys);
62
70
  }
63
71
  });
64
- };
72
+ }; // this below hook was tapped for collect I18n Key from files and add as Deppenensy
65
73
 
66
- // this below hook was tapped for collect I18n Key from files and add as Deppenensy
67
74
 
68
75
  const factory = params.normalModuleFactory;
69
76
  factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
70
77
  factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
71
78
  });
72
79
  }
80
+
73
81
  }
82
+
74
83
  exports.default = I18nKeysIdentifer;
84
+
75
85
  I18nKeysIdentifer.isChunkHasI18n = function (chunk) {
76
86
  for (const module of chunk.modulesIterable) {
77
87
  for (const dep of module.dependencies) {
@@ -80,5 +90,6 @@ I18nKeysIdentifer.isChunkHasI18n = function (chunk) {
80
90
  }
81
91
  }
82
92
  }
93
+
83
94
  return false;
84
95
  };
@@ -4,14 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _utils = require("./utils");
9
+
8
10
  var _webpack = require("webpack");
11
+
9
12
  var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
13
+
10
14
  var _I18nFilesEmitter = _interopRequireDefault(require("./I18nFilesEmitter"));
15
+
11
16
  var _I18nDownlodLogic = _interopRequireDefault(require("./I18nDownlodLogic"));
17
+
12
18
  var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKeysFormModules"));
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
14
22
  // #region initial
23
+
15
24
  /**
16
25
  * @TODO:
17
26
  * [?] add comment line options for properties file and get all keys form property file do right way to genarate them
@@ -30,16 +39,16 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
30
39
  * - file means your machine files
31
40
  * - asset means that also file but that will create by webpack after build
32
41
  */
33
-
34
42
  // const getI18nLocales = require('./utils/getI18nLocales');
35
43
  // const { ConcatSource, SourceMapSource, OriginalSource } = sources;
36
44
  const {
37
45
  createHash
38
46
  } = _webpack.util;
39
47
  const MODULE_TYPE = 'json/i18n';
48
+
40
49
  const i18ntype = locale => `${MODULE_TYPE}/${locale}`;
41
- const pluginName = 'i18n-plugin';
42
50
 
51
+ const pluginName = 'i18n-plugin';
43
52
  /**
44
53
  * @typedef I18nPluginOptions
45
54
  * @property {String} filenameTemplate this was template for i18n chunk
@@ -68,16 +77,15 @@ class I18nPlugin {
68
77
  propertiesFolder,
69
78
  jsonpFunc
70
79
  } = this.options;
71
- this.publicPath = publicPath;
72
- // gethere i18n keys and values
80
+ this.publicPath = publicPath; // gethere i18n keys and values
81
+
73
82
  this.jsResourceI18nKeys = jsResource ? (0, _utils.getPropertiesAsJSON)(jsResource) : {};
74
83
  this.allI18nObject = (0, _utils.getAllI18n)({
75
84
  folderPath: propertiesFolder,
76
85
  disableDefault,
77
86
  jsResourceI18nKeys: this.jsResourceI18nKeys
78
- });
87
+ }); // initialize base data's and plugis
79
88
 
80
- // initialize base data's and plugis
81
89
  this.locales = Object.keys(this.allI18nObject);
82
90
  this.i18nKeysIdentifer = new _I18nKeysIdentifer.default(this.jsResourceI18nKeys);
83
91
  this.i18nFilesEmitter = new _I18nFilesEmitter.default({
@@ -94,6 +102,7 @@ class I18nPlugin {
94
102
  localeVarName
95
103
  });
96
104
  }
105
+
97
106
  maintainHashForAllI18nAssets(compilation) {
98
107
  /**
99
108
  * we write chunkHash logic inside of our plugin Because we only add Dependency not Module.
@@ -113,13 +122,14 @@ class I18nPlugin {
113
122
  hashDigestLength
114
123
  } = outputOptions;
115
124
  const i18nKeys = (0, _getI18nKeysFormModules.default)(chunk.modulesIterable);
125
+
116
126
  if (!i18nKeys.length) {
117
127
  return;
118
128
  }
129
+
119
130
  const {
120
131
  contentHash
121
- } = chunk;
122
- // contentHash = {
132
+ } = chunk; // contentHash = {
123
133
  // javascript: 'abcd2938',
124
134
  // 'css/mini-extract': 'askdijasod'
125
135
  // };
@@ -131,20 +141,19 @@ class I18nPlugin {
131
141
  });
132
142
  });
133
143
  }
144
+
134
145
  apply(compiler) {
135
146
  this.i18nKeysIdentifer.apply(compiler);
136
147
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
137
148
  // this below hook was tapped for hash for the specific i18nChunk Files and write logic to requireEnsure
138
- this.maintainHashForAllI18nAssets(compilation);
139
-
140
- // const { mainTemplate } = compilation;
149
+ this.maintainHashForAllI18nAssets(compilation); // const { mainTemplate } = compilation;
141
150
  // this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
142
151
  });
143
152
  this.i18nFilesEmitter.apply(compiler);
144
153
  this.i18nDownlodLogic.apply(compiler);
145
154
  }
146
- }
147
155
 
156
+ }
148
157
  /*
149
158
  // TODO: need to reimplement this logic
150
159
  // NOTE: this logic for split all content hash per mani chunk
@@ -171,4 +180,6 @@ class I18nPlugin {
171
180
 
172
181
  }
173
182
  */
183
+
184
+
174
185
  exports.default = I18nPlugin;
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.collectI18nKeysfromAST = collectI18nKeysfromAST;
7
7
  exports.collectI18nKeysfromComments = collectI18nKeysfromComments;
8
+
8
9
  const {
9
10
  walk
10
11
  } = require('estree-walker');
12
+
11
13
  function collectI18nKeysfromAST(ast, allI18n) {
12
14
  let i18nKeys = {};
13
15
  walk(ast, {
@@ -21,34 +23,42 @@ function collectI18nKeysfromAST(ast, allI18n) {
21
23
  });
22
24
  return Object.keys(i18nKeys);
23
25
  }
26
+
24
27
  const prefixI18nComment = 'I18N';
25
28
  const prefixI18nComment1 = 'dynamic-i18n-key';
29
+
26
30
  function getI18nKeysFromComment(comment) {
27
31
  let commentString = comment.value.trim();
28
32
  let i18nKeyStr;
33
+
29
34
  if (commentString.startsWith(prefixI18nComment)) {
30
35
  i18nKeyStr = commentString.slice(prefixI18nComment.length).trim();
31
36
  } else if (commentString.startsWith(prefixI18nComment1)) {
32
37
  i18nKeyStr = commentString.slice(prefixI18nComment1.length).trim();
33
38
  }
39
+
34
40
  if (!i18nKeyStr) {
35
41
  return [];
36
42
  }
43
+
37
44
  const i18nKeys = i18nKeyStr.split(',');
38
45
  return i18nKeys;
39
- }
46
+ } // export function fromComments(comments, allI18n) {
47
+
40
48
 
41
- // export function fromComments(comments, allI18n) {
42
49
  function collectI18nKeysfromComments(comments, allI18n) {
43
50
  // TODO: need to implement
44
51
  let i18nKeys = {};
52
+
45
53
  for (let comment of comments) {
46
54
  let keys = getI18nKeysFromComment(comment);
55
+
47
56
  for (let key of keys) {
48
57
  if (key && allI18n[key]) {
49
58
  i18nKeys[key] = allI18n[key];
50
59
  }
51
60
  }
52
61
  }
62
+
53
63
  return Object.keys(i18nKeys);
54
64
  }
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getI18nFileUrlPathTemplate = getI18nFileUrlPathTemplate;
7
+
7
8
  function getI18nFileUrlPathTemplate(compilation, chunk, filenameTemplate, localeTemplate) {
8
9
  let urlpath = compilation.getPath(filenameTemplate, {
9
10
  chunk
@@ -4,18 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getI18nKeysFormModules;
7
+
7
8
  var _I18nDependency = require("../I18nDependency");
9
+
8
10
  function getI18nKeysFormModules(modules) {
9
11
  const i18nTemObj = {};
12
+
10
13
  for (let m of modules) {
11
14
  for (let dep of m.dependencies) {
12
15
  if (!(dep instanceof _I18nDependency.I18nDependency)) {
13
16
  continue;
14
17
  }
18
+
15
19
  for (const key of dep.i18nKeys) {
16
20
  i18nTemObj[key] = 1;
17
21
  }
18
22
  }
19
23
  }
24
+
20
25
  return Object.keys(i18nTemObj);
21
26
  }