@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,20 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = ShadowDOMSupportPlugin;
7
+
7
8
  var _Template = _interopRequireDefault(require("webpack/lib/Template"));
9
+
8
10
  var _JsonpMainTemplatePlugin = _interopRequireDefault(require("webpack/lib/web/JsonpMainTemplatePlugin"));
11
+
9
12
  var _tapable = require("tapable");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- /* eslint-disable no-unused-vars */
12
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ /* eslint-disable no-unused-vars */
13
17
  //eslint-disable-next-line
14
18
  function ShadowDOMSupportPlugin() {}
19
+
15
20
  ShadowDOMSupportPlugin.prototype.apply = function () {
16
21
  this.patchJsonpMainTemplatePlugin();
17
22
  };
23
+
18
24
  ShadowDOMSupportPlugin.prototype.patchJsonpMainTemplatePlugin = function () {
19
25
  _JsonpMainTemplatePlugin.default.prototype.apply = this._apply;
20
26
  };
27
+
21
28
  ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
22
29
  const needChunkOnDemandLoadingCode = chunk => {
23
30
  for (const chunkGroup of chunk.groupsIterable) {
@@ -25,38 +32,46 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
25
32
  return true;
26
33
  }
27
34
  }
35
+
28
36
  return false;
29
37
  };
38
+
30
39
  const needChunkLoadingCode = chunk => {
31
40
  for (const chunkGroup of chunk.groupsIterable) {
32
41
  if (chunkGroup.chunks.length > 1) {
33
42
  return true;
34
43
  }
44
+
35
45
  if (chunkGroup.getNumberOfChildren() > 0) {
36
46
  return true;
37
47
  }
38
48
  }
49
+
39
50
  return false;
40
51
  };
52
+
41
53
  const needEntryDeferringCode = chunk => {
42
54
  for (const chunkGroup of chunk.groupsIterable) {
43
55
  if (chunkGroup.chunks.length > 1) {
44
56
  return true;
45
57
  }
46
58
  }
59
+
47
60
  return false;
48
61
  };
62
+
49
63
  const needPrefetchingCode = chunk => {
50
64
  const allPrefetchChunks = chunk.getChildIdsByOrdersMap(true).prefetch;
51
65
  return allPrefetchChunks && Object.keys(allPrefetchChunks).length;
52
- };
66
+ }; // TODO webpack 5, no adding to .hooks, use WeakMap and static methods
67
+
53
68
 
54
- // TODO webpack 5, no adding to .hooks, use WeakMap and static methods
55
69
  ['jsonpScript', 'linkPreload', 'linkPrefetch'].forEach(hook => {
56
70
  if (!mainTemplate.hooks[hook]) {
57
71
  mainTemplate.hooks[hook] = new _tapable.SyncWaterfallHook(['source', 'chunk', 'hash']);
58
72
  }
59
73
  });
74
+
60
75
  const getScriptSrcPath = (hash, chunk, chunkIdExpression) => {
61
76
  const {
62
77
  chunkFilename
@@ -68,15 +83,19 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
68
83
  chunk: {
69
84
  id: `" + ${chunkIdExpression} + "`,
70
85
  hash: `" + ${JSON.stringify(chunkMaps.hash)}[${chunkIdExpression}] + "`,
86
+
71
87
  hashWithLength(length) {
72
88
  const shortChunkHashMap = Object.create(null);
89
+
73
90
  for (const chunkId of Object.keys(chunkMaps.hash)) {
74
91
  if (typeof chunkMaps.hash[chunkId] === 'string') {
75
92
  shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
76
93
  }
77
94
  }
95
+
78
96
  return `" + ${JSON.stringify(shortChunkHashMap)}[${chunkIdExpression}] + "`;
79
97
  },
98
+
80
99
  name: `" + (${JSON.stringify(chunkMaps.name)}[${chunkIdExpression}]||${chunkIdExpression}) + "`,
81
100
  contentHash: {
82
101
  javascript: `" + ${JSON.stringify(chunkMaps.contentHash.javascript)}[${chunkIdExpression}] + "`
@@ -85,11 +104,13 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
85
104
  javascript: length => {
86
105
  const shortContentHashMap = {};
87
106
  const contentHash = chunkMaps.contentHash.javascript;
107
+
88
108
  for (const chunkId of Object.keys(contentHash)) {
89
109
  if (typeof contentHash[chunkId] === 'string') {
90
110
  shortContentHashMap[chunkId] = contentHash[chunkId].substr(0, length);
91
111
  }
92
112
  }
113
+
93
114
  return `" + ${JSON.stringify(shortContentHashMap)}[${chunkIdExpression}] + "`;
94
115
  }
95
116
  }
@@ -97,17 +118,22 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
97
118
  contentHashType: 'javascript'
98
119
  });
99
120
  };
