@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
@@ -1,123 +1,124 @@
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
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ var _webpackSources = require("webpack-sources");
10
11
 
11
- var ModuleStatsPlugin = function () {
12
- function ModuleStatsPlugin() {
13
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
13
 
15
- _classCallCheck(this, ModuleStatsPlugin);
14
+ let isValidModule = name => {
15
+ if (name.includes('node_modules') && (name.includes(`@zohodesk${_path.default.sep}components`) || name.includes(`@zohodesk${_path.default.sep}dot`) || name.includes(`@zohodesk${_path.default.sep}icons`) || name.includes(`@zohodesk${_path.default.sep}svg`)) && !name.endsWith('docs.js')) {
16
+ return true;
17
+ }
16
18
 
17
- this.options = options;
18
- this.options.filename = options.filename || 'moduleStats.js';
19
+ return !name.includes('index.js') && !name.endsWith('.css') && !name.endsWith('.png') && !name.includes('node_modules') && name.includes('src');
20
+ };
21
+
22
+ let getModuleName = modulePath => {
23
+ let [name] = _path.default.parse(modulePath).name.split('.');
24
+
25
+ if (modulePath.includes(`@zohodesk${_path.default.sep}components`)) {
26
+ name = `@zohodesk/components/${name}`;
27
+ } else if (modulePath.includes(`@zohodesk${_path.default.sep}dot`)) {
28
+ name = `@zohodesk/dot/${name}`;
19
29
  }
20
30
 
21
- _createClass(ModuleStatsPlugin, [{
22
- key: 'apply',
23
- value: function apply(compiler) {
24
- var _this = this;
25
-
26
- compiler.hooks.emit.tap('ModuleStatsPlugin', function (compilation) {
27
- var stats = compilation.getStats().toJson();
28
-
29
- var modules = stats.modules;
30
-
31
- var moduleName = '';
32
- var rModuleName = '';
33
- var rReferencesArray = [];
34
- var rReferencedByArray = [];
35
- var data = { results: [] };
36
- var moduleDetails = {};
37
- var references = '';
38
- var referencedBy = '';
39
- // let normalizedData = '';
40
- var dre = void 0;
41
-
42
- // eslint-disable-next-line guard-for-in
43
- for (var i in modules) {
44
- moduleName = modules[i].name;
45
- if (moduleName.startsWith('./src') && !(moduleName.indexOf('index.js') > -1) && !moduleName.endsWith('css')) {
46
- rModuleName = moduleName.substring(moduleName.lastIndexOf('/') + 1, moduleName.lastIndexOf('.'));
47
- if (rModuleName.endsWith('docs')) {
48
- rModuleName = rModuleName.substring(0, rModuleName.lastIndexOf('.'));
49
- }
31
+ return name;
32
+ };
50
33
 
51
- if (modules[i].reasons.length > 0) {
52
- // eslint-disable-next-line guard-for-in
53
- for (var l in modules[i].reasons) {
54
- referencedBy = modules[i].reasons[l].moduleName;
55
- if (!referencedBy.endsWith('index.js')) {
56
- var referencedby = referencedBy.substring(referencedBy.lastIndexOf('/') + 1, referencedBy.lastIndexOf('.'));
57
- if (referencedby.endsWith('docs')) {
58
- rReferencedByArray.push(referencedby.substring(0, referencedby.lastIndexOf('.')));
59
- } else {
60
- rReferencedByArray.push(referencedBy.substring(referencedBy.lastIndexOf('/') + 1, referencedBy.lastIndexOf('.')));
61
- }
62
- }
63
- }
64
- }
34
+ class ModuleStatsPlugin {
35
+ constructor(options = {}) {
36
+ this.options = options;
37
+ this.options.filename = options.filename || 'js/moduleStats.js';
38
+ }
65
39
 
66
- for (var module in modules) {
67
- if (modules[module].name.startsWith('./src')) {
68
- for (var reason in modules[module].reasons) {
69
- if (moduleName === modules[module].reasons[reason].moduleName && !(modules[module].name.indexOf('css') > -1)) {
70
- if (!modules[module].name.endsWith('react.js') && !(modules[module].name.indexOf('react-dom') > -1) && !modules[module].name.endsWith('.png')) {
71
- references = modules[module].name;
72
- rReferencesArray.push(references.substring(references.lastIndexOf('/') + 1, references.lastIndexOf('.')));
73
- }
74
- }
40
+ apply(compiler) {
41
+ compiler.hooks.emit.tap('ModuleStatsPlugin', compilation => {
42
+ let stats = compilation.getStats().toJson();
43
+ let results = {};
44
+ let {
45
+ modules
46
+ } = stats;
47
+
48
+ for (let module of modules) {
49
+ let {
50
+ name,
51
+ reasons
52
+ } = module;
53
+
54
+ if (isValidModule(name)) {
55
+ let references = new Set();
56
+ let referencedby = new Set();
57
+ let docsName;
58
+ let fileName;
59
+ compilation.modules.forEach(module => {
60
+ module.reasons.forEach(reason => {
61
+ let exportedValue = reason.dependency;
62
+
63
+ if (exportedValue.type === 'harmony export imported specifier') {
64
+ if (exportedValue.module.userRequest.includes(name.replace('.', ''))) {
65
+ docsName = exportedValue.name;
75
66
  }
76
67
  }
77
- }
78
-
79
- rReferencesArray = rReferencesArray.filter(function (item, index, inputArray) {
80
- return inputArray.indexOf(item) === index;
81
68
  });
69
+ });
70
+ let currentModuleName = name;
71
+
72
+ if (Array.isArray(reasons)) {
73
+ for (let reason of reasons) {
74
+ let {
75
+ moduleName
76
+ } = reason;
77
+
78
+ if (isValidModule(moduleName)) {
79
+ let reasonedModuleName = moduleName;
80
+ referencedby.add(reasonedModuleName);
81
+ }
82
+ }
83
+ }
82
84
 
83
- moduleDetails = {
84
- name: rModuleName,
85
- references: rReferencesArray,
86
- referencedby: rReferencedByArray
87
- };
85
+ for (let subModule of modules) {
86
+ let {
87
+ name: subModuleName,
88
+ reasons
89
+ } = subModule;
88
90
 
89
- dre = '';
91
+ if (isValidModule(subModuleName)) {
92
+ let currentModuleName = subModuleName;
90
93
 
91
- data.results.push(moduleDetails);
92
- moduleDetails = {};
93
- rReferencesArray = [];
94
- rReferencedByArray = [];
95
- referencedBy = '';
96
- references = '';
94
+ if (Array.isArray(reasons)) {
95
+ for (let reason of reasons) {
96
+ let {
97
+ moduleName: reasonedModuleName
98
+ } = reason;
97
99
 
98
- //eslint-disable-next-line no-loop-func
99
- data.results.forEach(function (mod) {
100
- dre += '\'' + mod.name + '\':' + JSON.stringify(mod) + ',';
101
- });
100
+ if (name === reasonedModuleName) {
101
+ references.add(currentModuleName);
102
+ }
103
+ }
104
+ }
105
+ }
102
106
  }
103
- }
104
107
 
105
- var dataResult = '{' + dre + '}';
106
- var mResult = 'let mdata = ' + dataResult;
108
+ results[currentModuleName] = {
109
+ name: currentModuleName,
110
+ references: Array.from(references),
111
+ referencedby: Array.from(referencedby),
112
+ docsName: docsName ? docsName : '',
113
+ fileName: name ? name : currentModuleName
114
+ };
115
+ }
116
+ }
107
117
 
108
- compilation.assets[_this.options.filename] = {
109
- source: function source() {
110
- return mResult;
111
- },
112
- size: function size() {
113
- return mResult.length;
114
- }
115
- };
116
- });
117
- }
118
- }]);
118
+ compilation.assets[this.options.filename] = new _webpackSources.RawSource(JSON.stringify(results));
119
+ });
120
+ }
119
121
 
120
- return ModuleStatsPlugin;
121
- }();
122
+ }
122
123
 
123
124
  exports.default = ModuleStatsPlugin;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _optimizeJs = _interopRequireDefault(require("optimize-js"));
9
+
10
+ var _webpackSources = require("webpack-sources");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ class OptimizeJSPlugin {
15
+ constructor(options = {}) {
16
+ this.optimize = options.optimize;
17
+ }
18
+
19
+ apply(compiler) {
20
+ compiler.hooks.compilation.tap('OptimizeJSPlugin', compilation => {
21
+ compilation.hooks.afterOptimizeChunks.tap('OptimizeJSPlugin', chunks => {
22
+ chunks.forEach(chunk => {
23
+ const files = chunk.files.map(file => file);
24
+ files.filter(file => /\.js$/.test(file)).forEach(file => {
25
+ try {
26
+ const asset = compilation.assets[file].source();
27
+ const result = (0, _optimizeJs.default)(asset);
28
+ compilation.assets[file] = new _webpackSources.RawSource(result);
29
+ } catch (e) {
30
+ compilation.errors.push(e);
31
+ }
32
+ });
33
+ });
34
+ });
35
+ });
36
+ }
37
+
38
+ }
39
+
40
+ var _default = OptimizeJSPlugin;
41
+ exports.default = _default;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const MODULE_TYPE = 'css/mini-extract';
8
+
9
+ class PublicPathCallbackPlugin {
10
+ constructor({
11
+ callback
12
+ }) {
13
+ this.publicPathCallback = callback;
14
+ }
15
+
16
+ getCssChunkObject(mainChunk) {
17
+ const obj = {};
18
+
19
+ for (const chunk of mainChunk.getAllAsyncChunks()) {
20
+ for (const module of chunk.modulesIterable) {
21
+ if (module.type === MODULE_TYPE) {
22
+ obj[chunk.id] = 1;
23
+ break;
24
+ }
25
+ }
26
+ }
27
+
28
+ return obj;
29
+ }
30
+
31
+ needChunkOnDemandLoadingCode(chunk) {
32
+ for (const chunkGroup of chunk.groupsIterable) {
33
+ if (chunkGroup.getNumberOfChildren() > 0) {
34
+ return true;
35
+ }
36
+ }
37
+
38
+ return false;
39
+ }
40
+
41
+ apply(compiler) {
42
+ compiler.hooks.thisCompilation.tap('PublicPathCallbackPlugin', compilation => {
43
+ compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathCallbackPlugin', (source, chunk) => {
44
+ const chunkMap = this.getCssChunkObject(chunk);
45
+
46
+ if (Object.keys(chunkMap).length > 0) {
47
+ return source.replace('__webpack_require__.p', `${this.publicPathCallback}("css")`);
48
+ }
49
+ });
50
+ });
51
+ compiler.hooks.compilation.tap('PublicPathCallbackPlugin', compilation => {
52
+ compilation.mainTemplate.hooks.localVars.tap('PublicPathCallbackPlugin', (source, chunk) => {
53
+ if (this.needChunkOnDemandLoadingCode(chunk)) {
54
+ return source.replace('__webpack_require__.p', `${this.publicPathCallback}("js")`);
55
+ }
56
+ });
57
+ });
58
+ }
59
+
60
+ }
61
+
62
+ var _default = PublicPathCallbackPlugin;
63
+ exports.default = _default;
@@ -0,0 +1,226 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _webpackSources = require("webpack-sources");
11
+
12
+ var _utils = require("../utils");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const MODULE_TYPE = 'css/mini-extract';
17
+ let {
18
+ chunkSplitEnable
19
+ } = (0, _utils.getOptions)().i18n || {};
20
+
21
+ let filenameParser = filename => {
22
+ let filepaths = filename.split('/');
23
+ let hashedName = filepaths[filepaths.length - 1];
24
+
25
+ let {
26
+ name,
27
+ ext
28
+ } = _path.default.parse(hashedName);
29
+
30
+ let nameparts = name.split('.');
31
+ return {
32
+ name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
33
+ hashedName,
34
+ ext
35
+ };
36
+ };
37
+
38
+ class PublicPathChangePlugin {
39
+ constructor({
40
+ publicPaths,
41
+ resourceHints
42
+ }) {
43
+ if (Array.isArray(publicPaths)) {
44
+ let [js, css, image, font, i18njs] = publicPaths; //eslint-disable-next-line
45
+
46
+ publicPaths = {
47
+ __REACT_CLI_PUBLIC_PATHS__: {
48
+ js,
49
+ css,
50
+ image,
51
+ font,
52
+ i18njs
53
+ }
54
+ };
55
+ }
56
+
57
+ this.publicPaths = publicPaths;
58
+ this.resourceHints = resourceHints;
59
+ }
60
+
61
+ getCssChunkObject(mainChunk) {
62
+ const obj = {};
63
+
64
+ for (const chunk of mainChunk.getAllAsyncChunks()) {
65
+ for (const module of chunk.modulesIterable) {
66
+ if (module.type === MODULE_TYPE) {
67
+ obj[chunk.id] = 1;
68
+ break;
69
+ }
70
+ }
71
+ }
72
+
73
+ return obj;
74
+ }
75
+
76
+ needChunkOnDemandLoadingCode(chunk) {
77
+ for (const chunkGroup of chunk.groupsIterable) {
78
+ if (chunkGroup.getNumberOfChildren() > 0) {
79
+ return true;
80
+ }
81
+ }
82
+
83
+ return false;
84
+ }
85
+
86
+ getResourceHints(resourceHints, manifest, publicPaths) {
87
+ let ruleMapping = {};
88
+ let validFiles = Object.keys(manifest).filter(filename => {
89
+ let isValidFile = false;
90
+
91
+ for (let pattern of resourceHints) {
92
+ if (typeof pattern === 'string') {
93
+ isValidFile = new RegExp(pattern).test(filename);
94
+ } else {
95
+ isValidFile = new RegExp(pattern.pattern).test(filename);
96
+ }
97
+
98
+ if (isValidFile) {
99
+ ruleMapping[filename] = typeof pattern !== 'string' ? pattern : {};
100
+ break;
101
+ }
102
+ }
103
+
104
+ return isValidFile;
105
+ });
106
+ let resourceHintsContent = '';
107
+
108
+ for (let file of validFiles) {
109
+ let {
110
+ fileType,
111
+ filename
112
+ } = manifest[file];
113
+ let rules = ruleMapping[file];
114
+ resourceHintsContent += `<link rel=${rules.hint || 'preload'} href='${publicPaths[fileType] + filename}'${rules.hint === 'prefetch' ? '' : `as='${fileType}' crossorigin='${rules.crossorigin || 'false'}'`} />`;
115
+ }
116
+
117
+ return resourceHintsContent;
118
+ }
119
+
120
+ apply(compiler) {
121
+ compiler.hooks.thisCompilation.tap('PublicPathChangePlugin', compilation => {
122
+ compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathChangePlugin', (source, chunk) => {
123
+ const chunkMap = this.getCssChunkObject(chunk);
124
+
125
+ if (Object.keys(chunkMap).length > 0) {
126
+ return source.replace('__webpack_require__.p', '__REACT_CLI_CSS_PUBLIC_PATH__');
127
+ }
128
+ });
129
+ });
130
+ compiler.hooks.compilation.tap('PublicPathChangePlugin', compilation => {
131
+ compilation.mainTemplate.hooks.localVars.tap('PublicPathChangePlugin', (source, chunk) => {
132
+ if (this.needChunkOnDemandLoadingCode(chunk)) {
133
+ return source.replace('__webpack_require__.p', '__REACT_CLI_JS_PUBLIC_PATH__');
134
+ }
135
+ });
136
+ });
137
+ compiler.hooks.emit.tap('PublicPathChangePlugin', compilation => {
138
+ let cdns = Object.keys(this.publicPaths);
139
+ let stats = compilation.getStats().toJson();
140
+ let manifest = stats.assets.reduce((files, asset) => {
141
+ let {
142
+ name: filename
143
+ } = asset;
144
+ let fileType = (0, _utils.getFileType)(filename);
145
+
146
+ if (fileType === 'image' || fileType === 'font') {
147
+ let {
148
+ name,
149
+ hashedName,
150
+ ext
151
+ } = filenameParser(filename);
152
+ files[name] = {
153
+ hashedName,
154
+ ext,
155
+ fileType,
156
+ filename
157
+ };
158
+ }
159
+
160
+ return files;
161
+ }, {});
162
+ Object.keys(compilation.assets).forEach(filename => {
163
+ if (Array.isArray(cdns)) {
164
+ cdns.forEach(cdn => {
165
+ let source = compilation.assets[filename].source();
166
+
167
+ if (/\.css$/g.test(filename)) {
168
+ let publicPaths = this.publicPaths[cdn];
169
+ source = (0, _utils.cssUrlReplacer)(source, publicPaths, manifest, cdn);
170
+ } else if (/\.js$/g.test(filename)) {
171
+ let {
172
+ js,
173
+ css,
174
+ image,
175
+ font
176
+ } = this.publicPaths[cdn];
177
+
178
+ if (typeof source === 'string') {
179
+ source = source.replace(/__REACT_CLI_JS_PUBLIC_PATH__/g, `"${js}"`);
180
+ source = source.replace(/__REACT_CLI_CSS_PUBLIC_PATH__/g, `"${css}"`);
181
+ source = source.replace(/__REACT_CLI_IMAGE_PUBLIC_PATH__/g, `"${image}"`);
182
+ source = source.replace(/__REACT_CLI_FONT_PUBLIC_PATH__/g, `"${font}"`);
183
+ }
184
+ } else if (/\.html$/g.test(filename)) {
185
+ let {
186
+ js,
187
+ css,
188
+ i18njs
189
+ } = this.publicPaths[cdn];
190
+ source = source.replace(new RegExp('<script defer src="([^"]*)"', 'g'), (match, arg) => match.replace(arg, js + arg));
191
+ source = source.replace(new RegExp('<link href="([^"]*)"', 'g'), (match, arg) => match.replace(arg, css + arg));
192
+ let [i18nStr] = source.match(/<!--I18nInfoToServer(.*?)I18nInfoToServer-->/gm);
193
+
194
+ if (i18nStr && !chunkSplitEnable) {
195
+ try {
196
+ let [i18nObj] = i18nStr.match(/{(.*?)}/gm);
197
+ i18nObj = JSON.parse(JSON.parse(JSON.stringify(i18nObj)));
198
+ Object.keys(i18nObj).forEach(locale => {
199
+ i18nObj[locale] = i18njs + i18nObj[locale];
200
+ });
201
+ source = source.replace(/<!--I18nInfoToServer(.*?)I18nInfoToServer-->/gm, `<!--I18nInfoToServer${JSON.stringify(i18nObj)}I18nInfoToServer-->`);
202
+ } catch (e) {
203
+ // eslint-disable-next-line no-console
204
+ console.warn('may be I18nInfoToServer inside object was not valid make sure it is parseable by JSON.parse'); // eslint-disable-next-line no-console
205
+
206
+ console.warn(e);
207
+ }
208
+ }
209
+
210
+ if (Array.isArray(this.resourceHints) && this.resourceHints.length) {
211
+ let resourceHintsContent = this.getResourceHints(this.resourceHints, manifest, this.publicPaths[cdn]);
212
+ source = source.replace(/<\/head>/g, `${resourceHintsContent}</head>`);
213
+ }
214
+ }
215
+
216
+ compilation.assets[cdn === '__REACT_CLI_PUBLIC_PATHS__' ? filename : `${cdn}/${filename}`] = new _webpackSources.RawSource(source);
217
+ });
218
+ }
219
+ });
220
+ });
221
+ }
222
+
223
+ }
224
+
225
+ var _default = PublicPathChangePlugin;
226
+ exports.default = _default;