@zohodesk/react-cli 1.1.12 → 1.1.14-exp.1

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.
package/README.md CHANGED
@@ -44,50 +44,49 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
- # 1.1.12
47
+ # 1.1.14-exp.1 (20-9-2023)
48
48
 
49
- **Features**
50
- - Generating stats.json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
51
- - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by custom attributes enable flag.
49
+ **Feature:-**
52
50
 
53
- **Changes**
54
- - Added a new config `stats` to control stats file generation.
55
- - Using Existing custom attributes flag, we can control resource cleanup plugin.
51
+ - externals was added to Prevent bundling of certain imported packages and instead retrieve these external dependencies at runtime.
52
+ - to use externals, we use the following pattern in `app > externals` :
56
53
 
57
- # 1.1.11-exp.6 (31-8-2023)
54
+ For example
55
+ ```
56
+ externals: {
57
+ <key> : <value>
58
+ }
59
+ ```
60
+ # 1.1.14 (11-9-2023)
58
61
 
59
- **Features**
62
+ **Feature:-**
60
63
 
61
- - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by custom attributes enable flag.
64
+ - Value Replacer supports `^` before and `$` after the word to consider the whole word for replacement. Only if the exact word comes as value, there will be a replacement made.
62
65
 
63
- **Changes**
66
+ **Issue Fix**
64
67
 
65
- - For stats plugin, added the separation of object manipulation method with converting object to string.
68
+ - 'space' character on variable conversion changes to undefined fixed.
69
+ - calc(100%) variable conversion to undefined fixed.
70
+ - height value if text converts to undefined, issue fixed.
66
71
 
67
- # 1.1.11-exp.3 (22-8-2023)
72
+ # 1.1.13 (4-9-2023)
68
73
 
69
74
  **Changes**
70
75
 
71
- - Changed the default name of stats file to `build-report-integrity.json`
72
- - Added optimization to reduce the stats file creation time. like streaming.
73
- - Added support to exclude keys suggested
76
+ - Fixed the issue related to the resource cleanup plugin. (EfcResouceCleanupPlugin)
74
77
 
75
- # 1.1.11-exp.2 (11-8-2023)
76
78
 
77
- **Changes**
79
+ # 1.1.12 (1-9-2023)
78
80
 
79
- - Added more customization support for `stats.json` output.
80
- - Disabling `bundle-analyser` stats report for our customized stats output based on a flag.
81
+ **Features**
81
82
 
82
- # 1.1.11-exp.1 (8-8-2023)
83
+ - Generating stats.json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
84
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by custom attributes enable flag.
83
85
 
84
86
  **Changes**
85
87
 
86
88
  - Added a new config `stats` to control stats file generation.
87
-
88
- **Features:-**
89
-
90
- - Generating stats.json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
89
+ - Using Existing custom attributes flag, we can control resource cleanup plugin.
91
90
 
92
91
  # 1.1.11 (4-8-2023)
93
92
 
@@ -58,3 +58,30 @@ new option `valueReplacer` added for replace css property value while build runn
58
58
  font: zdf-rCallBar_1 !important;
59
59
  }