121
+
100
122
  mainTemplate.hooks.localVars.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
101
123
  const extraCode = [];
124
+
102
125
  if (needChunkLoadingCode(chunk)) {
103
126
  extraCode.push('', '// object to store loaded and loading chunks', '// undefined = chunk not loaded, null = chunk preloaded/prefetched', '// Promise = chunk loading, 0 = chunk loaded', 'var installedChunks = {', _Template.default.indent(chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};', '', needEntryDeferringCode(chunk) ? 'var deferredModules = [];' : '');
104
127
  }
128
+
105
129
  if (needChunkOnDemandLoadingCode(chunk)) {
106
130
  extraCode.push('', '// script path function', 'function jsonpScriptSrc(chunkId) {', _Template.default.indent([`return ${mainTemplate.requireFn}.p + ${getScriptSrcPath(hash, chunk, 'chunkId')}`]), '}');
107
131
  }
132
+
108
133
  if (extraCode.length === 0) {
109
134
  return source;
110
135
  }
136
+
111
137
  return _Template.default.asString([source, ...extraCode]);
112
138
  });
113
139
  mainTemplate.hooks.jsonpScript.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
@@ -143,15 +169,18 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
143
169
  stage: 10
144
170
  }, (source, chunk, hash) => {
145
171
  const chunkMap = chunk.getChildIdsByOrdersMap().preload;
172
+
146
173
  if (!chunkMap || Object.keys(chunkMap).length === 0) {
147
174
  return source;
148
175
  }
176
+
149
177
  return _Template.default.asString([source, '', '// chunk preloadng for javascript', '', `var chunkPreloadMap = ${JSON.stringify(chunkMap, null, '\t')};`, '', 'var chunkPreloadData = chunkPreloadMap[chunkId];', 'if(chunkPreloadData) {', _Template.default.indent(['chunkPreloadData.forEach(function(chunkId) {', _Template.default.indent(['if(installedChunks[chunkId] === undefined) {', _Template.default.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'window.ZDShadowRoot.getElementById("head").appendChild(link);']), '}']), '});']), '}']);
150
178
  });
151
179
  mainTemplate.hooks.requireExtensions.tap('JsonpMainTemplatePlugin', (source, chunk) => {
152
180
  if (!needChunkOnDemandLoadingCode(chunk)) {
153
181
  return source;
154
182
  }
183
+
155
184
  return _Template.default.asString([source, '', '// on error function for async loading', `${mainTemplate.requireFn}.oe = function(err) { console.error(err); throw err; };`]);
156
185
  });
157
186
  mainTemplate.hooks.bootstrap.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
@@ -160,6 +189,7 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
160
189
  const withPrefetch = needPrefetchingCode(chunk);
