@zohodesk/react-cli 0.0.1-beta.17 → 0.0.1-beta.170

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 (292) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +49 -10
  3. package/.prettierrc +6 -0
  4. package/CHANGELOG.md +5 -0
  5. package/README.md +855 -0
  6. package/bin/cli.js +215 -46
  7. package/cert/Tsicsezwild-22-23.crt +37 -0
  8. package/cert/Tsicsezwild-22-23.key +27 -0
  9. package/docs/CustomChunks.md +26 -0
  10. package/docs/DevStart.md +18 -0
  11. package/docs/HoverActive.md +12 -0
  12. package/docs/InstallNode.md +28 -0
  13. package/docs/TODOS.md +10 -0
  14. package/docs/ValueReplacer.md +60 -0
  15. package/docs/warnings_while_install.txt +35 -0
  16. package/files/eslintrc.js +62 -0
  17. package/files/prettierrc.js +3 -0
  18. package/lib/babel/cmjs-plugins-presets.js +24 -0
  19. package/lib/babel/es-plugins-presets.js +34 -0
  20. package/lib/common/getEntries.js +33 -46
  21. package/lib/common/getPublicPathConfig.js +40 -0
  22. package/lib/common/index.js +24 -19
  23. package/lib/common/splitChunks.js +110 -25
  24. package/lib/common/sslcertUpdater.js +59 -0
  25. package/lib/common/templateParameters.js +25 -0
  26. package/lib/common/testPattern.js +69 -0
  27. package/lib/common/valueReplacer.js +55 -0
  28. package/lib/configs/jest.config.js +31 -27
  29. package/lib/configs/libAlias.js +31 -0
  30. package/lib/configs/webpack.component.umd.config.js +46 -53
  31. package/lib/configs/webpack.css.umd.config.js +47 -46
  32. package/lib/configs/webpack.dev.config.js +98 -84
  33. package/lib/configs/webpack.docs.config.js +64 -57
  34. package/lib/configs/webpack.impact.config.js +108 -0
  35. package/lib/configs/webpack.prod.config.js +146 -104
  36. package/lib/hooks/docsProptypeHook.js +32 -38
  37. package/lib/jest/commitedFilesResult.js +144 -71
  38. package/lib/jest/coverageCollector.js +68 -35
  39. package/lib/jest/jsonMaker.js +54 -0
  40. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  41. package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
  42. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  43. package/lib/jest/result.js +92 -42
  44. package/lib/jest/run.js +75 -28
  45. package/lib/jest/setup.js +103 -102
  46. package/lib/loaderUtils/configsAssetsLoaders.js +117 -0
  47. package/lib/loaderUtils/getCSSLoaders.js +113 -0
  48. package/lib/loaderUtils/getDevJsLoaders.js +35 -23
  49. package/lib/loaderUtils/index.js +14 -7
  50. package/lib/loaders/docsLoader.js +15 -15
  51. package/lib/loaders/docsPropsLoader.js +14 -17
  52. package/lib/loaders/fileBountryLoader.js +17 -0
  53. package/lib/loaders/fileLoader.js +47 -38
  54. package/lib/loaders/scriptInstrumentLoader.js +23 -20
  55. package/lib/loaders/selectorMappingLoader.js +75 -0
  56. package/lib/loaders/workerLoader.js +136 -0
  57. package/lib/middlewares/HMRMiddleware.js +90 -72
  58. package/lib/middlewares/SSTMiddleware.js +21 -0
  59. package/lib/pluginUtils/getDevPlugins.js +177 -30
  60. package/lib/pluginUtils/getDocsPlugins.js +36 -15
  61. package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
  62. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  63. package/lib/pluginUtils/getProdPlugins.js +244 -37
  64. package/lib/pluginUtils/getServerPlugins.js +8 -11
  65. package/lib/pluginUtils/getUMDCSSPlugins.js +14 -18
  66. package/lib/pluginUtils/getUMDComponentPlugins.js +14 -9
  67. package/lib/pluginUtils/index.js +36 -43
  68. package/lib/plugins/CdnChangePlugin.js +77 -0
  69. package/lib/plugins/CleanupStatsPlugin.js +28 -0
  70. package/lib/plugins/EFCPlugin.js +241 -0
  71. package/lib/plugins/EFCPlugin.md +6 -0
  72. package/lib/plugins/EFCTemplatePlugin.js +151 -0
  73. package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
  74. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  75. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  76. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  77. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  78. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  79. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +95 -0
  80. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  81. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  82. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  83. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  84. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  85. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  86. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  87. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  88. package/lib/plugins/ManifestPlugin.js +86 -0
  89. package/lib/plugins/ModuleStatsPlugin.js +98 -97
  90. package/lib/plugins/OptimizeJSPlugin.js +41 -0
  91. package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
  92. package/lib/plugins/PublicPathChangePlugin.js +226 -0
  93. package/lib/plugins/ReportGeneratePlugin.js +181 -0
  94. package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
  95. package/lib/plugins/ResourceHintsPlugin.js +67 -0
  96. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
  97. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
  98. package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
  99. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
  100. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  101. package/lib/plugins/ServiceWorkerPlugin.js +107 -0
  102. package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
  103. package/lib/plugins/SourceMapHookPlugin.js +25 -59
  104. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  105. package/lib/plugins/UglifyCSSPlugin.js +39 -0
  106. package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
  107. package/lib/plugins/index.js +127 -37
  108. package/lib/plugins/libraryImpactPlugin.js +190 -0
  109. package/lib/plugins/webpackwatchrunplugin.js +26 -0
  110. package/lib/postcss-plugins/ExcludePlugin.js +23 -0
  111. package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
  112. package/lib/postcss-plugins/ValueReplacer.js +46 -0
  113. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +22 -0
  114. package/lib/postcss-plugins/__test__/test1Input.css +39 -0
  115. package/lib/postcss-plugins/__test__/test1Output.css +39 -0
  116. package/lib/postcss-plugins/hoverActivePlugin.js +365 -0
  117. package/lib/postcss-plugins/variableModifier.js +243 -0
  118. package/lib/schemas/index.js +534 -66
  119. package/lib/servers/clusterHubServer.js +22 -26
  120. package/lib/servers/devBuild.js +102 -0
  121. package/lib/servers/docsServer.js +3 -5
  122. package/lib/servers/docsServerCore.js +94 -79
  123. package/lib/servers/getCliPath.js +28 -0
  124. package/lib/servers/helpServer.js +19 -21
  125. package/lib/servers/httpsOptions.js +18 -0
  126. package/lib/servers/impactServer.js +123 -115
  127. package/lib/servers/mockserver.js +44 -0
  128. package/lib/servers/nowatchserver.js +200 -0
  129. package/lib/servers/scrServer.js +147 -0
  130. package/lib/servers/server.js +134 -132
  131. package/lib/servers/ssServer.js +106 -70
  132. package/lib/sh/reportPublish.sh +16 -10
  133. package/lib/templates/CoverageScriptTemplate.js +45 -18
  134. package/lib/templates/WMSTemplate.js +17 -18
  135. package/lib/templates/linterConstant.js +10 -0
  136. package/lib/utils/babelPresets.js +12 -4
  137. package/lib/utils/buildstats.html +148 -0
  138. package/lib/utils/clean.js +12 -11
  139. package/lib/utils/copy.js +16 -109
  140. package/lib/utils/copyTimezones.js +21 -0
  141. package/lib/utils/createEventStream.js +24 -19
  142. package/lib/utils/cssClassNameGenerate.js +77 -0
  143. package/lib/utils/cssURLReplacer.js +136 -0
  144. package/lib/utils/dependencyPostPublish.js +42 -0
  145. package/lib/utils/fileUtils.js +125 -0
  146. package/lib/utils/folderIterator.js +47 -0
  147. package/lib/utils/getComponents.js +126 -0
  148. package/lib/utils/getCurrentBranch.js +11 -17
  149. package/lib/utils/getDependenciesImpactList.js +151 -0
  150. package/lib/utils/getHash.js +26 -0
  151. package/lib/utils/getIp.js +20 -0
  152. package/lib/utils/getOptions.js +113 -28
  153. package/lib/utils/getServerURL.js +25 -8
  154. package/lib/utils/index.js +283 -68
  155. package/lib/utils/init.js +2 -2
  156. package/lib/utils/initPreCommitHook.js +47 -27
  157. package/lib/utils/jsonHelper.js +106 -0
  158. package/lib/utils/libraryImpactConfig.js +63 -0
  159. package/lib/utils/lint/addScripts.js +27 -0
  160. package/lib/utils/lint/checkExistingConfig.js +67 -0
  161. package/lib/utils/lint/copyConfigs.js +24 -0
  162. package/lib/utils/lint/index.js +54 -0
  163. package/lib/utils/lint/lintScripts.js +11 -0
  164. package/lib/utils/lint/lintSetup.js +31 -0
  165. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  166. package/lib/utils/lint/question.js +30 -0
  167. package/lib/utils/lintReporter.js +142 -0
  168. package/lib/utils/mailSender.js +16 -25
  169. package/lib/utils/pullOrigin.js +28 -0
  170. package/lib/utils/reinstallDependencies.js +133 -0
  171. package/lib/utils/removeAttributes.js +25 -23
  172. package/lib/utils/repoClone.js +59 -63
  173. package/lib/utils/request.js +64 -77
  174. package/lib/utils/resultSchema.json +73 -0
  175. package/lib/utils/rtl.js +59 -0
  176. package/lib/utils/setEnvVariables.js +13 -0
  177. package/lib/utils/ssTestHack.js +48 -0
  178. package/lib/utils/switchBranch.js +28 -0
  179. package/lib/utils/urlConcat.js +22 -0
  180. package/lib/utils/useExitCleanup.js +55 -0
  181. package/npm8.md +9 -0
  182. package/package.json +96 -64
  183. package/postpublish.js +6 -0
  184. package/templates/app/.eslintrc.js +140 -0
  185. package/templates/app/README.md +12 -12
  186. package/templates/app/app/index.html +24 -8
  187. package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
  188. package/templates/app/app/properties/i18nkeys.json +3 -3
  189. package/templates/app/docs/all.html +69 -69
  190. package/templates/app/mockapi/index.js +18 -13
  191. package/templates/app/package.json +37 -17
  192. package/templates/app/src/actions/SampleActions/index.js +37 -0
  193. package/templates/app/src/actions/index.js +65 -0
  194. package/templates/app/src/appUrls.js +19 -0
  195. package/templates/app/src/components/Alert/Alert.js +134 -0
  196. package/templates/app/src/components/Alert/Alert.module.css +79 -0
  197. package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
  198. package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
  199. package/templates/app/src/components/Sample/Sample.module.css +11 -0
  200. package/templates/app/src/components/Sample/SampleList.js +61 -0
  201. package/templates/app/src/components/Slider/Slider.css +41 -0
  202. package/templates/app/src/components/Slider/Slider.js +55 -0
  203. package/templates/app/src/containers/AlertContainer/index.js +15 -0
  204. package/templates/app/src/containers/AppContainer/index.js +96 -0
  205. package/templates/app/src/containers/AppContainer/index.module.css +27 -0
  206. package/templates/app/src/containers/CustomMatch/index.js +65 -0
  207. package/templates/app/src/containers/DevTools/index.js +10 -0
  208. package/templates/app/src/containers/Header/index.js +67 -0
  209. package/templates/app/src/containers/Header/index.module.css +43 -0
  210. package/templates/app/src/containers/Redirect/index.js +63 -0
  211. package/templates/app/src/containers/Redirector/index.js +47 -0
  212. package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
  213. package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
  214. package/templates/app/src/historyChange.js +5 -0
  215. package/templates/app/src/index.html +10 -0
  216. package/templates/app/src/index.js +24 -0
  217. package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
  218. package/templates/app/src/reducers/alertData.js +11 -0
  219. package/templates/app/src/reducers/index.js +6 -0
  220. package/templates/app/src/reducers/samples.js +19 -0
  221. package/templates/app/src/store/configureStore.dev.js +51 -0
  222. package/templates/app/src/store/configureStore.js +5 -0
  223. package/templates/app/src/store/configureStore.prod.js +26 -0
  224. package/templates/app/src/util/Common.js +5 -0
  225. package/templates/app/src/util/RequestAPI.js +132 -0
  226. package/templates/appold/README.md +12 -0
  227. package/templates/appold/app/index.html +8 -0
  228. package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
  229. package/templates/appold/app/properties/i18nkeys.json +3 -0
  230. package/templates/appold/docs/all.html +69 -0
  231. package/templates/appold/mockapi/index.js +13 -0
  232. package/templates/{app → appold}/mockapi/tickets.json +0 -0
  233. package/templates/appold/package.json +17 -0
  234. package/templates/appold/src/components/Text/Text.css +0 -0
  235. package/templates/appold/src/components/Text/Text.js +23 -0
  236. package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
  237. package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
  238. package/templates/appold/src/components/docs.js +1 -0
  239. package/templates/appold/src/components/index.js +5 -0
  240. package/templates/appold/src/index.js +13 -0
  241. package/templates/docs/all.html +1 -1
  242. package/templates/docs/component.html +110 -69
  243. package/templates/docs/components.html +221 -0
  244. package/templates/docs/css/component.css +12 -14
  245. package/templates/docs/css/componentTest.css +7 -0
  246. package/templates/docs/css/style.css +150 -206
  247. package/templates/docs/impactReportTemplate.html +154 -0
  248. package/templates/docs/index.html +1482 -1336
  249. package/templates/library/src/index.js +0 -0
  250. package/.npmignore +0 -3
  251. package/cert/cert.pem +0 -129
  252. package/cert/key.pem +0 -27
  253. package/lib/common/getInsertAt.js +0 -36
  254. package/lib/common/getInsertIntoFunction.js +0 -13
  255. package/lib/configs/webpack.server.config.js +0 -93
  256. package/lib/plugins/ChunkManifestReplacePlugin.js +0 -94
  257. package/lib/plugins/RuntimePublicPathPlugin.js +0 -46
  258. package/lib/rmcntrlm.sh +0 -14
  259. package/lib/servers/nodeServer.js +0 -238
  260. package/lib/templates/HMRTemplate.js +0 -256
  261. package/lib/templates/publicPathTemplate.js +0 -16
  262. package/lib/utils/setConfig.js +0 -14
  263. package/node_modules/history/CHANGES.md +0 -395
  264. package/node_modules/history/DOMUtils.js +0 -3
  265. package/node_modules/history/ExecutionEnvironment.js +0 -3
  266. package/node_modules/history/LICENSE +0 -21
  267. package/node_modules/history/LocationUtils.js +0 -3
  268. package/node_modules/history/PathUtils.js +0 -3
  269. package/node_modules/history/README.md +0 -282
  270. package/node_modules/history/cjs/history.js +0 -933
  271. package/node_modules/history/cjs/history.min.js +0 -1
  272. package/node_modules/history/createBrowserHistory.js +0 -3
  273. package/node_modules/history/createHashHistory.js +0 -3
  274. package/node_modules/history/createMemoryHistory.js +0 -3
  275. package/node_modules/history/createTransitionManager.js +0 -3
  276. package/node_modules/history/es/DOMUtils.js +0 -7
  277. package/node_modules/history/es/ExecutionEnvironment.js +0 -7
  278. package/node_modules/history/es/LocationUtils.js +0 -7
  279. package/node_modules/history/es/PathUtils.js +0 -7
  280. package/node_modules/history/es/createBrowserHistory.js +0 -7
  281. package/node_modules/history/es/createHashHistory.js +0 -7
  282. package/node_modules/history/es/createMemoryHistory.js +0 -7
  283. package/node_modules/history/es/createTransitionManager.js +0 -7
  284. package/node_modules/history/es/warnAboutDeprecatedESMImport.js +0 -35
  285. package/node_modules/history/esm/history.js +0 -904
  286. package/node_modules/history/index.js +0 -7
  287. package/node_modules/history/package.json +0 -134
  288. package/node_modules/history/umd/history.js +0 -1059
  289. package/node_modules/history/umd/history.min.js +0 -1
  290. package/node_modules/history/warnAboutDeprecatedCJSRequire.js +0 -35
  291. package/templates/app/.npmignore +0 -9
  292. package/templates/library/.npmignore +0 -9
