@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,22 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
+
8
10
  var _utils = require("../utils");
11
+
9
12
  var _urlConcat = require("../utils/urlConcat");
13
+
10
14
  var _path = _interopRequireDefault(require("path"));
15
+
11
16
  var _webpackSources = require("webpack-sources");
17
+
12
18
  var _hashUtils = require("./I18nSplitPlugin/utils/hashUtils");
19
+
13
20
  var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
15
24
  let i18nObj = null;
16
25
  const options = (0, _utils.getOptions)();
26
+
17
27
  function newAssign(target, data) {
18
28
  return Object.assign({}, target, data);
19
29
  }
30
+
20
31
  const {
21
32
  i18n
22
33
  } = options;
34
+
23
35
  class I18NInjectIntoIndexPlugin {
24
36
  constructor(options) {
25
37
  this.isDevelopment = options.isDevelopment;
@@ -29,33 +41,35 @@ class I18NInjectIntoIndexPlugin {
29
41
  this.i18nManifestFileName = options.i18nManifestFileName;
30
42
  this.entryPointName = options.mainChunkName;
31
43
  }
44
+
32
45
  getI18nFileUrlPath(chunk, compilation) {
33
46
  const urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
34
47
  return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
35
48
  }
49
+
36
50
  getI18nManifest(compilation) {
37
51
  const i18nManifestFile = compilation.assets[this.i18nManifestFileName];
52
+
38
53
  if (!i18nManifestFile) {
39
54
  return {};
40
55
  }
56
+
41
57
  const manifest = JSON.parse(i18nManifestFile.source());
42
58
  return manifest;
43
59
  }
60
+
44
61
  injectI18nURLsToHTML(compilation) {
45
62
  _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
46
63
  const {
47
64
  assets
48
- } = data;
49
- // Manipulate the content
50
- // const i18nManifest = this.getI18nManifest(compilation);
51
- // const entryPoint = compilation.entrypoints.get(this.entryPointName);
52
- const i18nScriptURLs = [];
53
- i18nScriptURLs.push("i18n-chunk/desk-i18n-manifest.js");
54
- i18nScriptURLs.push(`i18n-chunk/${this.templateLabel}/master.i18n.js`);
55
-
56
- // .map(url => getI18nScriptTagObj(url));
65
+ } = data; // Manipulate the content
66
+
67
+ const i18nManifest = this.getI18nManifest(compilation);
68
+ const entryPoint = compilation.entrypoints.get(this.entryPointName);
69
+ const i18nScriptURLs = entryPoint.chunks.filter(c => !!i18nManifest[c.id]).map(c => this.getI18nFileUrlPath(c, compilation)); // .map(url => getI18nScriptTagObj(url));
57
70
  // .join('');
58
71
  // Tell webpack to move on
72
+
59
73
  cb(null, newAssign(data, {
60
74
  assets: newAssign(assets, {
61
75
  js: i18nScriptURLs.concat(assets.js)
@@ -63,6 +77,7 @@ class I18NInjectIntoIndexPlugin {
63
77
  }));
64
78
  });
65
79
  }
80
+
66
81
  withI18nSpitHandling(compiler) {
67
82
  compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
68
83
  // let cdns = Object.keys(this.publicPaths);
@@ -70,17 +85,19 @@ class I18NInjectIntoIndexPlugin {
70
85
  this.injectI18nURLsToHTML(compilation);
71
86
  return;
72
87
  }
88
+
73
89
  _htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
74
90
  // Manipulate the content
75
91
  const i18nManifest = this.getI18nManifest(compilation);
76
92
  const entryPoint = compilation.entrypoints.get(this.entryPointName);
77
93
  const i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
78
- data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets)));
79
- // Tell webpack to move on
94
+ data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
95
+
80
96
  cb(null, data);
81
97
  });
82
98
  });
83
99
  }
