@zohodesk/react-cli 1.1.1 → 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 (78) hide show
  1. package/.vscode/settings.json +25 -0
  2. package/README.md +446 -35
  3. package/bin/cli.js +17 -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 +10 -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/workerLoader.js +37 -22
  34. package/lib/logger.js +7 -0
  35. package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
  36. package/lib/pluginUtils/getDevPlugins.js +24 -8
  37. package/lib/pluginUtils/getProdPlugins.js +34 -6
  38. package/lib/plugins/CssOrderControlPlugin.js +36 -0
  39. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
  40. package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
  41. package/lib/plugins/EventsHandlingPlugin.js +34 -0
  42. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
  43. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +4 -1
  44. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +14 -0
  45. package/lib/plugins/ReportGeneratePlugin.js +8 -6
  46. package/lib/plugins/ResourceHintsPlugin.js +13 -3
  47. package/lib/plugins/StatsPlugin.js +82 -0
  48. package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
  49. package/lib/plugins/utils/fileHandling.js +36 -51
  50. package/lib/plugins/variableConvertorUtils.js +4 -2
  51. package/lib/postcss-plugins/ValueReplacer.js +7 -17
  52. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
  53. package/lib/postcss-plugins/variableModificationPlugin/index.js +70 -18
  54. package/lib/schemas/index.js +67 -39
  55. package/lib/servers/getCliPath.js +3 -5
  56. package/lib/servers/requireLocalOrGlobal.js +1 -1
  57. package/lib/utils/cssClassNameGenerate.js +43 -5
  58. package/lib/utils/deprecationSupport.js +134 -0
  59. package/lib/utils/getFileType.js +1 -1
  60. package/lib/utils/getOptions.js +31 -69
  61. package/lib/utils/getServerURL.js +7 -2
  62. package/lib/utils/index.js +27 -11
  63. package/lib/utils/initPreCommitHook.js +5 -5
  64. package/lib/utils/log.js +11 -0
  65. package/lib/utils/object-manipulation.js +88 -0
  66. package/lib/utils/pullOrigin.js +3 -3
  67. package/lib/utils/reinstallDependencies.js +3 -3
  68. package/lib/utils/switchBranch.js +4 -2
  69. package/lib/utils/typeCheck.js +10 -0
  70. package/lib/utils/variableConverter.js +26 -11
  71. package/npm-shrinkwrap.json +929 -39
  72. package/package.json +12 -4
  73. package/templates/docs/all.html +1 -0
  74. package/templates/docs/component.html +1 -0
  75. package/templates/docs/components.html +1 -0
  76. package/templates/docs/css/markdown.css +202 -0
  77. package/templates/docs/css/style.css +136 -169
  78. package/templates/docs/index.html +796 -632
@@ -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+"")
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _postcss = _interopRequireDefault(require("postcss"));
4
+
5
+ var _ValueReplacer = _interopRequireDefault(require("../ValueReplacer"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ /* eslint-disable no-use-before-define */
10
+ describe('postcss value replacer tests', () => {
11
+ it('is creating value replaced code', () => {
12
+ const cssInputStr = `.abc{ cursor : text }`;
13
+ const cssOutputStr = `.abc{ cursor : --textCursor }`;
14
+ const cssOptions = [{
15
+ props: ['font', 'font-family', 'cursor'],
16
+ values: {
17
+ 'zdf-': 'zd-react-app-',
18
+ '^text$': '--textCursor'
19
+ }
20
+ }];
21
+ const result = runValueReplacerForCssString(cssInputStr, cssOptions);
22
+ expect(result.css).toEqual(cssOutputStr);
23
+ });
24
+ });
25
+ describe('postcss value replacer tests', () => {
26
+ it('is creating value replaced code', () => {
27
+ const cssInputStr = `.def{ cursor : var(--textBoxCursor) }`;
28
+ const cssOutputStr = `.def{ cursor : var(--textBoxCursor) }`;
29
+ const cssOptions = [{
30
+ props: ['font', 'font-family', 'cursor'],
31
+ values: {
32
+ 'zdf-': 'zd-react-app-',
33
+ '^text$': '--textCursor'
34
+ }
35
+ }];
36
+ const result = runValueReplacerForCssString(cssInputStr, cssOptions);
37
+ expect(result.css).toEqual(cssOutputStr);
38
+ });
39
+ });
40
+
41
+ function runValueReplacerForCssString(cssInputStr, cssOptions) {
42
+ return (0, _postcss.default)([(0, _ValueReplacer.default)(cssOptions)]).process(cssInputStr);
43
+ }
@@ -89,11 +89,16 @@ function pxToCalc(value) {
89
89
  }
90
90
  });
91
91
  });
92
- console.log(arr.join(' '));
93
92
  return arr.join(' ');
94
93
  }
95
94
 
