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

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 (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
@@ -4,11 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _fs = _interopRequireDefault(require("fs"));
9
+
8
10
  var _path = _interopRequireDefault(require("path"));
11
+
9
12
  var _redis = _interopRequireDefault(require("redis"));
13
+
10
14
  var _utils = require("../utils");
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
12
18
  let options = (0, _utils.getOptions)();
13
19
  let {
14
20
  app: {
@@ -17,47 +23,60 @@ let {
17
23
  redisPort
18
24
  }
19
25
  } = options;
26
+
20
27
  class reportGeneratePlugin {
21
28
  apply(compiler) {
22
29
  compiler.hooks.emit.tapAsync('reportGeneratePlugin', (compilation, callback) => {
23
30
  function formatBytes(bytes) {
24
31
  if (bytes) {
25
32
  let isNegative;
33
+
26
34
  if (bytes < 0) {
27
35
  bytes = bytes * -1; //eslint-disable-line
36
+
28
37
  isNegative = true;
29
38
  }
39
+
30
40
  if (bytes < 1024) {
31
41
  if (isNegative) {
32
42
  return `- ${bytes} Bytes`;
33
43
  }
44
+
34
45
  return `${bytes} Bytes`;
35
46
  } else if (bytes < 1048576) {
36
47
  if (isNegative) {
37
48
  return `- ${(bytes / 1024).toFixed(3)} KB`;
38
49
  }
50
+
39
51
  return `${(bytes / 1024).toFixed(3)} KB`;
40
52
  } else if (bytes < 1073741824) {
41
53
  if (isNegative) {
42
54
  return `- ${(bytes / 1048576).toFixed(3)} MB`;
43
55
  }
56
+
44
57
  return `${(bytes / 1048576).toFixed(3)} MB`;
45
58
  }
59
+
46
60
  if (isNegative) {
47
61
  return `- ${(bytes / 1073741824).toFixed(3)} GB`;
48
62
  }
63
+
49
64
  return `${(bytes / 1073741824).toFixed(3)} GB`;
50
65
  }
51
66
  }
67
+
52
68
  let client = _redis.default.createClient(redisPort, redisHost);
69
+
53
70
  client.on('connect', () => {
54
71
  (0, _utils.log)('Redis client connected');
55
72
  });
56
73
  client.on('error', err => {
57
74
  (0, _utils.log)(`Something went wrong ${err}`);
58
75
  });
76
+
59
77
  if (_fs.default.existsSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'))) {
60
78
  let statsJSON = _fs.default.readFileSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'), 'utf8');
79
+
61
80
  statsJSON = JSON.parse(statsJSON);
62
81
  let finalObj = {};
63
82
  let branchName = branch ? branch : (0, _utils.getCurrentBranch)();
@@ -74,8 +93,8 @@ class reportGeneratePlugin {
74
93
  name,
75
94
  hash,
76
95
  size
77
- };
78
- // eslint-disable-next-line
96
+ }; // eslint-disable-next-line
97
+
79
98
  if (!finalObj.hasOwnProperty(name)) {
80
99
  finalObj[name] = tempObject;
81
100
  }
@@ -95,6 +114,7 @@ class reportGeneratePlugin {
95
114
  (0, _utils.log)(err);
96
115
  } else {
97
116
  reply = JSON.parse(reply); // eslint-disable-line
117
+
98
118
  Object.keys(reply).forEach(fileName => {
99
119
  // eslint-disable-next-line
100
120
  if (finalObj.hasOwnProperty(fileName)) {
@@ -108,6 +128,7 @@ class reportGeneratePlugin {
108
128
  }
109
129
  });
110
130
  }
131
+
111
132
  if (reply[fileName].hash !== finalObj[fileName].hash) {
112
133
  reportObj.hashChanged.push({
113
134
  name: fileName,
@@ -120,16 +141,17 @@ class reportGeneratePlugin {
120
141
  }
121
142
  });
122
143
  let json = JSON.stringify(reportObj);
144
+
123
145
  _fs.default.writeFile(_path.default.resolve(process.cwd(), 'build', 'buildtrack.js'), `let statsJson=${json}`, err => {
124
146
  if (err) {
125
147
  throw err;
126
148
  }
149
+
127
150
  (0, _utils.log)('Stats Json generated!');
128
151
  });
129
152
  }
130
153
  });
131
- client.set(branchName, JSON.stringify(finalObj), _redis.default.print);
132
- // fs.copyFileSync(
154
+ client.set(branchName, JSON.stringify(finalObj), _redis.default.print); // fs.copyFileSync(
133
155
  // path.resolve(
134
156
  // process.cwd(),
135
157
  // 'node_modules',
@@ -141,9 +163,11 @@ class reportGeneratePlugin {
141
163
  // ),
142
164
  // path.resolve(process.cwd(), 'build', 'buildstats.html')
143
165
  // );
166
+
144
167
  client.quit();
145
168
  callback && callback();
146
169
  }
170
+
147
171
  if (err) {
148
172
  (0, _utils.log)(err);
149
173
  }
@@ -151,5 +175,7 @@ class reportGeneratePlugin {
151
175
  }
152
176
  });
153
177
  }
178
+
154
179
  }
180
+
155
181
  exports.default = reportGeneratePlugin;
@@ -4,14 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  const {
8
9
  Template
9
10
  } = require('webpack');
11
+
10
12
  const pluginName = 'RequireVariablePublicPlugin';
13
+
11
14
  class RequireVariablePublicPlugin {
12
15
  constructor(options) {
13
16
  this.requireFuncName = options.requireFuncName;
14
17
  }
18
+
15
19
  apply(compiler) {
16
20
  compiler.hooks.thisCompilation.tap(pluginName, ({
17
21
  mainTemplate
@@ -19,6 +23,8 @@ class RequireVariablePublicPlugin {
19
23
  mainTemplate.hooks.requireExtensions.tap(pluginName, source => Template.asString([source, '', `window[${JSON.stringify(this.requireFuncName)}] = ${mainTemplate.requireFn};`]));
20
24
  });
21
25
  }
26
+
22
27
  }
28
+
23
29
  var _default = RequireVariablePublicPlugin;
24
30
  exports.default = _default;
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  const {
8
9
  Template
9
10
  } = require('webpack');
11
+
10
12
  const pluginName = 'prefetch-preload-chunk-plugin';
13
+
11
14
  class ResourceHintsPlugin {
12
15
  apply(compiler) {
13
16
  compiler.hooks.thisCompilation.tap(pluginName, ({
@@ -17,15 +20,18 @@ class ResourceHintsPlugin {
17
20
  const idNameMap = chunk.getChunkMaps().name;
18
21
  const nameIdMap = {};
19
22
  let needsMap = false;
23
+
20
24
  for (const key in idNameMap) {
21
25
  if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
22
26
  const value = idNameMap[key];
23
27
  nameIdMap[value] = key;
28
+
24
29
  if (key !== value) {
25
30
  needsMap = true;
26
31
  }
27
32
  }
28
33
  }
34
+
29
35
  return Template.asString([source, '', `${mainTemplate.requireFn}.getChunkId = function getChunkId(chunkId) {`, Template.indent((needsMap ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`] : []).concat(['return chunkId;'])), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, `${mainTemplate.requireFn}.e(chunkId);`]), '};',
30
36
  /*
31
37
  (needsMap
@@ -38,6 +44,7 @@ class ResourceHintsPlugin {
38
44
  'installedChunks[chunkId] = null;',
39
45
  /* mainTemplate.hooks.linkPrefetch.call('', chunk, hash),
40
46
  'document.head.appendChild(link);', */
47
+
41
48
  /*
42
49
  mainTemplate.hooks.requireEnsure.call('', chunk, hash)
43
50
  ]),
@@ -46,15 +53,15 @@ class ResourceHintsPlugin {
46
53
  ),
47
54
  '}',
48
55
  */
49
- `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, 'if(installedChunks[chunkId] === undefined) {', Template.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'document.head.appendChild(link);', `${mainTemplate.requireFn}.e(chunkId);`
50
-
51
- // 'var head = document.getElementsByTagName(\'head\')[0];',
56
+ `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkId(chunkId)`, 'if(installedChunks[chunkId] === undefined) {', Template.indent(['installedChunks[chunkId] = null;', mainTemplate.hooks.linkPreload.call('', chunk, hash), 'document.head.appendChild(link);', `${mainTemplate.requireFn}.e(chunkId);` // 'var head = document.getElementsByTagName(\'head\')[0];',
52
57
  // mainTemplate.hooks.jsonpScript.call('', chunk, hash),
53
58
  // 'head.appendChild(script);'
54
59
  ]), '}']), '};']);
55
60
  });
56
61
  });
57
62
  }
63
+
58
64
  }
65
+
59
66
  var _default = ResourceHintsPlugin;
60
67
  exports.default = _default;
@@ -4,17 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
+
8
10
  var _replaceCssDirTemplate = require("./replaceCssDirTemplate");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- // const HtmlWebpackPlugin = require('html-webpack-plugin');
11
11
 
12
- const pluginName = 'OverwriteCssPathForRTL';
13
- // const pluginName = 'rtl-css-transform-webpack-plugin';
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
13
 
14
+ // const HtmlWebpackPlugin = require('html-webpack-plugin');
15
+ const pluginName = 'OverwriteCssPathForRTL'; // const pluginName = 'rtl-css-transform-webpack-plugin';
15
16
  // if we choose file name as style.ltr.css and style.rtl.css it will be easy for html template
16
-
17
17
  // this plugin code copy from https://github.com/nicolashemonic/rtl-css-transform-webpack-plugin
18
+
18
19
  class OverwriteCssPathForRTL {
19
20
  constructor(options = {
20
21
  dirVarName: 'document.dir'
@@ -22,6 +23,7 @@ class OverwriteCssPathForRTL {
22
23
  this.dirVarName = options.dirVarName || 'document.dir';
23
24
  this.templateLabel = options.templateLabel || '{{--dir}}';
24
25
  }
26
+
25
27
  overwriteCssPathinHTML(compilation) {
26
28
  _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (data, cb) => {
27
29
  let {
@@ -34,27 +36,26 @@ class OverwriteCssPathForRTL {
34
36
  }));
35
37
  });
36
38
  }
39
+
37
40
  overwriteCssPathinRequireEnsure(compilation) {
38
41
  // NOTE: if you goig to change an thing here you may check with EFCPlugin, ServiceWorkerPlugin
39
42
  const {
40
43
  mainTemplate
41
- } = compilation;
42
- // TODO: must verify when we move to webpack5 ay be we need to change this
44
+ } = compilation; // TODO: must verify when we move to webpack5 ay be we need to change this
43
45
  // TODO it's may not be perfect solution, but it will work
44
46
  // mainTemplate.hooks.assetPath.tap(pluginName, (path, data) => {
47
+
45
48
  mainTemplate.hooks.assetPath.tap(pluginName, filePath => {
46
49
  if (!filePath.endsWith('.css"')) {
47
50
  return filePath;
48
51
  }
49
- const ENDS = '.ltr.css"';
50
- // if we need total differend temlate for file name it will be too hard
51
- const templateText = `"+(${this.dirVarName} === "rtl" ? ".rtl": ".ltr")+".css"`;
52
52
 
53
- // const templateText = `"+(${this.dirVarName} === "rtl" ? ".rtl": "")+".css"`;
53
+ const ENDS = '.ltr.css"'; // if we need total differend temlate for file name it will be too hard
54
+
55
+ const templateText = `"+(${this.dirVarName} === "rtl" ? ".rtl": ".ltr")+".css"`; // const templateText = `"+(${this.dirVarName} === "rtl" ? ".rtl": "")+".css"`;
54
56
  // NOTE:
55
57
  // we don't use rtlFilename as full replace because it may increace runtime chunk file size
56
58
  // they replace [chunkhash] with object full chunk hash so it may dub
57
-
58
59
  // const templateText = `(${this.dirVarName} === "rtl" ? ${JSON.stringify(this.rtlFilename)}: ${filePath})`;
59
60
  // const templateText = '."+(document.dir === "rtl" ? ".rtl": "")+".css"';
60
61
  // File path going to be like below
@@ -62,14 +63,18 @@ class OverwriteCssPathForRTL {
62
63
  // '"style.css"' ==>> `"style."+(document.dir === "rtl" ? ".rtl": "")+".css"`
63
64
  // replace like this
64
65
  // '.ltr.css"' ==>> `."+(document.dir === "rtl" ? ".rtl": ".ltr")+".css"`
66
+
65
67
  return filePath.replace(ENDS, templateText);
66
68
  });
67
69
  }
70
+
68
71
  apply(compiler) {
69
72
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
70
73
  this.overwriteCssPathinHTML(compilation);
71
74
  this.overwriteCssPathinRequireEnsure(compilation);
72
75
  });
73
76
  }
77
+
74
78
  }