100
+
84
101
  apply(compiler) {
85
102
  if (i18n.chunkSplitEnable) {
86
103
  this.withI18nSpitHandling(compiler);
@@ -88,12 +105,13 @@ class I18NInjectIntoIndexPlugin {
88
105
  this.withoutI18nSpitHandling(compiler);
89
106
  }
90
107
  }
108
+
91
109
  withoutI18nSpitHandling(compiler) {
92
110
  compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
93
111
  // let cdns = Object.keys(this.publicPaths);
94
112
  if (i18nObj === null) {
95
- const i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1);
96
- //hook for i18n url contains i18n/ may cause problem
113
+ const i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
114
+
97
115
  i18nObj = i18nFiles.reduce((res, next) => {
98
116
  const fileName = next.replace(`i18n${_path.default.sep}`, '');
99
117
  const splittedFileName = fileName.split('.');
@@ -102,16 +120,21 @@ class I18NInjectIntoIndexPlugin {
102
120
  } else {
103
121
  res[splittedFileName[0]] = fileName;
104
122
  } */
123
+
105
124
  res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
106
125
  return res;
107
126
  }, {});
108
127
  }
128
+
109
129
  const [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
130
+
110
131
  if (indexFile) {
111
132
  const source = compilation.assets[indexFile].source();
112
133
  compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
113
134
  }
114
135
  });
115
136
  }
137
+
116
138
  }
139
+
117
140
  exports.default = I18NInjectIntoIndexPlugin;
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _utils = require("./utils");
8
- const pluginName = 'I18nDebugPlugin';
9
- // this plugin only for debug related purpose
9
+
10
+ const pluginName = 'I18nDebugPlugin'; // this plugin only for debug related purpose
10
11
 
11
12
  class I18nDebugPlugin {
12
13
  constructor(jsResourceI18nKeys) {
13
14
  this.jsResourceI18nKeys = jsResourceI18nKeys;
14
15
  this.warnings = [];
15
16
  }
17
+
16
18
  apply(compiler) {
17
19
  compiler.hooks.thisCompilation.tap(pluginName, (compilation, compilationParams) => {
18
20
  // TEMP : only for debugging purpose
@@ -23,19 +25,20 @@ class I18nDebugPlugin {
23
25
  if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
24
26
  return;
25
27
  }
28
+
26
29
  const handler = parser => {
27
30
  parser.hooks.program.tap(pluginName, (ast, commmets) => {
28
31
  const {
29
32
  module
30
- } = parser.state;
31
- //
33
+ } = parser.state; //
34
+
32
35
  if (!(module && /\.jsx?$/.test(module.resource))) {
33
36
  return;
34
- }
35
- // i18n grep proper contract regex
37
+ } // i18n grep proper contract regex
38
+
39
+
36
40
  let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
37
- i18nKeys = i18nKeys.concat(
38
- // i18n grep proper contract regex
41
+ i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
39
42
  (0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
40
43
  i18nKeys.length && this.warnings.push({
41
44
  message: 'skiped i18n keys',
@@ -45,10 +48,12 @@ class I18nDebugPlugin {
45
48
  });
46
49
  });
47
50
  };
51
+
48
52
  factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
49
- factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
50
- // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
53
+ factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler); // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
51
54
  });
52
55
  }
56
+
53
57
  }
58
+
54
59
  exports.default = I18nDebugPlugin;
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.I18nDependencyTemplate = exports.I18nDependency = void 0;
7
+
7
8
  var _webpack = require("webpack");
8
- // const webpack = require('webpack');
9
9
 