@@ -0,0 +1,270 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = ShadowDOMSupportPlugin;
7
+
8
+ var _Template = _interopRequireDefault(require("webpack/lib/Template"));
9
+
10
+ var _JsonpMainTemplatePlugin = _interopRequireDefault(require("webpack/lib/web/JsonpMainTemplatePlugin"));
11
+
12
+ var _tapable = require("tapable");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ /* eslint-disable no-unused-vars */
17
+ //eslint-disable-next-line
18
+ function ShadowDOMSupportPlugin() {}
19
+
20
+ ShadowDOMSupportPlugin.prototype.apply = function () {
21
+ this.patchJsonpMainTemplatePlugin();
22
+ };
23
+
24
+ ShadowDOMSupportPlugin.prototype.patchJsonpMainTemplatePlugin = function () {
25
+ _JsonpMainTemplatePlugin.default.prototype.apply = this._apply;
26
+ };
27
+
28
+ ShadowDOMSupportPlugin.prototype._apply = function (mainTemplate) {
29
+ const needChunkOnDemandLoadingCode = chunk => {
30
+ for (const chunkGroup of chunk.groupsIterable) {
31
+ if (chunkGroup.getNumberOfChildren() > 0) {
32
+ return true;
33
+ }
34
+ }
35
+
36
+ return false;
37
+ };
38
+
39
+ const needChunkLoadingCode = chunk => {
40
+ for (const chunkGroup of chunk.groupsIterable) {
41
+ if (chunkGroup.chunks.length > 1) {
42
+ return true;
43
+ }
44
+
45
+ if (chunkGroup.getNumberOfChildren() > 0) {
46
+ return true;
47
+ }
48
+ }
49
+
50
+ return false;
51
+ };
52
+
53
+ const needEntryDeferringCode = chunk => {
54
+ for (const chunkGroup of chunk.groupsIterable) {
55
+ if (chunkGroup.chunks.length > 1) {
56
+ return true;
57
+ }
58
+ }
59
+
60
+ return false;
61
+ };
62
+
63
+ const needPrefetchingCode = chunk => {
64
+ const allPrefetchChunks = chunk.getChildIdsByOrdersMap(true).prefetch;
65
+ return allPrefetchChunks && Object.keys(allPrefetchChunks).length;
66
+ }; // TODO webpack 5, no adding to .hooks, use WeakMap and static methods
67
+
68
+
69
+ ['jsonpScript', 'linkPreload', 'linkPrefetch'].forEach(hook => {
70
+ if (!mainTemplate.hooks[hook]) {
71
+ mainTemplate.hooks[hook] = new _tapable.SyncWaterfallHook(['source', 'chunk', 'hash']);
72
+ }
73
+ });
74
+
75
+ const getScriptSrcPath = (hash, chunk, chunkIdExpression) => {
76
+ const {
77
+ chunkFilename
78
+ } = mainTemplate.outputOptions;
79
+ const chunkMaps = chunk.getChunkMaps();
80
+ return mainTemplate.getAssetPath(JSON.stringify(chunkFilename), {
81
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
82
+ hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
83
+ chunk: {
84
+ id: `" + ${chunkIdExpression} + "`,
85
+ hash: `" + ${JSON.stringify(chunkMaps.hash)}[${chunkIdExpression}] + "`,
86
+
87
+ hashWithLength(length) {
88
+ const shortChunkHashMap = Object.create(null);
89
+
90
+ for (const chunkId of Object.keys(chunkMaps.hash)) {
91
+ if (typeof chunkMaps.hash[chunkId] === 'string') {
92
+ shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
93
+ }
94
+ }
95
+
96
+ return `" + ${JSON.stringify(shortChunkHashMap)}[${chunkIdExpression}] + "`;
97
+ },
98
+
99
+ name: `" + (${JSON.stringify(chunkMaps.name)}[${chunkIdExpression}]||${chunkIdExpression}) + "`,
100
+ contentHash: {
101
+ javascript: `" + ${JSON.stringify(chunkMaps.contentHash.javascript)}[${chunkIdExpression}] + "`
102
+ },
103
+ contentHashWithLength: {
104
+ javascript: length => {
105
+ const shortContentHashMap = {};
106
+ const contentHash = chunkMaps.contentHash.javascript;
107
+
108
+ for (const chunkId of Object.keys(contentHash)) {
109
+ if (typeof contentHash[chunkId] === 'string') {
110
+ shortContentHashMap[chunkId] = contentHash[chunkId].substr(0, length);
111
+ }
112
+ }
113
+
114
+ return `" + ${JSON.stringify(shortContentHashMap)}[${chunkIdExpression}] + "`;
115
+ }
116
+ }
117
+ },
118
+ contentHashType: 'javascript'
119
+ });
120
+ };
121
+
122
+ mainTemplate.hooks.localVars.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
123
+ const extraCode = [];
124
+
125
+ if (needChunkLoadingCode(chunk)) {
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 = [];' : '');
127
+ }
128
+
129
+ if (needChunkOnDemandLoadingCode(chunk)) {
130
+ extraCode.push('', '// script path function', 'function jsonpScriptSrc(chunkId) {', _Template.default.indent([`return ${mainTemplate.requireFn}.p + ${getScriptSrcPath(hash, chunk, 'chunkId')}`]), '}');
131
+ }
132
+
133
+ if (extraCode.length === 0) {
134
+ return source;
135
+ }
136
+
137
+ return _Template.default.asString([source, ...extraCode]);
138
+ });
139
+ mainTemplate.hooks.jsonpScript.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
140
+ const {
141
+ crossOriginLoading
142
+ } = mainTemplate.outputOptions;
143
+ const {
144
+ chunkLoadTimeout
145
+ } = mainTemplate.outputOptions;
146
+ const {
147
+ jsonpScriptType
148
+ } = mainTemplate.outputOptions;
149
+ return _Template.default.asString(['var script = document.createElement(\'script\');', 'var onScriptComplete;', jsonpScriptType ? `script.type = ${JSON.stringify(jsonpScriptType)};` : '', 'script.charset = \'utf-8\';', `script.timeout = ${chunkLoadTimeout / 1000};`, `if (${mainTemplate.requireFn}.nc) {`, _Template.default.indent(`script.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`), '}', 'script.src = jsonpScriptSrc(chunkId);', crossOriginLoading ? _Template.default.asString(['if (script.src.indexOf(window.location.origin + \'/\') !== 0) {', _Template.default.indent(`script.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', 'onScriptComplete = function (event) {', _Template.default.indent(['// avoid mem leaks in IE.', 'script.onerror = script.onload = null;', 'clearTimeout(timeout);', 'var chunk = installedChunks[chunkId];', 'if(chunk !== 0) {', _Template.default.indent(['if(chunk) {', _Template.default.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src;', 'var error = new Error(\'Loading chunk \' + chunkId + \' failed.\\n(\' + errorType + \': \' + realSrc + \')\');', 'error.type = errorType;', 'error.request = realSrc;', 'chunk[1](error);']), '}', 'installedChunks[chunkId] = undefined;']), '}']), '};', 'var timeout = setTimeout(function(){', _Template.default.indent(['onScriptComplete({ type: \'timeout\', target: script });']), `}, ${chunkLoadTimeout});`, 'script.onerror = script.onload = onScriptComplete;']);
150
+ });
151
+ mainTemplate.hooks.linkPreload.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
152
+ const {
153
+ crossOriginLoading
154
+ } = mainTemplate.outputOptions;
155
+ const {
156
+ jsonpScriptType
157
+ } = mainTemplate.outputOptions;
158
+ return _Template.default.asString(['var link = document.createElement(\'link\');', jsonpScriptType ? `link.type = ${JSON.stringify(jsonpScriptType)};` : '', 'link.charset = \'utf-8\';', `if (${mainTemplate.requireFn}.nc) {`, _Template.default.indent(`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`), '}', 'link.rel = "preload";', 'link.as = "script";', 'link.href = jsonpScriptSrc(chunkId);', crossOriginLoading ? _Template.default.asString(['if (link.href.indexOf(window.location.origin + \'/\') !== 0) {', _Template.default.indent(`link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '']);
159
+ });
160
+ mainTemplate.hooks.linkPrefetch.tap('JsonpMainTemplatePlugin', (_, chunk, hash) => {
161
+ const {
162
+ crossOriginLoading
163
+ } = mainTemplate.outputOptions;
164
+ return _Template.default.asString(['var link = document.createElement(\'link\');', crossOriginLoading ? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : '', `if (${mainTemplate.requireFn}.nc) {`, _Template.default.indent(`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`), '}', 'link.rel = "prefetch";', 'link.as = "script";', 'link.href = jsonpScriptSrc(chunkId);']);
165
+ });
166
+ mainTemplate.hooks.requireEnsure.tap('JsonpMainTemplatePlugin load', (source, chunk, hash) => _Template.default.asString([source, '', '// JSONP chunk loading for javascript', '', 'var installedChunkData = installedChunks[chunkId];', 'if(installedChunkData !== 0) { // 0 means "already installed".', _Template.default.indent(['', '// a Promise means "currently loading".', 'if(installedChunkData) {', _Template.default.indent(['promises.push(installedChunkData[2]);']), '} else {', _Template.default.indent(['// setup Promise in chunk cache', 'var promise = new Promise(function(resolve, reject) {', _Template.default.indent(['installedChunkData = installedChunks[chunkId] = [resolve, reject];']), '});', 'promises.push(installedChunkData[2] = promise);', '', '// start chunk loading', mainTemplate.hooks.jsonpScript.call('', chunk, hash), 'window.ZDShadowRoot.getElementById("head").appendChild(script);']), '}']), '}']));
167
+ mainTemplate.hooks.requireEnsure.tap({
168
+ name: 'JsonpMainTemplatePlugin preload',
169
+ stage: 10
170
+ }, (source, chunk, hash) => {
171
+ const chunkMap = chunk.getChildIdsByOrdersMap().preload;
172
+
173
+ if (!chunkMap || Object.keys(chunkMap).length === 0) {
174
+ return source;
175
+ }
176
+
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);']), '}']), '});']), '}']);
178
+ });
179
+ mainTemplate.hooks.requireExtensions.tap('JsonpMainTemplatePlugin', (source, chunk) => {
180
+ if (!needChunkOnDemandLoadingCode(chunk)) {
181
+ return source;
182
+ }
183
+
184
+ return _Template.default.asString([source, '', '// on error function for async loading', `${mainTemplate.requireFn}.oe = function(err) { console.error(err); throw err; };`]);
185
+ });
186
+ mainTemplate.hooks.bootstrap.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
187
+ if (needChunkLoadingCode(chunk)) {
188
+ const withDefer = needEntryDeferringCode(chunk);
189
+ const withPrefetch = needPrefetchingCode(chunk);
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;']), '}']) : '']);
191
+ }
192
+
193
+ return source;
194
+ });
195
+ mainTemplate.hooks.beforeStartup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
196
+ if (needChunkLoadingCode(chunk)) {
197
+ let {
198
+ jsonpFunction
199
+ } = mainTemplate.outputOptions;
200
+ let {
201
+ globalObject
202
+ } = mainTemplate.outputOptions;
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]);
204
+ }
205
+
206
+ return source;
207
+ });
208
+ mainTemplate.hooks.beforeStartup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
209
+ const prefetchChunks = chunk.getChildIdsByOrders().prefetch;
210
+
211
+ if (needChunkLoadingCode(chunk) && prefetchChunks && prefetchChunks.length) {
212
+ return _Template.default.asString([source, `webpackJsonpCallback([[], {}, 0, ${JSON.stringify(prefetchChunks)}]);`]);
213
+ }
214
+
215
+ return source;
216
+ });
217
+ mainTemplate.hooks.startup.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
218
+ if (needEntryDeferringCode(chunk)) {
219
+ if (chunk.hasEntryModule()) {
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)));
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();']);
222
+ }
223
+
224
+ return _Template.default.asString(['// run deferred modules from other chunks', 'checkDeferredModules();']);
225
+ }
226
+
227
+ return source;
228
+ });
229
+ mainTemplate.hooks.hotBootstrap.tap('JsonpMainTemplatePlugin', (source, chunk, hash) => {
230
+ const {
231
+ globalObject
232
+ } = mainTemplate.outputOptions;
233
+ const {
234
+ hotUpdateChunkFilename
235
+ } = mainTemplate.outputOptions;
236
+ const {
237
+ hotUpdateMainFilename
238
+ } = mainTemplate.outputOptions;
239
+ const {
240
+ crossOriginLoading
241
+ } = mainTemplate.outputOptions;
242
+ const {
243
+ hotUpdateFunction
244
+ } = mainTemplate.outputOptions;
245
+ const currentHotUpdateChunkFilename = mainTemplate.getAssetPath(JSON.stringify(hotUpdateChunkFilename), {
246
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
247
+ hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
248
+ chunk: {
249
+ id: '" + chunkId + "'
250
+ }
251
+ });
252
+ const currentHotUpdateMainFilename = mainTemplate.getAssetPath(JSON.stringify(hotUpdateMainFilename), {
253
+ hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
254
+ hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
255
+ });
256
+
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
+
259
+ return `${source}
260
+ function hotDisposeChunk(chunkId) {
261
+ delete installedChunks[chunkId];
262
+ }
263
+ var parentHotUpdateCallback = ${globalObject}[${JSON.stringify(hotUpdateFunction)}];
264
+ ${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
265
+ });
266
+ mainTemplate.hooks.hash.tap('JsonpMainTemplatePlugin', hash => {
267
+ hash.update('jsonp');
268
+ hash.update('6');
269
+ });
270
+ };
@@ -1,75 +1,41 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+ var _path = _interopRequireDefault(require("path"));
8
9
 
9
- var _optimizeJs = require('optimize-js');
10
-
11
- var _optimizeJs2 = _interopRequireDefault(_optimizeJs);
12
-
13
- var _fs = require('fs');
14
-
15
- var _fs2 = _interopRequireDefault(_fs);
16
-
17
- var _path = require('path');
18
-
19
- var _path2 = _interopRequireDefault(_path);
20
-
21
- var _utils = require('../utils');
10
+ var _webpackSources = require("webpack-sources");
22
11
 
23
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
13
 
25
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ class SourceMapHookPlugin {
15
+ apply(compiler) {
16
+ compiler.hooks.emit.tap('SourceMapHookPlugin', compilation => {
17
+ Object.keys(compilation.assets).forEach(filename => {
18
+ if (/\.js$/g.test(filename) && !/(\.map.|tp\/)/g.test(filename)) {
19
+ let source = compilation.assets[filename].source();
26
20
 
27
- var SourceMapHookPlugin = function () {
28
- function SourceMapHookPlugin() {
29
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
21
+ let {
22
+ name
23
+ } = _path.default.parse(filename);
30
24
 
31
- _classCallCheck(this, SourceMapHookPlugin);
32
-
33
- this.optimize = options.optimize;
34
- }
25
+ let src = source;
35
26
 
36
- _createClass(SourceMapHookPlugin, [{
37
- key: 'apply',
38
- value: function apply(compiler) {
39
- var _this = this;
40
-
41
- compiler.hooks.afterEmit.tapAsync('SourceMapHookPlugin', function (compilation, callback) {
42
- var outputPath = compilation.options.output.path;
43
-
44
- var jsPath = _path2.default.join(outputPath, 'js');
45
- var smapJsPath = _path2.default.join(outputPath, 'js-sm');
46
- (0, _utils.makeDir)([outputPath, jsPath, smapJsPath]);
47
-
48
- var promises = [];
49
- var files = _fs2.default.readdirSync(jsPath);
50
-
51
- files.forEach(function (file) {
52
- var src = _fs2.default.readFileSync(_path2.default.join(jsPath, file)).toString();
53
- promises.push((0, _utils.writeFile)(_path2.default.join(smapJsPath, file), src + '\n//# sourceMappingURL=../smap/' + file + '.map').catch(function (err) {
54
- throw err;
55
- }));
56
-
57
- if (_this.optimize) {
58
- promises.push((0, _utils.writeFile)(_path2.default.join(jsPath, file), (0, _optimizeJs2.default)(src)).catch(function (err) {
59
- throw err;
60
- }));
27
+ if (!/(i18n-chunk\/)/g.test(filename)) {
28
+ src = `${source}\n//# sourceMappingURL=../../js/${name}.js.map`;
29
+ compilation.assets[filename.replace(/js\//g, 'smap/js/')] = new _webpackSources.RawSource(src);
30
+ } else {
31
+ compilation.assets[filename.replace(/i18n-chunk\//g, 'smap/i18n-chunk/')] = new _webpackSources.RawSource(src);
61
32
  }
62
- });
63
-
64
- Promise.all(promises).then(function () {
65
- (0, _utils.log)('Source map hook completed');
66
- callback();
67
- });
33
+ }
68
34
  });