79
+
75
80
  exports.default = OverwriteCssPathForRTL;
@@ -4,20 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.RtlCssPlugin = void 0;
7
+
7
8
  var _path = _interopRequireDefault(require("path"));
9
+
8
10
  var _webpackSources = require("webpack-sources");
11
+
9
12
  var _OverwriteCssPathForRTL = _interopRequireDefault(require("./OverwriteCssPathForRTL"));
13
+
10
14
  var _RTLSplitPlugin = require("../../postcss-plugins/RTLSplitPlugin");
15
+
11
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- // import HtmlWebpackPlugin from 'html-webpack-plugin';
13
17
 
18
+ // import HtmlWebpackPlugin from 'html-webpack-plugin';
14
19
  // import rtlcss from 'rtlcss';
20
+ const pluginName = 'RtlCssPlugin'; // const pluginName = 'rtl-css-transform-webpack-plugin';
21
+
22
+ const isCss = filename => _path.default.extname(filename) === '.css'; // this plugin code copy from https://github.com/nicolashemonic/rtl-css-transform-webpack-plugin
15
23
 
16
- const pluginName = 'RtlCssPlugin';
17
- // const pluginName = 'rtl-css-transform-webpack-plugin';
18
- const isCss = filename => _path.default.extname(filename) === '.css';
19
24
 