60
60
  ```
61
+
62
+
63
+ If we need the exact word to be considered for replacement ( that is, if value is `text` and only if the value is `text` and not `text_cursor` or `cursortext` for example, the conversion happens ) we have to use `^` before the word and `$` after the word in the key.
64
+
65
+ # For Example :
66
+ {
67
+ valueReplacer: [
68
+ {
69
+ "props": [
70
+ "cursor",
71
+ "--label_cursor",
72
+ "--checkbox_cursor",
73
+ "--tag_cursor",
74
+ "--button_cursor",
75
+ "--textboxicon_icon_cursor",
76
+ ],
77
+ "values": {
78
+ "^default$": "var(--zdr-cursor-default)",
79
+ "^pointer$": "var(--zdr-cursor-pointer)",
80
+ "^text$": "var(--zdr-cursor-text)",
81
+ "^move$": "var(--zdr-cursor-move)",
82
+ }
83
+ }
84
+ ]
85
+ }
86
+
87
+ - Here we have added `^` before and `$` after default, pointer, text and move. Only if the exact words default, pointer, text and move are used, the values will be converted.
@@ -41,7 +41,8 @@ const {
41
41
  devConsoleExculde,
42
42
  sourcemap,
43
43
  crossorigin,
44
- postCssPluginOrder
44
+ postCssPluginOrder,
45
+ externals
45
46
  }
46
47
  } = options;
47
48
  const {
@@ -151,9 +152,9 @@ module.exports = {
151
152
  }
152
153
  }].filter(Boolean)
153
154
  },
154
- externals: {
155
+ externals: Object.assign({
155
156
  ZC: '$ZC'
156
- },
157
+ }, externals),
157
158
  resolve: (0, _resolvers.moduleResolver)(options),
158
159
  resolveLoader: (0, _resolvers.loaderResolver)(options)
159
160
  };
@@ -46,7 +46,8 @@ const {
46
46
  removePropTypes,
47
47
  devConsoleExculde,
48
48
  crossorigin,
49
- postCssPluginOrder
49
+ postCssPluginOrder,
50
+ externals
50
51
  }
51
52
  } = options;
52
53
  let {
@@ -240,9 +241,9 @@ module.exports = {
240
241
  }
241
242
  }].filter(Boolean)
242
243
  },
243
- externals: {
244
+ externals: Object.assign(externals, {
244
245
  ZC: '$ZC'
245
- },
246
+ }),
246
247
  resolve: (0, _resolvers.moduleResolver)(options),
247
248
  resolveLoader: (0, _resolvers.loaderResolver)(options)
248
249
  };
@@ -193,7 +193,9 @@ const getDevPlugins = (options, publicPath) => {
193
193
  }));
194
194
  instrumentScript && pluginsArr.push(new _plugins.ScriptInstrumentPlugin());
195
195
  customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
196
- customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(customAttributes));
196
+ customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(Object.assign({}, customAttributes, {
197
+ globalCacheObj: context
198
+ })));
197
199
  hasShadowDOM && pluginsArr.push(new _plugins.ShadowDOMSupportPlugin());
198
200
 
199
201
  if (devCssFileBountry) {
@@ -298,7 +298,9 @@ const getProdPlugins = (options, publicPath = '') => {
298
298
 
299
299
 
300
300
  customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
301
- customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(customAttributes));
301
+ customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(Object.assign({}, customAttributes, {
302
+ globalCacheObj: context
303
+ })));
302
304
  enableStats && pluginsArr.push(new _StatsPlugin.default({
303
305
  statsOptions,
304
306
  statsOutputExcludeKeys,
@@ -15,10 +15,14 @@ module.exports = class EfcResouceCleanupPlugin {
15
15
  mainTemplate
16
16
  }) => {
17
17
  mainTemplate.hooks.afterStartup.tap(plugInName, source => {
18
- const attributesArr = Object.entries(this.options.attributes);
18
+ const {
19
+ attributes,
20
+ globalCacheObj
21
+ } = this.options;
22
+ const attributesArr = Object.entries(attributes);
19
23
  const [[attributekey, attributeValue]] = attributesArr;
20
24
  const resourceSelector = `[${attributekey}="${attributeValue}"]`;
21
- return Template.asString([source, Template.indent([` jsonpArray.unInstall = function() {
25
+ return Template.asString([source, Template.indent([` window['${globalCacheObj}Jsonp'].unInstall = function() {
22
26
  Object.keys(installedModules).forEach(installedModulesKey => installedModules[installedModulesKey] = null);
23
27
  Object.keys(modules).forEach(moduleKey => modules[moduleKey] = null);
24
28
  `, `
@@ -27,11 +31,11 @@ module.exports = class EfcResouceCleanupPlugin {
27
31
  __webpack_require__.m = null;
28
32
  __webpack_require__.c = null;
29
33
 
30
- `, `
31
- const addedResources = document.querySelectorAll('${resourceSelector}');
32
- addedResources.forEach(addedResource => addedResource.remove());
33
- }
34
- `])]);
34
+ `, attributekey && attributeValue ? `
35
+ const addedResources = document.querySelectorAll('${resourceSelector}');
36
+ addedResources.forEach(addedResource => addedResource.remove());
37
+ }
38
+ ` : ''])]);
35
39
  });
36
40
  });
37
41
  }
@@ -20,13 +20,13 @@ const statsSchema = {
20
20
 
21
21
  class StatsPlugin {
22
22
  constructor({
23
- statsOptions = {},
24
- statsOutputExcludeKeys = [],
25
- statsFileName = 'bundle-report-integrity.json'
23
+ statsOptions,
24
+ statsOutputExcludeKeys,
25
+ statsFileName
26
26
  }) {
27
- this.excludeKeysInStat = statsOutputExcludeKeys;
28
- this.statsOptions = Object.assign({}, statsSchema, statsOptions);
29
- this.statsFileName = statsFileName;
27
+ this.excludeKeysInStat = statsOutputExcludeKeys || [];
28
+ this.statsFileName = statsFileName || 'bundle-report-integrity.json';
29
+ this.statsOptions = Object.assign({}, statsSchema, statsOptions || {});
30
30
  }
31
31
 
32
32
  apply(compiler) {
@@ -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
+ }
@@ -92,7 +92,13 @@ function pxToCalc(value) {
92
92
  return arr.join(' ');
93
93
  }
94
94
 
95
- const singleConvertor = (value, changeVal, details, range) => {
95
+ const singleConvertor = ({
96
+ value,
97
+ changeVal,
98
+ details,
99
+ range,
100
+ allowed
101
+ }) => {
96
102
  const {
97
103
  path,
98
104
  filename,
@@ -106,6 +112,10 @@ const singleConvertor = (value, changeVal, details, range) => {
106
112
  }
107
113
  }
108
114
 
115
+ if (allowed && allowed.includes(decl.value) && decl.value.toString() !== '0') {
116
+ return decl.value;
117
+ }
118
+
109
119
  if (getNumericValue(value) >= range.start && getNumericValue(value) <= range.end || getNumericValue(value) === 0) {
110
120
  if (value.trim() === '0px') {
111
121
  return '0';
@@ -204,6 +214,9 @@ module.exports = {
204
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('-',''))
205
215
  // console.log('unit : ');
206
216
  // console.log(unit);
217
+ // if (decl.prop === 'height') {
218
+ // console.log(decl.prop, unit, 'case 1');
219
+ // }
207
220
 
208
221
  unit.forEach((val, index) => {
209
222
  allowed.forEach(alwdVal => {
@@ -223,21 +236,49 @@ module.exports = {
223
236
  unitErrorVal = val;
224
237
  }
225
238
  }
226
- }); // 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)
227
243
 
228
244
  if (!unitError) {
229
- // use variable decl.value.split(' ')
230
- 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) {
231
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
+
232
262
  let newVal = '';
233
- decl.value.split(' ').forEach(singleVal => {
234
- newVal += `${singleConvertor(singleVal, settings.replacements.px, {
235
- decl,
236
- filename,
237
- path: fromPath
238
- }, 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
+ })} `;
239
278
  });
240
- decl.value = newVal;
279
+ decl.value = newVal; // if (decl.prop === 'height') {
280
+ // console.log(decl.prop, tempVal, newVal, 'case 4');
281
+ // }
241
282
  }
242
283
  } else {
243
284
  if (!decl.value.includes('calc')) {
@@ -276,15 +317,22 @@ module.exports = {
276
317
  const valArr = decl.value.split(' ');
277
318
  const settings = settingsObject[decl.prop];
278
319
  const {
279
- range
320
+ range,
321
+ allowed
280
322
  } = settings;
281
323
  const convertedVals = valArr.map(val => {
282
324
  if (val.includes('px')) {
283
- const convertedVal = singleConvertor(val, settings.replacements.px, {
284
- decl,
285
- filename,
286
- path: fromPath
287
- }, 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
+ });
288
336
  return convertedVal ? convertedVal : val;
289
337
  }
290
338
 
@@ -729,9 +729,10 @@ var _default = {
729
729
  value: false,
730
730
  cli: 'enable_stats'
731
731
  },
732
- fileName: undefined,
733
- options: undefined,
734
- excludeKeys: undefined
735
- }
732
+ fileName: null,
733
+ options: null,
734
+ excludeKeys: null
735
+ },
736
+ externals: null
736
737
  };
737
738
  exports.default = _default;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.10",
3
+ "version": "1.1.14-exp.1",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@zohodesk/react-cli",
9
- "version": "1.1.10",
9
+ "version": "1.1.14-exp.1",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@babel/cli": "7.10.5",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.12",
3
+ "version": "1.1.14-exp.1",
4
4
  "description": "A CLI tool for build modern web application and libraries",
5
5
  "scripts": {
6
6
  "init": "node ./lib/utils/init.js",