161
190
  return _Template.default.asString([source, '', '// install a JSONP callback for chunk loading', 'function webpackJsonpCallback(data) {', _Template.default.indent(['var chunkIds = data[0];', 'var moreModules = data[1];', withDefer ? 'var executeModules = data[2];' : '', withPrefetch ? 'var prefetchChunks = data[3] || [];' : '', '// add "moreModules" to the modules object,', '// then flag all "chunkIds" as loaded and fire callback', 'var moduleId, chunkId, i = 0, resolves = [];', 'for(;i < chunkIds.length; i++) {', _Template.default.indent(['chunkId = chunkIds[i];', 'if(installedChunks[chunkId]) {', _Template.default.indent('resolves.push(installedChunks[chunkId][0]);'), '}', 'installedChunks[chunkId] = 0;']), '}', 'for(moduleId in moreModules) {', _Template.default.indent(['if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {', _Template.default.indent(mainTemplate.renderAddModule(hash, chunk, 'moduleId', 'moreModules[moduleId]')), '}']), '}', 'if(parentJsonpFunction) parentJsonpFunction(data);', withPrefetch ? _Template.default.asString(['// chunk prefetching for javascript', 'prefetchChunks.forEach(function(chunkId) {', _Template.default.indent(['if(installedChunks[chunkId] === undefined) {', _Template.default.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPrefetch.call('', chunk, hash), 'window.ZDShadowRoot.getElementById("head").appendChild(link);']), '}']), '});']) : '', 'while(resolves.length) {', _Template.default.indent('resolves.shift()();'), '}', withDefer ? _Template.default.asString(['', '// add entry modules from loaded chunk to deferred list', 'deferredModules.push.apply(deferredModules, executeModules || []);', '', '// run deferred modules when all chunks ready', 'return checkDeferredModules();']) : '']), '};', withDefer ? _Template.default.asString(['function checkDeferredModules() {', _Template.default.indent(['var result;', 'for(var i = 0; i < deferredModules.length; i++) {', _Template.default.indent(['var deferredModule = deferredModules[i];', 'var fulfilled = true;', 'for(var j = 1; j < deferredModule.length; j++) {', _Template.default.indent(['var depId = deferredModule[j];', 'if(installedChunks[depId] !== 0) fulfilled = false;']), '}', 'if(fulfilled) {', _Template.default.indent(['deferredModules.splice(i--, 1);', `result = ${mainTemplate.requireFn}(${mainTemplate.requireFn}.s = deferredModule[0]);`]), '}']), '}', 'return result;']), '}']) : '']);
162
191
  }
192
+
163
193
  return source;
164
194
  });
165
195
  mainTemplate.hooks.beforeStartup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
@@ -172,13 +202,16 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
172
202
  } = mainTemplate.outputOptions;
173
203
  return _Template.default.asString([`var jsonpArray = ${globalObject}[${JSON.stringify(jsonpFunction)}] = ${globalObject}[${JSON.stringify(jsonpFunction)}] || [];`, 'var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);', 'jsonpArray.push = webpackJsonpCallback;', 'jsonpArray = jsonpArray.slice();', 'for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);', 'var parentJsonpFunction = oldJsonpFunction;', '', source]);
174
204
  }
205
+
175
206
  return source;
176
207
  });
177
208
  mainTemplate.hooks.beforeStartup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
178
209
  const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
210
+
179
211
  if (needChunkLoadingCode(chunk) && prefetchChunks && prefetchChunks.length) {
180
212
  return _Template.default.asString([source, `webpackJsonpCallback([[], {}, 0, ${JSON.stringify(prefetchChunks)}]);`]);
181
213
  }
214
+
182
215
  return source;
183
216
  });
184
217
  mainTemplate.hooks.startup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
@@ -187,8 +220,10 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
187
220
  const entries = [chunk.entryModule].filter(Boolean).map(m => [m.id].concat(Array.from(chunk.groupsIterable)[0].chunks.filter(c => c !== chunk).map(c => c.id)));
188
221
  return _Template.default.asString(['// add entry module to deferred list', `deferredModules.push(${entries.map(e => JSON.stringify(e)).join(', ')});`, '// run deferred modules when ready', 'return checkDeferredModules();']);
189
222
  }
223
+
190
224
  return _Template.default.asString(['// run deferred modules from other chunks', 'checkDeferredModules();']);
191
225
  }
226
+
192
227
  return source;
193
228
  });
194
229
  mainTemplate.hooks.hotBootstrap.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
@@ -218,7 +253,9 @@ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
218
253
  hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
219
254
  hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
220
255
  });
256
+
221
257
  const runtimeSource = _Template.default.getFunctionContent(require('./JsonpMainTemplate.runtime')).replace(/\/\/\$semicolon/g, ';').replace(/\$require\$/g, mainTemplate.requireFn).replace(/\$crossOriginLoading\$/g, crossOriginLoading ? JSON.stringify(crossOriginLoading) : 'null').replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename).replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename).replace(/\$hash\$/g, JSON.stringify(hash));
