@zohodesk/react-cli 1.1.5 → 1.1.6-exp.2

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,30 @@ Now to run app
44
44
 
45
45
  # Change Logs
46
46
 
47
+ # 1.1.6-exp.2
48
+ - fixed file path separator issue with split chunks config for vendor exclude list.
49
+ - added support for not doing enforce true for chunks on splitchunks config.
50
+
51
+ # 1.1.5-exp.5
52
+ - fixed the issues regarding custom chunks base config schema.
53
+
54
+ # 1.1.5-exp.4
55
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
56
+
57
+ # 1.1.5-exp.3
58
+ - added options to split chunks base config
59
+ - added support for passing custom chunks split logic as function.
60
+ # 1.1.6
61
+
62
+ **Issue Fix**
63
+ - local install react-cli spawnSync Error fix in npm 8
64
+ - babel version update issue fix (Cannot read properties of undefined (reading 'file')) and (BABEL_TRANSFORM_ERROR)
65
+
66
+ # 1.1.5-exp.2
67
+
68
+ **Issue Fix**
69
+ - local install react-cli spawnSync Error fix in npm 8
70
+
47
71
  # 1.1.5
48
72
 
49
73
  **Issue Fix**
@@ -57,6 +81,11 @@ Now to run app
57
81
  - `0px` variable value conversion issue fixed
58
82
  - pattern exclude for postcss plugins case fixed
59
83
 
84
+ # 1.1.3
85
+
86
+ **Issue Fix**
87
+ - local install react-cli spawnSync Error fix
88
+
60
89
  # 1.1.2
61
90
 
62
91
  **Issue Fix**
@@ -4,17 +4,17 @@ In react-cli we provide options to create custom chunks.
4
4
  This Custom Chunk Option is array of Object
5
5
  that Object keys are
6
6
 
7
- - `pattern` regex pattern as string
8
- - `name` chunk name
9
- - `size` is count which is minmum chunk dublicated or need in chunks
7
+ - `pattern` **{ String | Function }** regex pattern as string and custom logic to split chunks can be defined using function
8
+ - `name` **{ String }** chunk name
9
+ - `size` **{ Number }** is count which is minimum chunk duplicated or need in chunks
10
10
 
11
11
  > Since 0.0.1-exp.164.1
12
12
 
13
13
  extra features in custom chunks :-