10
+ // const webpack = require('webpack');
10
11
  class I18nDependency extends _webpack.Dependency {
11
12
  constructor({
12
13
  identifier,
@@ -18,21 +19,26 @@ class I18nDependency extends _webpack.Dependency {
18
19
  this.i18nKeys = i18nKeys;
19
20
  this.context = context;
20
21
  }
22
+
21
23
  getResourceIdentifier() {
22
24
  return `i18n-module-${this.identifier}-${this.identifierIndex}`;
23
25
  }
26
+
24
27
  }
28
+
25
29
  exports.I18nDependency = I18nDependency;
30
+
26
31
  class I18nDependencyTemplate {
27
32
  //eslint-disable-next-line no-empty-function
28
- apply() {}
29
- // apply(dep, source) {
33
+ apply() {} // apply(dep, source) {
30
34
  // if (typeof dep.range === "number") {
31
35
  // source.insert(0, `/* comment by I18nSplitPlugin , i18n keys = ${JSON.stringify(dep.i18nKeys)} */`);
32
36
  // return;
33
37
  // }
34
-
35
38
  // source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
36
39
  // }
40
+
41
+
37
42
  }
43
+
38
44
  exports.I18nDependencyTemplate = I18nDependencyTemplate;
@@ -4,9 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _webpack = require("webpack");
9
+
8
10
  var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var _hashUtils = require("./utils/hashUtils");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
10
16
  /**
11
17
  * this plugin for the download i18n files
12
18
  * So, if need to downoad i18n in browser this plugin handle that
@@ -25,9 +31,43 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
25
31
  * some thing missing in this definetion
26
32
  *
27
33
  */
34
+ // import { REGEXP_HASH, REGEXP_CHUNKHASH } from './utils/hashUtils';
35
+ const pluginName = 'DownloadLogicOfI18n'; // const pluginName = 'i18n-plugin';
28
36
 
29
- const pluginName = 'DownloadLogicOfI18n';
30
37
  const MODULE_TYPE = 'json/i18n';
38
+
39
+ const ltype = locale => `${MODULE_TYPE}/${locale}`;
40
+
41
+ function hashesWithLength(hashes, length) {
42
+ const shortChunkHashMap = {};
43
+
44
+ for (let key of Object.keys(hashes)) {
45
+ if (typeof hashes[key] === 'string') {
46
+ shortChunkHashMap[key] = hashes.slice(0, length);
47
+ }
48
+ }
49
+
50
+ return shortChunkHashMap;
51
+ }
52
+
53
+ function getContentHashMaxLength(filenameTemplate) {
54
+ let length = 0;
55
+ let matches = filenameTemplate.match(_hashUtils.REGEXP_CONTENTHASH);
56
+
57
+ for (let match of matches) {
58
+ let tem = match.match(/\d+/);
59
+
60
+ if (tem) {
61
+ length = Math.max(parseInt(tem[0]), length);
62
+ } else {
63
+ length = 0;
64
+ break;
65
+ }
66
+ }
67
+
68
+ return length;
69
+ }
70
+
31
71
  class I18nDownlodLogic {
32
72
  constructor({
33
73
  filenameTemplate,
@@ -41,153 +81,190 @@ class I18nDownlodLogic {
41
81
  filenameTemplate,
42
82
  localeVarName
43
83
  };
44
- this.finalChunkIds = new Map();
45
84
  }
46
- captureChunkIds(compilation) {
47
- this.finalChunkIds.clear();
48
- compilation.chunks.forEach(chunk => {
49
- this.finalChunkIds.set(chunk.id, {
50
- original: chunk.id,
51
- name: chunk.name || null
52
- });
85
+
86
+ getShortContentHashes(chunk, hashLength) {
87
+ let allContenHashes = {};
88
+ const chunkMaps = chunk.getChunkMaps();
89
+ this.locales.forEach(locale => {
90
+ allContenHashes[locale] = chunkMaps.contentHash[ltype(locale)];
53
91
  });
92
+
93
+ if (!length) {
94
+ return allContenHashes;
95
+ }
96
+
97
+ let shortContentHashMap = {};
98
+
99
+ for (const locale of this.locales) {
100
+ shortContentHashMap[locale] = hashesWithLength(allContenHashes[locale], hashLength);
101
+ }
102
+
103
+ return shortContentHashMap;
54
104
  }
105
+
55
106
  getI18nChunkObject(mainChunk) {
56
107
  const obj = {};
108
+
57
109
  for (const chunk of mainChunk.getAllAsyncChunks()) {
58
- const finalChunkId = chunk.id;
59
110
  if (_I18nKeysIdentifer.default.isChunkHasI18n(chunk)) {
60
- // Store using the final chunk ID
61
- obj[finalChunkId] = 1;
62
-
63
- // Also keep track of which chunks have i18n content
64
- this.finalChunkIds.set(finalChunkId, {
65
- original: chunk.id,
66
- name: chunk.name || null
67
- });
111
+ obj[chunk.id] = 1;
68
112
  }
69
113
  }
114
+
70
115
  return obj;
71
116
  }
117
+
72
118
  addDownloadLogicOfI18nInMainTemplate(mainTemplate) {
73
- // Extend localVars to create a container for tracking loaded i18n chunks.
74
119
  mainTemplate.hooks.localVars.tap(pluginName, (source, mainChunk) => {
75
120
  const chunkMap = this.getI18nChunkObject(mainChunk);
121
+
76
122
  if (!Object.keys(chunkMap).length) {
77
123
  return source;
78
124
  }
79
- return _webpack.Template.asString([source, '', '// Object to store loaded I18N chunks', '// Using final chunk IDs from webpack', 'var installedI18nChunks = {', _webpack.Template.indent(mainChunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};']);
80
- });
81
125
 
82
- // Extend requireEnsure so that whenever a JS chunk is requested,
83
- // we also download its associated i18n file (if available).
126
+ return _webpack.Template.asString([source, '', '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(mainChunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};']);
127
+ });
84
128
  mainTemplate.hooks.requireEnsure.tap(pluginName, (source, mainChunk, hash) => {
129
+ /**
130
+ * for Information this is tapped in mainTemplate ,
131
+ * So this hooks argument chunk is main chunk means entry chunk mostly.
132
+ * if any chunk has i18n then we must write our download i18n logic,
133
+ */
85
134
  const chunkMap = this.getI18nChunkObject(mainChunk);
135
+
86
136
  if (!Object.keys(chunkMap).length) {
87
137
  return source;
88
138
  }
139
+ /**
140
+ * chunkMaps has
141
+ * @property {Object} hash [it has key as chunk id and value as chunkHash ]
142
+ * @property {Object} name [it has key as chunk id and value as chunk name ]
143
+ */
144
+
145
+
146
+ const chunkMaps = mainChunk.getChunkMaps();
89
147
  const {
90
148
  crossOriginLoading
91
149
  } = mainTemplate.outputOptions;
92
150
  const {
151
+ filenameTemplate,
93
152
  localeVarName = 'document.documentElement.lang'
94
153
  } = this.options;
154
+ const i18nSrcPath = mainTemplate.getAssetPath(JSON.stringify(filenameTemplate).replace(/\[locale\]/gi, '"+ locale +"'), // "i18n-chunk/[locale]/[name].[chunkhash].js"
155
+ {
156
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
157
+ hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
158
+ chunk: {
159
+ id: '" + chunkId + "',
160
+ hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
161
+
162
+ hashWithLength(length) {
163
+ const shortChunkHashMap = hashesWithLength(chunkMaps.hash, length);
164
+ return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
165
+ },
166
+
167
+ // contentHash: contentHashMap,
168
+ // contentHashWithLength: contentHashLengthMap,
169
+ contentHash: {
170
+ [MODULE_TYPE]: '" + contentHash + "'
171
+ },
172
+ contentHashWithLength: {
173
+ [MODULE_TYPE]: length => `" + contentHash.slice(0,${length}) + "`
174
+ },
175
+ name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
176
+ },
177
+ contentHashType: MODULE_TYPE
178
+ });
179
+ /** IDEA:
180
+ * as my suggestion ignore this `jsop` approch,
181
+ * Because json parse is faster then js parse.
182
+ * my suggestion is make ajax or fetch request
183
+ */
184
+
185
+ const buf = [];
186
+ /*
187
+ if (REGEXP_HASH.test(filenameTemplate)) {
188
+ buf.push(
189
+ `var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
190
+ );
191
+ }
192
+ if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
193
+ buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
194
+ }
195
+ */
196
+
197
+ if ((0, _hashUtils.hasContentHash)(filenameTemplate)) {
198
+ const hashLength = getContentHashMaxLength(filenameTemplate);
199
+ const contentHashes = this.getShortContentHashes(mainChunk, hashLength);
200
+ buf.push(_webpack.Template.asString(['// all i18n files contentHash ', `var i18nContentHashes = ${JSON.stringify(contentHashes)};`, '', 'if (!i18nContentHashes[locale]) {', ' console.warn("this locale is "+locale + " not has support")', ' return;', '}', 'if (!i18nContentHashes[locale][chunkId]) {', ' console.warn("this chunkId is " + chunkId + " does not have \'"+locale+"\' locale chunk")', ' return;', '}']));
201
+ buf.push('var contentHash = i18nContentHashes[locale][chunkId]');
202
+ }
203
+
204
+ const hashUtils = _webpack.Template.asString(buf);
95
205
 
96
- // Use the provided publicPath or fallback to the one provided by Webpack.
97
206
  const publicPath = this.publicPath ? JSON.stringify(this.publicPath) : `${mainTemplate.requireFn}.p`;
98
207
  return _webpack.Template.asString([source, `
99
208
  (function() {
100
- // ${pluginName} I18N loading with final chunk IDs
209
+ // ${pluginName} I18N loading
101
210
  var i18nChunks = ${JSON.stringify(chunkMap)};
102
211
  var locale = ${localeVarName};
103
-
104
- // Check if the current chunkId has an associated i18n resource
105
- if (installedI18nChunks[chunkId]) {
212
+ // ${pluginName} I18N hasehes
213
+ ${hashUtils}
214
+ if(installedI18nChunks[chunkId]) {
106
215
  promises.push(installedI18nChunks[chunkId]);
107
- } else if (installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {
216
+ } else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {
108
217
  promises.push(installedI18nChunks[chunkId] = new Promise(function(resolve, reject) {
109
- // Retrieve the i18n manifest from the global window.desk_i18n_manifest
110
- var deskManifest = window.desk_i18n_manifest;
111
-
112
- if (!deskManifest || !deskManifest.chunks || !deskManifest.chunks[chunkId]) {
113
- console.warn("No i18n file available for chunk " + chunkId);
114
- return resolve();
218
+ var srcPath = (${i18nSrcPath});
219
+ ${'' // TODO: I think this is the area for download chunk of i18n we can
220
+ // change mainTemplate.requireFn as our cdn server urls !!!
221
+ // and we can change the i18n download logic here
115
222
  }
116
-
117
- // Replace [locale] in the basePath with the actual locale
118
- var basePath = deskManifest.basePath.replace("[locale]", locale);
119
-
120
- // Construct the final URL for the i18n file
121
- var srcPath = basePath + deskManifest.chunks[chunkId];
122
223
  var fullsrcPath = ${publicPath} + srcPath;
123
-
124
- // Avoid duplicate loading by checking existing script tags
125
- var existingScriptTags = document.getElementsByTagName("script");
126
- for (var i = 0; i < existingScriptTags.length; i++) {
127
- var tag = existingScriptTags[i];
224
+ var existingLinkTags = document.getElementsByTagName("script");
225
+ for(var i = 0; i < existingLinkTags.length; i++) {
226
+ var tag = existingLinkTags[i];
128
227
  var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");
129
- if (dataSrc === srcPath || dataSrc === fullsrcPath) {
130
- return resolve();
131
- }
228
+ if(dataSrc === srcPath || dataSrc === fullsrcPath){ return resolve();}
132
229
  }
133
-
134
- // Create a script tag to load the i18n file
135
230
  var scriptTag = document.createElement("script");
136
- scriptTag.onload = function() {
231
+ scriptTag.onload = () => {
137
232
  scriptTag.onerror = scriptTag.onload = null;
138
233
  resolve();
139
234
  };
140
-
141
235
  scriptTag.onerror = function(event) {
142
236
  scriptTag.onerror = scriptTag.onload = null;
143
- var request = (event && event.target && event.target.src) || fullsrcPath;
237
+ var request = event && event.target && event.target.src || fullsrcPath;
144
238
  var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + request + ")");
145
239
  err.code = "I18N_CHUNK_LOAD_FAILED";
146
240
  err.request = request;
147
241
  delete installedI18nChunks[chunkId];
148
- if (scriptTag.parentNode) {
149
- scriptTag.parentNode.removeChild(scriptTag);
150
- }
242
+ scriptTag.parentNode.removeChild(scriptTag);
151
243
  reject(err);
152
244
  };
153
-
154
245
  ${mainTemplate.requireFn}.nc && scriptTag.setAttribute("nonce", ${mainTemplate.requireFn}.nc);
155
246
  scriptTag.src = fullsrcPath;
156
-
157
247
  ${crossOriginLoading ? `if (scriptTag.src.indexOf(window.location.origin + '/') !== 0) {
158
- scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};
159
- }` : ''}
160
-
248
+ scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};
249
+ }` : ''}
161
250
  document.body.appendChild(scriptTag);
162
251
  }).then(function() {
163
252
  installedI18nChunks[chunkId] = 0;
164
253
  }));
165
254
  }
166
- })()
167
- `]);
255
+ })()`]);
168
256
  });
169
257
  }
170
258
 
171
- /**
172
- * Applies the plugin by tapping into the appropriate Webpack hooks.
173
- * Now captures final chunk IDs after compilation is complete.
174
- *
175
- * @param {Compiler} compiler - The Webpack compiler instance.
176
- */
177
259
  apply(compiler) {
178
- // First capture final chunk IDs after compilation
179
- compiler.hooks.afterCompile.tap(pluginName, compilation => {
180
- this.captureChunkIds(compilation);
181
- });
182
-
183
- // Then inject download logic in thisCompilation
184
260
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
185
- // console.log(`${pluginName}: Adding download logic with final chunk IDs`);
186
261
  const {
187
262
  mainTemplate
188
263
  } = compilation;
189
264
  this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
190
265
  });
191
266
  }
267
+
192
268
  }
269
+
193
270
  exports.default = I18nDownlodLogic;