96
- const singleConvertor = (value, changeVal, details, range) => {
95
+ const singleConvertor = ({
96
+ value,
97
+ changeVal,
98
+ details,
99
+ range,
100
+ allowed
101
+ }) => {
97
102
  const {
98
103
  path,
99
104
  filename,
@@ -107,7 +112,15 @@ const singleConvertor = (value, changeVal, details, range) => {
107
112
  }
108
113
  }
109
114
 
115
+ if (allowed && allowed.includes(decl.value) && decl.value.toString() !== '0') {
116
+ return decl.value;
117
+ }
118
+
110
119
  if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
120
+ if (value.trim() === '0px') {
121
+ return '0';
122
+ }
123
+
111
124
  let retVal = value.replace(/(\d+)px/gi, changeVal.replace('$$', '$1'));
112
125
 
113
126
  if (/^-var/.test(retVal)) {
@@ -162,6 +175,7 @@ module.exports = {
162
175
  });
163
176
  const valRegex = new RegExp(regValStr, 'gi');
164
177
  return rootOriginal => {
178
+ // console.log(rootOriginal.source.input.from, 'passed through variable Plugin');
165
179
  rootOriginal.walkRules(rule => {
166
180
  // rule.nodes[-1] = {}
167
181
  // need map, forEach fine less memory
@@ -200,6 +214,9 @@ module.exports = {
200
214
  .replace(/\d+/gi, '').replace('var(--zd_size)', 'px').replace('var(--zd_font_size)', 'px').replace('rect(', '').replace(')', '').replace('px,', 'px').replace(',', '').split(' ').filter(x => x !== ''); // unit = unit.replace(unit, unit.replace('-',''))
201
215
  // console.log('unit : ');
202
216
  // console.log(unit);
217
+ // if (decl.prop === 'height') {
218
+ // console.log(decl.prop, unit, 'case 1');
219
+ // }
203
220
 
204
221
  unit.forEach((val, index) => {
205
222
  allowed.forEach(alwdVal => {
@@ -219,21 +236,49 @@ module.exports = {
219
236
  unitErrorVal = val;
220
237
  }
221
238
  }
222
- }); // console.log(allowed, replacements, range)
239
+ }); // if (decl.prop === 'height') {
240
+ // console.log(decl.prop, unitErrorVal, unitError, unit, 'case 2');
241
+ // }
242
+ // console.log(allowed, replacements, range)
223
243
 
224
244
  if (!unitError) {
225
- // use variable decl.value.split(' ')
226
- if (range) {
245
+ let calcValue = false;
246
+
247
+ if (decl.value.includes('calc')) {
248
+ decl.value = pxToCalc(decl.value);
249
+ calcValue = true;
250
+ } // use variable decl.value.split(' ')
251
+
252
+
253
+ if (range && !calcValue) {
227
254
  // console.log('multiple :', decl.value)
255
+ const tempVal = decl.value; // if (decl.prop === 'height') {
256
+ // console.log(decl.prop, tempVal, decl.value, allowed, 'case 3');
257
+ // }
258
+ // if (decl.prop === 'height') {
259
+ // console.log('allowed!', decl.prop, decl.value, allowed);
260
+ // }
261
+
228
262
  let newVal = '';
229
- decl.value.split(' ').forEach(singleVal => {
230
- newVal += `${singleConvertor(singleVal, settings.replacements.px, {
231
- decl,
232
- filename,
233
- path: fromPath
234
- }, range)} `;
263
+ let splitValues = decl.value.split(' ');
264
+ splitValues = splitValues.filter(val => val.trim() !== '');
265
+ splitValues = splitValues.map(val => val.replace(/\r|\t|\n/gi, ''));
266
+ splitValues.forEach(singleVal => {
267
+ newVal += `${singleConvertor({
268
+ value: singleVal,
269
+ changeVal: settings.replacements.px,
270
+ details: {
271
+ decl,
272
+ filename,
273
+ path: fromPath
274
+ },
275
+ range,
276
+ allowed
277
+ })} `;
235
278
  });
236
- decl.value = newVal;
279
+ decl.value = newVal; // if (decl.prop === 'height') {
280
+ // console.log(decl.prop, tempVal, newVal, 'case 4');
281
+ // }
237
282
  }
238
283
  } else {
239
284
  if (!decl.value.includes('calc')) {
@@ -272,15 +317,22 @@ module.exports = {
272
317
  const valArr = decl.value.split(' ');
273
318
  const settings = settingsObject[decl.prop];
274
319
  const {
275
- range
320
+ range,
321
+ allowed
276
322
  } = settings;
277
323
  const convertedVals = valArr.map(val => {
278
324
  if (val.includes('px')) {
279
- const convertedVal = singleConvertor(val, settings.replacements.px, {
280
- decl,
281
- filename,
282
- path: fromPath
283
- }, range);
325
+ const convertedVal = singleConvertor({
326
+ value: val,
327
+ changeVal: settings.replacements.px,
328
+ details: {
329
+ decl,
330
+ filename,
331
+ path: fromPath
332
+ },
333
+ range,
334
+ allowed
335
+ });
284
336
  return convertedVal ? convertedVal : val;
285
337
  }
286
338