@zohodesk/react-cli 1.1.14-exp.2 → 1.1.14-kubernetes

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. package/README.md +16 -281
  2. package/bin/cli.js +55 -30
  3. package/docs/CustomChunks.md +9 -12
  4. package/docs/SelectorWeight.md +0 -3
  5. package/docs/ValueReplacer.md +0 -27
  6. package/docs/VariableConversion.md +1 -6
  7. package/lib/common/splitChunks.js +45 -65
  8. package/lib/common/testPattern.js +11 -9
  9. package/lib/common/valueReplacer.js +3 -1
  10. package/lib/configs/resolvers.js +5 -16
  11. package/lib/configs/webpack.css.umd.config.js +2 -3
  12. package/lib/configs/webpack.dev.config.js +5 -15
  13. package/lib/configs/webpack.docs.config.js +3 -14
  14. package/lib/configs/webpack.impact.config.js +2 -8
  15. package/lib/configs/webpack.prod.config.js +5 -15
  16. package/lib/constants.js +3 -3
  17. package/lib/loaderUtils/getCSSLoaders.js +49 -98
  18. package/lib/loaderUtils/windowsModification.js +1 -6
  19. package/lib/loaders/docsLoader.js +7 -18
  20. package/lib/loaders/selectorMappingLoader.js +9 -9
  21. package/lib/pluginUtils/getDevPlugins.js +6 -25
  22. package/lib/pluginUtils/getProdPlugins.js +5 -32
  23. package/lib/pluginUtils/getUMDCSSPlugins.js +1 -1
  24. package/lib/pluginUtils/getUMDComponentPlugins.js +1 -1
  25. package/lib/plugins/EFCPlugin.js +9 -9
  26. package/lib/plugins/EFCTemplatePlugin.js +12 -10
  27. package/lib/plugins/I18NInjectIntoIndexPlugin.js +9 -8
  28. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +3 -2
  29. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +13 -29
  30. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +7 -2
  31. package/lib/plugins/I18nSplitPlugin/index.js +1 -1
  32. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +8 -8
  33. package/lib/plugins/ReportGeneratePlugin.js +6 -8
  34. package/lib/plugins/ResourceHintsPlugin.js +3 -13
  35. package/lib/plugins/SelectorPlugin.js +37 -77
  36. package/lib/plugins/{MinifyPlugin.js → UglifyCSSPlugin.js} +3 -3
  37. package/lib/plugins/UnusedFilesFindPlugin.js +5 -7
  38. package/lib/plugins/VariableConversionCollector.js +101 -40
  39. package/lib/plugins/composeCommonPlugin.js +30 -0
  40. package/lib/plugins/index.js +7 -7
  41. package/lib/postcss-plugins/ExcludePlugin.js +1 -1
  42. package/lib/postcss-plugins/RTLSplitPlugin.js +10 -4
  43. package/lib/postcss-plugins/ValueReplacer.js +29 -8
  44. package/lib/postcss-plugins/hoverActivePlugin.js +6 -0
  45. package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +1 -0
  46. package/lib/postcss-plugins/variableModificationPlugin/index.js +38 -94
  47. package/lib/postcss-plugins/variableModifier.js +244 -0
  48. package/lib/schemas/index.js +18 -94
  49. package/lib/servers/devBuild.js +11 -13
  50. package/lib/servers/getCliPath.js +5 -3
  51. package/lib/servers/httpsOptions.js +13 -12
  52. package/lib/servers/nowatchserver.js +55 -62
  53. package/lib/servers/server.js +52 -53
  54. package/lib/utils/cssClassNameGenerate.js +13 -70
  55. package/lib/utils/getOptions.js +28 -35
  56. package/lib/utils/getServerURL.js +9 -1
  57. package/lib/utils/index.js +12 -14
  58. package/lib/utils/initPreCommitHook.js +5 -5
  59. package/lib/utils/pullOrigin.js +3 -3
  60. package/lib/utils/reinstallDependencies.js +3 -3
  61. package/lib/utils/switchBranch.js +2 -4
  62. package/package.json +3 -5
  63. package/templates/docs/all.html +0 -1
  64. package/templates/docs/component.html +0 -1
  65. package/templates/docs/components.html +0 -1
  66. package/templates/docs/css/style.css +169 -136
  67. package/templates/docs/index.html +632 -796
  68. package/.vscode/settings.json +0 -25
  69. package/docs/ComposeMinification.md +0 -13
  70. package/docs/MarkdownParser.md +0 -18
  71. package/docs/ReactLive.md +0 -14
  72. package/docs/patternFiltering.md +0 -57
  73. package/lib/common/buildEs.js +0 -12
  74. package/lib/common/runPreProcess.js +0 -71
  75. package/lib/deprecationLogger.js +0 -40
  76. package/lib/loaderUtils/tests/windowsModification.test.js +0 -10
  77. package/lib/loaders/__test__/markdownLoader.spec.js +0 -145
  78. package/lib/loaders/composeLoader.js +0 -298
  79. package/lib/loaders/markdownLoader.js +0 -71
  80. package/lib/loaders/reactLiveConvertor.js +0 -105
  81. package/lib/logger.js +0 -27
  82. package/lib/plugins/CustomAttributePlugin.js +0 -82
  83. package/lib/plugins/CustomAttributePlugin.md +0 -35
  84. package/lib/plugins/EfcResourceCleanupPlugin.js +0 -43
  85. package/lib/plugins/StatsPlugin.js +0 -82
  86. package/lib/plugins/utils/classHandling.js +0 -35
  87. package/lib/plugins/utils/fileHandling.js +0 -92
  88. package/lib/plugins/utils/tests/fileHandling.test.js +0 -30
  89. package/lib/plugins/variableConvertorUtils.js +0 -133
  90. package/lib/postcss-plugins/EmptyPlugin.js +0 -8
  91. package/lib/postcss-plugins/IncludePlugin.js +0 -23
  92. package/lib/postcss-plugins/SelectorReplace.js +0 -80
  93. package/lib/postcss-plugins/__test__/selectorReplace.test.js +0 -28
  94. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +0 -43
  95. package/lib/servers/requireLocalOrGlobal.js +0 -61
  96. package/lib/utils/deprecationSupport.js +0 -134
  97. package/lib/utils/log.js +0 -11
  98. package/lib/utils/object-manipulation.js +0 -88
  99. package/lib/utils/selectorReplacer.js +0 -47
  100. package/lib/utils/variableConverter.js +0 -104
  101. package/npm-shrinkwrap.json +0 -33485
  102. package/templates/docs/css/markdown.css +0 -202
