@zohodesk/react-cli 1.1.22-exp.5 → 1.1.23-exp.1

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -44,6 +44,61 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.1.23 (28-06-2024)
48
+
49
+ **Features**
50
+
51
+ - alias feature added for library, application and jest. To enable it , configure your `react-cli.config.js` as below
52
+
53
+ ```
54
+ {
55
+ alias: {
56
+ "@components": './src/components,
57
+ }
58
+ }
59
+ ```
60
+
61
+ - For devmapping config jsConfig.json ad below
62
+
63
+ ```
64
+ {
65
+ "compilerOptions": {
66
+ "baseUrl": ".",
67
+ "paths": {
68
+ "@components/*": [ "./src/components/*"],
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ - Customized Script loading strategy added. To enabled it, configure your `react-cli.config.js` as below
75
+
76
+ ```
77
+ {
78
+ app: {
79
+ htmlTemplate: {
80
+ customScriptLoadingStrategey: {
81
+ enable: true,
82
+ options: {
83
+ async: [/.*js$/],
84
+ defer: [/^main.*\.js$/]
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ **Changes**
93
+
94
+ - Worker loading logic
95
+
96
+ # 1.1.22 (6-6-2024)
97
+
98
+ **Changes**
99
+
100
+ - Bug fix in Typescript
101
+
47
102
  # 1.1.21 (4-6-2024)
48
103
 
49
104
  - TypeScript support has been added for the application, library, and Jest.
@@ -59,6 +114,28 @@ Now to run app
59
114
  ```
60
115
  - The Memory leak issue while downloading i18n and CSS files has been fixed
61
116
 
117
+
118
+ # 1.1.20-exp.1
119
+
120
+ **Changes**
121
+
122
+ - Added memory leak fixes for script, links tags
123
+
124
+ **Feature**
125
+ - Custom Script loading strategy support for initial html script tags.
126
+
127
+ # 1.1.19-exp.18
128
+
129
+ **Changes**
130
+
131
+ - To do further build size optimization by utilizing webpack provided config.
132
+
133
+ ```
134
+ innerGraph: true,
135
+ usedExports: true,
136
+ sideEffects: true
137
+ ```
138
+
62
139
  # 1.1.20 (27-5-2024)
63
140
 
64
141
  **Feature**
@@ -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
  }
@@ -13,6 +13,10 @@ var _htmlWebpackInjectAttributesPlugin = _interopRequireDefault(require("html-we
13
13
 
14
14
  var _common = require("../common");
15
15
 
16
+ var _utils = require("../utils");
17
+
18
+ var _CustomScriptLoadingStrategyPlugin = _interopRequireDefault(require("../plugins/CustomScriptLoadingStrategyPlugin"));
19
+
16
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
21
 
18
22
  const defaultHTMLMiniFyOption = {
@@ -26,6 +30,51 @@ const defaultHTMLMiniFyOption = {
26
30
  removeStyleLinkTypeAttributes: true,
27
31
  useShortDoctype: true
28
32
  };
33
+ const defaultScriptLoadingStrategy = 'defer';
34
+ const allowedScriptLoadingStrategies = ['blocking', 'defer', 'async', 'module'];
35
+
36
+ function isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey) {
37
+ return allowedScriptLoadingStrategies.includes(scriptLoadingStategey);
38
+ }
39
+
40
+ function getScriptLoadingStrategyForStringType(scriptLoadingStategey) {
41
+ if (isAllowedScriptLoadingStrategyUsed(scriptLoadingStategey)) {
42
+ return scriptLoadingStategey;
43
+ }
44
+
45
+ return defaultScriptLoadingStrategy;
46
+ }
47
+
48
+ function getScriptLoadingStrategyForObject(scriptLoadingStategey) {
49
+ if (Object.keys(scriptLoadingStategey).length === 0) {
50
+ return defaultScriptLoadingStrategy;
51
+ }
52
+
53
+ const isAllowedScriptLoadingStrategy = Object.keys(scriptLoadingStategey).every(key => isAllowedScriptLoadingStrategyUsed(key));
54
+
55
+ if (isAllowedScriptLoadingStrategy) {
56
+ return Object.assign({}, scriptLoadingStategey);
57
+ }
58
+
59
+ console.warn('un supported script loading strategy used', scriptLoadingStategey);
60
+ return defaultScriptLoadingStrategy;
61
+ }
62
+
63
+ function getScriptLoadingStrategy(scriptLoadingStategey) {
64
+ if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'string') {
65
+ return {
66
+ [getScriptLoadingStrategyForStringType(scriptLoadingStategey)]: [/.*/]
67
+ };
68
+ }
69
+
70
+ if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'object') {
71
+ return getScriptLoadingStrategyForObject(scriptLoadingStategey);
72
+ }
73
+
74
+ return {
75
+ [defaultScriptLoadingStrategy]: [/.*/]
76
+ };
77
+ }
29
78
 
30
79
  function configHtmlWebpackPlugins(plugins, {
31
80
  enableChunkHash = false,
@@ -33,7 +82,8 @@ function configHtmlWebpackPlugins(plugins, {
33
82
  inject,
34
83
  crossorigin,
35
84
  hasEFC,
36
- minify: minifyHtmlOptions = false
85
+ minify: minifyHtmlOptions = false,
86
+ customScriptLoadingStrategey = {}
37
87
  }) {
38
88
  const optionsHtmlWebpack = {
39
89
  chunksSortMode: 'none',
@@ -44,7 +94,7 @@ function configHtmlWebpackPlugins(plugins, {
44
94
  // ? minifyHtmlOptions
45
95
  // : minifyHtmlOptions,,
46
96
  templateParameters: _common.templateParameters,
47
- scriptLoading: 'defer',
97
+ scriptLoading: defaultScriptLoadingStrategy,
48
98
  inject: inject
49
99
  };
50
100
 
@@ -56,4 +106,14 @@ function configHtmlWebpackPlugins(plugins, {
56
106
  crossorigin && plugins.push(new _htmlWebpackInjectAttributesPlugin.default({
57
107
  crossorigin: 'anonymous'
58
108
  }));
109
+
110
+ if (customScriptLoadingStrategey.enable) {
111
+ const currentScriptLoadingStrategy = getScriptLoadingStrategy(customScriptLoadingStrategey.options);
112
+
113
+ if ((0, _utils.getTypeOf)(currentScriptLoadingStrategy) === 'object') {
114
+ plugins.push(new _CustomScriptLoadingStrategyPlugin.default({
115
+ scriptLoadingStategey: currentScriptLoadingStrategy
116
+ }));
117
+ }
118
+ }
59
119
  }
@@ -62,7 +62,8 @@ const getDevPlugins = (options, publicPath) => {
62
62
  mode
63
63
  },
64
64
  htmlTemplate: {
65
- inject
65
+ inject,
66
+ customScriptLoadingStrategey
66
67
  },
67
68
  crossorigin
68
69
  },
@@ -161,15 +162,15 @@ const getDevPlugins = (options, publicPath) => {
161
162
  pluginsArr.push(new _lodashWebpackPlugin.default({
162
163
  collections: true,
163
164
  shorthands: true
164
- }));
165
- (0, _configHtmlWebpackPlugins.configHtmlWebpackPlugins)(pluginsArr, {
166
- enableChunkHash: false,
167
- folder,
168
- minify: false,
169
- inject,
170
- crossorigin,
171
- hasEFC
172
- });
165
+ })); // configHtmlWebpackPlugins(pluginsArr, {
166
+ // enableChunkHash: false,
167
+ // folder,
168
+ // minify: false,
169
+ // inject,
170
+ // crossorigin,
171
+ // hasEFC,
172
+ // customScriptLoadingStrategey,
173
+ // });
173
174
 
174
175
  if (hasEFC) {
175
176
  pluginsArr.push(new _plugins.EFCPlugin({
@@ -80,7 +80,8 @@ const getProdPlugins = (options, publicPath = '') => {
80
80
  } = options.app;
81
81
  const {
82
82
  inject,
83
- minify: minifyHtmlOptions
83
+ minify: minifyHtmlOptions,
84
+ customScriptLoadingStrategey
84
85
  } = htmlTemplate;
85
86
  const {
86
87
  i18n
@@ -178,6 +179,7 @@ const getProdPlugins = (options, publicPath = '') => {
178
179
  folder,
179
180
  inject,
180
181
  minify: minifyHtmlOptions,
182
+ customScriptLoadingStrategey,
181
183
  crossorigin,
182
184
  hasEFC
183
185
  });
@@ -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;
@@ -18,10 +18,10 @@ class EventsHandlingPlugin {
18
18
  fn: compilation => {
19
19
  compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
20
20
  // const str = attributeSetTemplate(cssAttributes, 'linkTag');
21
- const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null');
21
+ const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null;');
22
22
  const replacedSourceStr = sourceStr.replace('linkTag.onload = resolve', `linkTag.onload = () => {
23
+ linkTag.onerror = linkTag.onload = null;
23
24
  resolve();
24
- linkTag.onerror = linkTag.onload = null
25
25
  };`);
26
26
  return replacedSourceStr;
27
27
  });
@@ -229,8 +229,8 @@ class I18nDownlodLogic {
229
229
  }
230
230
  var scriptTag = document.createElement("script");
231
231
  scriptTag.onload = () => {
232
- resolve();
233
232
  scriptTag.onerror = scriptTag.onload = null;
233
+ resolve();
234
234
  };
235
235
  scriptTag.onerror = function(event) {
236
236
  scriptTag.onerror = scriptTag.onload = null;
@@ -323,7 +323,11 @@ var _default = {
323
323
  },
324
324
  htmlTemplate: {
325
325
  minify: null,
326
- inject: true
326
+ inject: true,
327
+ customScriptLoadingStrategey: {
328
+ enable: false,
329
+ options: null
330
+ }
327
331
  },
328
332
  removePropTypes: false,
329
333
  customChunksBaseConfig: null,
@@ -167,6 +167,20 @@ var _getComponents = _interopRequireDefault(require("./getComponents"));
167
167
 
168
168
  var _ssTestHack = _interopRequireDefault(require("./ssTestHack"));
169
169
 
170
+ var _typeCheck = require("./typeCheck");
171
+
172
+ Object.keys(_typeCheck).forEach(function (key) {
173
+ if (key === "default" || key === "__esModule") return;
174
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
175
+ if (key in exports && exports[key] === _typeCheck[key]) return;
176
+ Object.defineProperty(exports, key, {
177
+ enumerable: true,
178
+ get: function () {
179
+ return _typeCheck[key];
180
+ }
181
+ });
182
+ });
183
+
170
184
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
171
185
 
172
186
  // eslint-disable-next-line no-duplicate-imports
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTypeOf = getTypeOf;
7
+
8
+ function getTypeOf(value) {
9
+ return Object.prototype.toString.call(value).split(/\s/)[1].replace(/\]/, '').toLowerCase();
10
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.22-exp.2",
3
+ "version": "1.1.23",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/react-cli",
3
- "version": "1.1.22-exp.5",
3
+ "version": "1.1.23-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",