@zohodesk/react-cli 1.1.0 → 1.1.2-9.exp.3

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 (80) hide show
  1. package/.vscode/settings.json +25 -0
  2. package/README.md +453 -34
  3. package/bin/cli.js +25 -52
  4. package/docs/CustomChunks.md +12 -9
  5. package/docs/MarkdownParser.md +18 -0
  6. package/docs/ReactLive.md +8 -0
  7. package/docs/ValueReplacer.md +27 -0
  8. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  9. package/lib/babel/cmjs-plugins-presets.js +36 -7
  10. package/lib/babel/es-plugins-presets.js +45 -16
  11. package/lib/common/runPreProcess.js +71 -0
  12. package/lib/common/splitChunks.js +65 -45
  13. package/lib/common/testPattern.js +9 -9
  14. package/lib/configs/jest.config.js +4 -4
  15. package/lib/configs/libAlias.js +36 -2
  16. package/lib/configs/resolvers.js +7 -4
  17. package/lib/configs/webpack.css.umd.config.js +3 -2
  18. package/lib/configs/webpack.dev.config.js +28 -8
  19. package/lib/configs/webpack.docs.config.js +11 -5
  20. package/lib/configs/webpack.impact.config.js +9 -4
  21. package/lib/configs/webpack.prod.config.js +32 -10
  22. package/lib/constants.js +3 -3
  23. package/lib/deprecationLogger.js +40 -0
  24. package/lib/jest/preProcessors/jsPreprocessor.js +27 -2
  25. package/lib/loaderUtils/configsAssetsLoaders.js +1 -1
  26. package/lib/loaderUtils/getCSSLoaders.js +32 -8
  27. package/lib/loaderUtils/getDevJsLoaders.js +8 -2
  28. package/lib/loaders/__test__/markdownLoader.spec.js +145 -0
  29. package/lib/loaders/composeLoader.js +140 -14
  30. package/lib/loaders/docsLoader.js +5 -2
  31. package/lib/loaders/enhancedReactLiveConverter.js +151 -0
  32. package/lib/loaders/markdownLoader.js +71 -0
  33. package/lib/loaders/reactLiveConvertor.js +64 -66
  34. package/lib/loaders/workerLoader.js +37 -22
  35. package/lib/logger.js +7 -0
  36. package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
  37. package/lib/pluginUtils/getDevPlugins.js +24 -8
  38. package/lib/pluginUtils/getProdPlugins.js +34 -6
  39. package/lib/plugins/CssOrderControlPlugin.js +36 -0
  40. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
  41. package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
  42. package/lib/plugins/EventsHandlingPlugin.js +34 -0
  43. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
  44. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +4 -1
  45. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +14 -0
  46. package/lib/plugins/ReportGeneratePlugin.js +8 -6
  47. package/lib/plugins/ResourceHintsPlugin.js +13 -3
  48. package/lib/plugins/StatsPlugin.js +82 -0
  49. package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
  50. package/lib/plugins/utils/fileHandling.js +36 -51
  51. package/lib/plugins/variableConvertorUtils.js +4 -2
  52. package/lib/postcss-plugins/ValueReplacer.js +7 -17
  53. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
  54. package/lib/postcss-plugins/variableModificationPlugin/index.js +70 -18
  55. package/lib/schemas/index.js +96 -27
  56. package/lib/servers/getCliPath.js +3 -5
  57. package/lib/servers/requireLocalOrGlobal.js +1 -1
  58. package/lib/utils/cssClassNameGenerate.js +43 -5
  59. package/lib/utils/deprecationSupport.js +134 -0
  60. package/lib/utils/getFileType.js +1 -1
  61. package/lib/utils/getOptions.js +34 -43
  62. package/lib/utils/getServerURL.js +7 -2
  63. package/lib/utils/index.js +27 -11
  64. package/lib/utils/initPreCommitHook.js +5 -5
  65. package/lib/utils/log.js +11 -0
  66. package/lib/utils/object-manipulation.js +88 -0
  67. package/lib/utils/pullOrigin.js +3 -3
  68. package/lib/utils/reinstallDependencies.js +3 -3
  69. package/lib/utils/selectorReplacer.js +47 -0
  70. package/lib/utils/switchBranch.js +4 -2
  71. package/lib/utils/typeCheck.js +10 -0
  72. package/lib/utils/variableConverter.js +26 -11
  73. package/npm-shrinkwrap.json +1001 -106
  74. package/package.json +12 -4
  75. package/templates/docs/all.html +1 -0
  76. package/templates/docs/component.html +1 -0
  77. package/templates/docs/components.html +1 -0
  78. package/templates/docs/css/markdown.css +202 -0
  79. package/templates/docs/css/style.css +136 -169
  80. package/templates/docs/index.html +796 -632
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const pluginName = 'CustomScriptLoadingStrategyPlugin';
13
+
14
+ class CustomScriptLoadingStrategyPlugin {
15
+ constructor({
16
+ scriptLoadingStategey
17
+ } = {}) {
18
+ this.scriptLoadingStrategy = scriptLoadingStategey;
19
+ this.tagNamesToMatch = ['script'];
20
+ }
21
+
22
+ getFileNameFromTagSrc(src) {
23
+ const fileNameArr = src.split('/');
24
+ return fileNameArr[fileNameArr.length - 1];
25
+ }
26
+
27
+ addAttributestToTag(tag, attributes) {
28
+ tag.attributes = Object.assign({}, tag.attributes, attributes);
29
+ }
30
+
31
+ matchFileName(tag, fileName) {
32
+ return fileName.test(this.getFileNameFromTagSrc(tag.attributes.src));
33
+ }
34
+
35
+ blockingStrategy(tag) {
36
+ delete tag.attributes.defer;
37
+ delete tag.attributes.async;
38
+ }
39
+
40
+ deferStrategy(tag) {
41
+ delete tag.attributes.async;
42
+ }
43
+
44
+ asyncStrategy(tag) {
45
+ delete tag.attributes.defer;
46
+ }
47
+
48
+ moduleStrategy(tag) {
49
+ this.deferStrategy(tag);
50
+ }
51
+
52
+ matchStrategy(scriptLoadingStrategy, tag) {
53
+ if (scriptLoadingStrategy === 'blocking') {
54
+ this.blockingStrategy(tag);
55
+ }
56
+
57
+ if (scriptLoadingStrategy === 'defer') {
58
+ this.deferStrategy(tag);
59
+ }
60
+
61
+ if (scriptLoadingStrategy === 'async') {
62
+ this.asyncStrategy(tag);
63
+ }
64
+
65
+ if (scriptLoadingStrategy === 'module') {
66
+ this.moduleStrategy(tag);
67
+ }
68
+ }
69
+
70
+ matchAndApplyCustomLoadingStrategyToScripts(tags) {
71
+ Object.keys(this.scriptLoadingStrategy).forEach(scriptLoadingStrategy => {
72
+ const filesToMatch = this.scriptLoadingStrategy[scriptLoadingStrategy];
73
+ tags.forEach(tag => {
74
+ if (this.tagNamesToMatch.includes(tag.tagName) && tag.attributes.src) {
75
+ const isFileMatch = filesToMatch.some(fileName => this.matchFileName(tag, fileName));
76
+
77
+ if (isFileMatch) {
78
+ this.matchStrategy(scriptLoadingStrategy, tag);
79
+ this.addAttributestToTag(tag, {
80
+ [scriptLoadingStrategy]: true
81
+ });
82
+ }
83
+ } // filesToMatch.forEach(fileName => {
84
+ // if (!this.matchFileName(tag, fileName)) {
85
+ // return;
86
+ // }
87
+ // this.matchStrategy(scriptLoadingStrategy, tag);
88
+ // this.addAttributestToTag(tag, fileName, {
89
+ // [scriptLoadingStrategy]: true
90
+ // });
91
+ // });
92
+
93
+ });
94
+ });
95
+ }
96
+
97
+ apply(compiler) {
98
+ compiler.hooks.compilation.tap(pluginName, compilation => {
99
+ _htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, callback) => {
100
+ const tags = [...data.bodyTags, ...data.headTags];
101
+ this.matchAndApplyCustomLoadingStrategyToScripts(tags);
102
+ callback(null, data);
103
+ });
104
+ });
105
+ }
106
+
107
+ }
108
+
109
+ exports.default = CustomScriptLoadingStrategyPlugin;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ const {
4
+ Template
5
+ } = require('webpack');
6
+
7
+ const plugInName = 'EFCResourceCleanup';
8
+ module.exports = class EfcResouceCleanupPlugin {
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+
13
+ apply(compiler) {
14
+ compiler.hooks.thisCompilation.tap(plugInName, ({
15
+ mainTemplate
16
+ }) => {
17
+ mainTemplate.hooks.afterStartup.tap(plugInName, source => {
18
+ const {
19
+ attributes,
20
+ globalCacheObj
21
+ } = this.options;
22
+ const attributesArr = Object.entries(attributes);
23
+ const [[attributekey, attributeValue]] = attributesArr;
24
+ const resourceSelector = `[${attributekey}="${attributeValue}"]`;
25
+ return Template.asString([source, Template.indent([` window['${globalCacheObj}Jsonp'].unInstall = function() {
26
+ Object.keys(installedModules).forEach(installedModulesKey => installedModules[installedModulesKey] = null);
27
+ Object.keys(modules).forEach(moduleKey => modules[moduleKey] = null);
28
+ `, `
29
+ installedModules = null;
30
+ modules = null;
31
+ __webpack_require__.m = null;
32
+ __webpack_require__.c = null;
33
+
34
+ `, attributekey && attributeValue ? `
35
+ const addedResources = document.querySelectorAll('${resourceSelector}');
36
+ addedResources.forEach(addedResource => addedResource.remove());
37
+ }
38
+ ` : ''])]);
39
+ });
40
+ });
41
+ }
42
+
43
+ };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EventsHandlingPlugin = void 0;
7
+
8
+ /* eslint-disable no-use-before-define */
9
+ class EventsHandlingPlugin {
10
+ constructor(options) {}
11
+
12
+ apply(compiler) {
13
+ // NOTE: we not using this, Reason currently this option is only need for EFC,
14
+ // So it do not needed.
15
+ compiler.hooks.thisCompilation.tap({
16
+ name: 'CustomAttributePlugin',
17
+ stage: 1,
18
+ fn: compilation => {
19
+ compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
20
+ // const str = attributeSetTemplate(cssAttributes, 'linkTag');
21
+ const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null;');
22
+ const replacedSourceStr = sourceStr.replace('linkTag.onload = resolve', `linkTag.onload = () => {
23
+ linkTag.onerror = linkTag.onload = null;
24
+ resolve();
25
+ };`);
26
+ return replacedSourceStr;
27
+ });
28
+ }
29
+ });
30
+ }
31
+
32
+ }
33
+
34
+ exports.EventsHandlingPlugin = EventsHandlingPlugin;
@@ -228,8 +228,12 @@ class I18nDownlodLogic {
228
228
  if(dataSrc === srcPath || dataSrc === fullsrcPath){ return resolve();}
229
229
  }