14
14
  for more details [SplitChunkPlugin](https://webpack.js.org/plugins/split-chunks-plugin/) webpack
15
15
 
16
- - `minChunks`: `minChunks` is alies of `size` default value is `2`,
17
- - `rules`: `rules` is same as `pattern` with some easy hooks
16
+ - `minChunks`: `minChunks` is alias of `size` default value is `2`,
17
+ - `rules`: `rules` is same as `pattern` with some easy hooks **(removed after v1.1.5)**
18
18
  - use `/` for both windows and linux we will replace internally
19
19
  - for `.*` we need to use `*`
20
20
  - we can consider rules as regex when the `rules-string` has any of these `*`, `^`, `$`. So if you want regex then kindly use `*` in your `rules-string` for force regex
@@ -23,4 +23,4 @@ for more details [SplitChunkPlugin](https://webpack.js.org/plugins/split-chunks-
23
23
  - `enforce`: enforce default value is true,
24
24
  - `maxSize`: maxSize, default value is 0,
25
25
  - `minSize`: minSize, default value is 20000,
26
- includeDepenency: includeDepenency default value is false
26
+ includeDependency: includeDependency default value is false
@@ -15,35 +15,52 @@ var _testPattern = require("./testPattern");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- let isWindows = _os.default.platform().toLowerCase() === 'win32';
19
- let ps = _path.default.sep;
20
- let options = (0, _utils.getOptions)();
21
- let {
18
+ const isWindows = _os.default.platform().toLowerCase() === 'win32';
19
+ const ps = _path.default.sep;
20
+ const options = (0, _utils.getOptions)();
21
+ const {
22
22
  app: {
23
23
  vendorExclude,
24
24
  customChunks,
25
- vendorInclude
25
+ vendorInclude,
26
+ customChunksBaseConfig
26
27
  }
27
28
  } = options;
29
+ const reactBundleIncludeList = ['react', 'react-dom', 'react-redux', 'react-transition-group', 'scheduler', 'prop-types'];
30
+ const vendorExcludelist = ['script-loader', 'raw-loader', ...reactBundleIncludeList, ...vendorExclude.map(vendorPath => vendorPath.replace(/[/\\]/g, _path.default.sep))];
28
31
 
29
- let isVendor = function isVendor(module) {
30
- let {
32
+ const isVendor = function isVendor(module) {
33
+ const {
31
34
  userRequest
32
35
  } = module;
33
- let excludeList = ['script-loader', 'raw-loader', 'react', 'react-dom'];
34
- excludeList = [...excludeList, ...vendorExclude];
35
- return userRequest && (vendorInclude.some(item => userRequest.indexOf(item) !== -1) || userRequest.indexOf('node_modules') >= 0 && userRequest.endsWith('.css') === false && userRequest.endsWith('publicPathConfig.js') === false && excludeList.every(item => userRequest.indexOf(`node_modules${ps}${item}${ps}`) === -1));
36
+ return userRequest && (vendorInclude.some(item => userRequest.indexOf(item) !== -1) || userRequest.indexOf('node_modules') >= 0 && userRequest.endsWith('.css') === false && userRequest.endsWith('publicPathConfig.js') === false && vendorExcludelist.every(item => userRequest.indexOf(`node_modules${ps}${item}${ps}`) === -1));
36
37
  };
37
38
 
38
- let isReact = module => {
39
- let {
39
+ const isReact = module => {
40
+ const {
40
41
  userRequest
41
42
  } = module;
42
- let reactBundle = ['react', 'react-dom'];
43
- return userRequest && reactBundle.some(pkg => userRequest.indexOf(`node_modules${ps}${pkg}${ps}`) >= 0);
43
+ return userRequest && reactBundleIncludeList.some(pkg => userRequest.indexOf(`node_modules${ps}${pkg}${ps}`) >= 0);
44
44
  };
45
45
 
46
- let defaultChunks = {
46
+ function rulesMatcher(pattern) {
47
+ if (typeof pattern === 'function') {
48
+ return pattern;
49
+ }
50
+
51
+ if (Array.isArray(pattern)) {
52
+ return ({
53
+ userRequest
54
+ }) => (0, _testPattern.testPattern)(userRequest, pattern);
55
+ }
56
+
57
+ return new RegExp(isWindows ? pattern.replace(/\//g, '\\') : pattern);
58
+ }
59
+
60
+ const baseSplitChunkConfig = Object.assign({
61
+ minSize: 15000
62
+ }, customChunksBaseConfig);
63
+ const specificCacheGroupConfig = {
47
64
  'react.vendor': {
48
65
  name: 'react.vendor',
49
66
  chunks: 'all',
@@ -63,45 +80,37 @@ let defaultChunks = {
63
80
  priority: -10
64
81
  }
65
82
  };
66
- let customChunksConfig = {};
83
+ const customChunksConfig = {};
67
84
  customChunks.map((obj, index) => ({
68
85
  name: obj.name,
69
- pattern: obj.pattern,
86
+ chunks: obj.chunks || 'all',
70
87
  minChunks: obj.minChunks || obj.size || 2,
71
- rules: obj.rules,
72
- // includeDepenency: obj.includeDepenency || false,
88
+ pattern: obj.pattern,
73
89
  priority: obj.priority || -10 * (index + 2),
74
- enforce: obj.enforce || true,
75
- maxSize: obj.maxSize,
76
- // || 0,
90
+ enforce: obj.enforce,
77
91
  minSize: obj.minSize,
78
92
  // || 20000,
79
- chunks: obj.chunks || 'all'
80
- })).map(({
93
+ maxSize: obj.maxSize,
94
+ // || 0,
95
+ reuseExistingChunk: obj.reuseExistingChunk,
96
+ automaticNamePrefix: obj.automaticNamePrefix || '',
97
+ cacheGroupName: obj.cacheGroupName || obj.name
98
+ })).forEach(({
81
99
  name,
82
- pattern,
100
+ chunks = 'all',
83
101
  minChunks,
84
- rules,
102
+ pattern,
85
103
  priority,
86
- // includeDepenency,
87
104
  enforce,
88
105
  minSize,
89
106
  maxSize,
90
- chunks = 'all'
107
+ reuseExistingChunk,
108
+ automaticNamePrefix,
109
+ cacheGroupName
91
110
  }) => {
92
- let obj = {
93
- name,
94
- test: rules ? m => {
95
- const {
96
- userRequest
97
- } = m;
98
- return (0, _testPattern.testPattern)(userRequest, rules); // return (
99
- // pkgs.some(p => isRelated(userRequest, p)) ||
100
- // (includeDepenency && isDependency(m, pkgs))
101
- // );
102
- } : new RegExp(isWindows ? pattern.replace(/\//g, '\\') : pattern),
111
+ const obj = {
112
+ test: rulesMatcher(pattern),
103
113
  chunks,
104
- enforce,
105
114
  minChunks,
106
115
  priority
107
116
  };
@@ -114,13 +123,30 @@ customChunks.map((obj, index) => ({
114
123
  obj.maxSize = maxSize;
115
124
  }
116
125
 
117
- return customChunksConfig[name] = obj;
126
+ if (enforce !== false) {
127
+ obj.enforce = true;
128
+ }
129
+
130
+ if (name !== undefined) {
131
+ obj.name = name;
132
+ }
133
+
134
+ if (reuseExistingChunk !== undefined) {
135
+ obj.reuseExistingChunk = reuseExistingChunk;
136
+ }
137
+
138
+ if (automaticNamePrefix) {
139
+ obj.automaticNamePrefix = automaticNamePrefix;
140
+ }
141
+
142
+ customChunksConfig[cacheGroupName] = obj;
118
143
  });
119
- var _default = {
120
- minSize: 12000,
144
+ const splitChunkConfig = Object.assign({}, baseSplitChunkConfig, {
121
145
  cacheGroups: Object.assign({
122
146
  default: false,
123
147
  vendors: false
124
- }, defaultChunks, customChunksConfig)
125
- };
148
+ }, specificCacheGroupConfig, customChunksConfig)
149
+ });
150
+ console.log('split chunks', splitChunkConfig);
151
+ var _default = splitChunkConfig;
126
152
  exports.default = _default;
@@ -13,25 +13,25 @@ var _path = require("path");
13
13
  const isWindows = _path.sep !== '/'; // this function will return true if pattern matched
14
14
 
15
15
  function _testPattern(req, pattern) {
16
- let modifyedPattern = pattern;
16
+ let modifiedPattern = pattern;
17
17
 
18
- if (/[*.$^]/.test(modifyedPattern)) {
18
+ if (/[*.$^]/.test(modifiedPattern)) {
19
19
  if (isWindows) {
20
- // modifyedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
21
- modifyedPattern = modifyedPattern.replace(/\//g, '\\\\');
20
+ // modifiedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
21
+ modifiedPattern = modifiedPattern.replace(/\//g, '\\\\');
22
22
  }
23
23
 
24
- modifyedPattern = modifyedPattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
25
- const re = new RegExp(modifyedPattern);
24
+ modifiedPattern = modifiedPattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
25
+ const re = new RegExp(modifiedPattern);
26
26
  return re.test(req);
27
27
  }
28
28
 
29
29
  if (isWindows) {
30
- // modifyedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
31
- modifyedPattern = modifyedPattern.replace(/\//g, '\\');
30
+ // modifiedPattern = pattern.replace(/\//g, ps.replace(/\\/g, '\\\\'));
31
+ modifiedPattern = modifiedPattern.replace(/\//g, '\\');
32
32
  }
33
33
 
34
- return req.indexOf(modifyedPattern) !== -1;
34
+ return req.indexOf(modifiedPattern) !== -1;
35
35
  }
36
36
 
37
37
  function testPattern(req, pattern) {
@@ -19,7 +19,7 @@ class ResourceHintsPlugin {
19
19
  mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk, hash) => {
20
20
  const idNameMap = chunk.getChunkMaps().name;
21
21
  const nameIdMap = {};
22
- let needsMap = false;
22
+ let needsMap = true;
23
23
 
24
24
  for (const key in idNameMap) {
25
25
  if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
@@ -32,7 +32,9 @@ class ResourceHintsPlugin {
32
32
  }
33
33
  }
34
34
 
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);`]), '};',
35
+ return Template.asString([source, '', `${mainTemplate.requireFn}.getChunkIds = function getChunkIds(chunkId) {`, Template.indent((needsMap ? [`const nameToChunkIdMap = ${JSON.stringify(nameIdMap)}`, 'const chunkNames = Object.keys(nameToChunkIdMap)'] : []).concat(['return chunkNames.filter(chunkName => chunkId.test(chunkName)).map(chunkName => nameToChunkIdMap[chunkName]);'])), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`let chunkIds = ${mainTemplate.requireFn}.getChunkIds(new RegExp(chunkId, 'i'))`, `chunkIds.forEach(idOfAChunk => {
36
+ ${mainTemplate.requireFn}.e(idOfAChunk);
37
+ })`]), '};',
36
38
  /*
37
39
  (needsMap
38
40
  ? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
@@ -53,7 +55,7 @@ class ResourceHintsPlugin {
53
55
  ),
54
56
  '}',
55
57
  */
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];',
58
+ `// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkIds(new RegExp('^' + 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
59
  // mainTemplate.hooks.jsonpScript.call('', chunk, hash),
58
60
  // 'head.appendChild(script);'
59
61
  ]), '}']), '};']);
@@ -333,6 +333,7 @@ var _default = {
333
333
  inject: true
334
334
  },
335
335
  removePropTypes: false,
336
+ customChunksBaseConfig: null,
336
337
  customChunks: [{
337
338
  name: 'styles',
338
339
  pattern: '\\.css$'
@@ -7,7 +7,7 @@ exports.default = void 0;
7
7
 
8
8
  var _child_process = require("child_process");
9
9
 
10
- var _fs = _interopRequireDefault(require("fs"));
10
+ var _fs = _interopRequireWildcard(require("fs"));
11
11
 
12
12
  var _path = _interopRequireDefault(require("path"));
13
13
 
@@ -15,6 +15,10 @@ var _schemas = _interopRequireDefault(require("../schemas"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
18
22
  // import { argv } from 'process';
19
23
  const args = process.argv.slice(2); // console.log('argv', argv);
20
24
 
@@ -183,8 +187,9 @@ function deprecationSupport(options) {
183
187
  Object.keys(options.app.patterns).forEach(key => {
184
188
  if (options.app.exclude[key] && options.app.patterns[key].length === 0) {
185
189
  let tempArr = options.app.exclude[key];
186
- tempArr = tempArr.map(x => {
187
- x = x.replace(/\//gi, _path.default.sep);
190
+ tempArr = tempArr.map(_x => {
191
+ const x = _x.replace(/\//gi, _path.default.sep);
192
+
188
193
  return `!**${x[0] === _path.default.sep || x[0] === '@' ? '' : _path.default.sep}${x}${x[x.length - 1] === _path.default.sep ? '' : _path.default.sep}**`;
189
194
  });
190
195
  options.app.patterns[key] = tempArr;
@@ -193,8 +198,9 @@ function deprecationSupport(options) {
193
198
  Object.keys(options.docs.patterns).forEach(key => {
194
199
  if (options.docs.exclude[key] && options.docs.patterns[key].length === 0) {
195
200
  let tempArr = options.docs.exclude[key];
196
- tempArr = tempArr.map(x => {
197
- x = x.replace(/\//gi, _path.default.sep);
201
+ tempArr = tempArr.map(_x => {
202
+ const x = _x.replace(/\//gi, _path.default.sep);
203
+
198
204
  return `!**${x[0] === _path.default.sep || x[0] === '@' ? '' : _path.default.sep}${x}${x[x.length - 1] === _path.default.sep ? '' : _path.default.sep}**`;
199
205
  });
200
206
  options.docs.patterns[key] = tempArr;
@@ -202,18 +208,30 @@ function deprecationSupport(options) {
202
208
  });
203
209
  }
204
210
 
211
+ const getOptionsFromConfigFile = (appPath, configFileName) => {
212
+ const fileName = configFileName || 'build.config.js';
213
+
214
+ const packagePath = _path.default.join(appPath, fileName);
215
+
216
+ if ((0, _fs.existsSync)(packagePath)) {
217
+ return require(packagePath).config;
218
+ }
219
+
220
+ return null;
221
+ };
222
+
205
223
  const getOptions = () => {
206
224
  if (global.reactCLIOptions) {
207
225
  return global.reactCLIOptions;
208
226
  }
209
227
 
210
228
  const appPath = process.cwd();
211
- let userSchemas;
229
+ let userSchemas = getOptionsFromConfigFile(appPath, processEnv.config_file);
212
230
 
213
231
  const packagePath = _path.default.join(appPath, 'package.json');
214
232
 
215
233
  if (_fs.default.existsSync(packagePath)) {
216
- userSchemas = require(packagePath)['react-cli'] || {};
234
+ userSchemas = userSchemas || require(packagePath)['react-cli'] || {};
217
235
  }
218
236
 
219
237
  const options = defaulter(_schemas.default, userSchemas || {}); // for future may be for npm 8 edge cases