@zohodesk/react-cli 0.0.1-exp.175.1 → 0.0.1-exp.176.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. package/README.md +35 -40
  2. package/docs/SelectorWeight.md +6 -0
  3. package/docs/VariableConversion.md +33 -1
  4. package/lib/babel/cmjs-plugins-presets.js +4 -0
  5. package/lib/babel/es-plugins-presets.js +4 -0
  6. package/lib/common/getEntries.js +10 -0
  7. package/lib/common/getPublicPathConfig.js +6 -0
  8. package/lib/common/index.js +5 -0
  9. package/lib/common/splitChunks.js +13 -2
  10. package/lib/common/sslcertUpdater.js +17 -6
  11. package/lib/common/templateParameters.js +2 -0
  12. package/lib/common/testPattern.js +21 -10
  13. package/lib/common/valueReplacer.js +15 -0
  14. package/lib/configs/jest.config.js +9 -0
  15. package/lib/configs/libAlias.js +2 -4
  16. package/lib/configs/webpack.component.umd.config.js +5 -0
  17. package/lib/configs/webpack.css.umd.config.js +13 -5
  18. package/lib/configs/webpack.dev.config.js +36 -2
  19. package/lib/configs/webpack.docs.config.js +21 -1
  20. package/lib/configs/webpack.impact.config.js +19 -1
  21. package/lib/configs/webpack.prod.config.js +37 -3
  22. package/lib/hooks/docsProptypeHook.js +7 -3
  23. package/lib/jest/commitedFilesResult.js +45 -3
  24. package/lib/jest/coverageCollector.js +11 -0
  25. package/lib/jest/jsonMaker.js +6 -0
  26. package/lib/jest/preProcessors/cssPreprocessor.js +8 -0
  27. package/lib/jest/preProcessors/jsPreprocessor.js +2 -0
  28. package/lib/jest/preProcessors/otherFilesPreprocessor.js +3 -0
  29. package/lib/jest/result.js +22 -0
  30. package/lib/jest/run.js +17 -6
  31. package/lib/jest/setup.js +57 -5
  32. package/lib/loaderUtils/configsAssetsLoaders.js +11 -1
  33. package/lib/loaderUtils/getCSSLoaders.js +35 -20
  34. package/lib/loaderUtils/getDevJsLoaders.js +8 -0
  35. package/lib/loaderUtils/index.js +3 -0
  36. package/lib/loaderUtils/windowsModification.js +11 -0
  37. package/lib/loaders/docsLoader.js +7 -0
  38. package/lib/loaders/docsPropsLoader.js +7 -3
  39. package/lib/loaders/fileBountryLoader.js +2 -0
  40. package/lib/loaders/fileLoader.js +22 -11
  41. package/lib/loaders/scriptInstrumentLoader.js +13 -5
  42. package/lib/loaders/selectorMappingLoader.js +25 -7
  43. package/lib/loaders/workerLoader.js +20 -4
  44. package/lib/middlewares/HMRMiddleware.js +26 -13
  45. package/lib/middlewares/SSTMiddleware.js +3 -0
  46. package/lib/pluginUtils/configHtmlWebpackPlugins.js +9 -3
  47. package/lib/pluginUtils/getDevPlugins.js +63 -17
  48. package/lib/pluginUtils/getDocsPlugins.js +10 -1
  49. package/lib/pluginUtils/getLibraryImactPlugins.js +5 -4
  50. package/lib/pluginUtils/getLibraryPlugins.js +5 -0
  51. package/lib/pluginUtils/getProdPlugins.js +72 -23
  52. package/lib/pluginUtils/getServerPlugins.js +5 -0
  53. package/lib/pluginUtils/getUMDCSSPlugins.js +7 -0
  54. package/lib/pluginUtils/getUMDComponentPlugins.js +7 -0
  55. package/lib/pluginUtils/index.js +8 -0
  56. package/lib/plugins/CdnChangePlugin.js +14 -0
  57. package/lib/plugins/CleanupStatsPlugin.js +5 -0
  58. package/lib/plugins/EFCPlugin.js +34 -23
  59. package/lib/plugins/EFCTemplatePlugin.js +32 -23
  60. package/lib/plugins/I18NInjectIntoIndexPlugin.js +34 -8
  61. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +17 -12
  62. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +10 -4
  63. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +39 -8
  64. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +29 -14
  65. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +22 -13
  66. package/lib/plugins/I18nSplitPlugin/index.js +23 -13
  67. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +12 -2
  68. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +1 -0
  69. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +5 -0
  70. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +6 -0
  71. package/lib/plugins/I18nSplitPlugin/utils/index.js +4 -0
  72. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -2
  73. package/lib/plugins/ManifestPlugin.js +17 -0
  74. package/lib/plugins/ModuleStatsPlugin.js +23 -0
  75. package/lib/plugins/OptimizeJSPlugin.js +7 -0
  76. package/lib/plugins/PublicPathCallbackPlugin.js +10 -0
  77. package/lib/plugins/PublicPathChangePlugin.js +36 -4
  78. package/lib/plugins/ReportGeneratePlugin.js +30 -4
  79. package/lib/plugins/RequireVariablePublicPlugin.js +6 -0
  80. package/lib/plugins/ResourceHintsPlugin.js +10 -3
  81. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +17 -12
  82. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +16 -9
  83. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +5 -2
  84. package/lib/plugins/ScriptInstrumentPlugin.js +7 -0
  85. package/lib/plugins/SelectorPlugin.js +97 -0
  86. package/lib/plugins/ServiceWorkerPlugin.js +20 -4
  87. package/lib/plugins/ShadowDOMSupportPlugin.js +40 -3
  88. package/lib/plugins/SourceMapHookPlugin.js +9 -0
  89. package/lib/plugins/TPHashMappingPlugin.js +15 -1
  90. package/lib/plugins/UglifyCSSPlugin.js +9 -0
  91. package/lib/plugins/UnusedFilesFindPlugin.js +35 -2
  92. package/lib/plugins/VariableConversionCollector.js +252 -0
  93. package/lib/plugins/composeCommonPlugin.js +30 -0
  94. package/lib/plugins/index.js +19 -0
  95. package/lib/plugins/libraryImpactPlugin.js +32 -0
  96. package/lib/plugins/webpackwatchrunplugin.js +5 -0
  97. package/lib/postcss-plugins/ExcludePlugin.js +4 -0
  98. package/lib/postcss-plugins/RTLSplitPlugin.js +27 -14
  99. package/lib/postcss-plugins/ValueReplacer.js +6 -9
  100. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +3 -0
  101. package/lib/postcss-plugins/hoverActivePlugin.js +66 -30
  102. package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +40 -13
  103. package/lib/postcss-plugins/variableModificationPlugin/index.js +215 -141
  104. package/lib/postcss-plugins/variableModifier.js +20 -13
  105. package/lib/schemas/index.js +23 -4
  106. package/lib/servers/clusterHubServer.js +10 -0
  107. package/lib/servers/devBuild.js +24 -13
  108. package/lib/servers/docsServer.js +2 -0
  109. package/lib/servers/docsServerCore.js +21 -0
  110. package/lib/servers/getCliPath.js +9 -0
  111. package/lib/servers/helpServer.js +5 -0
  112. package/lib/servers/httpsOptions.js +4 -0
  113. package/lib/servers/impactServer.js +34 -2
  114. package/lib/servers/mockserver.js +9 -0
  115. package/lib/servers/nowatchserver.js +34 -12
  116. package/lib/servers/scrServer.js +20 -13
  117. package/lib/servers/server.js +35 -7
  118. package/lib/servers/ssServer.js +16 -0
  119. package/lib/templates/CoverageScriptTemplate.js +14 -0
  120. package/lib/templates/WMSTemplate.js +12 -6
  121. package/lib/utils/babelPresets.js +2 -0
  122. package/lib/utils/clean.js +8 -2
  123. package/lib/utils/copy.js +6 -0
  124. package/lib/utils/copyTimezones.js +8 -0
  125. package/lib/utils/createEventStream.js +4 -0
  126. package/lib/utils/cssClassNameGenerate.js +19 -3
  127. package/lib/utils/cssURLReplacer.js +50 -38
  128. package/lib/utils/dependencyPostPublish.js +9 -0
  129. package/lib/utils/fileUtils.js +26 -0
  130. package/lib/utils/folderIterator.js +10 -0
  131. package/lib/utils/getComponents.js +21 -0
  132. package/lib/utils/getCurrentBranch.js +5 -0
  133. package/lib/utils/getDependenciesImpactList.js +21 -0
  134. package/lib/utils/getFileType.js +49 -0
  135. package/lib/utils/getHash.js +7 -0
  136. package/lib/utils/getIp.js +2 -0
  137. package/lib/utils/getOptions.js +39 -14
  138. package/lib/utils/getServerURL.js +7 -0
  139. package/lib/utils/index.js +47 -2
  140. package/lib/utils/init.js +1 -0
  141. package/lib/utils/initPreCommitHook.js +29 -6
  142. package/lib/utils/jsonHelper.js +19 -2
  143. package/lib/utils/libraryImpactConfig.js +2 -0
  144. package/lib/utils/lint/addScripts.js +5 -2
  145. package/lib/utils/lint/checkExistingConfig.js +12 -3
  146. package/lib/utils/lint/copyConfigs.js +3 -0
  147. package/lib/utils/lint/index.js +9 -0
  148. package/lib/utils/lint/lintScripts.js +1 -0
  149. package/lib/utils/lint/lintSetup.js +4 -3
  150. package/lib/utils/lint/lintStagedPreCommitHook.js +1 -0
  151. package/lib/utils/lint/question.js +7 -0
  152. package/lib/utils/lintReporter.js +20 -0
  153. package/lib/utils/mailSender.js +7 -0
  154. package/lib/utils/pullOrigin.js +4 -0
  155. package/lib/utils/reinstallDependencies.js +28 -0
  156. package/lib/utils/removeAttributes.js +7 -0
  157. package/lib/utils/repoClone.js +27 -2
  158. package/lib/utils/request.js +12 -0
  159. package/lib/utils/rtl.js +16 -4
  160. package/lib/utils/setEnvVariables.js +2 -0
  161. package/lib/utils/ssTestHack.js +10 -0
  162. package/lib/utils/switchBranch.js +4 -0
  163. package/lib/utils/urlConcat.js +4 -0
  164. package/lib/utils/useExitCleanup.js +10 -9
  165. package/package.json +10 -9