230
230
  var scriptTag = document.createElement("script");
231
- scriptTag.onload = resolve;
231
+ scriptTag.onload = () => {
232
+ scriptTag.onerror = scriptTag.onload = null;
233
+ resolve();
234
+ };
232
235
  scriptTag.onerror = function(event) {
236
+ scriptTag.onerror = scriptTag.onload = null;
233
237
  var request = event && event.target && event.target.src || fullsrcPath;
234
238
  var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + request + ")");
235
239
  err.code = "I18N_CHUNK_LOAD_FAILED";
@@ -13,6 +13,8 @@ var _path = require("path");
13
13
 
14
14
  var _logger = require("../../../logger");
15
15
 
16
+ var _unicodeConversion = require("./unicodeConversion");
17
+
16
18
  function isComment(line) {
17
19
  return line[0] === '#';
18
20
  }
@@ -31,7 +33,8 @@ function getPropertiesAsJSON(filePath) {
31
33
 
32
34
  const ind = line.indexOf('=');
33
35
  const key = line.slice(0, ind).replace(/\\ /g, ' ');
34
- const value = line.slice(ind + 1);
36
+ let value = line.slice(ind + 1);
37
+ value = (0, _unicodeConversion.convertUnicode)(value);
35
38
 
36
39
  if (key && value) {
37
40
  i18nObj[key] = value;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertUnicode = convertUnicode;
7
+
8
+ function convertUnicode(str) {
9
+ const unicodeRegex = /\\u([a-fA-F0-9]{4})/g;
10
+ const converted = str.replace(unicodeRegex, (match, hex) => {
11
+ return String.fromCharCode(parseInt(hex, 16));
12
+ });
13
+ return converted;
14
+ }
@@ -13,6 +13,8 @@ var _redis = _interopRequireDefault(require("redis"));
13
13
 
14
14
  var _utils = require("../utils");
15
15
 
16
+ var _log = require("../utils/log");
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
20
  let options = (0, _utils.getOptions)();
@@ -68,10 +70,10 @@ class reportGeneratePlugin {
68
70
  let client = _redis.default.createClient(redisPort, redisHost);
69
71
 
70
72
  client.on('connect', () => {
71
- (0, _utils.log)('Redis client connected');
73
+ (0, _log.log)('Redis client connected');
72
74
  });
73
75
  client.on('error', err => {
74
- (0, _utils.log)(`Something went wrong ${err}`);
76
+ (0, _log.log)(`Something went wrong ${err}`);
75
77
  });
76
78
 
77
79
  if (_fs.default.existsSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'))) {
@@ -80,7 +82,7 @@ class reportGeneratePlugin {
80
82
  statsJSON = JSON.parse(statsJSON);
81
83
  let finalObj = {};
82
84
  let branchName = branch ? branch : (0, _utils.getCurrentBranch)();
83
- (0, _utils.log)(branchName);
85
+ (0, _log.log)(branchName);
84
86
  statsJSON.assets.forEach(assetObj => {
85
87
  let nameSplitList = assetObj.name.split('/')[assetObj.name.split('/').length - 1].split('.'); // eslint-disable-line
86
88
 
@@ -111,7 +113,7 @@ class reportGeneratePlugin {
111
113
  };
112
114
  client.get(branchName, (err, reply) => {
113
115
  if (err) {
114
- (0, _utils.log)(err);
116
+ (0, _log.log)(err);
115
117
  } else {
116
118
  reply = JSON.parse(reply); // eslint-disable-line
117
119
 
@@ -147,7 +149,7 @@ class reportGeneratePlugin {
147
149
  throw err;
148
150
  }
149
151
 
150
- (0, _utils.log)('Stats Json generated!');
152
+ (0, _log.log)('Stats Json generated!');
151
153
  });
152
154
  }
153
155
  });
@@ -169,7 +171,7 @@ class reportGeneratePlugin {
169
171
  }
170
172
 
171
173
  if (err) {
172
- (0, _utils.log)(err);
174
+ (0, _log.log)(err);
173
175
  }
174
176
  });
175
177
  }
@@ -12,14 +12,21 @@ const {
12
12
  const pluginName = 'prefetch-preload-chunk-plugin';
13
13
 
14
14
  class ResourceHintsPlugin {
15
+ constructor(options) {
16
+ this.options = options;
17
+ }
18
+
15
19
  apply(compiler) {
16
20
  compiler.hooks.thisCompilation.tap(pluginName, ({
17
21
  mainTemplate
18
22
  }) => {
19
23
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk, hash) => {
24
+ const {
25
+ allowPrefetchingMultipleChunks
26
+ } = this.options;
20
27
  const idNameMap = chunk.getChunkMaps().name;
21
28
  const nameIdMap = {};
22
- let needsMap = false;
29
+ let needsMap = allowPrefetchingMultipleChunks;
23
30
 
24
31
  for (const key in idNameMap) {
25
32
  if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
@@ -32,7 +39,10 @@ class ResourceHintsPlugin {
32
39
  }
33
40
  }
34
41
 
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);`]), '};',
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
+ })`]), '};',
36
46
  /*
37
47
  (needsMap
38
48
  ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
@@ -53,7 +63,7 @@ class ResourceHintsPlugin {
53
63
  ),
54
64
  '}',
55
65
  */
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];',
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];',
57
67
  // mainTemplate.hooks.jsonpScript.call('', chunk, hash),
58
68
  // 'head.appendChild(script);'
59
69
  ]), '}']), '};']);
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ const fs = require('fs');
4
+
5
+ const path = require('path');
6
+
7
+ const {
8
+ Readable
9
+ } = require('stream');
10
+
11
+ const {
12
+ removeKeysFromObject,
13
+ convertObjectToStringGen
14
+ } = require('../utils/object-manipulation');
15
+
16
+ const pluginName = 'stats-plugin';
17
+ const statsSchema = {
18
+ all: true
19
+ };
20
+
21
+ class StatsPlugin {
22
+ constructor({
23
+ statsOptions,
24
+ statsOutputExcludeKeys,
25
+ statsFileName
26
+ }) {
27
+ this.excludeKeysInStat = statsOutputExcludeKeys || [];
28
+ this.statsFileName = statsFileName || 'bundle-report-integrity.json';
29
+ this.statsOptions = Object.assign({}, statsSchema, statsOptions || {});
30
+ }
31
+
32
+ apply(compiler) {
33
+ compiler.hooks.done.tapAsync(pluginName, (stats, callback) => {
34
+ const statsJson = removeKeysFromObject(stats.toJson(this.statsOptions), this.excludeKeysInStat);
35
+ this.emitStats(statsJson).on('end', () => {
36
+ callback();
37
+ }).on('error', e => {
38
+ callback(e);
39
+ });
40
+ });
41
+ }
42
+
43
+ writeStatsFileInAStream(statsObj) {
44
+ const {
45
+ outputPath
46
+ } = statsObj;
47
+ const ouputFileName = path.join(outputPath, this.statsFileName);
48
+ return this.createReadStream(statsObj).pipe(fs.createWriteStream(ouputFileName));
49
+ }
50
+
51
+ createReadStream(statsObj) {
52
+ const excludeKeys = this.excludeKeysInStat;
53
+ return new Readable({
54
+ read() {
55
+ let isDone = false;
56
+ const objToStringGen = convertObjectToStringGen(statsObj, excludeKeys);
57
+
58
+ while (!isDone) {
59
+ const {
60
+ done,
61
+ value
62
+ } = objToStringGen.next();
63
+
64
+ if (done) {
65
+ isDone = true;
66
+ this.push(null);
67
+ } else {
68
+ this.push(value);
69
+ }
70
+ }
71
+ }
72
+
73
+ });
74
+ }
75
+
76
+ emitStats(statsJson) {
77
+ return this.writeStatsFileInAStream(statsJson);
78
+ }
79
+
80
+ }
81
+
82
+ module.exports = StatsPlugin;
@@ -11,6 +11,8 @@ var _fs = _interopRequireDefault(require("fs"));
11
11
 