69
- }
70
- }]);
35
+ });
36
+ }
71
37
 
72
- return SourceMapHookPlugin;
73
- }();
38
+ }
74
39
 
75
- exports.default = SourceMapHookPlugin;
40
+ var _default = SourceMapHookPlugin;
41
+ exports.default = _default;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _webpack = require("webpack");
9
+
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+
12
+ var _path = _interopRequireDefault(require("path"));
13
+
14
+ var _crypto = _interopRequireDefault(require("crypto"));
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ /**
19
+ * Plugin that generates hash for the provided list of third party files
20
+ * Map the provided key with the file hash and add it to the list of exisiting global constants.
21
+ * Plugin in turn uses the defineplugin to generate global constants.
22
+ */
23
+ class TPHashMappingPlugin {
24
+ constructor(options) {
25
+ this.fileMappings = options.fileMappings;
26
+ this.tpFolder = options.tpFolder;
27
+ return new _webpack.DefinePlugin(this.getFiles());
28
+ }
29
+
30
+ getHash(content) {
31
+ let hash = _crypto.default.createHash('md5');
32
+
33
+ let data = hash.update(content, 'utf-8');
34
+ let gen_hash = data.digest('hex');
35
+ return gen_hash;
36
+ }
37
+
38
+ getFiles() {
39
+ let hashMapping = {};
40
+ this.fileMappings.forEach(fileInfo => {
41
+ let filePath = `${_path.default.join(this.tpFolder, fileInfo.filePath, fileInfo.fileName)}`;
42
+
43
+ if (_fs.default.existsSync(filePath)) {
44
+ let fileContent = _fs.default.readFileSync(filePath, {
45
+ encoding: 'utf-8'
46
+ });
47
+
48
+ let generatedHash = this.getHash(fileContent);
49
+ let outputFileSplit = fileInfo.fileName.split('.');
50
+ outputFileSplit.splice(outputFileSplit.length - 1, 0, generatedHash);
51
+ let outputFileName = outputFileSplit.join('.');
52
+ let outputFilePath = `${_path.default.join(this.tpFolder, fileInfo.filePath, outputFileName)}`;
53
+
54
+ _fs.default.writeFileSync(outputFilePath, fileContent);
55
+
56
+ hashMapping[fileInfo.key] = JSON.stringify(generatedHash);
57
+ } else {
58
+ throw new Error(`Third party file ${fileInfo.fileName} does not exist`);
59
+ }
60
+ });
61
+ return hashMapping;
62
+ }
63
+
64
+ }
65
+
66
+ var _default = TPHashMappingPlugin;
67
+ exports.default = _default;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _webpackSources = require("webpack-sources");
9
+
10
+ var _uglifycss = _interopRequireDefault(require("uglifycss"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ class UglifyCSSPlugin {
15
+ apply(compiler) {
16
+ compiler.hooks.emit.tap('UglifyCSSPlugin', compilation => {
17
+ Object.keys(compilation.assets).forEach(filename => {
18
+ if (/\.css$/.test(filename)) {
19
+ try {
20
+ let asset = compilation.assets[filename].source();
21
+
22
+ if (typeof asset !== 'string') {
23
+ asset = asset.toString();
24
+ }
25
+
26
+ const result = _uglifycss.default.processString(asset);
27
+
28
+ compilation.assets[filename] = new _webpackSources.RawSource(result);
29
+ } catch (e) {
30
+ compilation.errors.push(e);
31
+ }
32
+ }
33
+ });
34
+ });
35
+ }
36
+
37
+ }
38
+
39
+ exports.default = UglifyCSSPlugin;