@zohodesk/react-cli 0.0.1-beta.16 → 0.0.1-beta.162

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 (228) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.js +46 -3
  3. package/CHANGELOG.md +5 -0
  4. package/README.md +708 -0
  5. package/bin/cli.js +134 -27
  6. package/cert/cert.pem +37 -129
  7. package/cert/key.pem +27 -27
  8. package/cert/passphrase.pem +1 -0
  9. package/files/eslintrc.js +62 -0
  10. package/files/prettierrc.js +3 -0
  11. package/lib/babel/cmjs-plugins-presets.js +16 -9
  12. package/lib/babel/es-plugins-presets.js +26 -14
  13. package/lib/common/getEntries.js +33 -24
  14. package/lib/common/getPublicPathConfig.js +40 -0
  15. package/lib/common/index.js +27 -13
  16. package/lib/common/splitChunks.js +64 -26
  17. package/lib/common/sslcertUpdater.js +59 -0
  18. package/lib/common/templateParameters.js +25 -0
  19. package/lib/configs/jest.config.js +26 -27
  20. package/lib/configs/libAlias.js +31 -0
  21. package/lib/configs/webpack.component.umd.config.js +31 -37
  22. package/lib/configs/webpack.css.umd.config.js +44 -44
  23. package/lib/configs/webpack.dev.config.js +96 -56
  24. package/lib/configs/webpack.docs.config.js +104 -98
  25. package/lib/configs/webpack.impact.config.js +116 -0
  26. package/lib/configs/webpack.prod.config.js +137 -85
  27. package/lib/hooks/docsProptypeHook.js +32 -38
  28. package/lib/jest/commitedFilesResult.js +144 -71
  29. package/lib/jest/coverageCollector.js +62 -29
  30. package/lib/jest/jsonMaker.js +54 -0
  31. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  32. package/lib/jest/preProcessors/jsPreprocessor.js +5 -6
  33. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  34. package/lib/jest/result.js +91 -41
  35. package/lib/jest/run.js +74 -27
  36. package/lib/jest/setup.js +103 -102
  37. package/lib/loaderUtils/getCSSLoaders.js +77 -0
  38. package/lib/loaderUtils/getDevJsLoaders.js +30 -23
  39. package/lib/loaderUtils/index.js +14 -7
  40. package/lib/loaders/docsLoader.js +15 -15
  41. package/lib/loaders/docsPropsLoader.js +14 -17
  42. package/lib/loaders/fileBountryLoader.js +17 -0
  43. package/lib/loaders/fileLoader.js +47 -38
  44. package/lib/loaders/scriptInstrumentLoader.js +21 -20
  45. package/lib/loaders/selectorMappingLoader.js +75 -0
  46. package/lib/loaders/workerLoader.js +136 -0
  47. package/lib/middlewares/HMRMiddleware.js +59 -41
  48. package/lib/middlewares/SSTMiddleware.js +21 -0
  49. package/lib/pluginUtils/getDevPlugins.js +175 -26
  50. package/lib/pluginUtils/getDocsPlugins.js +32 -17
  51. package/lib/pluginUtils/getLibraryImactPlugins.js +23 -0
  52. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  53. package/lib/pluginUtils/getProdPlugins.js +240 -37
  54. package/lib/pluginUtils/getServerPlugins.js +8 -11
  55. package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
  56. package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
  57. package/lib/pluginUtils/index.js +36 -43
  58. package/lib/plugins/CdnChangePlugin.js +77 -0
  59. package/lib/plugins/CleanupStatsPlugin.js +28 -0
  60. package/lib/plugins/EFCPlugin.js +241 -0
  61. package/lib/plugins/EFCPlugin.md +6 -0
  62. package/lib/plugins/EFCTemplatePlugin.js +151 -0
  63. package/lib/plugins/I18NInjectIntoIndexPlugin.js +141 -0
  64. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  65. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  66. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  67. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  68. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  69. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
  70. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  71. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  72. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  73. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  74. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  75. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  76. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  77. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  78. package/lib/plugins/ManifestPlugin.js +59 -62
  79. package/lib/plugins/ModuleStatsPlugin.js +98 -97
  80. package/lib/plugins/OptimizeJSPlugin.js +24 -41
  81. package/lib/plugins/PublicPathCallbackPlugin.js +63 -0
  82. package/lib/plugins/PublicPathChangePlugin.js +187 -174
  83. package/lib/plugins/ReportGeneratePlugin.js +181 -0
  84. package/lib/plugins/RequireVariablePublicPlugin.js +30 -0
  85. package/lib/plugins/ResourceHintsPlugin.js +53 -35
  86. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +80 -0
  87. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +82 -0
  88. package/lib/plugins/RtlSplitPlugin/RtrSplit.md +30 -0
  89. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +26 -0
  90. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  91. package/lib/plugins/ServiceWorkerPlugin.js +107 -0
  92. package/lib/plugins/ShadowDOMSupportPlugin.js +270 -0
  93. package/lib/plugins/SourceMapHookPlugin.js +25 -31
  94. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  95. package/lib/plugins/UglifyCSSPlugin.js +23 -30
  96. package/lib/plugins/UnusedFilesFindPlugin.js +150 -97
  97. package/lib/plugins/index.js +118 -55
  98. package/lib/plugins/libraryImpactPlugin.js +190 -0
  99. package/lib/plugins/webpackwatchrunplugin.js +26 -0
  100. package/lib/postcss-plugins/ExcludeRTLPlugin.js +23 -0
  101. package/lib/postcss-plugins/RTLSplitPlugin.js +138 -0
  102. package/lib/schemas/index.js +466 -52
  103. package/lib/servers/clusterHubServer.js +22 -26
  104. package/lib/servers/docsServer.js +3 -5
  105. package/lib/servers/docsServerCore.js +93 -85
  106. package/lib/servers/helpServer.js +19 -21
  107. package/lib/servers/httpsOptions.js +19 -0
  108. package/lib/servers/impactServer.js +99 -92
  109. package/lib/servers/mockserver.js +44 -0
  110. package/lib/servers/nowatchserver.js +275 -0
  111. package/lib/servers/scrServer.js +147 -0
  112. package/lib/servers/server.js +118 -124
  113. package/lib/servers/ssServer.js +107 -65
  114. package/lib/sh/reportPublish.sh +16 -10
  115. package/lib/templates/CoverageScriptTemplate.js +45 -18
  116. package/lib/templates/WMSTemplate.js +17 -18
  117. package/lib/templates/linterConstant.js +10 -0
  118. package/lib/utils/babelPresets.js +12 -5
  119. package/lib/utils/buildstats.html +148 -0
  120. package/lib/utils/clean.js +12 -11
  121. package/lib/utils/copy.js +13 -127
  122. package/lib/utils/copyTimezones.js +21 -0
  123. package/lib/utils/createEventStream.js +24 -19
  124. package/lib/utils/cssClassNameGenerate.js +77 -0
  125. package/lib/utils/cssURLReplacer.js +67 -54
  126. package/lib/utils/dependencyPostPublish.js +42 -0
  127. package/lib/utils/fileUtils.js +125 -0
  128. package/lib/utils/folderIterator.js +47 -0
  129. package/lib/utils/getComponents.js +126 -0
  130. package/lib/utils/getCurrentBranch.js +11 -17
  131. package/lib/utils/getDependenciesImpactList.js +151 -0
  132. package/lib/utils/getHash.js +26 -0
  133. package/lib/utils/getIp.js +20 -0
  134. package/lib/utils/getOptions.js +55 -30
  135. package/lib/utils/getServerURL.js +25 -8
  136. package/lib/utils/index.js +259 -82
  137. package/lib/utils/init.js +2 -2
  138. package/lib/utils/initPreCommitHook.js +40 -31
  139. package/lib/utils/jsonHelper.js +97 -0
  140. package/lib/utils/libraryImpactConfig.js +63 -0
  141. package/lib/utils/lint/addScripts.js +27 -0
  142. package/lib/utils/lint/checkExistingConfig.js +67 -0
  143. package/lib/utils/lint/copyConfigs.js +24 -0
  144. package/lib/utils/lint/index.js +54 -0
  145. package/lib/utils/lint/lintScripts.js +11 -0
  146. package/lib/utils/lint/lintSetup.js +31 -0
  147. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  148. package/lib/utils/lint/question.js +30 -0
  149. package/lib/utils/lintReporter.js +142 -0
  150. package/lib/utils/mailSender.js +16 -25
  151. package/lib/utils/pullOrigin.js +28 -0
  152. package/lib/utils/reinstallDependencies.js +133 -0
  153. package/lib/utils/removeAttributes.js +25 -23
  154. package/lib/utils/repoClone.js +56 -63
  155. package/lib/utils/request.js +64 -77
  156. package/lib/utils/resultSchema.json +73 -0
  157. package/lib/utils/rtl.js +42 -0
  158. package/lib/utils/setEnvVariables.js +5 -6
  159. package/lib/utils/ssTestHack.js +48 -0
  160. package/lib/utils/switchBranch.js +28 -0
  161. package/lib/utils/urlConcat.js +22 -0
  162. package/package.json +92 -64
  163. package/templates/app/.eslintrc.js +140 -0
  164. package/templates/app/README.md +12 -12
  165. package/templates/app/app/index.html +24 -8
  166. package/templates/app/app/properties/ApplicationResources_en_US.properties +1 -1
  167. package/templates/app/app/properties/i18nkeys.json +3 -3
  168. package/templates/app/docs/all.html +69 -69
  169. package/templates/app/mockapi/index.js +18 -13
  170. package/templates/app/package.json +37 -17
  171. package/templates/app/src/actions/SampleActions/index.js +37 -0
  172. package/templates/app/src/actions/index.js +65 -0
  173. package/templates/app/src/appUrls.js +19 -0
  174. package/templates/app/src/components/Alert/Alert.js +134 -0
  175. package/templates/app/src/components/Alert/Alert.module.css +79 -0
  176. package/templates/app/src/components/FreezeLayer/FreezeLayer.css +37 -0
  177. package/templates/app/src/components/FreezeLayer/FreezeLayer.js +84 -0
  178. package/templates/app/src/components/Sample/Sample.module.css +11 -0
  179. package/templates/app/src/components/Sample/SampleList.js +61 -0
  180. package/templates/app/src/components/Slider/Slider.css +41 -0
  181. package/templates/app/src/components/Slider/Slider.js +55 -0
  182. package/templates/app/src/containers/AlertContainer/index.js +15 -0
  183. package/templates/app/src/containers/AppContainer/index.js +96 -0
  184. package/templates/app/src/containers/AppContainer/index.module.css +27 -0
  185. package/templates/app/src/containers/CustomMatch/index.js +65 -0
  186. package/templates/app/src/containers/DevTools/index.js +10 -0
  187. package/templates/app/src/containers/Header/index.js +67 -0
  188. package/templates/app/src/containers/Header/index.module.css +43 -0
  189. package/templates/app/src/containers/Redirect/index.js +63 -0
  190. package/templates/app/src/containers/Redirector/index.js +47 -0
  191. package/templates/app/src/containers/SampleListContainer/ListContainer.js +42 -0
  192. package/templates/app/src/containers/SampleListContainer/ListContainer.module.css +3 -0
  193. package/templates/app/src/historyChange.js +5 -0
  194. package/templates/app/src/index.html +10 -0
  195. package/templates/app/src/index.js +24 -0
  196. package/templates/app/src/middleware/PromiseMiddleware.js +59 -0
  197. package/templates/app/src/reducers/alertData.js +11 -0
  198. package/templates/app/src/reducers/index.js +6 -0
  199. package/templates/app/src/reducers/samples.js +19 -0
  200. package/templates/app/src/store/configureStore.dev.js +51 -0
  201. package/templates/app/src/store/configureStore.js +5 -0
  202. package/templates/app/src/store/configureStore.prod.js +26 -0
  203. package/templates/app/src/util/Common.js +5 -0
  204. package/templates/app/src/util/RequestAPI.js +132 -0
  205. package/templates/appold/README.md +12 -0
  206. package/templates/appold/app/index.html +8 -0
  207. package/templates/appold/app/properties/ApplicationResources_en_US.properties +1 -0
  208. package/templates/appold/app/properties/i18nkeys.json +3 -0
  209. package/templates/appold/docs/all.html +69 -0
  210. package/templates/appold/mockapi/index.js +13 -0
  211. package/templates/{app → appold}/mockapi/tickets.json +0 -0
  212. package/templates/appold/package.json +17 -0
  213. package/templates/appold/src/components/Text/Text.css +0 -0
  214. package/templates/appold/src/components/Text/Text.js +23 -0
  215. package/templates/appold/src/components/Text/__tests__/Text.spec.js +30 -0
  216. package/templates/appold/src/components/Text/docs/Text__default.docs.js +16 -0
  217. package/templates/appold/src/components/docs.js +1 -0
  218. package/templates/appold/src/components/index.js +5 -0
  219. package/templates/appold/src/index.js +13 -0
  220. package/templates/docs/all.html +1 -1
  221. package/templates/docs/component.html +110 -69
  222. package/templates/docs/components.html +221 -0
  223. package/templates/docs/css/component.css +12 -14
  224. package/templates/docs/css/componentTest.css +7 -0
  225. package/templates/docs/css/style.css +150 -206
  226. package/templates/docs/impactReportTemplate.html +154 -0
  227. package/templates/docs/index.html +1482 -1336
  228. package/templates/library/src/index.js +0 -0