12
12
  var _utils = require("../utils");
13
13
 
14
+ var _log = require("../utils/log");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  let excludeDocsJSON = '{}';
@@ -97,10 +99,10 @@ class UnusedFilesFindPlugin {
97
99
  Object.keys(unDocsCompObj).forEach(key => {
98
100
  if (unDocsCompObj[key].length > 0) {
99
101
  if (key === 'withoutDocs') {
100
- (0, _utils.log)('\x1b[36m%s\x1b[0m', '\nPlease write docs file for below componenst :- \n');
102
+ (0, _log.log)('\x1b[36m%s\x1b[0m', '\nPlease write docs file for below componenst :- \n');
101
103
  unDocsCompObj[key].forEach(value => {
102
104
  if (!excludeDocsArray.docs.exclude.includes(value)) {
103
- (0, _utils.log)('\x1b[33m%s\x1b[0m', `${value}`);
105
+ (0, _log.log)('\x1b[33m%s\x1b[0m', `${value}`);
104
106
  }
105
107
  });
106
108
  }
@@ -162,10 +164,10 @@ class UnusedFilesFindPlugin {
162
164
  });
163
165
 
164
166
  if (!unusedFiles.length) {
165
- (0, _utils.log)('There is no unused files');
167
+ (0, _log.log)('There is no unused files');
166
168
  } else {
167
169
  if (this.outputFileName) {
168
- (0, _utils.log)(`You can see unused files info from ${_path.default.join(outputPath, this.outputFileName)} path`);
170
+ (0, _log.log)(`You can see unused files info from ${_path.default.join(outputPath, this.outputFileName)} path`);
169
171
  (0, _utils.makeDir)(outputPath);
170
172
  (0, _utils.writeFile)(_path.default.join(outputPath, this.outputFileName), JSON.stringify(unusedFiles)).then(() => {
171
173
  if (this.sstest) {
@@ -179,7 +181,7 @@ class UnusedFilesFindPlugin {
179
181
  unusedFiles.forEach(file => {
180
182
  _fs.default.unlinkSync(file);
181
183
 
182
- (0, _utils.log)(`Deleted - ${file}`);
184
+ (0, _log.log)(`Deleted - ${file}`);
183
185
  });
184
186
  }
185
187
  });
@@ -6,15 +6,13 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.isFileNameMatchingPattern = isFileNameMatchingPattern;
7
7
  exports.isFileNameMatchingPluginPattern = isFileNameMatchingPluginPattern;
8
8
 
9
- var _windowsModification = require("../../loaderUtils/windowsModification");
10
-
11
9
  var _ignore = _interopRequireDefault(require("ignore"));
12
10
 
13
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
12
 
15
13
  const path = require('path');
16
14
 
17
- let aliasNames = {
15
+ const aliasNames = {
18
16
  valueReplacer: 'postcss-value-replacer',
19
17
  selectorReplace: 'postcss-selector-replace-new',
20
18
  hasRTL: 'postcss-rtl',
@@ -48,60 +46,47 @@ unique scenario
48
46
  function isFileNameMatchingPattern({
49
47
  filename,
50
48
  filterObject,
51
- plugins
49
+ plugins,
50
+ order
52
51
  }) {
53
- const finalPlugins = []; // console.log(rootDir);
54
- // const regex = `^(.+?)${rootDir}?\\\\`;
55
-
56
- const newFilename = path.relative(path.parse(process.cwd()).base, filename); //windowsModificationFile(filename).replace(
57
- // new RegExp(regex, 'gi'),
58
- // ''
59
- // );
60
- // path.relative('supportapp', 'd:\')
61
-
62
- Object.keys(filterObject).forEach(key => {
63
- plugins.forEach(x => {
64
- // console.log(key, x.postcssPlugin);
65
- if (aliasNames[key] === x.postcssPlugin) {
66
- const ig = (0, _ignore.default)({
67
- allowRelativePaths: true
68
- }).add(filterObject[key]);
52
+ const pluginObj = {};
53
+ plugins.forEach(p => {
54
+ pluginObj[p.postcssPlugin] = p;
55
+ });
56
+ const finalPlugins = order.filter(key => {
57
+ const pluginSpecificFilter = filterObject[key];
58
+
59
+ if (!pluginSpecificFilter || pluginSpecificFilter.length === 0) {
60
+ return true;
61
+ } // eslint-disable-next-line no-use-before-define
62
+
63
+
64
+ const isMatching = isFilePathMatchingPattern(filename, pluginSpecificFilter);
65
+ return isMatching;
66
+ }).map(key => {
67
+ const p = pluginObj[aliasNames[key]];
68
+ return p;
69
+ }); // if unknown key given in plugins and pattern loop will run but post-css plugin won't be available and will be undefined in array
70
+ // So we do filter as safety measure.
71
+
72
+ return finalPlugins.filter(Boolean);
73
+ }
69
74
 
70
- if (ig.ignores(newFilename)) {
71
- // console.log(newFilename);
72
- finalPlugins.push(x);
73
- }
74
- }
75
- });
76
- }); // console.log(filename);
77
- // console.log(finalPlugins);
78
- // console.log('----------------------------------------------------------------------')
75
+ function isFilePathMatchingPattern(filePath, patterns) {
76
+ if (patterns.length === 0) {
77
+ return true;
78
+ }
79
79
 
80
- return finalPlugins; // console.log(filename, filterObject);
80
+ const ig = (0, _ignore.default)({
81
+ allowRelativePaths: true
82
+ }).add(patterns);
83
+ return ig.ignores(filePath);
81
84
  }
82
85
 
83
86
  function isFileNameMatchingPluginPattern({
84
87
  filename,
85
- filterArr // =process.cwd()
86
-
88
+ filterArr
87
89
  }) {
88
- // console.log(rootDir);
89
- let include = true; // console.log(rootDir);
90
- // const regex = `^(.+?)${rootDir}?\\\\`;
91
- // console.log(plugin);
92
-
93
- const newFilename = path.relative(path.parse(process.cwd()).base, filename); // const newFilename = windowsModificationFile(filename).replace(
94
- // new RegExp(regex, 'gi'),
95
- // ''
96
- // );
97
-
98
- const ig = (0, _ignore.default)({
99
- allowRelativePaths: true
100
- }).add(filterArr);
101
-
102
- if (!ig.ignores(newFilename)) {
103
- include = false;
104
- }
105
-
106
- return include;
90
+ const newFilename = path.relative(path.parse(process.cwd()).base, filename);
91
+ return isFilePathMatchingPattern(newFilename, filterArr);
107
92
  }
@@ -63,7 +63,7 @@ function convertToCalc(pxReplacement, value) {
63
63
 
64
64
  function convertCalcValue(pxReplacement, parsedValue) {
65
65
  Object.keys(parsedValue).forEach(key => {
66
- if (parsedValue[key].includes('px')) {
66
+ if (pxReplacement && parsedValue[key].includes('px')) {
67
67
  parsedValue[key] = pxReplacement.replace('$$', parsedValue[key].replace('px', ''));
68
68
  }
69
69
  });
@@ -95,7 +95,9 @@ function variableConverter(rootOriginal, variables, settingsObject) {
95
95
  }
96
96
 
97
97
  const pxReplacement = settingsObject[variables[decl.prop]].replacements.px;
98
- const valArr = decl.value.split(' '); // single values are considered in the above array and converted below
98
+ let valArr = decl.value.split(' ');
99
+ valArr = valArr.filter(x => x.trim() !== '');
100
+ valArr = valArr.map(x => x.replace(/\r|\t|\n/gi, '')); // single values are considered in the above array and converted below
99
101
 
100
102
  valArr.forEach((value, index) => {
101
103
  if (value.includes('px')) {
@@ -4,29 +4,19 @@ var _postcss = _interopRequireDefault(require("postcss"));
4
4
 
5
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
6
 
7
- // module.exports = postcss.plugin('postcss-value-replacer', opts => {
8
- // const { plugins } = opts;
9
- // return (root, result) => {
10
- // const inputFile = root.source.input.file;
11
- // let isIgnoredFile= opts.ignore.some(file => inputFile.indexOf(file)!==-1);
12
- // if (!isIgnoredFile) {
13
- // const handler = response =>
14
- // response.messages.forEach(msg => result.messages.push(msg));
15
- // return postcss(plugins)
16
- // .process(root, { from: undefined })
17
- // .then(handler);
18
- // }
19
- // };
20
- // });
21
- // export default
22
7
  module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
23
8
  root => {
24
9
  root.walkDecls(decl => {
25
10
  valueReplacer.forEach(obj => {
26
11
  if (obj.props.indexOf(decl.prop) !== -1) {
27
- let ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
12
+ const ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
28
13
  ks.forEach(k => {
29
- decl.value = decl.value.replace(k, obj.values[k]);
14
+ // if (/^\^.*\$$/gi.test(k)) {
15
+ if (k.startsWith('^') && k.endsWith('$')) {
16
+ decl.value = decl.value.replace(new RegExp(k), obj.values[k]);
17
+ } else {
18
+ decl.value = decl.value.replace(k, obj.values[k]);
19
+ }
30
20
  }); //decl.value = obj.values[decl.value];
31
21
  }
32
22
  }); //console.log({root, roots:root+""}, root+"")