20
- // this plugin code copy from https://github.com/nicolashemonic/rtl-css-transform-webpack-plugin
21
25
  class RtlCssPlugin {
22
26
  constructor(options = {}) {
23
27
  /**
@@ -39,16 +43,17 @@ class RtlCssPlugin {
39
43
  disableMiniFiySelector: options.disableMiniFiySelector
40
44
  };
41
45
  }
46
+
42
47
  apply(compiler) {
43
48
  new _OverwriteCssPathForRTL.default({
44
49
  templateLabel: this.templateLabel,
45
50
  dirVarName: this.dirVarName
46
- }).apply(compiler);
47
- // const { filename, sourcemap, config } = this.options;
51
+ }).apply(compiler); // const { filename, sourcemap, config } = this.options;
48
52
  // const { devtool } = compiler.options;
49
53
  // const postcssOptions = {
50
54
  // map: (sourcemap === undefined && !!devtool) || !!sourcemap
51
55
  // };
56
+
52
57
  compiler.hooks.compilation.tap(pluginName, compilation => {
53
58
  compilation.hooks.optimizeChunkAssets.tapAsync(pluginName, (chunks, callback) => {
54
59
  chunks.forEach(chunk => {
@@ -58,10 +63,10 @@ class RtlCssPlugin {
58
63
  const {
59
64
  ltr,
60
65
  rtl
61
- } = (0, _RTLSplitPlugin.separateRtlAndLtr)(sourceStr, this.rtlSplitOptions);
62
- // const result = rtlcss
66
+ } = (0, _RTLSplitPlugin.separateRtlAndLtr)(sourceStr, this.rtlSplitOptions); // const result = rtlcss
63
67
  // .configure(config)
64
68
  // .process(asset.source(), postcssOptions);
69
+
65
70
  const assetFilename = chunkFilename.replace('.ltr.', '.rtl.');
66
71
  compilation.assets[chunkFilename] = new _webpackSources.RawSource(ltr);
67
72
  compilation.assets[assetFilename] = new _webpackSources.RawSource(rtl);
@@ -71,5 +76,7 @@ class RtlCssPlugin {
71
76
  });
72
77
  });
73
78
  }
79
+
74
80
  }
81
+
75
82
  exports.RtlCssPlugin = RtlCssPlugin;
@@ -6,18 +6,21 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.replaceCssDirTemplate = replaceCssDirTemplate;
7
7
  exports.replaceCssDirTemplateMapper = replaceCssDirTemplateMapper;
8
8
  exports.strFunctionTempalteToReplaceCssDir = void 0;
9
+
9
10
  function replaceCssDirTemplate(filePath, cssDirTemplate) {
10
- return filePath.endsWith('.ltr.css') ?
11
- // ? cssPath.replace('.ltr.css', '.{{--dir}}.css')
11
+ return filePath.endsWith('.ltr.css') ? // ? cssPath.replace('.ltr.css', '.{{--dir}}.css')
12
12
  filePath.replace('.ltr.css', `.${cssDirTemplate}.css`) : filePath;
13
13
  }
14
+
14
15
  function replaceCssDirTemplateMapper(assets, cssDirTemplate) {
15
16
  return assets.map(filePath => replaceCssDirTemplate(filePath, cssDirTemplate));
16
17
  }
18
+
17
19
  const strFunctionTempalteToReplaceCssDir = cssDirTemplate => `function replaceCssDirTemplate(filePath, cssDirTemplate) {
18
20
  return filePath.endsWith(".ltr.css")
19
21
  ? // ? cssPath.replace('.ltr.css', '.{{--dir}}.css')
20
22
  filePath.replace(".ltr.css", ".${cssDirTemplate}.css")
21
23
  : filePath;
22
24
  }`;
25
+
23
26
  exports.strFunctionTempalteToReplaceCssDir = strFunctionTempalteToReplaceCssDir;
@@ -4,10 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _fs = _interopRequireDefault(require("fs"));
9
+
8
10
  var _path = _interopRequireDefault(require("path"));
11
+
9
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
10
14
  let coverageScript = _fs.default.readFileSync(_path.default.resolve(__dirname, '..', 'templates', 'CoverageScriptTemplate.js')).toString();
15
+
11
16
  class ScriptInstrumentPlugin {
12
17
  apply(compiler) {
13
18
  compiler.hooks.emit.tapAsync('ScriptInstrumentPlugin', (compilation, callback) => {
@@ -25,5 +30,7 @@ class ScriptInstrumentPlugin {
25
30
  callback();
26
31
  });
27
32
  }
33
+
28
34
  }
35
+
29
36
  exports.default = ScriptInstrumentPlugin;
@@ -0,0 +1,97 @@
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 _webpackSources = require("webpack-sources");
13
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const path = require('path');
17
+
18
+ const isCss = filename => path.extname(filename) === '.css';
19
+
20
+ function rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings) {
21
+ rootOriginal.walkRules((rule, index) => {
22
+ const prevNode = rootOriginal.nodes[index - 1];
23
+
24
+ if (index !== 0 && prevNode.type && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'updateselector:ignore') {
25
+ return;
26
+ }
27
+
28
+ if (rule.parent && rule.parent.type === 'atrule') {
29
+ if (rule.parent.name !== 'media') {
30
+ return;
31
+ }
32
+ }
33
+
34
+ if (excludeStrings.includes(rule.selector)) {
35
+ return;
36
+ }
37
+
38
+ let ruleArr = rule.selector.split(',');
39
+ ruleArr.forEach((rule, index) => {
40
+ if (rule.includes(']')) {
41
+ if (rule.slice(rule.lastIndexOf(']') + 2).trim() === '') {
42
+ return;
43
+ } // console.log(
44
+ // rule.slice(rule.lastIndexOf(']') + 2).trim(),
45
+ // rule.slice(rule.lastIndexOf(']') + 2).trim() !== ''
46
+ // );
47
+
48
+
49
+ ruleArr[index] = `${rule.slice(0, rule.lastIndexOf(']') + 1).trim()} ${defaultSelector}${rule.slice(rule.lastIndexOf(']') + 2).trim()}`; // console.log(ruleArr[index]);
50
+
51
+ return;
52
+ }
53
+
54
+ ruleArr[index] = data[chunkFilename] ? `${data[chunkFilename].defaultSelector}${rule}` : `${defaultSelector}${rule}`;
55
+ });
56
+ rule.selector = ruleArr.join(',\n'); // console.log(`${rule.selector} converted`);
57
+ });
58
+ return rootOriginal;
59
+ }
60
+
61
+ class SelectorPlugin {
62
+ constructor(options = {}) {
63
+ this.optimize = options.optimize;
64
+ this.selectorWeightConfig = options.selectorWeightConfig;
65
+ }
66
+
67
+ apply(compiler) {
68
+ const {
69
+ defaultSelector,
70
+ customFileDetails,
71
+ excludeStrings
72
+ } = this.selectorWeightConfig;
73
+
74
+ const rawdata = _fs.default.readFileSync(customFileDetails);
75
+
76
+ const data = JSON.parse(rawdata);
77
+ compiler.hooks.compilation.tap('selector-weight-rewrite', compilation => {
78
+ compilation.hooks.optimizeChunkAssets.tapAsync('selector-weight-rewrite', (chunks, callback) => {
79
+ chunks.forEach(chunk => {
80
+ chunk.files.filter(isCss).forEach(chunkFilename => {
81
+ const asset = compilation.assets[chunkFilename];
82
+ const sourceStr = asset.source();
83
+
84
+ const rootOriginal = _postcss.default.parse(sourceStr);
85
+
86
+ compilation.assets[chunkFilename] = new _webpackSources.RawSource(rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings).toString());
87
+ });
88
+ });
89
+ callback();
90
+ });
91
+ });
92
+ }
93
+
94
+ }
95
+
96
+ var _default = SelectorPlugin;
97
+ exports.default = _default;
@@ -4,13 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _fs = _interopRequireDefault(require("fs"));
9
+
8
10
  var _path = _interopRequireDefault(require("path"));
11
+
9
12
  var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
13
+
10
14
  var _utils = require("../utils");
15
+
11
16
  var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
17
+
12
18
  var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
19
+
13
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
14
22
  const {
15
23
  css: {
16
24
  enableRTLSplit
@@ -19,22 +27,24 @@ const {
19
27
  chunkSplitEnable
20
28
  }
21
29
  } = (0, _utils.getOptions)();
30
+
22
31
  class ServiceWorkerPlugin {
23
32
  constructor(options) {
24
33
  this.i18nFileNameTemplate = options.i18nFileNameTemplate;
25
34
  this.fileName = options.fileName;
26
35
  this.serviceWorkerPath = options.filePath;
27
36
  this.writePath = options.exitPath;
28
- this.replaceText = options.replaceText;
29
- // this.publicPaths = options.publicPaths;
37
+ this.replaceText = options.replaceText; // this.publicPaths = options.publicPaths;
30
38
  }
31
39
 
32
40
  isInitialChunk(chunk) {
33
41
  if ('canBeInitial' in chunk) {
34
42
  return chunk.canBeInitial();
35
43
  }
44
+
36
45
  return chunk.isInitial();
37
46
  }
47
+
38
48
  apply(compiler) {
39
49
  compiler.hooks.emit.tap('ServiceWorkerPlugin', compilation => {
40
50
  _fs.default.readFile(this.serviceWorkerPath, 'utf-8', (err, data) => {
@@ -47,7 +57,6 @@ class ServiceWorkerPlugin {
47
57
  }
48
58
  return chunk.isInitial();
49
59
  }); */
50
-
51
60
  // let [js, css, , , i18nPublicPath] = this.publicPaths;
52
61
  // let initialChunkUrls = [];
53
62
  let allChunkUrls = [];
@@ -60,32 +69,39 @@ class ServiceWorkerPlugin {
60
69
  * if chunkSplitEnable is false means,
61
70
  * serviceWorker will get i18n files path for html
62
71
  */
72
+
63
73
  let initalI18nAssets = chunkSplitEnable ? entrypoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@')) : [];
64
74
  chunkSplitEnable && compilation.chunks.filter(c => !this.isInitialChunk(c)).filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).forEach(chunk => {
65
75
  // let isInitial = this.isInitialChunk(chunk);
66
76
  allChunkUrls = allChunkUrls.concat(chunk.files);
67
77
  allI18nAssets.push((0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
68
78
  });
69
-
70
79
  /** Removing source map files from getting added */
80
+
71
81
  initialChunkUrls = initialChunkUrls.filter(fileName => !fileName.endsWith('.map'));
72
82
  allChunkUrls = allChunkUrls.filter(fileName => !fileName.endsWith('.map'));
83
+
73
84
  if (enableRTLSplit) {
74
85
  initialChunkUrls = (0, _replaceCssDirTemplate.replaceCssDirTemplateMapper)(initialChunkUrls, cssDirTemplate);
75
86
  allChunkUrls = (0, _replaceCssDirTemplate.replaceCssDirTemplateMapper)(allChunkUrls, cssDirTemplate);
76
87
  }
88
+
77
89
  let mod = data.replace(this.replaceText, `
78
90
  self.assets = ${JSON.stringify(initialChunkUrls.concat(initalI18nAssets))};
79
91
  self.allChunks = ${JSON.stringify(allChunkUrls.concat(allI18nAssets))};`);
92
+
80
93
  if (!_fs.default.existsSync(this.writePath)) {
81
94
  _fs.default.mkdirSync(this.writePath, {
82
95
  recursive: true
83
96
  });
84
97
  }
98
+
85
99
  _fs.default.writeFileSync(_path.default.join(this.writePath, this.fileName), mod);
86
100
  }
87
101
  });
88
102
  });
89
103
  }
104
+
90
105
  }
106
+
91
107
  exports.default = ServiceWorkerPlugin;