@@ -1,213 +1,226 @@
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 _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
8
+ var _path = _interopRequireDefault(require("path"));
8
9
 
9
- 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; }; }();
10
+ var _webpackSources = require("webpack-sources");
10
11
 
11
- var _path = require('path');
12
-
13
- var _path2 = _interopRequireDefault(_path);
14
-
15
- var _webpackSources = require('webpack-sources');
16
-
17
- var _utils = require('../utils');
12
+ var _utils = require("../utils");
18
13
 
19
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
15
 
21
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
+ const MODULE_TYPE = 'css/mini-extract';
17
+ let {
18
+ chunkSplitEnable
19
+ } = (0, _utils.getOptions)().i18n || {};
22
20
 
23
- var MODULE_TYPE = 'css/mini-extract';
21
+ let filenameParser = filename => {
22
+ let filepaths = filename.split('/');
23
+ let hashedName = filepaths[filepaths.length - 1];
24
24
 
25
- var filenameParser = function filenameParser(filename) {
26
- var filepaths = filename.split('/');
27
- var hashedName = filepaths[filepaths.length - 1];
25
+ let {
26
+ name,
27
+ ext
28
+ } = _path.default.parse(hashedName);
28
29
 
29
- var _path$parse = _path2.default.parse(hashedName),
30
- name = _path$parse.name,
31
- ext = _path$parse.ext;
32
-
33
- var nameparts = name.split('.');
30
+ let nameparts = name.split('.');
34
31
  return {
35
32
  name: nameparts.slice(0, nameparts.length - 1).join('.') + ext,
36
- hashedName: hashedName
33
+ hashedName,
34
+ ext
37
35
  };
38
36
  };
39
37
 
40
- var PublicPathChangePlugin = function () {
41
- function PublicPathChangePlugin(_ref) {
42
- var publicPaths = _ref.publicPaths;
43
-
44
- _classCallCheck(this, PublicPathChangePlugin);
45
-
38
+ class PublicPathChangePlugin {
39
+ constructor({
40
+ publicPaths,
41
+ resourceHints
42
+ }) {
46
43
  if (Array.isArray(publicPaths)) {
47
- var _publicPaths = publicPaths,
48
- _publicPaths2 = _slicedToArray(_publicPaths, 4),
49
- js = _publicPaths2[0],
50
- css = _publicPaths2[1],
51
- image = _publicPaths2[2],
52
- font = _publicPaths2[3];
53
-
54
- publicPaths = { __REACT_CLI_PUBLIC_PATHS__: { js: js, css: css, image: image, font: font } }; //eslint-disable-line
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
55
  }
56
+
56
57
  this.publicPaths = publicPaths;
58
+ this.resourceHints = resourceHints;
57
59
  }
58
60
 
59
- _createClass(PublicPathChangePlugin, [{
60
- key: 'getCssChunkObject',
61
- value: function getCssChunkObject(mainChunk) {
62
- var obj = {};
63
- var _iteratorNormalCompletion = true;
64
- var _didIteratorError = false;
65
- var _iteratorError = undefined;
66
-
67
- try {
68
- for (var _iterator = mainChunk.getAllAsyncChunks()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
69
- var chunk = _step.value;
70
- var _iteratorNormalCompletion2 = true;
71
- var _didIteratorError2 = false;
72
- var _iteratorError2 = undefined;
73
-
74
- try {
75
- for (var _iterator2 = chunk.modulesIterable[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
76
- var module = _step2.value;
77
-
78
- if (module.type === MODULE_TYPE) {
79
- obj[chunk.id] = 1;
80
- break;
81
- }
82
- }
83
- } catch (err) {
84
- _didIteratorError2 = true;
85
- _iteratorError2 = err;
86
- } finally {
87
- try {
88
- if (!_iteratorNormalCompletion2 && _iterator2.return) {
89
- _iterator2.return();
90
- }
91
- } finally {
92
- if (_didIteratorError2) {
93
- throw _iteratorError2;
94
- }
95
- }
96
- }
97
- }
98
- } catch (err) {
99
- _didIteratorError = true;
100
- _iteratorError = err;
101
- } finally {
102
- try {
103
- if (!_iteratorNormalCompletion && _iterator.return) {
104
- _iterator.return();
105
- }
106
- } finally {
107
- if (_didIteratorError) {
108
- throw _iteratorError;
109
- }
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;
110
69
  }
111
70
  }
71
+ }
72
+
73
+ return obj;
74
+ }
112
75
 
113
- return obj;
76
+ needChunkOnDemandLoadingCode(chunk) {
77
+ for (const chunkGroup of chunk.groupsIterable) {
78
+ if (chunkGroup.getNumberOfChildren() > 0) {
79
+ return true;
80
+ }
114
81
  }
115
- }, {
116
- key: 'needChunkOnDemandLoadingCode',
117
- value: function needChunkOnDemandLoadingCode(chunk) {
118
- var _iteratorNormalCompletion3 = true;
119
- var _didIteratorError3 = false;
120
- var _iteratorError3 = undefined;
121
-
122
- try {
123
- for (var _iterator3 = chunk.groupsIterable[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
124
- var chunkGroup = _step3.value;
125
-
126
- if (chunkGroup.getNumberOfChildren() > 0) {
127
- return true;
128
- }
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);
129
96
  }
130
- } catch (err) {
131
- _didIteratorError3 = true;
132
- _iteratorError3 = err;
133
- } finally {
134
- try {
135
- if (!_iteratorNormalCompletion3 && _iterator3.return) {
136
- _iterator3.return();
137
- }
138
- } finally {
139
- if (_didIteratorError3) {
140
- throw _iteratorError3;
141
- }
97
+
98
+ if (isValidFile) {
99
+ ruleMapping[filename] = typeof pattern !== 'string' ? pattern : {};
100
+ break;
142
101
  }
143
102
  }
144
103
 
145
- return false;
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'}'`} />`;
146
115
  }
147
- }, {
148
- key: 'apply',
149
- value: function apply(compiler) {
150
- var _this = this;
151
-
152
- compiler.hooks.thisCompilation.tap('PublicPathChangePlugin', function (compilation) {
153
- compilation.mainTemplate.hooks.requireEnsure.tap('PublicPathChangePlugin', function (source, chunk) {
154
- var chunkMap = _this.getCssChunkObject(chunk);
155
- if (Object.keys(chunkMap).length > 0) {
156
- return source.replace('__webpack_require__.p', '__REACT_CLI_CSS_PUBLIC_PATH__');
157
- }
158
- });
159
- });
160
116
 
161
- compiler.hooks.compilation.tap('PublicPathChangePlugin', function (compilation) {
162
- compilation.mainTemplate.hooks.localVars.tap('PublicPathChangePlugin', function (source, chunk) {
163
- if (_this.needChunkOnDemandLoadingCode(chunk)) {
164
- return source.replace('__webpack_require__.p', '__REACT_CLI_JS_PUBLIC_PATH__');
165
- }
166
- });
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
+ }
167
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
+ }
168
209
 
169
- compiler.hooks.emit.tap('PublicPathChangePlugin', function (compilation) {
170
- var cdns = Object.keys(_this.publicPaths);
171
- var stats = compilation.getStats().toJson();
172
-
173
- var manifest = stats.assets.reduce(function (files, asset) {
174
- var filename = asset.name;
175
-
176
- var fileType = (0, _utils.getFileType)(filename);
177
- if (fileType === 'image' || fileType === 'font') {
178
- var _filenameParser = filenameParser(filename),
179
- name = _filenameParser.name,
180
- hashedName = _filenameParser.hashedName;
181
-
182
- files[name] = hashedName;
183
- }
184
- return files;
185
- }, {});
186
-
187
- Object.keys(compilation.assets).forEach(function (filename) {
188
- var source = compilation.assets[filename].source();
189
- if (Array.isArray(cdns)) {
190
- cdns.forEach(function (cdn) {
191
- if (/\.css$/g.test(filename)) {
192
- var publicPaths = _this.publicPaths[cdn];
193
- source = (0, _utils.cssUrlReplacer)(source, publicPaths, manifest);
194
- } else if (/\.js$/g.test(filename)) {
195
- var _publicPaths$cdn = _this.publicPaths[cdn],
196
- js = _publicPaths$cdn.js,
197
- css = _publicPaths$cdn.css;
198
-
199
- source = source.replace(/__REACT_CLI_JS_PUBLIC_PATH__/g, '"' + js + '"');
200
- source = source.replace(/__REACT_CLI_CSS_PUBLIC_PATH__/g, '"' + css + '"');
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>`);
201
213
  }
202
- compilation.assets['' + (cdn === '__REACT_CLI_PUBLIC_PATHS__' ? '' : cdn + '/') + (cdn === '__REACT_CLI_PUBLIC_PATHS__' ? filename : filename.split('/').slice(1).join('/'))] = new _webpackSources.RawSource(source);
203
- });
204
- }
205
- });
214
+ }
215
+
216
+ compilation.assets[cdn === '__REACT_CLI_PUBLIC_PATHS__' ? filename : `${cdn}/${filename}`] = new _webpackSources.RawSource(source);
217
+ });
218
+ }
206
219
  });
207
- }
208
- }]);
220
+ });
221
+ }
209
222
 
210
- return PublicPathChangePlugin;
211
- }();
223
+ }
212
224
 
213
- exports.default = PublicPathChangePlugin;
225
+ var _default = PublicPathChangePlugin;
226
+ exports.default = _default;
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
+ var _redis = _interopRequireDefault(require("redis"));
13
+
14
+ var _utils = require("../utils");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ let options = (0, _utils.getOptions)();
19
+ let {
20
+ app: {
21
+ branch,
22
+ redisHost,
23
+ redisPort
24
+ }
25
+ } = options;
26
+
27
+ class reportGeneratePlugin {
28
+ apply(compiler) {
29
+ compiler.hooks.emit.tapAsync('reportGeneratePlugin', (compilation, callback) => {
30
+ function formatBytes(bytes) {
31
+ if (bytes) {
32
+ let isNegative;
33
+
34
+ if (bytes < 0) {
35
+ bytes = bytes * -1; //eslint-disable-line
36
+
37
+ isNegative = true;
38
+ }
39
+
40
+ if (bytes < 1024) {
41
+ if (isNegative) {
42
+ return `- ${bytes} Bytes`;
43
+ }
44
+
45
+ return `${bytes} Bytes`;
46
+ } else if (bytes < 1048576) {
47
+ if (isNegative) {
48
+ return `- ${(bytes / 1024).toFixed(3)} KB`;
49
+ }
50
+
51
+ return `${(bytes / 1024).toFixed(3)} KB`;
52
+ } else if (bytes < 1073741824) {
53
+ if (isNegative) {
54
+ return `- ${(bytes / 1048576).toFixed(3)} MB`;
55
+ }
56
+
57
+ return `${(bytes / 1048576).toFixed(3)} MB`;
58
+ }
59
+
60
+ if (isNegative) {
61
+ return `- ${(bytes / 1073741824).toFixed(3)} GB`;
62
+ }
63
+
64
+ return `${(bytes / 1073741824).toFixed(3)} GB`;
65
+ }
66
+ }
67
+
68
+ let client = _redis.default.createClient(redisPort, redisHost);
69
+
70
+ client.on('connect', () => {
71
+ (0, _utils.log)('Redis client connected');
72
+ });
73
+ client.on('error', err => {
74
+ (0, _utils.log)(`Something went wrong ${err}`);
75
+ });
76
+
77
+ if (_fs.default.existsSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'))) {
78
+ let statsJSON = _fs.default.readFileSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'), 'utf8');
79
+
80
+ statsJSON = JSON.parse(statsJSON);
81
+ let finalObj = {};
82
+ let branchName = branch ? branch : (0, _utils.getCurrentBranch)();
83
+ (0, _utils.log)(branchName);
84
+ statsJSON.assets.forEach(assetObj => {
85
+ let nameSplitList = assetObj.name.split('/')[assetObj.name.split('/').length - 1].split('.'); // eslint-disable-line
86
+
87
+ let [, hash] = nameSplitList;
88
+ let name = `${nameSplitList[0]}.${nameSplitList[2]}`;
89
+ let {
90
+ size
91
+ } = assetObj;
92
+ let tempObject = {
93
+ name,
94
+ hash,
95
+ size
96
+ }; // eslint-disable-next-line
97
+
98
+ if (!finalObj.hasOwnProperty(name)) {
99
+ finalObj[name] = tempObject;
100
+ }
101
+ });
102
+ client.exists(branchName, (err, bool) => {
103
+ if (!bool) {
104
+ client.set(branchName, JSON.stringify(finalObj), _redis.default.print);
105
+ client.quit();
106
+ } else {
107
+ let reportObj = {
108
+ increased: [],
109
+ hashChanged: [],
110
+ branchName
111
+ };
112
+ client.get(branchName, (err, reply) => {
113
+ if (err) {
114
+ (0, _utils.log)(err);
115
+ } else {
116
+ reply = JSON.parse(reply); // eslint-disable-line
117
+
118
+ Object.keys(reply).forEach(fileName => {
119
+ // eslint-disable-next-line
120
+ if (finalObj.hasOwnProperty(fileName)) {
121
+ if (parseInt(reply[fileName].size) < parseInt(finalObj[fileName].size)) {
122
+ reportObj.increased.push({
123
+ name: fileName,
124
+ size: {
125
+ old: formatBytes(reply[fileName].size),
126
+ new: formatBytes(finalObj[fileName].size),
127
+ diff: formatBytes(parseInt(finalObj[fileName].size) - parseInt(reply[fileName].size))
128
+ }
129
+ });
130
+ }
131
+
132
+ if (reply[fileName].hash !== finalObj[fileName].hash) {
133
+ reportObj.hashChanged.push({
134
+ name: fileName,
135
+ hash: {
136
+ old: reply[fileName].hash,
137
+ new: finalObj[fileName].hash
138
+ }
139
+ });
140
+ }
141
+ }
142
+ });
143
+ let json = JSON.stringify(reportObj);
144
+
145
+ _fs.default.writeFile(_path.default.resolve(process.cwd(), 'build', 'buildtrack.js'), `let statsJson=${json}`, err => {
146
+ if (err) {
147
+ throw err;
148
+ }
149
+
150
+ (0, _utils.log)('Stats Json generated!');
151
+ });
152
+ }
153
+ });
154
+ client.set(branchName, JSON.stringify(finalObj), _redis.default.print); // fs.copyFileSync(
155
+ // path.resolve(
156
+ // process.cwd(),
157
+ // 'node_modules',
158
+ // '@zohodesk',
159
+ // 'react-cli',
160
+ // 'lib',
161
+ // 'utils',
162
+ // 'buildstats.html'
163
+ // ),
164
+ // path.resolve(process.cwd(), 'build', 'buildstats.html')
165
+ // );
166
+
167
+ client.quit();
168
+ callback && callback();
169
+ }
170
+
171
+ if (err) {
172
+ (0, _utils.log)(err);
173
+ }
174
+ });
175
+ }
176
+ });
177
+ }
178
+
179
+ }
180
+
181
+ exports.default = reportGeneratePlugin;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ const {
9
+ Template
10
+ } = require('webpack');
11
+
12
+ const pluginName = 'RequireVariablePublicPlugin';
13
+
14
+ class RequireVariablePublicPlugin {
15
+ constructor(options) {
16
+ this.requireFuncName = options.requireFuncName;
17
+ }
18
+
19
+ apply(compiler) {
20
+ compiler.hooks.thisCompilation.tap(pluginName, ({
21
+ mainTemplate
22
+ }) => {
23
+ mainTemplate.hooks.requireExtensions.tap(pluginName, source => Template.asString([source, '', `window[${JSON.stringify(this.requireFuncName)}] = ${mainTemplate.requireFn};`]));
24
+ });
25
+ }
26
+
27
+ }
28
+
29
+ var _default = RequireVariablePublicPlugin;
30
+ exports.default = _default;