258
+
222
259
  return `${source}
223
260
  function hotDisposeChunk(chunkId) {
224
261
  delete installedChunks[chunkId];
@@ -4,19 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _webpackSources = require("webpack-sources");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
10
14
  class SourceMapHookPlugin {
11
15
  apply(compiler) {
12
16
  compiler.hooks.emit.tap('SourceMapHookPlugin', compilation => {
13
17
  Object.keys(compilation.assets).forEach(filename => {
14
18
  if (/\.js$/g.test(filename) && !/(\.map.|tp\/)/g.test(filename)) {
15
19
  let source = compilation.assets[filename].source();
20
+
16
21
  let {
17
22
  name
18
23
  } = _path.default.parse(filename);
24
+
19
25
  let src = source;
26
+
20
27
  if (!/(i18n-chunk\/)/g.test(filename)) {
21
28
  src = `${source}\n//# sourceMappingURL=../../js/${name}.js.map`;
22
29
  compilation.assets[filename.replace(/js\//g, 'smap/js/')] = new _webpackSources.RawSource(src);
@@ -27,5 +34,8 @@ class SourceMapHookPlugin {
27
34
  });
28
35
  });
29
36
  }
37
+
30
38
  }
31
- var _default = exports.default = SourceMapHookPlugin;
39
+
40
+ var _default = SourceMapHookPlugin;
41
+ exports.default = _default;
@@ -1,18 +1,23 @@
1
1
  "use strict";
2
2
 
3
3
  const fs = require('fs');
4
+
4
5
  const path = require('path');
6
+
5
7
  const {
6
8
  Readable
7
9
  } = require('stream');
10
+
8
11
  const {
9
12
  removeKeysFromObject,
10
13
  convertObjectToStringGen
11
14
  } = require('../utils/object-manipulation');
15
+
12
16
  const pluginName = 'stats-plugin';
13
17
  const statsSchema = {
14
18
  all: true
15
19
  };
