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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. package/README.md +35 -40
  2. package/docs/SelectorWeight.md +6 -0
  3. package/docs/VariableConversion.md +33 -1
  4. package/lib/babel/cmjs-plugins-presets.js +4 -0
  5. package/lib/babel/es-plugins-presets.js +4 -0
  6. package/lib/common/getEntries.js +10 -0
  7. package/lib/common/getPublicPathConfig.js +6 -0
  8. package/lib/common/index.js +5 -0
  9. package/lib/common/splitChunks.js +13 -2
  10. package/lib/common/sslcertUpdater.js +17 -6
  11. package/lib/common/templateParameters.js +2 -0
  12. package/lib/common/testPattern.js +21 -10
  13. package/lib/common/valueReplacer.js +15 -0
  14. package/lib/configs/jest.config.js +9 -0
  15. package/lib/configs/libAlias.js +2 -4
  16. package/lib/configs/webpack.component.umd.config.js +5 -0
  17. package/lib/configs/webpack.css.umd.config.js +13 -5
  18. package/lib/configs/webpack.dev.config.js +36 -2
  19. package/lib/configs/webpack.docs.config.js +21 -1
  20. package/lib/configs/webpack.impact.config.js +19 -1
  21. package/lib/configs/webpack.prod.config.js +37 -3
  22. package/lib/hooks/docsProptypeHook.js +7 -3
  23. package/lib/jest/commitedFilesResult.js +45 -3
  24. package/lib/jest/coverageCollector.js +11 -0
  25. package/lib/jest/jsonMaker.js +6 -0
  26. package/lib/jest/preProcessors/cssPreprocessor.js +8 -0
  27. package/lib/jest/preProcessors/jsPreprocessor.js +2 -0
  28. package/lib/jest/preProcessors/otherFilesPreprocessor.js +3 -0
  29. package/lib/jest/result.js +22 -0
  30. package/lib/jest/run.js +17 -6
  31. package/lib/jest/setup.js +57 -5
  32. package/lib/loaderUtils/configsAssetsLoaders.js +11 -1
  33. package/lib/loaderUtils/getCSSLoaders.js +35 -20
  34. package/lib/loaderUtils/getDevJsLoaders.js +8 -0
  35. package/lib/loaderUtils/index.js +3 -0
  36. package/lib/loaderUtils/windowsModification.js +11 -0
  37. package/lib/loaders/docsLoader.js +7 -0
  38. package/lib/loaders/docsPropsLoader.js +7 -3
  39. package/lib/loaders/fileBountryLoader.js +2 -0
  40. package/lib/loaders/fileLoader.js +22 -11
  41. package/lib/loaders/scriptInstrumentLoader.js +13 -5
  42. package/lib/loaders/selectorMappingLoader.js +25 -7
  43. package/lib/loaders/workerLoader.js +20 -4
  44. package/lib/middlewares/HMRMiddleware.js +26 -13
  45. package/lib/middlewares/SSTMiddleware.js +3 -0
  46. package/lib/pluginUtils/configHtmlWebpackPlugins.js +9 -3
  47. package/lib/pluginUtils/getDevPlugins.js +63 -17
  48. package/lib/pluginUtils/getDocsPlugins.js +10 -1
  49. package/lib/pluginUtils/getLibraryImactPlugins.js +5 -4
  50. package/lib/pluginUtils/getLibraryPlugins.js +5 -0
  51. package/lib/pluginUtils/getProdPlugins.js +72 -23
  52. package/lib/pluginUtils/getServerPlugins.js +5 -0
  53. package/lib/pluginUtils/getUMDCSSPlugins.js +7 -0
  54. package/lib/pluginUtils/getUMDComponentPlugins.js +7 -0
  55. package/lib/pluginUtils/index.js +8 -0
  56. package/lib/plugins/CdnChangePlugin.js +14 -0
  57. package/lib/plugins/CleanupStatsPlugin.js +5 -0
  58. package/lib/plugins/EFCPlugin.js +34 -23
  59. package/lib/plugins/EFCTemplatePlugin.js +32 -23
  60. package/lib/plugins/I18NInjectIntoIndexPlugin.js +34 -8
  61. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +17 -12
  62. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +10 -4
  63. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +39 -8
  64. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +29 -14
  65. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +22 -13
  66. package/lib/plugins/I18nSplitPlugin/index.js +23 -13
  67. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +12 -2
  68. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +1 -0
  69. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +5 -0
  70. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +6 -0
  71. package/lib/plugins/I18nSplitPlugin/utils/index.js +4 -0
  72. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -2
  73. package/lib/plugins/ManifestPlugin.js +17 -0
  74. package/lib/plugins/ModuleStatsPlugin.js +23 -0
  75. package/lib/plugins/OptimizeJSPlugin.js +7 -0
  76. package/lib/plugins/PublicPathCallbackPlugin.js +10 -0
  77. package/lib/plugins/PublicPathChangePlugin.js +36 -4
  78. package/lib/plugins/ReportGeneratePlugin.js +30 -4
  79. package/lib/plugins/RequireVariablePublicPlugin.js +6 -0
  80. package/lib/plugins/ResourceHintsPlugin.js +10 -3
  81. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +17 -12
  82. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +16 -9
  83. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +5 -2
  84. package/lib/plugins/ScriptInstrumentPlugin.js +7 -0
  85. package/lib/plugins/SelectorPlugin.js +97 -0
  86. package/lib/plugins/ServiceWorkerPlugin.js +20 -4
  87. package/lib/plugins/ShadowDOMSupportPlugin.js +40 -3
  88. package/lib/plugins/SourceMapHookPlugin.js +9 -0
  89. package/lib/plugins/TPHashMappingPlugin.js +15 -1
  90. package/lib/plugins/UglifyCSSPlugin.js +9 -0
  91. package/lib/plugins/UnusedFilesFindPlugin.js +35 -2
  92. package/lib/plugins/VariableConversionCollector.js +252 -0
  93. package/lib/plugins/composeCommonPlugin.js +30 -0
  94. package/lib/plugins/index.js +19 -0
  95. package/lib/plugins/libraryImpactPlugin.js +32 -0
  96. package/lib/plugins/webpackwatchrunplugin.js +5 -0
  97. package/lib/postcss-plugins/ExcludePlugin.js +4 -0
  98. package/lib/postcss-plugins/RTLSplitPlugin.js +27 -14
  99. package/lib/postcss-plugins/ValueReplacer.js +6 -9
  100. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +3 -0
  101. package/lib/postcss-plugins/hoverActivePlugin.js +66 -30
  102. package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +40 -13
  103. package/lib/postcss-plugins/variableModificationPlugin/index.js +215 -141
  104. package/lib/postcss-plugins/variableModifier.js +20 -13
  105. package/lib/schemas/index.js +23 -4
  106. package/lib/servers/clusterHubServer.js +10 -0
  107. package/lib/servers/devBuild.js +24 -13
  108. package/lib/servers/docsServer.js +2 -0
  109. package/lib/servers/docsServerCore.js +21 -0
  110. package/lib/servers/getCliPath.js +9 -0
  111. package/lib/servers/helpServer.js +5 -0
  112. package/lib/servers/httpsOptions.js +4 -0
  113. package/lib/servers/impactServer.js +34 -2
  114. package/lib/servers/mockserver.js +9 -0
  115. package/lib/servers/nowatchserver.js +34 -12
  116. package/lib/servers/scrServer.js +20 -13
  117. package/lib/servers/server.js +35 -7
  118. package/lib/servers/ssServer.js +16 -0
  119. package/lib/templates/CoverageScriptTemplate.js +14 -0
  120. package/lib/templates/WMSTemplate.js +12 -6
  121. package/lib/utils/babelPresets.js +2 -0
  122. package/lib/utils/clean.js +8 -2
  123. package/lib/utils/copy.js +6 -0
  124. package/lib/utils/copyTimezones.js +8 -0
  125. package/lib/utils/createEventStream.js +4 -0
  126. package/lib/utils/cssClassNameGenerate.js +19 -3
  127. package/lib/utils/cssURLReplacer.js +50 -38
  128. package/lib/utils/dependencyPostPublish.js +9 -0
  129. package/lib/utils/fileUtils.js +26 -0
  130. package/lib/utils/folderIterator.js +10 -0
  131. package/lib/utils/getComponents.js +21 -0
  132. package/lib/utils/getCurrentBranch.js +5 -0
  133. package/lib/utils/getDependenciesImpactList.js +21 -0
  134. package/lib/utils/getFileType.js +49 -0
  135. package/lib/utils/getHash.js +7 -0
  136. package/lib/utils/getIp.js +2 -0
  137. package/lib/utils/getOptions.js +39 -14
  138. package/lib/utils/getServerURL.js +7 -0
  139. package/lib/utils/index.js +47 -2
  140. package/lib/utils/init.js +1 -0
  141. package/lib/utils/initPreCommitHook.js +29 -6
  142. package/lib/utils/jsonHelper.js +19 -2
  143. package/lib/utils/libraryImpactConfig.js +2 -0
  144. package/lib/utils/lint/addScripts.js +5 -2
  145. package/lib/utils/lint/checkExistingConfig.js +12 -3
  146. package/lib/utils/lint/copyConfigs.js +3 -0
  147. package/lib/utils/lint/index.js +9 -0
  148. package/lib/utils/lint/lintScripts.js +1 -0
  149. package/lib/utils/lint/lintSetup.js +4 -3
  150. package/lib/utils/lint/lintStagedPreCommitHook.js +1 -0
  151. package/lib/utils/lint/question.js +7 -0
  152. package/lib/utils/lintReporter.js +20 -0
  153. package/lib/utils/mailSender.js +7 -0
  154. package/lib/utils/pullOrigin.js +4 -0
  155. package/lib/utils/reinstallDependencies.js +28 -0
  156. package/lib/utils/removeAttributes.js +7 -0
  157. package/lib/utils/repoClone.js +27 -2
  158. package/lib/utils/request.js +12 -0
  159. package/lib/utils/rtl.js +16 -4
  160. package/lib/utils/setEnvVariables.js +2 -0
  161. package/lib/utils/ssTestHack.js +10 -0
  162. package/lib/utils/switchBranch.js +4 -0
  163. package/lib/utils/urlConcat.js +4 -0
  164. package/lib/utils/useExitCleanup.js +10 -9
  165. package/package.json +10 -9
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _postcss = _interopRequireDefault(require("postcss"));
9
+
10
+ var _fs = _interopRequireDefault(require("fs"));
11
+
12
+ var _ErrorHandler = require("../postcss-plugins/variableModificationPlugin/ErrorHandler");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ // import { RawSource } from 'webpack-sources';
17
+ const ignoreVals = ['--zd_size', '--zd_font_size', '--size', '--size_']; // -- is issue IO --
18
+
19
+ /*
20
+ issues eg :
21
+ issues = ['--zd_size', '--zd_font_size', '--size', '--size_'];
22
+ input :
23
+ --zd_size
24
+ output :
25
+ true
26
+ comment :
27
+ do not execute when --zd_size comes as prop
28
+ */
29
+
30
+ function isIgnoreValuePresent(ignoreVals, prop) {
31
+ let present = false;
32
+ ignoreVals.forEach(issue => {
33
+ if (prop && prop.includes(issue)) {
34
+ present = true;
35
+ }
36
+ });
37
+ return present;
38
+ } // -- to convert the hyphen values to values --
39
+
40
+ /*
41
+ input :
42
+ var(--zdt_uploadlist_default_width)
43
+ output :
44
+ --zdt_uploadlist_default_width
45
+
46
+ comment :
47
+ to make the variable object using the output as key and decl.prop such as font-size as value
48
+ */
49
+
50
+
51
+ function extractVariableName(val) {
52
+ return val.replace(/calc\((.+)\)/gi, '$1').replace(/var\((.+)\)/gi, '$1').replace('-1', '').replace('*', '').replace('\n', '').trim();
53
+ }
54
+
55
+ function rootConvertor(rootOriginal, variables, settingsObject) {
56
+ rootOriginal.walkRules(rule => {
57
+ rule.nodes.forEach((decl, index) => {
58
+ let prevNode = rule.nodes[index - 1];
59
+ let currentNode = rule.nodes[index];
60
+
61
+ if (decl.prop && decl.prop.includes('--')) {
62
+ if (prevNode && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'variable:ignore') {
63
+ return;
64
+ }
65
+
66
+ if (isIgnoreValuePresent(ignoreVals, decl.prop)) {
67
+ return;
68
+ }
69
+
70
+ if (settingsObject[variables[decl.prop]]) {
71
+ /* if there is no value for property, set it to default so that undefined doesn't get called as key */
72
+ if (!variables[decl.prop] || !settingsObject[variables[decl.prop]]) {
73
+ variables[decl.prop] = 'default';
74
+ }
75
+
76
+ const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
77
+ let valArr = decl.value.split(' '); // single values are considered in the above array and converted below
78
+
79
+ valArr.forEach((value, index) => {
80
+ if (value.includes('px')) {
81
+ let num = value.replace('px', '');
82
+ valArr[index] = pxReplacement.replace('$$', num);
83
+ }
84
+ });
85
+ currentNode.value = valArr.join(' ');
86
+ }
87
+ }
88
+ });
89
+ });
90
+ return rootOriginal;
91
+ }
92
+
93
+ class VariableConversionCollector {
94
+ constructor(options = {}) {
95
+ this.optimize = options.optimize;
96
+ this.filename = options.cssVariableReplacementConfig;
97
+ }
98
+
99
+ apply(compiler) {
100
+ let variables = {};
101
+
102
+ const rawdata = _fs.default.readFileSync(this.filename);
103
+
104
+ const data = JSON.parse(rawdata);
105
+ const {
106
+ settings: settingsObject,
107
+ errorLog: errorLogStatus,
108
+ errorInConsole: errorConsoleStatus
109
+ } = data; // If theres is no setting for default prop in settingsObject, set one.
110
+
111
+ if (!settingsObject.default) {
112
+ settingsObject.default = {
113
+ allowed: ['px', 'em', 'fit-content', 'auto', '%', 'inherit', '-moz-fit-content', 'vh', '0', 'initial', 'vw'],
114
+ replacements: {
115
+ px: 'var(--zd_size$$)'
116
+ },
117
+ range: {
118
+ start: -99999,
119
+ end: 99999
120
+ }
121
+ };
122
+ }
123
+ /*
124
+ purpose of tap : to create a variable object such as:
125
+ {
126
+ --zdt_uploadlist_default_width : width,
127
+ --zdt_uploadlist_default_height : height,
128
+ }
129
+ which will help in the conversion further
130
+ */
131
+
132
+
133
+ compiler.hooks.compilation.tap('VariableConversionCollector', compilation => {
134
+ compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
135
+ const mods = modules.filter(x => x.type.includes('css'));
136
+ mods.forEach(module => {
137
+ const rootOriginal = _postcss.default.parse(module.content);
138
+
139
+ const filename = module.issuer.resource;
140
+ rootOriginal.walkRules(rule => {
141
+ rule.walkDecls(decl => {
142
+ decl.value.split(' ').forEach(val => {
143
+ if (val && val.includes('--') && !new RegExp(ignoreVals.join('|'), 'gi').test(val)) {
144
+ variables[extractVariableName(val)] = decl.prop;
145
+ }
146
+ });
147
+ });
148
+ });
149
+ /*
150
+ current value example:
151
+ {
152
+ --zdt_uploadlist_default_width : --zd_upload_width,
153
+ --zd_upload_width : width
154
+ }
155
+ expected value :
156
+ {
157
+ --zdt_uploadlist_default_width : width,
158
+ --zd_upload_width : width
159
+ }
160
+
161
+ conversion is done in the while loop below
162
+ */
163
+
164
+ Object.keys(variables).forEach(key => {
165
+ while (variables[variables[key]]) {
166
+ variables[key] = variables[variables[key]];
167
+ }
168
+ });
169
+ });
170
+ }); // -- conversion for the root using rootConvertor --
171
+
172
+ /*
173
+ input :
174
+ .a{
175
+ padding : 20px
176
+ }
177
+ output :
178
+ // on settingObject file :
179
+ { padding : { replacements : { px : 'zd_size$$' }}}
180
+ .a{
181
+ padding : zd_size20;
182
+ }
183
+ */
184
+
185
+ compilation.hooks.optimizeModules.tap('VariableConversionCollector', modules => {
186
+ const mods = modules.filter(x => x.type.includes('css'));
187
+ mods.forEach(module => {
188
+ const rootOriginal = _postcss.default.parse(module.content);
189
+
190
+ module.content = rootConvertor(rootOriginal, variables, settingsObject).toString();
191
+ });
192
+ });
193
+ });
194
+ /*
195
+ purpose of tap : to display the errors encountered so far
196
+ input :
197
+ all css files
198
+ output :
199
+ all errors that are present in the errTable arr
200
+ */
201
+
202
+ compiler.hooks.afterEmit.tap('error-display', () => {
203
+ const {
204
+ errors,
205
+ errTable
206
+ } = require('../postcss-plugins/variableModificationPlugin/index');
207
+
208
+ let avlTypes = new Set([]);
209
+ let srtArr = errTable.sort((a, b) => {
210
+ avlTypes.add(a.type);
211
+ avlTypes.add(b.type);
212
+
213
+ if (a.type < b.type) {
214
+ return -1;
215
+ }
216
+ });
217
+
218
+ if (errorConsoleStatus) {
219
+ const errHandler = new _ErrorHandler.ErrorHandler();
220
+ avlTypes.forEach(type => {
221
+ console.log('---------------------------------------------------------------------------------------------------------------------------');
222
+ console.log(`Error Type : ${type}`);
223
+ console.log('---------------------------------------------------------------------------------------------------------------------------');
224
+ srtArr.forEach(err => {
225
+ if (err.decl.prop && err.decl.value && err.type === type) {
226
+ errHandler.printError(err);
227
+ }
228
+ });
229
+ console.log('---------------------------------------------------------------------------------------------------------------------------');
230
+ });
231
+ }
232
+
233
+ if (errorLogStatus) {
234
+ _fs.default.writeFileSync('./css_error.log', '');
235
+
236
+ console.log('writing to logFile...');
237
+
238
+ if (errors.length > 0) {
239
+ errors.forEach((err, index) => {
240
+ if (errTable[index].decl.prop && errTable[index].decl.value) {
241
+ _fs.default.appendFileSync('./css_error.log', err);
242
+ }
243
+ });
244
+ }
245
+ }
246
+ });
247
+ }
248
+
249
+ }
250
+
251
+ var _default = VariableConversionCollector;
252
+ exports.default = _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _postcss = _interopRequireDefault(require("postcss"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ class ComposeCommonPlugin {
13
+ constructor(options = {}) {
14
+ this.optimize = options.optimize;
15
+ }
16
+
17
+ apply(compiler) {
18
+ compiler.hooks.compilation.tap('OptimizeJSPlugin', compilation => {
19
+ compilation.hooks.optimizeModules.tap('OptimizeMods', modules => {
20
+ modules.forEach(module => {
21
+ console.log(module);
22
+ });
23
+ });
24
+ });
25
+ }
26
+
27
+ }
28
+
29
+ var _default = ComposeCommonPlugin;
30
+ exports.default = _default;
@@ -111,22 +111,41 @@ Object.defineProperty(exports, "UnusedFilesFindPlugin", {
111
111
  return _UnusedFilesFindPlugin.default;
112
112
  }
113
113
  });
114
+
114
115
  var _ModuleStatsPlugin = _interopRequireDefault(require("./ModuleStatsPlugin"));
116
+
115
117
  var _SourceMapHookPlugin = _interopRequireDefault(require("./SourceMapHookPlugin"));
118
+
116
119
  var _UnusedFilesFindPlugin = _interopRequireDefault(require("./UnusedFilesFindPlugin"));
120
+
117
121
  var _ScriptInstrumentPlugin = _interopRequireDefault(require("./ScriptInstrumentPlugin"));
122
+
118
123
  var _PublicPathChangePlugin = _interopRequireDefault(require("./PublicPathChangePlugin"));
124
+
119
125
  var _OptimizeJSPlugin = _interopRequireDefault(require("./OptimizeJSPlugin"));
126
+
120
127
  var _ResourceHintsPlugin = _interopRequireDefault(require("./ResourceHintsPlugin"));
128
+
121
129
  var _UglifyCSSPlugin = _interopRequireDefault(require("./UglifyCSSPlugin"));
130
+
122
131
  var _ManifestPlugin = _interopRequireDefault(require("./ManifestPlugin"));
132
+
123
133
  var _CleanupStatsPlugin = _interopRequireDefault(require("./CleanupStatsPlugin"));
134
+
124
135
  var _EFCPlugin = _interopRequireDefault(require("./EFCPlugin"));
136
+
125
137
  var _PublicPathCallbackPlugin = _interopRequireDefault(require("./PublicPathCallbackPlugin"));
138
+
126
139
  var _I18NInjectIntoIndexPlugin = _interopRequireDefault(require("./I18NInjectIntoIndexPlugin"));
140
+
127
141
  var _ReportGeneratePlugin = _interopRequireDefault(require("./ReportGeneratePlugin"));
142
+
128
143
  var _ShadowDOMSupportPlugin = _interopRequireDefault(require("./ShadowDOMSupportPlugin"));
144
+
129
145
  var _ServiceWorkerPlugin = _interopRequireDefault(require("./ServiceWorkerPlugin"));
146
+
130
147
  var _TPHashMappingPlugin = _interopRequireDefault(require("./TPHashMappingPlugin"));
148
+
131
149
  var _CdnChangePlugin = _interopRequireDefault(require("./CdnChangePlugin"));
150
+
132
151
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -4,12 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _fs = _interopRequireDefault(require("fs"));
11
+
9
12
  var _webpackSources = require("webpack-sources");
13
+
10
14
  var _jsonHelper = require("../utils/jsonHelper");
15
+
11
16
  var _utils = require("../utils");
17
+
12
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
13
20
  let resultFileName = `${process.cwd()}/result.json`;
14
21
  let options = (0, _utils.getOptions)();
15
22
  let {
@@ -24,21 +31,27 @@ let {
24
31
  (0, _jsonHelper.jsonHelper)(resultFileName, 'tests.libraryImpactOnSource.compareBranch', referBranch);
25
32
  (0, _jsonHelper.jsonHelper)(resultFileName, 'tests.libraryImpactOnSource.TestBranch', currentBranch);
26
33
  (0, _jsonHelper.jsonHelper)(resultFileName, 'tests.libraryImpactOnSource.isExecuted', true);
34
+
27
35
  let isValidModule = name => {
28
36
  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')) {
29
37
  return true;
30
38
  }
39
+
31
40
  return !name.includes('index.js') && !name.endsWith('.css') && !name.endsWith('.png') && !name.includes('node_modules') && name.includes('src');
32
41
  };
42
+
33
43
  let getModuleName = modulePath => {
34
44
  let [name] = _path.default.parse(modulePath).name.split('.');
45
+
35
46
  if (modulePath.includes(`@zohodesk${_path.default.sep}components`)) {
36
47
  name = `@zohodesk/components/${name}`;
37
48
  } else if (modulePath.includes(`@zohodesk${_path.default.sep}dot`)) {
38
49
  name = `@zohodesk/dot/${name}`;
39
50
  }
51
+
40
52
  return name;
41
53
  };
54
+
42
55
  class LibraryImpactPlugin {
43
56
  constructor(options = {}) {
44
57
  this.options = options;
@@ -47,10 +60,12 @@ class LibraryImpactPlugin {
47
60
  this.bottomHtml = '</div> <script type="text/javascript"> const details = document.querySelectorAll("details"); details.forEach((targetDetail) => { targetDetail.addEventListener("click", () => { // Close all the details that are not targetDetail. details.forEach((detail) => { if (detail !== targetDetail) { detail.removeAttribute("open"); } }); }); }); </script></body></html>';
48
61
  this.resultJson = {};
49
62
  }
63
+
50
64
  apply(compiler) {
51
65
  let loggedInfo = false;
52
66
  compiler.hooks.beforeCompile.tap('LibraryImpactPlugin', () => {
53
67
  (0, _jsonHelper.jsonHelper)(resultFileName, 'tests.libraryImpactOnSource.startTime', Date.now());
68
+
54
69
  if (!loggedInfo) {
55
70
  (0, _utils.log)('\x1b[33m%s\x1b[0m', '************************************************************ \n ');
56
71
  (0, _utils.log)('\x1b[5m\x1b[44m%s\x1b[0m', 'Finding Impacted Source Files Please Wait ...');
@@ -63,11 +78,13 @@ class LibraryImpactPlugin {
63
78
  let {
64
79
  modules
65
80
  } = stats;
81
+
66
82
  for (let module of modules) {
67
83
  let {
68
84
  name,
69
85
  reasons
70
86
  } = module;
87
+
71
88
  if (isValidModule(name)) {
72
89
  let references = new Set();
73
90
  let referencedby = new Set();
@@ -76,6 +93,7 @@ class LibraryImpactPlugin {
76
93
  compilation.modules.forEach(module => {
77
94
  module.reasons.forEach(reason => {
78
95
  let exportedValue = reason.dependency;
96
+
79
97
  if (exportedValue.type === 'harmony export imported specifier') {
80
98
  if (exportedValue.module.userRequest.includes(name.replace('.', ''))) {
81
99
  docsName = exportedValue.name;
@@ -84,29 +102,35 @@ class LibraryImpactPlugin {
84
102
  });
85
103
  });
86
104
  let currentModuleName = name;
105
+
87
106
  if (Array.isArray(reasons)) {
88
107
  for (let reason of reasons) {
89
108
  let {
90
109
  moduleName
91
110
  } = reason;
111
+
92
112
  if (isValidModule(moduleName)) {
93
113
  let reasonedModuleName = moduleName;
94
114
  referencedby.add(reasonedModuleName);
95
115
  }
96
116
  }
97
117
  }
118
+
98
119
  for (let subModule of modules) {
99
120
  let {
100
121
  name: subModuleName,
101
122
  reasons
102
123
  } = subModule;
124
+
103
125
  if (isValidModule(subModuleName)) {
104
126
  let currentModuleName = subModuleName;
127
+
105
128
  if (Array.isArray(reasons)) {
106
129
  for (let reason of reasons) {
107
130
  let {
108
131
  moduleName: reasonedModuleName
109
132
  } = reason;
133
+
110
134
  if (name === reasonedModuleName) {
111
135
  references.add(currentModuleName);
112
136
  }
@@ -114,6 +138,7 @@ class LibraryImpactPlugin {
114
138
  }
115
139
  }
116
140
  }
141
+
117
142
  results[currentModuleName] = {
118
143
  name: currentModuleName,
119
144
  references: Array.from(references),
@@ -123,9 +148,11 @@ class LibraryImpactPlugin {
123
148
  };
124
149
  }
125
150
  }
151
+
126
152
  (0, _utils.getDependenciesImpactList)(currentBranch, referBranch, tokenGit, serviceName).then(impactedList => {
127
153
  this.resultJson = (0, _utils.getLibraryConflict)(JSON.stringify(results), impactedList, changesOnly);
128
154
  (0, _jsonHelper.jsonHelper)(resultFileName, 'tests.libraryImpactOnSource.result', this.resultJson);
155
+
129
156
  if (this.resultJson.result.status) {
130
157
  (0, _utils.log)(this.resultJson.response);
131
158
  this.resultJson.response.forEach(fileObject => {
@@ -140,12 +167,15 @@ class LibraryImpactPlugin {
140
167
  (0, _utils.log)(this.resultJson.result.message);
141
168
  this.topHtml = this.topHtml + '<div style="font-size: xxx-large; text-align: center; padding-top: 50px;"> ' + this.resultJson.result.message + '</div>';
142
169
  }
170
+
143
171
  if (!_fs.default.existsSync('./coverageTest')) {
144
172
  _fs.default.mkdirSync('./coverageTest');
173
+
145
174
  _fs.default.writeFileSync('./coverageTest/impactLibrary.html', this.topHtml + this.bottomHtml, 'utf8');
146
175
  } else {
147
176
  _fs.default.writeFileSync('./coverageTest/impactLibrary.html', this.topHtml + this.bottomHtml, 'utf8');
148
177
  }
178
+
149
179
  (0, _jsonHelper.jsonHelper)(resultFileName, 'tests.libraryImpactOnSource.endTime', Date.now());
150
180
  });
151
181
  });
@@ -154,5 +184,7 @@ class LibraryImpactPlugin {
154
184
  (0, _utils.log)('Compilation finished!!!');
155
185
  });
156
186
  }
187
+
157
188
  }
189
+
158
190
  exports.default = LibraryImpactPlugin;
@@ -4,12 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _utils = require("../utils");
9
+
8
10
  class WebpackWatchRunPlugin {
9
11
  apply(compiler) {
10
12
  compiler.hooks.watchRun.tap('WatchRun', comp => {
11
13
  const changedTimes = comp.watchFileSystem.watcher.mtimes;
12
14
  const changedFiles = Object.keys(changedTimes).map(file => `\n ${file}`).join('');
15
+
13
16
  if (changedFiles.length) {
14
17
  (0, _utils.log)('====================================');
15
18
  (0, _utils.log)('NEW BUILD FILES CHANGED:', changedFiles);
@@ -17,5 +20,7 @@ class WebpackWatchRunPlugin {
17
20
  }
18
21
  });
19
22
  }
23
+
20
24
  }
25
+
21
26
  exports.default = WebpackWatchRunPlugin;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
 
3
3
  var _postcss = _interopRequireDefault(require("postcss"));
4
+
4
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
5
7
  module.exports = _postcss.default.plugin('postcss-exclude-files', opts => {
6
8
  const {
7
9
  plugins
@@ -9,8 +11,10 @@ module.exports = _postcss.default.plugin('postcss-exclude-files', opts => {
9
11
  return (root, result) => {
10
12
  const inputFile = root.source.input.file;
11
13
  let isIgnoredFile = opts.ignore.some(file => inputFile.indexOf(file) !== -1);
14
+
12
15
  if (!isIgnoredFile) {
13
16
  const handler = response => response.messages.forEach(msg => result.messages.push(msg));
17
+
14
18
  return (0, _postcss.default)(plugins).process(root, {
15
19
  from: undefined
16
20
  }).then(handler);
@@ -5,23 +5,32 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.separateRtlAndLtr = separateRtlAndLtr;
7
7
  exports.separateSingleDir = separateSingleDir;
8
+
8
9
  var postcss = _interopRequireWildcard(require("postcss"));
10
+
9
11
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+
10
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+
11
15
  const oppositeDir = {
12
16
  ltr: 'rtl',
13
17
  rtl: 'ltr'
14
18
  };
19
+
15
20
  function compareSelector(selector1, selector2) {
16
21
  // console.log({ selector1, selector2 }, selector1 === selector2);
17
22
  return selector1 === selector2;
18
23
  }
24
+
19
25
  const directionRegexs = {
20
26
  ltr: /\[dir=ltr\]/,
21
27
  rtl: /\[dir=rtl\]/
22
28
  };
29
+
23
30
  const getRegex = dir => directionRegexs[dir];
31
+
24
32
  const getOppositeRegex = dir => getRegex(oppositeDir[dir]);
33
+
25
34
  function selectorMinifySameDir(selector, direction) {
26
35
  // NOTE: if this rule is same dir as current need
27
36
  // then we can just remove that [dir=ltr] or [dir=rtl]
@@ -29,16 +38,18 @@ function selectorMinifySameDir(selector, direction) {
29
38
  const regex = getRegex(direction);
30
39
  return selector.replace(regex, '').trim();
31
40
  }
32
-
33
41
  /**
34
42
  * this funtion will remove given rule,
35
43
  * if given selector and it's previous sibiling rule selector are same
36
44
  * current rule properties will move to previous sibiling rule.
37
45
  * @param {Rule} rule current rule
38
46
  */
47
+
48
+
39
49
  function mergeIfSameSelector(rule) {
40
50
  // NOTE: to merge dublicate selector rules
41
51
  const prev = rule.prev();
52
+
42
53
  if (prev && compareSelector(prev.selector, rule.selector)) {
43
54
  rule.each(decl => {
44
55
  prev.append(decl);
@@ -46,25 +57,27 @@ function mergeIfSameSelector(rule) {
46
57
  rule.remove();
47
58
  }
48
59
  }
49
-
50
60
  /**
51
61
  * this funtion will remove given rule,
52
62
  * if given selector and it's previous sibiling rule selector are same
53
63
  * current rule properties will move to previous sibiling rule.
54
64
  * @param {Rule} rule current rule
55
65
  */
66
+
67
+
56
68
  function removeIfOppsiteDirRule(rule, direction, rootOptions) {
57
69
  // console.log({ rule, type: rule.type });
58
- const selectors = rule.selector.split(/\s*,\s*/);
59
-
60
- // NOTE: if we use opposite dir selector as custom override reason,
70
+ const selectors = rule.selector.split(/\s*,\s*/); // NOTE: if we use opposite dir selector as custom override reason,
61
71
  // and compain normal selector with it, In this case
62
72
  // we just a have to remove that selector only not full rule
73
+
63
74
  const oppositeDirRegex = getOppositeRegex(direction);
64
75
  let remainingSelectors = selectors.filter(selector => !oppositeDirRegex.test(selector));
76
+
65
77
  if (!rootOptions.disableMiniFiySelector) {
66
78
  remainingSelectors = remainingSelectors.map(selector => selectorMinifySameDir(selector, direction));
67
79
  }
80
+
68
81
  if (remainingSelectors.length) {
69
82
  rule.selector = remainingSelectors.join(', ');
70
83
  } else {
@@ -72,14 +85,17 @@ function removeIfOppsiteDirRule(rule, direction, rootOptions) {
72
85
  rule.remove();
73
86
  }
74
87
  }
88
+
75
89
  function removeIfOppsiteDirKeyframe(rule, direction) {
76
90
  let name = rule.params;
77
91
  let keyFrameDirName = name.slice(name.lastIndexOf('-') + 1);
92
+
78
93
  if (keyFrameDirName === oppositeDir[direction]) {
79
94
  // console.log({ m: 'removed', keyFrameName: rule.params });
80
95
  rule.remove();
81
96
  }
82
97
  }
98
+
83
99
  function separateSingleDir(root, direction, rootOptions) {
84
100
  root.walkRules(rule => {
85
101
  removeIfOppsiteDirRule(rule, direction, rootOptions);
@@ -90,14 +106,15 @@ function separateSingleDir(root, direction, rootOptions) {
90
106
  });
91
107
  return root;
92
108
  }
109
+
93
110
  function separateRtlAndLtr(css, rootOptions) {
94
111
  // let processor = postcss([]).process(css);
95
- let root = postcss.parse(css);
96
- // let { root } = processor;
112
+ let root = postcss.parse(css); // let { root } = processor;
97
113
  // console.log(processor, root);
98
114
  // NOTE: I did first rtl then ltr , Because for ltr I use original root ref
99
- const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions);
100
- // console.log('############################');
115
+
116
+ const rtlRoot = separateSingleDir(root.clone(), 'rtl', rootOptions); // console.log('############################');
117
+
101
118
  const ltrRoot = separateSingleDir(root, 'ltr', rootOptions);
102
119
  return {
103
120
  ltrRoot,
@@ -105,11 +122,8 @@ function separateRtlAndLtr(css, rootOptions) {
105
122
  ltr: ltrRoot.toString(),
106
123
  rtl: rtlRoot.toString()
107
124
  };
108
- }
109
-
110
- // NOTE: to test in https://astexplorer.net/
125
+ } // NOTE: to test in https://astexplorer.net/
111
126
  // you can test with sample input https://astexplorer.net/#/gist/a892a509eb585099355ef53ef094f836/1ca70d5f7af3b88ca4910296e12f118e9712c874
112
-
113
127
  // export default postcss.plugin('postcss-rtl-remove', (options = {}) =>
114
128
  // // Work with options here
115
129
  // root => {
@@ -118,7 +132,6 @@ function separateRtlAndLtr(css, rootOptions) {
118
132
  // // root.append(postcss.comment({ text: 'comment' }));
119
133
  // root.append(postcss.comment({ text: 'this is spliting part ' }));
120
134
  // root.append(rtlRoot);
121
-
122
135
  // //console.log({root, roots:root+""}, root+"")
123
136
  // // Transform CSS AST here
124
137
  // }