@@ -4,10 +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"));
11
+
9
12
  var _hashUtils = require("./utils/hashUtils");
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
11
16
  /**
12
17
  * this plugin for the download i18n files
13
18
  * So, if need to downoad i18n in browser this plugin handle that
@@ -26,27 +31,32 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
26
31
  * some thing missing in this definetion
27
32
  *
28
33
  */
29
-
30
34
  // import { REGEXP_HASH, REGEXP_CHUNKHASH } from './utils/hashUtils';
35
+ const pluginName = 'DownloadLogicOfI18n'; // const pluginName = 'i18n-plugin';
31
36
 
32
- const pluginName = 'DownloadLogicOfI18n';
33
- // const pluginName = 'i18n-plugin';
34
37
  const MODULE_TYPE = 'json/i18n';
38
+
35
39
  const ltype = locale => `${MODULE_TYPE}/${locale}`;
40
+
36
41
  function hashesWithLength(hashes, length) {
37
42
  const shortChunkHashMap = {};
43
+
38
44
  for (let key of Object.keys(hashes)) {
39
45
  if (typeof hashes[key] === 'string') {
40
46
  shortChunkHashMap[key] = hashes.slice(0, length);
41
47
  }
42
48
  }
49
+
43
50
  return shortChunkHashMap;
44
51
  }