20
+
16
21
  class StatsPlugin {
17
22
  constructor({
18
23
  statsOptions,
@@ -23,6 +28,7 @@ class StatsPlugin {
23
28
  this.statsFileName = statsFileName || 'bundle-report-integrity.json';
24
29
  this.statsOptions = Object.assign({}, statsSchema, statsOptions || {});
25
30
  }
31
+
26
32
  apply(compiler) {
27
33
  compiler.hooks.done.tapAsync(pluginName, (stats, callback) => {
28
34
  const statsJson = removeKeysFromObject(stats.toJson(this.statsOptions), this.excludeKeysInStat);
@@ -33,6 +39,7 @@ class StatsPlugin {
33
39
  });
34
40
  });
35
41
  }
42
+
36
43
  writeStatsFileInAStream(statsObj) {
37
44
  const {
38
45
  outputPath
@@ -40,17 +47,20 @@ class StatsPlugin {
40
47
  const ouputFileName = path.join(outputPath, this.statsFileName);
41
48
  return this.createReadStream(statsObj).pipe(fs.createWriteStream(ouputFileName));
42
49
  }
50
+
43
51
  createReadStream(statsObj) {
44
52
  const excludeKeys = this.excludeKeysInStat;
45
53
  return new Readable({
46
54
  read() {
47
55
  let isDone = false;
48
56
  const objToStringGen = convertObjectToStringGen(statsObj, excludeKeys);
57
+
49
58
  while (!isDone) {
50
59
  const {
51
60
  done,
52
61
  value
53
62
  } = objToStringGen.next();
63
+
54
64
  if (done) {
55
65
  isDone = true;
56
66
  this.push(null);
@@ -59,10 +69,14 @@ class StatsPlugin {
59
69
  }
60
70
  }
61
71
  }
72
+
62
73
  });
63
74
  }
75
+
64
76
  emitStats(statsJson) {
65
77
  return this.writeStatsFileInAStream(statsJson);
66
78
  }
79
+
67
80
  }
81
+
68
82
  module.exports = StatsPlugin;
@@ -4,43 +4,55 @@ 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 _fs = _interopRequireDefault(require("fs"));
11
+
9
12
  var _path = _interopRequireDefault(require("path"));
13
+
10
14
  var _crypto = _interopRequireDefault(require("crypto"));
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
12
18
  /**
13
19
  * Plugin that generates hash for the provided list of third party files
14
20
  * Map the provided key with the file hash and add it to the list of exisiting global constants.
15
21
  * Plugin in turn uses the defineplugin to generate global constants.
16
22
  */
17
-
18
23
  class TPHashMappingPlugin {
19
24
  constructor(options) {
20
25
  this.fileMappings = options.fileMappings;
21
26
  this.tpFolder = options.tpFolder;
22
27
  return new _webpack.DefinePlugin(this.getFiles());
23
28
  }
29
+
24
30
  getHash(content) {
25
31
  let hash = _crypto.default.createHash('md5');
32
+
26
33
  let data = hash.update(content, 'utf-8');
27
34
  let gen_hash = data.digest('hex');
28
35
  return gen_hash;
29
36
  }
37
+
30
38
  getFiles() {
31
39
  let hashMapping = {};
32
40
  this.fileMappings.forEach(fileInfo => {
33
41
  let filePath = `${_path.default.join(this.tpFolder, fileInfo.filePath, fileInfo.fileName)}`;
42
+
34
43
  if (_fs.default.existsSync(filePath)) {
35
44
  let fileContent = _fs.default.readFileSync(filePath, {
36
45
  encoding: 'utf-8'
37
46
  });
47
+
38
48
  let generatedHash = this.getHash(fileContent);
39
49
  let outputFileSplit = fileInfo.fileName.split('.');
40
50
  outputFileSplit.splice(outputFileSplit.length - 1, 0, generatedHash);
41
51
  let outputFileName = outputFileSplit.join('.');
42
52
  let outputFilePath = `${_path.default.join(this.tpFolder, fileInfo.filePath, outputFileName)}`;
53
+
43
54
  _fs.default.writeFileSync(outputFilePath, fileContent);
55
+
44
56
  hashMapping[fileInfo.key] = JSON.stringify(generatedHash);
45
57
  } else {
46
58
  throw new Error(`Third party file ${fileInfo.fileName} does not exist`);
@@ -48,5 +60,8 @@ class TPHashMappingPlugin {
48
60
  });
49
61
  return hashMapping;
50
62
  }
63
+
51
64
  }
52
- var _default = exports.default = TPHashMappingPlugin;
65
+
66
+ var _default = TPHashMappingPlugin;
67
+ exports.default = _default;
@@ -4,23 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _fs = _interopRequireDefault(require("fs"));
11
+
9
12
  var _utils = require("../utils");
13
+
10
14
  var _log = require("../utils/log");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
12
18
  let excludeDocsJSON = '{}';
19
+
13
20
  if (_fs.default.existsSync('./__testUtils__/conf/excludeDocs.json')) {
14
21
  excludeDocsJSON = _fs.default.readFileSync('./__testUtils__/conf/excludeDocs.json').toString();
22
+
15
23
  if (excludeDocsJSON.indexOf('\\') !== -1) {
16
24
  excludeDocsJSON = excludeDocsJSON.replace(/\\/g, '\\\\');
17
25
  }
18
26
  }
19
- let excludeDocsArray = JSON.parse(excludeDocsJSON);
20
- // if (Object.keys(excludeDocsArray).length > 0) {
27
+
28
+ let excludeDocsArray = JSON.parse(excludeDocsJSON); // if (Object.keys(excludeDocsArray).length > 0) {
21
29
  // }
22
30
 
23
31
  let getRegex = regexString => regexString.map(str => new RegExp(str));
32
+
24
33
  class UnusedFilesFindPlugin {
25
34
  constructor(options = {}) {
26
35
  this.usedFilesExcludes = getRegex(options.usedFilesExcludes);
@@ -30,28 +39,38 @@ class UnusedFilesFindPlugin {
30
39
  this.sstest = options.ssTest || false;
31
40
  this.outputFileName = options.outputFileName;
32
41
  this.docsFilename = options.docsFilename || 'Undocsfiles.json';
42
+
33
43
  if (!this.origin) {
34
44
  throw new Error('You must provide origin point of the app');
35
45
  }
36
46
  }
47
+
37
48
  isIgnoredUsedFile(file) {
38
49
  let result;
50
+
39
51
  for (let i = 0; i < this.usedFilesExcludes.length; i++) {
40
52
  let exclude = this.usedFilesExcludes[i];
41
53
  result = exclude.test(file);
54
+
42
55
  if (result) {
43
56
  break;
44
57
  }
45
58
  }
59
+
46
60
  return result;
47
61
  }
62
+
48
63
  unDocumentedFiles(outputPath) {
49
64
  let status = _fs.default.existsSync(_path.default.join(outputPath, this.outputFileName));
65
+
50
66
  let unDocsCompObj = {};
67
+
51
68
  if (status) {
52
69
  let data = _fs.default.readFileSync(_path.default.join(outputPath, this.outputFileName)).toString();
70
+
53
71
  let walkSync = (dir, filelist = [], undocList = []) => {
54
72
  let files = _fs.default.readdirSync(dir);
73
+
55
74
  files.forEach(file => {
56
75
  if (_fs.default.statSync(`${dir}/${file}`).isDirectory()) {
57
76
  filelist = walkSync(`${dir}/${file}`, filelist, undocList); //eslint-disable-line
@@ -74,6 +93,7 @@ class UnusedFilesFindPlugin {
74
93
  unDocsCompObj.withoutDocs = undocList;
75
94
  return filelist;
76
95
  };
96
+
77
97
  unDocsCompObj.noEnteredComp = walkSync(_path.default.join(process.cwd(), 'src', 'components'), [], []);
78
98
  (0, _utils.writeFile)(_path.default.join(outputPath, this.docsFilename), JSON.stringify(unDocsCompObj));
79
99
  Object.keys(unDocsCompObj).forEach(key => {
@@ -90,20 +110,27 @@ class UnusedFilesFindPlugin {
90
110
  });
91
111
  }
92
112
  }
113
+
93
114
  isIgnoredAllFile(file) {
94
115
  let result;
116
+
95
117
  for (let i = 0; i < this.appFilesExcludes.length; i++) {
96
118
  let exclude = this.appFilesExcludes[i];
97
119
  result = exclude.test(file);
120
+
98
121
  if (result) {
99
122
  break;
100
123
  }
101
124
  }
125
+
102
126
  return result;
103
127
  }
128
+
104
129
  getAllFiles(rootPath) {
105
130
  let allFiles = [];
131
+
106
132
  let files = _fs.default.readdirSync(rootPath).map(file => _path.default.join(rootPath, file));
133
+
107
134
  files.forEach(file => {
108
135
  if (_fs.default.statSync(file).isDirectory()) {
109
136
  allFiles = allFiles.concat(this.getAllFiles(file));
@@ -115,6 +142,7 @@ class UnusedFilesFindPlugin {
115
142
  });
116
143
  return allFiles;
117
144
  }
145
+
118
146
  apply(compiler) {
119
147
  compiler.hooks.afterEmit.tap('UnusedFilesShowPlugin', compilation => {
120
148
  let {
@@ -124,6 +152,7 @@ class UnusedFilesFindPlugin {
124
152
  if (!this.isIgnoredUsedFile(usedFile)) {
125
153
  files[usedFile] = true;
126
154
  }
155
+
127
156
  return files;
128
157
  }, {});
129
158
  let allFiles = this.getAllFiles(this.origin);
@@ -133,6 +162,7 @@ class UnusedFilesFindPlugin {
133
162
  unusedFiles.push(file);
134
163
  }
135
164
  });
165
+
136
166
  if (!unusedFiles.length) {
137
167
  (0, _log.log)('There is no unused files');
138
168
  } else {
@@ -146,13 +176,18 @@ class UnusedFilesFindPlugin {
146
176
  });
147
177
  }
148
178
  }
179
+
149
180
  if (this.delete) {
150
181
  unusedFiles.forEach(file => {
151
182
  _fs.default.unlinkSync(file);
183
+
152
184
  (0, _log.log)(`Deleted - ${file}`);
153
185
  });
154
186
  }
155
187
  });
156
188
  }
189
+
157
190
  }
158
- var _default = exports.default = UnusedFilesFindPlugin;
191
+
192
+ var _default = UnusedFilesFindPlugin;
193
+ exports.default = _default;