@zohodesk/react-cli 1.1.19-exp.17 → 1.1.19-exp.18

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,6 +44,18 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.1.19-exp.18
48
+
49
+ **Changes**
50
+
51
+ - To do further build size optimization by utilizing webpack provided config.
52
+
53
+ ```
54
+ innerGraph: true,
55
+ usedExports: true,
56
+ sideEffects: true
57
+ ```
58
+
47
59
  # 1.1.19 (5-2-2024)
48
60
 
49
61
  **Feature:-**
package/docs/ReactLive.md CHANGED
@@ -11,4 +11,8 @@
11
11
 
12
12
  # v1.1.2 update:
13
13
 
14
- * ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
14
+ * ReactLiveConverter filepath changed to 'reactLiveConverter.js' in docLoader file
15
+
16
+ # v1.1.20 update:
17
+
18
+ * enhancedReactLiveConverter.js added and imported in docLoader file
@@ -102,7 +102,10 @@ module.exports = {
102
102
  // exclude: /\/smap/
103
103
  // })
104
104
  // ],
105
- moduleIds: 'named'
105
+ moduleIds: 'named',
106
+ usedExports: true,
107
+ innerGraph: true,
108
+ sideEffects: true
106
109
  },
107
110
  stats: {
108
111
  children: false,
@@ -6,7 +6,7 @@ var _getOptions = _interopRequireDefault(require("../utils/getOptions.js"));
6
6
 
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
 
9
- var _reactLiveConvertor = require("./reactLiveConvertor");
9
+ var _enhancedReactLiveConverter = require("./enhancedReactLiveConverter.js");
10
10
 
11
11
  var _markdownLoader = require("./markdownLoader.js");
12
12
 
@@ -27,7 +27,7 @@ module.exports = function (source) {
27
27
  const src = _fs.default.readFileSync(originalFilePath).toString();
28
28
 
29
29
  options.docs.enableMDParser && (source = (0, _markdownLoader.markdownParser)(source));
30
- options.docs.enableReactLive && (source = (0, _reactLiveConvertor.reactLiveConvertor)(source, originalFilePath)); //to Enable the ReactLive Converter
30
+ options.docs.enableReactLive && (source = (0, _enhancedReactLiveConverter.enhancedReactLiveConverter)(source, originalFilePath)); //to Enable the ReactLive Converter
31
31
 
32
32
  return `${source};${name}.source=${JSON.stringify(src)};${name}.filePath=${JSON.stringify(filePath)}`;
33
33
  };
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.enhancedReactLiveConverter = enhancedReactLiveConverter;
7
+
8
+ const parser = require('@babel/parser');
9
+
10
+ const traverse = require('@babel/traverse').default;
11
+
12
+ const t = require("@babel/types");
13
+
14
+ const path = require('path');
15
+
16
+ function getFilename(originalFilePath) {
17
+ const [fileName] = path.basename(originalFilePath).split('.');
18
+ return fileName;
19
+ }
20
+
21
+ function convertKeyToValue(object = {}) {
22
+ let keys = Object.keys(object);
23
+ let values = Object.values(object);
24
+ return keys.reduce((value, item, i) => {
25
+ if (item.includes(',')) {
26
+ item = item.replace(/{|}/g, "");
27
+ item = '{ ' + item + ' }';
28
+ }
29
+
30
+ value = value + "'" + values[i] + "'" + ": " + item + ",";
31
+ return value;
32
+ }, '');
33
+ }
34
+
35
+ function mergeDuplicateValues(obj) {
36
+ let mergedObj = {};
37
+
38
+ for (let key in obj) {
39
+ if (obj.hasOwnProperty(key)) {
40
+ let value = obj[key];
41
+ let existingKey = Object.keys(mergedObj).find(k => mergedObj[k] === value);
42
+
43
+ if (existingKey) {
44
+ mergedObj[existingKey + ' , ' + key] = value;
45
+ delete mergedObj[existingKey];
46
+ } else {
47
+ mergedObj[key] = value;
48
+ }
49
+ }
50
+ }
51
+
52
+ return mergedObj;
53
+ }
54
+
55
+ function enhancedReactLiveConverter(source, originalFilePath) {
56
+ const fileName = getFilename(originalFilePath);
57
+
58
+ if (!source) {
59
+ return '';
60
+ }
61
+
62
+ let docCode = '';
63
+ const fileContent = source.replace(/[\s\r\n]*$/, '');
64
+ const ast = parser.parse(fileContent, {
65
+ sourceType: 'module',
66
+ plugins: ['jsx', 'classProperties']
67
+ });
68
+
69
+ function createImportStatements(input) {
70
+ let output = '';
71
+
72
+ for (const key in input) {
73
+ if (input.hasOwnProperty(key) && key !== 'React') {
74
+ output += `import ${key} from '${input[key]}';\n`;
75
+ }
76
+ }
77
+
78
+ return output;
79
+ }
80
+
81
+ const importBlock = {};
82
+ const printableCode = {};
83
+ let remainingBlock = ''; // Traverse the AST and find the import and export blocks
84
+
85
+ let remainingCode = ast.program.body.filter(node => node.type !== 'ImportDeclaration').filter(node => node.type !== 'ExpressionStatement').map(node => fileContent.substring(node.start, node.end)).join('').trim();
86
+ traverse(ast, {
87
+ ImportDeclaration(path) {
88
+ path.node.specifiers.map(specifier => {
89
+ if (t.isImportSpecifier(specifier)) {
90
+ importBlock[`{ ${specifier.local.name} }`] = path.node.source.value;
91
+ printableCode[`{ ${specifier.local.name} }`] = path.node.source.value;
92
+ return `{'${specifier.imported.name}': ${specifier.local.name}}`;
93
+ } else if (t.isImportDefaultSpecifier(specifier)) {
94
+ importBlock[`${specifier.local.name}`] = `${path.node.source.value}`;
95
+ printableCode[`${specifier.local.name}`] = `${path.node.source.value} `;
96
+ return specifier.local.name;
97
+ }
98
+ }).join(", ");
99
+ },
100
+
101
+ ExpressionStatement(path) {
102
+ const expression = path.get('expression');
103
+ const expressionLeft = expression.get('left');
104
+
105
+ if (path.isExpressionStatement() && expression.isAssignmentExpression() && expressionLeft.isMemberExpression()) {
106
+ const docCheck = expressionLeft.toString();
107
+
108
+ if (docCheck === `${fileName}.docs`) {
109
+ docCode = expression.toString();
110
+ } else if (docCheck.includes(fileName)) {
111
+ const startIndex = path.node.start;
112
+ const endIndex = path.node.end;
113
+ remainingBlock += fileContent.slice(startIndex, endIndex);
114
+ }
115
+ }
116
+ }
117
+
118
+ });
119
+ remainingCode = remainingCode.replace(/__DOCS__/, true);
120
+ remainingCode = remainingCode.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
121
+ remainingBlock = remainingBlock.replace(/`/g, '\\`').replace(/\$\{/g, '$\\{');
122
+ const addBractick = `\`
123
+ ${createImportStatements(printableCode)}
124
+ ${remainingCode}
125
+
126
+ ${remainingBlock}\`
127
+ `;
128
+ const template = `
129
+
130
+ ${createImportStatements(importBlock)}
131
+
132
+ import { LiveProviderv3, LiveEditorv3, LiveErrorv3, LivePreviewv3, Wrapper, EditorWrapper , ErrorWrapper, PreviewWrapper } from '@zohodesk-private/react-live/es/index'
133
+
134
+ export default class ${fileName} extends React.Component{
135
+ render(){
136
+ return(
137
+ <LiveProviderv3 needToolBox scope={{import: {${convertKeyToValue(mergeDuplicateValues(printableCode))}}}} code={${addBractick}}>
138
+ <Wrapper>
139
+ <EditorWrapper><LiveEditorv3 /></EditorWrapper>
140
+ <PreviewWrapper><LivePreviewv3 /></PreviewWrapper>
141
+ <LiveErrorv3 needStyle />
142
+ </Wrapper>
143
+ </LiveProviderv3>
144
+ )
145
+ }
146
+ }
147
+
148
+ ${docCode}
149
+ `;
150
+ return template;
151
+ }
@@ -19,32 +19,32 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
19
19
  /* import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';
20
20
  import ExternalsPlugin from 'webpack/lib/ExternalsPlugin'; */
21
21
  const schema = {
22
- 'type': 'object',
23
- 'properties': {
24
- 'publicPath': {
25
- 'anyOf': [{
26
- 'type': 'string'
22
+ type: 'object',
23
+ properties: {
24
+ publicPath: {
25
+ anyOf: [{
26
+ type: 'string'
27
27
  }, {
28
- 'instanceof': 'Function'
28
+ instanceof: 'Function'
29
29
  }]
30
30
  },
31
- 'filename': {
32
- 'anyOf': [{
33
- 'type': 'string',
34
- 'minLength': 1
31
+ filename: {
32
+ anyOf: [{
33
+ type: 'string',
34
+ minLength: 1
35
35
  }, {
36
- 'instanceof': 'Function'
36
+ instanceof: 'Function'
37
37
  }]
38
38
  },
39
- 'chunkFilename': {
40
- 'type': 'string',
41
- 'minLength': 1
39
+ chunkFilename: {
40
+ type: 'string',
41
+ minLength: 1
42
42
  },
43
- 'esModule': {
44
- 'type': 'boolean'
43
+ esModule: {
44
+ type: 'boolean'
45
45
  }
46
46
  },
47
- 'additionalProperties': false
47
+ additionalProperties: false
48
48
  }; // eslint-disable-next-line
49
49
 
50
50
  function loader() {}
@@ -112,25 +112,40 @@ function pitch(request) {
112
112
  }
113
113
 
114
114
  function workerCode() {
115
+ if (this.workerInstance) {
116
+ return this.workerInstance;
117
+ }
118
+
115
119
  let blob;
116
120
 
117
121
  try {
118
122
  blob = new Blob([`importScripts('${this.workerUrl}');`], {
119
- 'type': 'application/javascript'
123
+ type: 'application/javascript'
120
124
  });
121
125
  } catch (e1) {
122
126
  throw new Error(e1);
123
127
  }
124
128
 
125
- let url = window.URL || window.webkitURL;
126
- let blobUrl = url.createObjectURL(blob);
127
- let worker = new Worker(blobUrl);
128
- return worker;
129
+ const url = window.URL || window.webkitURL;
130
+ const blobUrl = url.createObjectURL(blob);
131
+ this.workerInstance = new Worker(blobUrl);
132
+ return this.workerInstance;
129
133
  }
130
134
 
131
- return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} {\n
135
+ return cb(null, `const workerObj ={\n
136
+ workerInstance: null, \n
132
137
  workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
133
138
  getInstance: ${workerCode} \n
134
- }`);
139
+ };\n
140
+ workerObj.getInstance();
141
+ ${options.esModule ? 'export default' : 'module.exports ='} workerObj;
142
+ `); // return cb(
143
+ // null,
144
+ // `${options.esModule ? 'export default' : 'module.exports ='} {\n
145
+ // workerInstance: null, \n
146
+ // workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
147
+ // getInstance: ${workerCode} \n
148
+ // }`
149
+ // );
135
150
  });
136
151
  }
@@ -26,6 +26,12 @@ const defaultHTMLMiniFyOption = {
26
26
  removeStyleLinkTypeAttributes: true,
27
27
  useShortDoctype: true
28
28
  };
29
+ const defaultScriptLoadingStrategy = 'defer';
30
+
31
+ function getScriptLoadingStrategy(scriptLoadingStategey) {
32
+ const allowedScriptLoadingStrategies = ['blocking', 'defer'];
33
+ return allowedScriptLoadingStrategies.includes(scriptLoadingStategey) ? scriptLoadingStategey : defaultScriptLoadingStrategy;
34
+ }
29
35
 
30
36
  function configHtmlWebpackPlugins(plugins, {
31
37
  enableChunkHash = false,
@@ -33,7 +39,8 @@ function configHtmlWebpackPlugins(plugins, {
33
39
  inject,
34
40
  crossorigin,
35
41
  hasEFC,
36
- minify: minifyHtmlOptions = false
42
+ minify: minifyHtmlOptions = false,
43
+ scriptLoadingStrategey
37
44
  }) {
38
45
  const optionsHtmlWebpack = {
39
46
  chunksSortMode: 'none',
@@ -44,7 +51,7 @@ function configHtmlWebpackPlugins(plugins, {
44
51
  // ? minifyHtmlOptions
45
52
  // : minifyHtmlOptions,,
46
53
  templateParameters: _common.templateParameters,
47
- scriptLoading: 'defer',
54
+ scriptLoading: getScriptLoadingStrategy(scriptLoadingStrategey),
48
55
  inject: inject
49
56
  };
50
57
 
@@ -37,8 +37,6 @@ var _configHtmlWebpackPlugins = require("./configHtmlWebpackPlugins");
37
37
 
38
38
  var _EfcResourceCleanupPlugin = _interopRequireDefault(require("../plugins/EfcResourceCleanupPlugin"));
39
39
 
40
- var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
41
-
42
40
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
41
 
44
42
  // import { windowsModification } from '../loaderUtils/windowsModification';
@@ -62,7 +60,8 @@ const getDevPlugins = (options, publicPath) => {
62
60
  mode
63
61
  },
64
62
  htmlTemplate: {
65
- inject
63
+ inject,
64
+ scriptLoadingStrategey
66
65
  },
67
66
  crossorigin
68
67
  },
@@ -168,7 +167,8 @@ const getDevPlugins = (options, publicPath) => {
168
167
  minify: false,
169
168
  inject,
170
169
  crossorigin,
171
- hasEFC
170
+ hasEFC,
171
+ scriptLoadingStrategey
172
172
  });
173
173
 
174
174
  if (hasEFC) {
@@ -193,16 +193,11 @@ const getDevPlugins = (options, publicPath) => {
193
193
  i18nManifestFileName,
194
194
  mainChunkName: 'main'
195
195
  }));
196
- instrumentScript && pluginsArr.push(new _plugins.ScriptInstrumentPlugin()); // customAttributes.enable &&
197
- // console.log('hello ')
198
- // pluginsArr.push(new CustomAttributePlugin(customAttributes));
199
- // customAttributes.enable &&
200
- // pluginsArr.push(
201
- // new EfcResouc eCleanupPlugin(
202
- // Object.assign({}, customAttributes, { globalCacheObj: context })
203
- // )
204
- // );
205
-
196
+ instrumentScript && pluginsArr.push(new _plugins.ScriptInstrumentPlugin());
197
+ customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
198
+ customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(Object.assign({}, customAttributes, {
199
+ globalCacheObj: context
200
+ })));
206
201
  hasShadowDOM && pluginsArr.push(new _plugins.ShadowDOMSupportPlugin());
207
202
 
208
203
  if (devCssFileBountry) {
@@ -224,13 +219,12 @@ const getDevPlugins = (options, publicPath) => {
224
219
  exclude: exclude.selectorWeight,
225
220
  patterns
226
221
  }));
227
- }
228
-
229
- pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin()); // if (pluginObject.minifier) {
222
+ } // if (pluginObject.minifier) {
230
223
  // // console.log('minifier active');
231
224
  // pluginsArr.push(new MinifierPlugin());
232
225
  // }
233
226
 
227
+
234
228
  return pluginsArr.filter(Boolean);
235
229
  };
236
230
 
@@ -78,7 +78,8 @@ const getProdPlugins = (options, publicPath = '') => {
78
78
  } = options.app;
79
79
  const {
80
80
  inject,
81
- minify: minifyHtmlOptions
81
+ minify: minifyHtmlOptions,
82
+ scriptLoadingStrategey
82
83
  } = htmlTemplate;
83
84
  const {
84
85
  i18n
@@ -176,6 +177,7 @@ const getProdPlugins = (options, publicPath = '') => {
176
177
  folder,
177
178
  inject,
178
179
  minify: minifyHtmlOptions,
180
+ scriptLoadingStrategey,
179
181
  crossorigin,
180
182
  hasEFC
181
183
  });
@@ -237,7 +239,7 @@ const getProdPlugins = (options, publicPath = '') => {
237
239
  if (bundleAnalyze) {
238
240
  pluginsArr.push(new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
239
241
  analyzerMode: 'static',
240
- generateStatsFile: !enableStats,
242
+ generateStatsFile: false,
241
243
  openAnalyzer: false,
242
244
  statsOptions: enableStats ? null : {
243
245
  source: false,
@@ -228,12 +228,8 @@ class I18nDownlodLogic {
228
228
  if(dataSrc === srcPath || dataSrc === fullsrcPath){ return resolve();}
229
229
  }
230
230
  var scriptTag = document.createElement("script");
231
- scriptTag.onload = () => {
232
- resolve();
233
- scriptTag.onerror = scriptTag.onload = null;
234
- };
231
+ scriptTag.onload = resolve;
235
232
  scriptTag.onerror = function(event) {
236
- scriptTag.onerror = scriptTag.onload = null;
237
233
  var request = event && event.target && event.target.src || fullsrcPath;
238
234
  var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + request + ")");
239
235
  err.code = "I18N_CHUNK_LOAD_FAILED";
@@ -241,7 +237,6 @@ class I18nDownlodLogic {
241
237
  delete installedI18nChunks[chunkId];
242
238
  scriptTag.parentNode.removeChild(scriptTag);
243
239
  reject(err);
244
- scriptTag.onerror = scriptTag.onload = null;
245
240
  };
246
241
  ${mainTemplate.requireFn}.nc && scriptTag.setAttribute("nonce", ${mainTemplate.requireFn}.nc);
247
242
  scriptTag.src = fullsrcPath;
@@ -322,7 +322,8 @@ var _default = {
322
322
  },
323
323
  htmlTemplate: {
324
324
  minify: null,
325
- inject: true
325
+ inject: true,
326
+ scriptLoadingStrategey: ''
326
327
  },
327
328
  removePropTypes: false,
328
329
  customChunksBaseConfig: null,
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.18-exp.1",
3
+ "version": "1.1.19-exp.18",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@zohodesk/react-cli",
9
- "version": "1.1.18-exp.1",
9
+ "version": "1.1.19-exp.18",
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.19-exp.17",
3
+ "version": "1.1.19-exp.18",
4
4
  "description": "A CLI tool for build modern web application and libraries",
5
5
  "scripts": {
6
6
  "init": "node ./lib/utils/init.js",
@@ -1,36 +0,0 @@
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
- console.log("hi"); // NOTE: we not using this, Reason currently this option is only need for EFC,
14
- // So it do not needed.
15
-
16
- compiler.hooks.thisCompilation.tap({
17
- name: 'CustomAttributePlugin',
18
- stage: 1,
19
- fn: compilation => {
20
- compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
21
- // const str = attributeSetTemplate(cssAttributes, 'linkTag');
22
- const replacesourcedStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null');
23
- const re = replacesourcedStr.replace('linkTag.onload = resolve', `linkTag.onload = () => {
24
- resolve();
25
- linkTag.onerror = linkTag.onload = null
26
- };`); // console.log({ s: source, r: replacedStr });
27
-
28
- return re;
29
- });
30
- }
31
- });
32
- }
33
-
34
- }
35
-
36
- exports.EventsHandlingPlugin = EventsHandlingPlugin;