@@ -22,7 +22,7 @@ var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUr
22
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
23
 
24
24
  let i18nObj = null;
25
- const options = (0, _utils.getOptions)();
25
+ let options = (0, _utils.getOptions)();
26
26
 
27
27
  function newAssign(target, data) {
28
28
  return Object.assign({}, target, data);
@@ -43,7 +43,7 @@ class I18NInjectIntoIndexPlugin {
43
43
  }
44
44
 
45
45
  getI18nFileUrlPath(chunk, compilation) {
46
- const urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
46
+ let urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
47
47
  return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
48
48
  }
49
49
 
@@ -81,6 +81,7 @@ class I18NInjectIntoIndexPlugin {
81
81
  withI18nSpitHandling(compiler) {
82
82
  compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
83
83
  // let cdns = Object.keys(this.publicPaths);
84
+ // console.log('compilation.assets', Object.keys(compilation.assets).filter(a => a.includes('i18n')));
84
85
  if (!(0, _hashUtils.hasContentHash)(this.i18nFileNameTemplate)) {
85
86
  this.injectI18nURLsToHTML(compilation);
86
87
  return;
@@ -90,7 +91,7 @@ class I18NInjectIntoIndexPlugin {
90
91
  // Manipulate the content
91
92
  const i18nManifest = this.getI18nManifest(compilation);
92
93
  const entryPoint = compilation.entrypoints.get(this.entryPointName);
93
- const i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
94
+ let i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
94
95
  data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
95
96
 
96
97
  cb(null, data);
@@ -110,11 +111,11 @@ class I18NInjectIntoIndexPlugin {
110
111
  compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
111
112
  // let cdns = Object.keys(this.publicPaths);
112
113
  if (i18nObj === null) {
113
- const i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
114
+ let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
114
115
 
115
116
  i18nObj = i18nFiles.reduce((res, next) => {
116
- const fileName = next.replace(`i18n${_path.default.sep}`, '');
117
- const splittedFileName = fileName.split('.');
117
+ let fileName = next.replace(`i18n${_path.default.sep}`, '');
118
+ let splittedFileName = fileName.split('.');
118
119
  /* if (this.isDevelopment) {
119
120
  res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
120
121
  } else {
@@ -126,10 +127,10 @@ class I18NInjectIntoIndexPlugin {
126
127
  }, {});
127
128
  }
128
129
 
129
- const [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
130
+ let [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
130
131
 
131
132
  if (indexFile) {
132
- const source = compilation.assets[indexFile].source();
133
+ let source = compilation.assets[indexFile].source();
133
134
  compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
134
135
  }
135
136
  });
@@ -24,9 +24,10 @@ class I18nDebugPlugin {
24
24
  compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
25
25
  if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
26
26
  return;
27
- }
27
+ } // console.log('skiped');
28
28
 
29
- const handler = parser => {
29
+
30
+ let handler = parser => {
30
31
  parser.hooks.program.tap(pluginName, (ast, commmets) => {
31
32
  const {
32
33
  module
@@ -184,15 +184,15 @@ class I18nDownlodLogic {
184
184
 
185
185
  const buf = [];
186
186
  /*
187
- if (REGEXP_HASH.test(filenameTemplate)) {
188
- buf.push(
189
- `var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
190
- );
191
- }
192
- if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
193
- buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
194
- }
195
- */
187
+ if (REGEXP_HASH.test(filenameTemplate)) {
188
+ buf.push(
189
+ `var hash = ${mainTemplate.renderCurrentHashCode(hash)};`
190
+ );
191
+ }
192
+ if (REGEXP_CHUNKHASH.test(filenameTemplate)) {
193
+ buf.push(`var chunkHashes = ${JSON.stringify(chunkMaps.hash)};`);
194
+ }
195
+ */
196
196
 
197
197
  if ((0, _hashUtils.hasContentHash)(filenameTemplate)) {
198
198
  const hashLength = getContentHashMaxLength(filenameTemplate);
@@ -205,18 +205,12 @@ class I18nDownlodLogic {
205
205
 
206
206
  const publicPath = this.publicPath ? JSON.stringify(this.publicPath) : `${mainTemplate.requireFn}.p`;
207
207
  return _webpack.Template.asString([source, `
208
- function downloadScriptTagForI18nDynamicChunks(chunkName = '', language = '') {
208
+ (function() {
209
209
  // ${pluginName} I18N loading
210
210
  var i18nChunks = ${JSON.stringify(chunkMap)};
211
211
  var locale = ${localeVarName};
212
212
  // ${pluginName} I18N hasehes
213
213
  ${hashUtils}
214
- if(chunkName) {
215
- chunkId = chunkName;
216
- }
217
- if (language) {
218
- locale = language;
219
- }
220
214
  if(installedI18nChunks[chunkId]) {
221
215
  promises.push(installedI18nChunks[chunkId]);
222
216
  } else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {
@@ -251,19 +245,10 @@ function downloadScriptTagForI18nDynamicChunks(chunkName = '', language = '') {
251
245
  }` : ''}
252
246
  document.body.appendChild(scriptTag);
253
247
  }).then(function() {
254
- installedI18nChunks[chunkId] = 0;
248
+ installedI18nChunks[chunkId] = 0;
255
249
  }));
256
250
  }
257
- };
258
- downloadScriptTagForI18nDynamicChunks();
259
- ${mainTemplate.requireFn}.changeLanguage = function changeLanguage(language) {
260
- window.userLangCode=language;
261
- Object.keys(installedI18nChunks).map(chunks => {
262
- if (chunks !== './runtime~main' && installedI18nChunks[chunks] == 0) {
263
- installedI18nChunks[chunks] = null;
264
- downloadScriptTagForI18nDynamicChunks(chunks, language);
265
- }
266
- });}`]);
251
+ })()`]);
267
252
  });
268
253
  }
269
254
 
@@ -271,8 +256,7 @@ downloadScriptTagForI18nDynamicChunks();
271
256
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
272
257
  const {
273
258
  mainTemplate
274
- } = compilation; // this.createChangeLanguageFunction(mainTemplate);
275
-
259
+ } = compilation;
276
260
  this.addDownloadLogicOfI18nInMainTemplate(mainTemplate);
277
261
  });