52
+
45
53
  function getContentHashMaxLength(filenameTemplate) {
46
54
  let length = 0;
47
55
  let matches = filenameTemplate.match(_hashUtils.REGEXP_CONTENTHASH);
56
+
48
57
  for (let match of matches) {
49
58
  let tem = match.match(/\d+/);
59
+
50
60
  if (tem) {
51
61
  length = Math.max(parseInt(tem[0]), length);
52
62
  } else {
@@ -54,8 +64,10 @@ function getContentHashMaxLength(filenameTemplate) {
54
64
  break;
55
65
  }
56
66
  }
67
+
57
68
  return length;
58
69
  }
70
+
59
71
  class I18nDownlodLogic {
60
72
  constructor({
61
73
  filenameTemplate,
@@ -70,36 +82,47 @@ class I18nDownlodLogic {
70
82
  localeVarName
71
83
  };
72
84
  }
85
+
73
86
  getShortContentHashes(chunk, hashLength) {
74
87
  let allContenHashes = {};
75
88
  const chunkMaps = chunk.getChunkMaps();
76
89
  this.locales.forEach(locale => {
77
90
  allContenHashes[locale] = chunkMaps.contentHash[ltype(locale)];
78
91
  });
92
+
79
93
  if (!length) {
80
94
  return allContenHashes;
81
95
  }
96
+
82
97
  let shortContentHashMap = {};
98
+
83
99
  for (const locale of this.locales) {
84
100
  shortContentHashMap[locale] = hashesWithLength(allContenHashes[locale], hashLength);
85
101
  }
102
+
86
103
  return shortContentHashMap;
87
104
  }
105
+
88
106
  getI18nChunkObject(mainChunk) {
89
107
  const obj = {};
108
+
90
109
  for (const chunk of mainChunk.getAllAsyncChunks()) {
91
110
  if (_I18nKeysIdentifer.default.isChunkHasI18n(chunk)) {
92
111
  obj[chunk.id] = 1;
93
112
  }
94
113
  }
114
+
95
115
  return obj;
96
116
  }
117
+
97
118
  addDownloadLogicOfI18nInMainTemplate(mainTemplate) {
98
119
  mainTemplate.hooks.localVars.tap(pluginName, (source, mainChunk) => {
99
120
  const chunkMap = this.getI18nChunkObject(mainChunk);
121
+
100
122
  if (!Object.keys(chunkMap).length) {
101
123
  return source;
102
124
  }
125
+
103
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')), '};']);
104
127
  });
105
128
  mainTemplate.hooks.requireEnsure.tap(pluginName, (source, mainChunk, hash) => {
@@ -109,6 +132,7 @@ class I18nDownlodLogic {
109
132
  * if any chunk has i18n then we must write our download i18n logic,
110
133
  */
111
134
  const chunkMap = this.getI18nChunkObject(mainChunk);
135
+
112
136
  if (!Object.keys(chunkMap).length) {
113
137
  return source;
114
138
  }
@@ -117,6 +141,8 @@ class I18nDownlodLogic {
117
141
  * @property {Object} hash [it has key as chunk id and value as chunkHash ]
118
142
  * @property {Object} name [it has key as chunk id and value as chunk name ]
119
143
  */
144
+
145
+
120
146
  const chunkMaps = mainChunk.getChunkMaps();
121
147
  const {
122
148
  crossOriginLoading
@@ -125,18 +151,19 @@ class I18nDownlodLogic {
125
151
  filenameTemplate,
126
152
  localeVarName = 'document.documentElement.lang'
127
153
  } = this.options;
128
- const i18nSrcPath = mainTemplate.getAssetPath(JSON.stringify(filenameTemplate).replace(/\[locale\]/gi, '"+ locale +"'),
129
- // "i18n-chunk/[locale]/[name].[chunkhash].js"
154
+ const i18nSrcPath = mainTemplate.getAssetPath(JSON.stringify(filenameTemplate).replace(/\[locale\]/gi, '"+ locale +"'), // "i18n-chunk/[locale]/[name].[chunkhash].js"
130
155
  {
131
156
  hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
132
157
  hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
133
158
  chunk: {
134
159
  id: '" + chunkId + "',
135
160
  hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
161
+
136
162
  hashWithLength(length) {
137
163
  const shortChunkHashMap = hashesWithLength(chunkMaps.hash, length);
138
164
  return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
139
165
  },
166
+
140
167
  // contentHash: contentHashMap,
141
168
  // contentHashWithLength: contentHashLengthMap,
142
169
  contentHash: {
@@ -149,7 +176,6 @@ class I18nDownlodLogic {
149
176
  },
150
177
  contentHashType: MODULE_TYPE
151
178
  });
152
-
153
179
  /** IDEA:
154
180
  * as my suggestion ignore this `jsop` approch,
155
181
  * Because json parse is faster then js parse.
@@ -167,13 +193,16 @@ class I18nDownlodLogic {
167
193
  buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
168
194
  }
169
195
  */
196
+
170
197
  if ((0, _hashUtils.hasContentHash)(filenameTemplate)) {
171
198
  const hashLength = getContentHashMaxLength(filenameTemplate);
172
199
  const contentHashes = this.getShortContentHashes(mainChunk, hashLength);
173
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;', '}']));
174
201
  buf.push('var contentHash = i18nContentHashes[locale][chunkId]');
175
202
  }
203
+
176
204
  const hashUtils = _webpack.Template.asString(buf);
205
+
177
206
  const publicPath = this.publicPath ? JSON.stringify(this.publicPath) : `${mainTemplate.requireFn}.p`;
178
207
  return _webpack.Template.asString([source, `
179
208
  (function() {
@@ -187,8 +216,7 @@ class I18nDownlodLogic {
187
216
  } else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {
188
217
  promises.push(installedI18nChunks[chunkId] = new Promise(function(resolve, reject) {
189
218
  var srcPath = (${i18nSrcPath});
190
- ${''
191
- // TODO: I think this is the area for download chunk of i18n we can
219
+ ${'' // TODO: I think this is the area for download chunk of i18n we can
192
220
  // change mainTemplate.requireFn as our cdn server urls !!!
193
221
  // and we can change the i18n download logic here
194
222
  }
@@ -223,6 +251,7 @@ class I18nDownlodLogic {
223
251
  })()`]);
224
252
  });
225
253
  }
254
+
226
255
  apply(compiler) {
227
256
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
228
257
  const {
@@ -231,5 +260,7 @@ class I18nDownlodLogic {
231
260
  this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
232
261
  });
233
262
  }
263
+
234
264
  }
265
+
235
266
  exports.default = I18nDownlodLogic;
@@ -4,19 +4,24 @@ 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"));
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
11
16
  /**
12
17
  * this plugin was creating the chunk specific i18n chunk's.
13
18
  */
14
-
15
19
  // this plugin's kick starter is apply method
16
-
17
20
  const pluginName = 'I18nFilesEmitter';
18
21
  const MODULE_TYPE = 'json/i18n';
22
+
19
23
  const i18ntype = locale => `${MODULE_TYPE}/${locale}`;
24
+
20
25
  class I18nFilesEmitter {
21
26
  constructor({
22
27
  allI18nObject,
@@ -27,12 +32,13 @@ class I18nFilesEmitter {
27
32
  }) {
28
33
  this.locales = locales;
29
34
  this.allI18nObject = allI18nObject;
30
- this.filenameTemplate = filenameTemplate;
31
- // this.filenameTemplate = "i18n-chunk/[locale]/[name].js"
35
+ this.filenameTemplate = filenameTemplate; // this.filenameTemplate = "i18n-chunk/[locale]/[name].js"
36
+
32
37
  this.jsonpFunc = jsonpFunc;
33
38
  this.prevHashes = {};
34
39
  this.i18nManifestFileName = i18nManifestFileName;
35
40
  }
41
+
36
42
  emitAsset(compilation, filename, source, info) {
37
43
  // NOTE: info support available since webpack v4.40.0 https://webpack.js.org/api/stats/#asset-objects
38
44
  if (!compilation.emitAsset) {
@@ -40,9 +46,9 @@ class I18nFilesEmitter {
40
46
  } else {
41
47
  compilation.emitAsset(filename, source, info);
42
48
  }
43
- }
49
+ } // this method for create object and assign value for i18nkeys
50
+
44
51
 
45
- // this method for create object and assign value for i18nkeys
46
52
  getI18nObjectByLocale(i18nKeys, locale) {
47
53
  const data = {};
48
54
  i18nKeys.forEach(key => {
@@ -50,10 +56,10 @@ class I18nFilesEmitter {
50
56
  });
51
57
  return data;
52
58
  }
59
+
53
60
  getTemplateString(i18nKeys, locale) {
54
61
  let i18nObject = this.getI18nObjectByLocale(i18nKeys, locale);
55
- return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`;
56
- // return `${this.jsonpFunc}(JSON.parse(${JSON.stringify(jsonToString(i18nObject))}));`;
62
+ return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`; // return `${this.jsonpFunc}(JSON.parse(${JSON.stringify(jsonToString(i18nObject))}));`;
57
63
  }
58
64
 
59
65
  renderI18nLocaleChunk(chunk, locale, i18nKeys) {
@@ -71,6 +77,7 @@ class I18nFilesEmitter {
71
77
  hash: chunk.contentHash[i18ntype(locale)]
72
78
  };
73
79
  }
80
+
74
81
  emitI18nFilesForChunk(chunk, compilation) {
75
82
  const i18nKeys = (0, _getI18nKeysFormModules.default)(chunk.modulesIterable);
76
83
  const manifestForChunk = {
@@ -78,12 +85,14 @@ class I18nFilesEmitter {
78
85
  hasI18n: false,
79
86
  hasChanges: false
80
87
  };
88
+
81
89
  if (!i18nKeys.length) {
82
90
  // why it is not checked as 0
83
91
  return manifestForChunk;
84
92
  }
85
- manifestForChunk.hasI18n = true;
86
- // const locales = ['en_US'];
93
+
94
+ manifestForChunk.hasI18n = true; // const locales = ['en_US'];
95
+
87
96
  this.locales.forEach(locale => {
88
97
  const result = this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation);
89
98
  const {
@@ -95,31 +104,34 @@ class I18nFilesEmitter {
95
104
  } = result;
96
105
  const filePath = compilation.getPath(filenameTemplate, pathOptions);
97
106
  manifestForChunk.assets[locale] = filePath;
107
+
98
108
  if (this.prevHashes[identifier] === hash) {
99
109
  return;
100
110
  }
111
+
101
112
  manifestForChunk.hasChanges = true;
102
113
  this.prevHashes[identifier] = hash;
103
114
  this.emitAsset(compilation, filePath, render(), {
104
115
  locale,
105
116
  chunkId: chunk.id,
106
117
  chunkName: chunk.name
107
- });
108
- // compilation.assets[filePath] = render();
118
+ }); // compilation.assets[filePath] = render();
109
119
  });
110
-
111
120
  return manifestForChunk;
112
121
  }
122
+
113
123
  emitI18nAssert(compilation) {
114
124
  let manifest = {};
115
125
  let needEmitManifest = false;
116
126
  compilation.chunks.forEach(chunk => {
117
127
  const manifestForChunk = this.emitI18nFilesForChunk(chunk, compilation);
128
+
118
129
  if (manifestForChunk.hasI18n) {
119
130
  manifest[chunk.id] = manifestForChunk.assets;
120
131
  needEmitManifest = needEmitManifest || manifestForChunk.hasChanges;
121
132
  }
122
133
  });
134
+
123
135
  if (needEmitManifest) {
124
136
  const manifestSource = new _webpackSources.RawSource(JSON.stringify(manifest));
125
137
  this.emitAsset(compilation, this.i18nManifestFileName, manifestSource, {
@@ -127,6 +139,7 @@ class I18nFilesEmitter {
127
139
  });
128
140
  }
129
141
  }
142
+
130
143
  apply(compiler) {
131
144
  /*
132
145
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
@@ -149,7 +162,6 @@ class I18nFilesEmitter {
149
162
  this.emitI18nAssert(compilation);
150
163
  });
151
164
  }
152
-
153
165
  /*
154
166
  renderChunk(result, compilation, chunk) {
155
167
  const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
@@ -164,5 +176,8 @@ class I18nFilesEmitter {
164
176
  }
165
177
  }
166
178
  */
179
+
180
+
167
181
  }
182
+
168
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"));
13
+
10
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- const pluginName = 'I18nKeysIdentifer';
12
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,22 +23,24 @@ 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({
33
40
  identifier,
34
41
  i18nKeys
35
42
  }, module.context, 0);
36
- module.addDependency(dep);
37
- // console.log('module', i18nKeys, identifier);
43
+ module.addDependency(dep); // console.log('module', i18nKeys, identifier);
38
44
  }
39
45
 
40
46
  apply(compiler) {
@@ -42,23 +48,23 @@ class I18nKeysIdentifer {
42
48
  // this below hook was tapped for we use I18nDependency
43
49
  // so we must define module factory for I18nDependency
44
50
  // and we must define how it import statement look like I18nDependencyTemplate
45
- this.defineConfigarationForI18nDependency(compilation);
51
+ this.defineConfigarationForI18nDependency(compilation); // handler for parser
46
52
 
47
- // handler for parser
48
53
  let handler = parser => {
49
54
  parser.hooks.program.tap(pluginName, (ast, commmets) => {
50
55
  const {
51
56
  module
52
- } = parser.state;
53
- //
57
+ } = parser.state; //
58
+
54
59
  if (!(module && /\.jsx?$/.test(module.resource))) {
55
60
  return;
56
- }
57
- // i18n grep proper contract regex
61
+ } // i18n grep proper contract regex
62
+
63
+
58
64
  let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
59
- i18nKeys = i18nKeys.concat(
60
- // i18n grep proper contract regex
65
+ i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
61
66
  (0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
67
+
62
68
  if (i18nKeys.length) {
63
69
  // console.log(
64
70
  // 'i18nKeys.length',
@@ -68,17 +74,19 @@ class I18nKeysIdentifer {
68
74
  this.addI18nDependency(module, i18nKeys);
69
75
  }
70
76
  });
71
- };
77
+ }; // this below hook was tapped for collect I18n Key from files and add as Deppenensy
72
78
 
73
- // this below hook was tapped for collect I18n Key from files and add as Deppenensy
74
79
 
75
80
  const factory = params.normalModuleFactory;
76
81
  factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
77
82
  factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
78
83
  });
79
84
  }
85
+
80
86
  }
87
+
81
88
  exports.default = I18nKeysIdentifer;
89
+
82
90
  I18nKeysIdentifer.isChunkHasI18n = function (chunk) {
83
91
  for (const module of chunk.modulesIterable) {
84
92
  for (const dep of module.dependencies) {
@@ -87,5 +95,6 @@ I18nKeysIdentifer.isChunkHasI18n = function (chunk) {
87
95
  }
88
96
  }
89
97
  }
98
+
90
99
  return false;
91
100
  };
@@ -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"));
19
+
13
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(obj) { return obj && obj.__esModule ? obj : { de
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,21 +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
-
144
152
  this.i18nFilesEmitter.apply(compiler);
145
153
  this.i18nDownlodLogic.apply(compiler);
146
154
  }
147
- }
148
155
 
156
+ }
149
157
  /*
150
158
  // TODO: need to reimplement this logic
151
159
  // NOTE: this logic for split all content hash per mani chunk
@@ -172,4 +180,6 @@ class I18nPlugin {
172
180
  console.log('entry, ', c, hashSource.toString());
173
181
  }
174
182
  */
183
+
184
+
175
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
  }
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.REGEXP_CONTENTHASH = void 0;
7
7
  exports.getShortI18nAssets = getShortI18nAssets;
8
8
  exports.hasContentHash = hasContentHash;
9
+
9
10
  var _urlConcat = require("../../../utils/urlConcat");
11
+
10
12
  // export const REGEXP_CHUNKHASH = /\[chunkhash(?::(\d+))?\]/gi;
11
13
  // export const REGEXP_HASH = /\[hash(?::(\d+))?\]/gi;
12
14
  // export const REGEXP_NAME = /\[name\]/gi;
@@ -14,18 +16,22 @@ var _urlConcat = require("../../../utils/urlConcat");
14
16
  // TODO: want to choose file type for i18n load
15
17
  const REGEXP_CONTENTHASH = /\[contenthash(?::(\d+))?\]/gi;
16
18
  exports.REGEXP_CONTENTHASH = REGEXP_CONTENTHASH;
19
+
17
20
  function hasContentHash(filenameTemplate) {
18
21
  return REGEXP_CONTENTHASH.test(filenameTemplate);
19
22
  }
23
+
20
24
  function getShortI18nAssets(chunks, i18nManifest, publicPathPrefix) {
21
25
  const i18nAssets = {};
22
26
  chunks.forEach(chunk => {
23
27
  const i18nFiles = i18nManifest[chunk.id];
28
+
24
29
  if (i18nFiles) {
25
30
  Object.keys(i18nFiles).forEach(locale => {
26
31
  if (!i18nAssets[locale]) {
27
32
  i18nAssets[locale] = [];
28
33
  }
34
+
29
35
  i18nAssets[locale].push((0, _urlConcat.urlConcat)(publicPathPrefix, i18nFiles[locale]));
30
36
  });
31
37
  }