@zohodesk/react-cli 1.1.22-exp.1 → 1.1.22-exp.3

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -59,28 +59,6 @@ Now to run app
59
59
  ```
60
60
  - The Memory leak issue while downloading i18n and CSS files has been fixed
61
61
 
62
-
63
- # 1.1.20-exp.1
64
-
65
- **Changes**
66
-
67
- - Added memory leak fixes for script, links tags
68
-
69
- **Feature**
70
- - Custom Script loading strategy support for initial html script tags.
71
-
72
- # 1.1.19-exp.18
73
-
74
- **Changes**
75
-
76
- - To do further build size optimization by utilizing webpack provided config.
77
-
78
- ```
79
- innerGraph: true,
80
- usedExports: true,
81
- sideEffects: true
82
- ```
83
-
84
62
  # 1.1.20 (27-5-2024)
85
63
 
86
64
  **Feature**
@@ -13,7 +13,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
 
14
14
  const {
15
15
  module: {
16
- mode
16
+ mode,
17
+ alias
17
18
  },
18
19
  babelCustomizationForLibrary: {
19
20
  babelPlugins
@@ -22,8 +23,11 @@ const {
22
23
  } = (0, _utils.getOptions)();
23
24
  const isProd = mode.toLowerCase() === 'prod';
24
25
  const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
25
- __DOCS__: false
26
- } : {}], require.resolve('@babel/plugin-syntax-dynamic-import')];
26
+ __DaliasOCS__: false
27
+ } : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), [require.resolve('babel-plugin-module-resolver'), {
28
+ "root": ["./"],
29
+ alias
30
+ }]];
27
31
  const resolvedPlugins = [];
28
32
  babelPlugins.forEach(plugin => {
29
33
  resolvedPlugins.push(require.resolve(plugin));
@@ -24,7 +24,7 @@ const {
24
24
  const isProd = mode.toLowerCase() === 'prod';
25
25
  const defaultPlugins = [[require.resolve('babel-plugin-transform-define'), isProd ? {
26
26
  __DOCS__: false
27
- } : {}], require.resolve('@babel/plugin-syntax-dynamic-import')];
27
+ } : {}], require.resolve('@babel/plugin-syntax-dynamic-import'), require.resolve('../utils/addModulePathAlias')];
28
28
  const resolvedPlugins = [];
29
29
  babelPlugins.forEach(plugin => {
30
30
  resolvedPlugins.push(require.resolve(plugin));
@@ -21,6 +21,7 @@ function moduleResolver(options) {
21
21
  moduleResolvePath,
22
22
  disableES5Transpile
23
23
  } = options.app;
24
+ const customAlias = options.app.alias;
24
25
  let required = moduleResolvePath && (0, _requireLocalOrGlobal.requireLocal)(moduleResolvePath);
25
26
 
26
27
  if (!required) {
@@ -32,10 +33,11 @@ function moduleResolver(options) {
32
33
  }
33
34
 
34
35
  const nodeModulesPath = required ? required.nodeModulesPath : _client_packages_group.nodeModulesPath;
36
+ const totalAlias = Object.assign({}, _libAlias.libAlias, customAlias);
35
37
  return {
36
38
  extensions: ['.js', '.jsx', '.ts', '.tsx'],
37
39
  modules: [nodeModulesPath, _constants.cliNodeModulesPath, 'node_modules'].filter(Boolean),
38
- alias: disableES5Transpile ? _libAlias.libAlias : {} // alias: { ...libAlias, ...clientDependenies }
40
+ alias: disableES5Transpile ? totalAlias : {} // alias: { ...libAlias, ...clientDependenies }
39
41
 
40
42
  };
41
43
  }
@@ -103,10 +103,7 @@ module.exports = {
103
103
  // exclude: /\/smap/
104
104
  // })
105
105
  // ],
106
- moduleIds: 'named',
107
- usedExports: true,
108
- // innerGraph: true, // this property present on webpack 5
109
- sideEffects: true
106
+ moduleIds: 'named'
110
107
  },
111
108
  stats: {
112
109
  children: false,
@@ -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,40 +112,25 @@ function pitch(request) {
112
112
  }
113
113
 
114
114
  function workerCode() {
115
- if (this.workerInstance) {
116
- return this.workerInstance;
117
- }
118
-
119
115
  let blob;
120
116
 
121
117
  try {
122
118
  blob = new Blob([`importScripts('${this.workerUrl}');`], {
123
- type: 'application/javascript'
119
+ 'type': 'application/javascript'
124
120
  });
125
121
  } catch (e1) {
126
122
  throw new Error(e1);
127
123
  }
128
124
 
129
- const url = window.URL || window.webkitURL;
130
- const blobUrl = url.createObjectURL(blob);
131
- this.workerInstance = new Worker(blobUrl);
132
- return this.workerInstance;
125
+ let url = window.URL || window.webkitURL;
126
+ let blobUrl = url.createObjectURL(blob);
127
+ let worker = new Worker(blobUrl);
128
+ return worker;
133
129
  }
134
130
 
135
- return cb(null, `const workerObj ={\n
136
- workerInstance: null, \n
131
+ return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} {\n
137
132
  workerUrl: __webpack_public_path__ + ${JSON.stringify(entry)}, \n
138
133
  getInstance: ${workerCode} \n
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
- // );
134
+ }`);
150
135
  });
151
136
  }
@@ -13,10 +13,6 @@ 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
-
20
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
17
 
22
18
  const defaultHTMLMiniFyOption = {
@@ -30,47 +26,6 @@ const defaultHTMLMiniFyOption = {
30
26
  removeStyleLinkTypeAttributes: true,
31
27
  useShortDoctype: true
32
28
  };
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 getScriptLoadingStrategyForStringType(scriptLoadingStategey);
66
- }
67
-
68
- if ((0, _utils.getTypeOf)(scriptLoadingStategey) === 'object') {
69
- return getScriptLoadingStrategyForObject(scriptLoadingStategey);
70
- }
71
-
72
- return 'defer';
73
- }
74
29
 
75
30
  function configHtmlWebpackPlugins(plugins, {
76
31
  enableChunkHash = false,
@@ -78,8 +33,7 @@ function configHtmlWebpackPlugins(plugins, {
78
33
  inject,
79
34
  crossorigin,
80
35
  hasEFC,
81
- minify: minifyHtmlOptions = false,
82
- customScriptLoadingStrategey = {}
36
+ minify: minifyHtmlOptions = false
83
37
  }) {
84
38
  const optionsHtmlWebpack = {
85
39
  chunksSortMode: 'none',
@@ -102,14 +56,4 @@ function configHtmlWebpackPlugins(plugins, {
102
56
  crossorigin && plugins.push(new _htmlWebpackInjectAttributesPlugin.default({
103
57
  crossorigin: 'anonymous'
104
58
  }));
105
-
106
- if (customScriptLoadingStrategey.enable) {
107
- const currentScriptLoadingStrategy = getScriptLoadingStrategy(customScriptLoadingStrategey.options);
108
-
109
- if ((0, _utils.getTypeOf)(currentScriptLoadingStrategy) === 'object') {
110
- plugins.push(new _CustomScriptLoadingStrategyPlugin.default({
111
- scriptLoadingStategey: currentScriptLoadingStrategy
112
- }));
113
- }
114
- }
115
59
  }
@@ -62,8 +62,7 @@ const getDevPlugins = (options, publicPath) => {
62
62
  mode
63
63
  },
64
64
  htmlTemplate: {
65
- inject,
66
- customScriptLoadingStrategey
65
+ inject
67
66
  },
68
67
  crossorigin
69
68
  },
@@ -169,8 +168,7 @@ const getDevPlugins = (options, publicPath) => {
169
168
  minify: false,
170
169
  inject,
171
170
  crossorigin,
172
- hasEFC,
173
- customScriptLoadingStrategey
171
+ hasEFC
174
172
  });
175
173
 
176
174
  if (hasEFC) {
@@ -80,8 +80,7 @@ const getProdPlugins = (options, publicPath = '') => {
80
80
  } = options.app;
81
81
  const {
82
82
  inject,
83
- minify: minifyHtmlOptions,
84
- customScriptLoadingStrategey
83
+ minify: minifyHtmlOptions
85
84
  } = htmlTemplate;
86
85
  const {
87
86
  i18n
@@ -179,7 +178,6 @@ const getProdPlugins = (options, publicPath = '') => {
179
178
  folder,
180
179
  inject,
181
180
  minify: minifyHtmlOptions,
182
- customScriptLoadingStrategey,
183
181
  crossorigin,
184
182
  hasEFC
185
183
  });
@@ -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;
24
23
  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
- scriptTag.onerror = scriptTag.onload = null;
233
232
  resolve();
233
+ scriptTag.onerror = scriptTag.onload = null;
234
234
  };
235
235
  scriptTag.onerror = function(event) {
236
236
  scriptTag.onerror = scriptTag.onload = null;
@@ -125,6 +125,7 @@ var _default = {
125
125
  cssDirStatement: null
126
126
  },
127
127
  app: {
128
+ alias: null,
128
129
  moduleResolvePath: {
129
130
  value: '@zohodesk/client_packages_group',
130
131
  cli: 'module_resolve_path'
@@ -322,11 +323,7 @@ var _default = {
322
323
  },
323
324
  htmlTemplate: {
324
325
  minify: null,
325
- inject: true,
326
- customScriptLoadingStrategey: {
327
- enable: false,
328
- options: null
329
- }
326
+ inject: true
330
327
  },
331
328
  removePropTypes: false,
332
329
  customChunksBaseConfig: null,
@@ -732,7 +729,8 @@ var _default = {
732
729
  value: 'prod',
733
730
  cli: 'module_mode'
734
731
  },
735
- disableES5Transpile: true
732
+ disableES5Transpile: true,
733
+ alias: null
736
734
  },
737
735
  stats: {
738
736
  enable: {
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ var _getOptions = _interopRequireDefault(require("./getOptions"));
4
+
5
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
+
7
+ const options = (0, _getOptions.default)();
8
+ const alias = options.app.alias;
9
+
10
+ module.exports = () => ({
11
+ visitor: {
12
+ ImportDeclaration(path) {
13
+ const source = path.node.source.value;
14
+ const aliasName = Object.keys(alias);
15
+ aliasName.forEach(name => {
16
+ if (source.includes(name)) {
17
+ path.node.source.value = source.replace(name, alias[name]);
18
+ }
19
+ });
20
+ }
21
+
22
+ }
23
+ });
@@ -167,20 +167,6 @@ 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
-
184
170
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
185
171
 
186
172
  // eslint-disable-next-line no-duplicate-imports