278
262
  }
@@ -40,7 +40,7 @@ class I18nKeysIdentifer {
40
40
  identifier,
41
41
  i18nKeys
42
42
  }, module.context, 0);
43
- module.addDependency(dep);
43
+ module.addDependency(dep); // console.log('module', i18nKeys, identifier);
44
44
  }
45
45
 
46
46
  apply(compiler) {
@@ -50,7 +50,7 @@ class I18nKeysIdentifer {
50
50
  // and we must define how it import statement look like I18nDependencyTemplate
51
51
  this.defineConfigarationForI18nDependency(compilation); // handler for parser
52
52
 
53
- const handler = parser => {
53
+ let handler = parser => {
54
54
  parser.hooks.program.tap(pluginName, (ast, commmets) => {
55
55
  const {
56
56
  module
@@ -66,6 +66,11 @@ class I18nKeysIdentifer {
66
66
  (0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
67
67
 
68
68
  if (i18nKeys.length) {
69
+ // console.log(
70
+ // 'i18nKeys.length',
71
+ // module.resource,
72
+ // i18nKeys.length < 5 ? i18nKeys : i18nKeys.length
73
+ // );
69
74
  this.addI18nDependency(module, i18nKeys);
70
75
  }
71
76
  });
@@ -177,7 +177,7 @@ class I18nPlugin {
177
177
  compilation.moduleTemplate.javascript,
178
178
  compilation.dependencyTemplates
179
179
  );
180
-
180
+ console.log('entry, ', c, hashSource.toString());
181
181
  }
182
182
  */
183
183
 
@@ -11,8 +11,6 @@ var _fs = require("fs");
11
11
 
12
12
  var _path = require("path");
13
13
 
14
- var _logger = require("../../../logger");
15
-
16
14
  function isComment(line) {
17
15
  return line[0] === '#';
18
16
  }
@@ -20,7 +18,7 @@ function isComment(line) {
20
18
  function getPropertiesAsJSON(filePath) {
21
19
  try {
22
20
  const data = (0, _fs.readFileSync)(filePath);
23
- const source = data.toString();
21
+ let source = data.toString();
24
22
  const i18nObj = {};
25
23
  source.split(/\r?\n\r?/).forEach(fline => {
26
24
  const line = fline.trim();
@@ -44,7 +42,7 @@ function getPropertiesAsJSON(filePath) {
44
42
  }
45
43
 
46
44
  function getLang(file) {
47
- const underScoreIndex = file.indexOf('_');
45
+ let underScoreIndex = file.indexOf('_');
48
46
  let language = 'en_US';
49
47
 
50
48
  if (underScoreIndex !== -1) {
@@ -70,24 +68,26 @@ function getAllI18n({
70
68
  const filePath = (0, _path.join)(context, file);
71
69
 
72
70
  if (exclude.test(filePath) || !include.test(filePath)) {
71
+ // console.log('exclude', filePath);
73
72
  return;
74
- }
73
+ } // console.log('include', filePath);
74
+
75
75
 
76
76
  const i18n = getPropertiesAsJSON(filePath);
77
77
  allLangI18n[getLang(file)] = disableDefault ? i18n : Object.assign({}, jsResourceI18nKeys, i18n);
78
78
  });
79
79
  return allLangI18n;
80
80
  } catch (err) {
81
- (0, _logger.errorLogger)(err);
81
+ // console.log(err);
82
82
  return {};
83
83
  }
84
84
  }
85
85
 
86
86
  function jsonToString(json, keySeperator) {
87
87
  let str = '{';
88
- const keys = Object.keys(json);
88
+ let keys = Object.keys(json);
89
89
  keys.forEach((key, i) => {
90
- const value = json[key];
90
+ let value = json[key];
91
91
 
92
92
  if (!value) {
93
93
  return;
@@ -13,8 +13,6 @@ var _redis = _interopRequireDefault(require("redis"));
13
13
 
14
14
  var _utils = require("../utils");
15
15
 
16
- var _log = require("../utils/log");
17
-
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
17
 
20
18
  let options = (0, _utils.getOptions)();
@@ -70,10 +68,10 @@ class reportGeneratePlugin {
70
68
  let client = _redis.default.createClient(redisPort, redisHost);
71
69
 
72
70
  client.on('connect', () => {
73
- (0, _log.log)('Redis client connected');
71
+ (0, _utils.log)('Redis client connected');
74
72
  });
75
73
  client.on('error', err => {
76
- (0, _log.log)(`Something went wrong ${err}`);
74
+ (0, _utils.log)(`Something went wrong ${err}`);
77
75
  });
78
76
 
79
77
  if (_fs.default.existsSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'))) {
@@ -82,7 +80,7 @@ class reportGeneratePlugin {
82
80
  statsJSON = JSON.parse(statsJSON);
83
81
  let finalObj = {};
84
82
  let branchName = branch ? branch : (0, _utils.getCurrentBranch)();
85
- (0, _log.log)(branchName);
83
+ (0, _utils.log)(branchName);
86
84
  statsJSON.assets.forEach(assetObj => {
87
85
  let nameSplitList = assetObj.name.split('/')[assetObj.name.split('/').length - 1].split('.'); // eslint-disable-line
88
86
 
@@ -113,7 +111,7 @@ class reportGeneratePlugin {
113
111
  };
114
112
  client.get(branchName, (err, reply) => {
115
113
  if (err) {
116
- (0, _log.log)(err);
114
+ (0, _utils.log)(err);
117
115
  } else {
118
116
  reply = JSON.parse(reply); // eslint-disable-line
119
117
 
@@ -149,7 +147,7 @@ class reportGeneratePlugin {
149
147
  throw err;
150
148
  }
151
149
 
152
- (0, _log.log)('Stats Json generated!');
150
+ (0, _utils.log)('Stats Json generated!');
153
151
  });
154
152
  }
155
153
  });
@@ -171,7 +169,7 @@ class reportGeneratePlugin {
171
169
  }
172
170
 
173
171
  if (err) {
174
- (0, _log.log)(err);
172
+ (0, _utils.log)(err);
175
173
  }
176
174
  });
177
175
  }
@@ -12,21 +12,14 @@ const {
12
12
  const pluginName = 'prefetch-preload-chunk-plugin';
13
13
 
14
14
  class ResourceHintsPlugin {
15
- constructor(options) {
16
- this.options = options;
17
- }
18
-
19
15
  apply(compiler) {
20
16
  compiler.hooks.thisCompilation.tap(pluginName, ({
21
17
  mainTemplate
22
18
  }) => {
23
19
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk, hash) => {
24
- const {
25
- allowPrefetchingMultipleChunks
26
- } = this.options;
27
20
  const idNameMap = chunk.getChunkMaps().name;
28
21
  const nameIdMap = {};
29
- let needsMap = allowPrefetchingMultipleChunks;
22
+ let needsMap = false;
30
23
 
31
24
  for (const key in idNameMap) {
32
25
  if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
@@ -39,10 +32,7 @@ class ResourceHintsPlugin {
39
32
  }
40
33
  }
41
34
 
42
- return Template.asString([source, Template.indent([`const nameToChunkIdMap = ${JSON.stringify(needsMap ? nameIdMap : {})};`, 'const chunkNames = Object.keys(nameToChunkIdMap);']), `${mainTemplate.requireFn}.getChunkIds = function getChunkIds(chunkId) {`, Template.indent([allowPrefetchingMultipleChunks ? `const isRegExAsChunkId = chunkId instanceof RegExp;
43
- return isRegExAsChunkId ? chunkNames.filter(chunkName => chunkId.test(chunkName)).map(chunkName => nameToChunkIdMap[chunkName]) : [nameToChunkIdMap[chunkId] || chunkId];` : needsMap ? 'return [nameToChunkIdMap[chunkId] || chunkId];' : 'return [chunkId];']), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`let chunkIds = ${mainTemplate.requireFn}.getChunkIds(chunkId)`, `chunkIds.forEach(idOfAChunk => {
44
- ${mainTemplate.requireFn}.e(idOfAChunk);
45
- })`]), '};',
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);`]), '};',
46
36
  /*
47
37
  (needsMap
48
38
  ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
@@ -63,7 +53,7 @@ class ResourceHintsPlugin {
63
53
  ),
64
54
  '}',
65
55
  */
66
- `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkIds(chunkId)[0]`, '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];',
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];',
67
57
  // mainTemplate.hooks.jsonpScript.call('', chunk, hash),
68
58
  // 'head.appendChild(script);'
69
59
  ]), '}']), '};']);
@@ -9,53 +9,51 @@ var _postcss = _interopRequireDefault(require("postcss"));
9
9
 
10
10
  var _fs = _interopRequireDefault(require("fs"));
11
11
 
12
- var _classHandling = require("./utils/classHandling");
12
+ var _webpackSources = require("webpack-sources");
13
13
 
14
- var _fileHandling = require("./utils/fileHandling");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
- var _windowsModification = require("../loaderUtils/windowsModification");
16
+ const path = require('path');
17
17
 
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ const isCss = filename => path.extname(filename) === '.css';
19
19
 
20
- function selectorWeightPrefixAdder(rootOriginal, selector, excludeStrings) {
20
+ function rootConvertor(rootOriginal, defaultSelector, data, chunkFilename, excludeStrings) {
21
21
  rootOriginal.walkRules((rule, index) => {
22
- const prevNode = rootOriginal.nodes[index - 1] || null;
22
+ const prevNode = rootOriginal.nodes[index - 1];
23
23
 
24
- if ((0, _classHandling.hasPrevNodeIgnore)(index, prevNode, 'updateselector:ignore')) {
24
+ if (index !== 0 && prevNode.type && prevNode.type === 'comment' && prevNode.text.toLowerCase() === 'updateselector:ignore') {
25
25
  return;
26
- } // console.log(rule.selector.split(','));
27
-
26
+ }
28
27
 
29
- const selectorArr = rule.selector.split(',');
30
- selectorArr.forEach((singleSelectorStr, index) => {
31
- if (excludeStrings.includes(singleSelectorStr.trim())) {
28
+ if (rule.parent && rule.parent.type === 'atrule') {
29
+ if (rule.parent.name !== 'media') {
32
30
  return;
33
- } // NOTE: below logic for attrbute related
34
-
31
+ }
32
+ }
35
33
 
36
- if (singleSelectorStr.includes(']')) {
37
- // console.log(singleSelectorStr);
38
- const prefixPart = singleSelectorStr.slice(0, singleSelectorStr.lastIndexOf(']') + 1).trim();
39
- const selectorPart = singleSelectorStr.slice(singleSelectorStr.lastIndexOf(']') + 1).trim();
34
+ if (excludeStrings.includes(rule.selector)) {
35
+ return;
36
+ }
40
37
 
41
- if (excludeStrings.includes(selectorPart.trim())) {
38
+ let ruleArr = rule.selector.split(',');
39
+ ruleArr.forEach((rule, index) => {
40
+ if (rule.includes(']')) {
41
+ if (rule.slice(rule.lastIndexOf(']') + 2).trim() === '') {
42
42
  return;
43
- }
43
+ } // console.log(
44
+ // rule.slice(rule.lastIndexOf(']') + 2).trim(),
45
+ // rule.slice(rule.lastIndexOf(']') + 2).trim() !== ''
46
+ // );
44
47
 
45
- if (/^:/gi.test(selectorPart)) {
46
- return;
47
- }
48
48
 
49
- if (selectorPart !== '') {
50
- selectorArr[index] = `${prefixPart} ${selector}${selectorPart}`;
51
- }
49
+ ruleArr[index] = `${rule.slice(0, rule.lastIndexOf(']') + 1).trim()} ${defaultSelector}${rule.slice(rule.lastIndexOf(']') + 2).trim()}`; // console.log(ruleArr[index]);
52
50
 
53
51
  return;
54
52
  }
55
53
 
56
- selectorArr[index] = `${selector}${singleSelectorStr}`;
54
+ ruleArr[index] = data[chunkFilename] ? `${data[chunkFilename].defaultSelector}${rule}` : `${defaultSelector}${rule}`;
57
55
  });
58
- rule.selector = selectorArr.join(',\n');
56
+ rule.selector = ruleArr.join(',\n'); // console.log(`${rule.selector} converted`);
59
57
  });
60
58
  return rootOriginal;
61
59
  }
@@ -64,8 +62,6 @@ class SelectorPlugin {
64
62
  constructor(options = {}) {
65
63
  this.optimize = options.optimize;
66
64
  this.selectorWeightConfig = options.selectorWeightConfig;
67
- this.exclude = options.exclude;
68
- this.patterns = options.patterns;
69
65
  }
70
66
 
71
67
  apply(compiler) {
@@ -78,55 +74,19 @@ class SelectorPlugin {
78
74
  const rawdata = _fs.default.readFileSync(customFileDetails);
79
75
 
80
76
  const data = JSON.parse(rawdata);
81
- this.exclude = (0, _windowsModification.windowsModification)(this.exclude);
82
77
  compiler.hooks.compilation.tap('selector-weight-rewrite', compilation => {
83
- compilation.hooks.optimizeModules.tap('selector-weight-rewrite', modules => {
84
- const mods = modules.filter(x => x.type.includes('css'));
85
- mods.forEach(module => {
86
- const rootOriginal = _postcss.default.parse(module.content);
87
-
88
- const filename = module.issuer.resource;
89
- /*
90
- input :
91
- filename : 'D:/MyWork/..../desk_client_app/supportapp/src/components/Avatar/Avatar.module.css,
92
-
93
- patterns.cssVariableReplacement:
94
- // include src folder, include deskapp folder, exclude node modules
95
- "selectorWeight": [
96
- "src",
97
- "deskapp",
98
- "!node_modules"
99
- ]
100
-
101
- output :
102
- true or false
103
- */
104
-
105
- if (!(0, _fileHandling.isFileNameMatchingPluginPattern)({
106
- filename,
107
- filterArr: this.patterns.selectorWeight
108
- })) {
109
- return;
110
- }
111
- /*
112
-
113
- filename : Deskapp.module.css ?
114
- data :
115
- {
116
- "DeskApp.module.css": {"defaultSelector" : ".desk_app_ui "}
117
- }
118
- selectorWeightConfig :
119
- defaultSelector : .zoho_desk_ui
120
-
121
- case filename = 'DeskApp.module.css' ?
122
- data[filename].defaultSelector = '.desk_app_ui'
123
- case filename is different ?
124
- defaultSelector = '.zoho_desk_ui'
125
- */
126
-
127
-
128
- module.content = selectorWeightPrefixAdder(rootOriginal, data[filename] ? data[filename].defaultSelector : defaultSelector, excludeStrings).toString();
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
+ });
129
88
  });
89
+ callback();
130
90
  });
131
91
  });
132
92
  }
@@ -11,9 +11,9 @@ var _uglifycss = _interopRequireDefault(require("uglifycss"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- class MinifierPlugin {
14
+ class UglifyCSSPlugin {
15
15
  apply(compiler) {
16
- compiler.hooks.emit.tap('MinifierPlugin', compilation => {
16
+ compiler.hooks.emit.tap('UglifyCSSPlugin', compilation => {
17
17
  Object.keys(compilation.assets).forEach(filename => {
18
18
  if (/\.css$/.test(filename)) {
19
19
  try {
@@ -36,4 +36,4 @@ class MinifierPlugin {
36
36
 
37
37
  }
38
38
 
39
- exports.default = MinifierPlugin;
39
+ exports.default = UglifyCSSPlugin;
@@ -11,8 +11,6 @@ var _fs = _interopRequireDefault(require("fs"));
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
14
- var _log = require("../utils/log");
15
-
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
16
  let excludeDocsJSON = '{}';
@@ -99,10 +97,10 @@ class UnusedFilesFindPlugin {
99
97
  Object.keys(unDocsCompObj).forEach(key => {
100
98
  if (unDocsCompObj[key].length > 0) {
101
99
  if (key === 'withoutDocs') {
102
- (0, _log.log)('\x1b[36m%s\x1b[0m', '\nPlease write docs file for below componenst :- \n');
100
+ (0, _utils.log)('\x1b[36m%s\x1b[0m', '\nPlease write docs file for below componenst :- \n');
103
101
  unDocsCompObj[key].forEach(value => {
104
102
  if (!excludeDocsArray.docs.exclude.includes(value)) {
105
- (0, _log.log)('\x1b[33m%s\x1b[0m', `${value}`);
103
+ (0, _utils.log)('\x1b[33m%s\x1b[0m', `${value}`);
106
104
  }
107
105
  });
108
106
  }
@@ -164,10 +162,10 @@ class UnusedFilesFindPlugin {
164
162
  });
165
163
 
166
164
  if (!unusedFiles.length) {
167
- (0, _log.log)('There is no unused files');
165
+ (0, _utils.log)('There is no unused files');
168
166
  } else {
169
167
  if (this.outputFileName) {
170
- (0, _log.log)(`You can see unused files info from ${_path.default.join(outputPath, this.outputFileName)} path`);
168
+ (0, _utils.log)(`You can see unused files info from ${_path.default.join(outputPath, this.outputFileName)} path`);
171
169
  (0, _utils.makeDir)(outputPath);
172
170
  (0, _utils.writeFile)(_path.default.join(outputPath, this.outputFileName), JSON.stringify(unusedFiles)).then(() => {
173
171
  if (this.sstest) {
@@ -181,7 +179,7 @@ class UnusedFilesFindPlugin {
181
179
  unusedFiles.forEach(file => {
182
180
  _fs.default.unlinkSync(file);
183
181
 
184
- (0, _log.log)(`Deleted - ${file}`);
182
+ (0, _utils.log)(`Deleted - ${file}`);
185
183
  });
186
184
  }
187
185
  });