@zohodesk/react-cli 1.1.8 → 1.1.9
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 +37 -0
- package/bin/cli.js +16 -12
- package/docs/CustomChunks.md +12 -9
- package/lib/common/splitChunks.js +65 -45
- package/lib/common/testPattern.js +9 -9
- package/lib/configs/webpack.dev.config.js +6 -3
- package/lib/configs/webpack.docs.config.js +4 -2
- package/lib/configs/webpack.impact.config.js +4 -2
- package/lib/configs/webpack.prod.config.js +6 -3
- package/lib/deprecationLogger.js +41 -0
- package/lib/loaderUtils/getCSSLoaders.js +24 -7
- package/lib/pluginUtils/getDevPlugins.js +3 -2
- package/lib/pluginUtils/getProdPlugins.js +1 -1
- package/lib/plugins/ReportGeneratePlugin.js +8 -6
- package/lib/plugins/ResourceHintsPlugin.js +13 -3
- package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
- package/lib/plugins/utils/fileHandling.js +35 -38
- package/lib/schemas/index.js +19 -36
- package/lib/utils/deprecationSupport.js +128 -0
- package/lib/utils/getOptions.js +19 -79
- package/lib/utils/index.js +14 -12
- package/lib/utils/initPreCommitHook.js +5 -5
- package/lib/utils/log.js +11 -0
- package/lib/utils/pullOrigin.js +3 -3
- package/lib/utils/reinstallDependencies.js +3 -3
- package/lib/utils/switchBranch.js +4 -2
- package/package.json +1 -1
- package/templates/docs/css/markdown.css +1 -1
@@ -12,14 +12,21 @@ const {
|
|
12
12
|
const pluginName = 'prefetch-preload-chunk-plugin';
|
13
13
|
|
14
14
|
class ResourceHintsPlugin {
|
15
|
+
constructor(options) {
|
16
|
+
this.options = options;
|
17
|
+
}
|
18
|
+
|
15
19
|
apply(compiler) {
|
16
20
|
compiler.hooks.thisCompilation.tap(pluginName, ({
|
17
21
|
mainTemplate
|
18
22
|
}) => {
|
19
23
|
mainTemplate.hooks.requireExtensions.tap(pluginName, (source, chunk, hash) => {
|
24
|
+
const {
|
25
|
+
allowPrefetchingMultipleChunks
|
26
|
+
} = this.options;
|
20
27
|
const idNameMap = chunk.getChunkMaps().name;
|
21
28
|
const nameIdMap = {};
|
22
|
-
let needsMap =
|
29
|
+
let needsMap = allowPrefetchingMultipleChunks;
|
23
30
|
|
24
31
|
for (const key in idNameMap) {
|
25
32
|
if (Object.prototype.hasOwnProperty.call(idNameMap, key)) {
|
@@ -32,7 +39,10 @@ class ResourceHintsPlugin {
|
|
32
39
|
}
|
33
40
|
}
|
34
41
|
|
35
|
-
return Template.asString([source,
|
42
|
+
return Template.asString([source, Template.indent([`const nameToChunkIdMap = ${JSON.stringify(needsMap ? nameIdMap : {})};`, 'const chunkNames = Object.keys(nameToChunkIdMap);']), `${mainTemplate.requireFn}.getChunkIds = function getChunkIds(chunkId) {`, Template.indent([allowPrefetchingMultipleChunks ? `const isRegExAsChunkId = chunkId instanceof RegExp;
|
43
|
+
return isRegExAsChunkId ? chunkNames.filter(chunkName => chunkId.test(chunkName)).map(chunkName => nameToChunkIdMap[chunkName]) : [nameToChunkIdMap[chunkId] || chunkId];` : needsMap ? 'return [nameToChunkIdMap[chunkId] || chunkId];' : 'return [chunkId];']), '}', `// Prefetch a chunk (${pluginName})`, `${mainTemplate.requireFn}.pfc = function prefetchChunk(chunkId) {`, Template.indent([`let chunkIds = ${mainTemplate.requireFn}.getChunkIds(chunkId)`, `chunkIds.forEach(idOfAChunk => {
|
44
|
+
${mainTemplate.requireFn}.e(idOfAChunk);
|
45
|
+
})`]), '};',
|
36
46
|
/*
|
37
47
|
(needsMap
|
38
48
|
? [`chunkId = ${JSON.stringify(nameIdMap)}[chunkId]||chunkId;`]
|
@@ -53,7 +63,7 @@ class ResourceHintsPlugin {
|
|
53
63
|
),
|
54
64
|
'}',
|
55
65
|
*/
|
56
|
-
`// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.
|
66
|
+
`// Preload a chunk (${pluginName})`, `${mainTemplate.requireFn}.plc = function preloadChunk(chunkId) {`, Template.indent([`chunkId = ${mainTemplate.requireFn}.getChunkIds(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
67
|
// mainTemplate.hooks.jsonpScript.call('', chunk, hash),
|
58
68
|
// 'head.appendChild(script);'
|
59
69
|
]), '}']), '};']);
|
@@ -11,6 +11,8 @@ var _fs = _interopRequireDefault(require("fs"));
|
|
11
11
|
|
12
12
|
var _utils = require("../utils");
|
13
13
|
|
14
|
+
var _log = require("../utils/log");
|
15
|
+
|
14
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
17
|
|
16
18
|
let excludeDocsJSON = '{}';
|
@@ -97,10 +99,10 @@ class UnusedFilesFindPlugin {
|
|
97
99
|
Object.keys(unDocsCompObj).forEach(key => {
|
98
100
|
if (unDocsCompObj[key].length > 0) {
|
99
101
|
if (key === 'withoutDocs') {
|
100
|
-
(0,
|
102
|
+
(0, _log.log)('\x1b[36m%s\x1b[0m', '\nPlease write docs file for below componenst :- \n');
|
101
103
|
unDocsCompObj[key].forEach(value => {
|
102
104
|
if (!excludeDocsArray.docs.exclude.includes(value)) {
|
103
|
-
(0,
|
105
|
+
(0, _log.log)('\x1b[33m%s\x1b[0m', `${value}`);
|
104
106
|
}
|
105
107
|
});
|
106
108
|
}
|
@@ -162,10 +164,10 @@ class UnusedFilesFindPlugin {
|
|
162
164
|
});
|
163
165
|
|
164
166
|
if (!unusedFiles.length) {
|
165
|
-
(0,
|
167
|
+
(0, _log.log)('There is no unused files');
|
166
168
|
} else {
|
167
169
|
if (this.outputFileName) {
|
168
|
-
(0,
|
170
|
+
(0, _log.log)(`You can see unused files info from ${_path.default.join(outputPath, this.outputFileName)} path`);
|
169
171
|
(0, _utils.makeDir)(outputPath);
|
170
172
|
(0, _utils.writeFile)(_path.default.join(outputPath, this.outputFileName), JSON.stringify(unusedFiles)).then(() => {
|
171
173
|
if (this.sstest) {
|
@@ -179,7 +181,7 @@ class UnusedFilesFindPlugin {
|
|
179
181
|
unusedFiles.forEach(file => {
|
180
182
|
_fs.default.unlinkSync(file);
|
181
183
|
|
182
|
-
(0,
|
184
|
+
(0, _log.log)(`Deleted - ${file}`);
|
183
185
|
});
|
184
186
|
}
|
185
187
|
});
|
@@ -6,15 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.isFileNameMatchingPattern = isFileNameMatchingPattern;
|
7
7
|
exports.isFileNameMatchingPluginPattern = isFileNameMatchingPluginPattern;
|
8
8
|
|
9
|
-
var _windowsModification = require("../../loaderUtils/windowsModification");
|
10
|
-
|
11
9
|
var _ignore = _interopRequireDefault(require("ignore"));
|
12
10
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
12
|
|
15
13
|
const path = require('path');
|
16
14
|
|
17
|
-
|
15
|
+
const aliasNames = {
|
18
16
|
valueReplacer: 'postcss-value-replacer',
|
19
17
|
selectorReplace: 'postcss-selector-replace-new',
|
20
18
|
hasRTL: 'postcss-rtl',
|
@@ -48,48 +46,47 @@ unique scenario
|
|
48
46
|
function isFileNameMatchingPattern({
|
49
47
|
filename,
|
50
48
|
filterObject,
|
51
|
-
plugins
|
49
|
+
plugins,
|
50
|
+
order
|
52
51
|
}) {
|
52
|
+
const pluginObj = {};
|
53
|
+
plugins.forEach(p => {
|
54
|
+
pluginObj[p.postcssPlugin] = p;
|
55
|
+
});
|
53
56
|
const finalPlugins = [];
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
order.forEach(key => {
|
58
|
+
const p = pluginObj[aliasNames[key]];
|
59
|
+
const pluginSpecificFilter = filterObject[key];
|
60
|
+
|
61
|
+
if (!pluginSpecificFilter || pluginSpecificFilter.length === 0) {
|
62
|
+
finalPlugins.push(p);
|
63
|
+
} else {
|
64
|
+
// eslint-disable-next-line no-use-before-define
|
65
|
+
const isMatching = isFilePathMatchingPattern(filename, pluginSpecificFilter);
|
66
|
+
|
67
|
+
if (isMatching) {
|
68
|
+
finalPlugins.push(p);
|
64
69
|
}
|
65
|
-
}
|
66
|
-
});
|
67
|
-
|
68
|
-
return finalPlugins; // console.log(filename, filterObject);
|
70
|
+
}
|
71
|
+
});
|
72
|
+
return finalPlugins;
|
69
73
|
}
|
70
74
|
|
71
|
-
function
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
}) {
|
76
|
-
// console.log(rootDir);
|
77
|
-
let include = true; // console.log(rootDir);
|
78
|
-
// const regex = `^(.+?)${rootDir}?\\\\`;
|
79
|
-
// console.log(plugin);
|
80
|
-
|
81
|
-
const newFilename = path.relative(path.parse(process.cwd()).base, filename); // const newFilename = windowsModificationFile(filename).replace(
|
82
|
-
// new RegExp(regex, 'gi'),
|
83
|
-
// ''
|
84
|
-
// );
|
75
|
+
function isFilePathMatchingPattern(filePath, patterns) {
|
76
|
+
if (patterns.length === 0) {
|
77
|
+
return true;
|
78
|
+
}
|
85
79
|
|
86
80
|
const ig = (0, _ignore.default)({
|
87
81
|
allowRelativePaths: true
|
88
|
-
}).add(
|
89
|
-
|
90
|
-
|
91
|
-
include = false;
|
92
|
-
}
|
82
|
+
}).add(patterns);
|
83
|
+
return ig.ignores(filePath);
|
84
|
+
}
|
93
85
|
|
94
|
-
|
86
|
+
function isFileNameMatchingPluginPattern({
|
87
|
+
filename,
|
88
|
+
filterArr
|
89
|
+
}) {
|
90
|
+
const newFilename = path.relative(path.parse(process.cwd()).base, filename);
|
91
|
+
return isFilePathMatchingPattern(newFilename, filterArr);
|
95
92
|
}
|
package/lib/schemas/index.js
CHANGED
@@ -36,6 +36,9 @@ var _default = {
|
|
36
36
|
cli: 'stop_nodemon'
|
37
37
|
}
|
38
38
|
},
|
39
|
+
resourceHints: {
|
40
|
+
allowPrefetchingMultipleChunks: false
|
41
|
+
},
|
39
42
|
i18n: {
|
40
43
|
chunkSplitEnable: {
|
41
44
|
value: false,
|
@@ -68,17 +71,9 @@ var _default = {
|
|
68
71
|
before: [],
|
69
72
|
after: []
|
70
73
|
},
|
71
|
-
plugins:
|
72
|
-
|
73
|
-
|
74
|
-
hasRTL: false,
|
75
|
-
hoverActive: false,
|
76
|
-
combinerMediaQuery: false,
|
77
|
-
cssVariableReplacement: false,
|
78
|
-
selectorWeight: false,
|
79
|
-
minifier: false,
|
80
|
-
composeMinification: false
|
81
|
-
},
|
74
|
+
plugins: null,
|
75
|
+
// @type {Boolean | Array}
|
76
|
+
postCssPluginOrder: null,
|
82
77
|
patterns: {
|
83
78
|
valueReplacer: [],
|
84
79
|
selectorReplace: [],
|
@@ -95,7 +90,8 @@ var _default = {
|
|
95
90
|
hoverActive: [],
|
96
91
|
combinerMediaQuery: [],
|
97
92
|
cssVariableReplacement: [],
|
98
|
-
selectorWeight: []
|
93
|
+
selectorWeight: [],
|
94
|
+
hasRTL: []
|
99
95
|
},
|
100
96
|
cssVariableReplacementConfig: '',
|
101
97
|
selectorWeightConfig: {
|
@@ -267,17 +263,8 @@ var _default = {
|
|
267
263
|
value: true,
|
268
264
|
cli: 'enable_smaphook'
|
269
265
|
},
|
270
|
-
plugins:
|
271
|
-
|
272
|
-
selectorReplace: false,
|
273
|
-
hasRTL: false,
|
274
|
-
hoverActive: false,
|
275
|
-
combinerMediaQuery: false,
|
276
|
-
cssVariableReplacement: false,
|
277
|
-
selectorWeight: false,
|
278
|
-
minifier: false,
|
279
|
-
composeMinification: false
|
280
|
-
},
|
266
|
+
plugins: null,
|
267
|
+
postCssPluginOrder: null,
|
281
268
|
patterns: {
|
282
269
|
valueReplacer: [],
|
283
270
|
selectorReplace: [],
|
@@ -294,7 +281,8 @@ var _default = {
|
|
294
281
|
hoverActive: [],
|
295
282
|
combinerMediaQuery: [],
|
296
283
|
cssVariableReplacement: [],
|
297
|
-
selectorWeight: []
|
284
|
+
selectorWeight: [],
|
285
|
+
hasRTL: []
|
298
286
|
},
|
299
287
|
cssVariableReplacementConfig: '',
|
300
288
|
selectorWeightConfig: {
|
@@ -333,6 +321,7 @@ var _default = {
|
|
333
321
|
inject: true
|
334
322
|
},
|
335
323
|
removePropTypes: false,
|
324
|
+
customChunksBaseConfig: null,
|
336
325
|
customChunks: [{
|
337
326
|
name: 'styles',
|
338
327
|
pattern: '\\.css$'
|
@@ -388,16 +377,8 @@ var _default = {
|
|
388
377
|
},
|
389
378
|
rtlExclude: [],
|
390
379
|
selectorReplace: null,
|
391
|
-
plugins:
|
392
|
-
|
393
|
-
hoverActive: false,
|
394
|
-
combinerMediaQuery: false,
|
395
|
-
cssVariableReplacement: false,
|
396
|
-
selectorWeight: false,
|
397
|
-
minifier: false,
|
398
|
-
composeMinification: false,
|
399
|
-
selectorReplace: false
|
400
|
-
},
|
380
|
+
plugins: null,
|
381
|
+
postCssPluginOrder: null,
|
401
382
|
patterns: {
|
402
383
|
valueReplacer: [],
|
403
384
|
selectorReplace: [],
|
@@ -405,14 +386,16 @@ var _default = {
|
|
405
386
|
combinerMediaQuery: [],
|
406
387
|
hasRTL: [],
|
407
388
|
cssVariableReplacement: [],
|
408
|
-
selectorWeight: []
|
389
|
+
selectorWeight: [],
|
390
|
+
cssUniqueness: []
|
409
391
|
},
|
410
392
|
exclude: {
|
411
393
|
rtl: [],
|
412
394
|
hoverActive: [],
|
413
395
|
combinerMediaQuery: [],
|
414
396
|
cssVariableReplacement: [],
|
415
|
-
selectorWeight: []
|
397
|
+
selectorWeight: [],
|
398
|
+
hasRTL: []
|
416
399
|
},
|
417
400
|
cssVariableReplacementConfig: '',
|
418
401
|
selectorWeightConfig: {
|
@@ -0,0 +1,128 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.deprecationSupport = deprecationSupport;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var deprecationHandlers = _interopRequireWildcard(require("../deprecationLogger"));
|
11
|
+
|
12
|
+
var _windowsModification = require("../loaderUtils/windowsModification");
|
13
|
+
|
14
|
+
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); }
|
15
|
+
|
16
|
+
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; }
|
17
|
+
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19
|
+
|
20
|
+
let {
|
21
|
+
deprecateMessage,
|
22
|
+
deprecateOption,
|
23
|
+
deprecationLoggerEnd
|
24
|
+
} = deprecationHandlers;
|
25
|
+
|
26
|
+
function modifyCssArr(arr) {
|
27
|
+
return arr.map(x => {
|
28
|
+
const includeCss = !x.startsWith('!');
|
29
|
+
const modifier = includeCss ? '/*.css' : '';
|
30
|
+
const filePath = x.replace(/^!/, ''); // Remove the "!" symbol if present
|
31
|
+
|
32
|
+
return (0, _windowsModification.windowsModificationFile)(_path.default.join(includeCss ? '**' : '!**', filePath, '**', modifier));
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
const defaultPostCssPluginOptions = {
|
37
|
+
valueReplacer: null,
|
38
|
+
hasRTL: false,
|
39
|
+
selectorReplace: null,
|
40
|
+
hoverActive: false,
|
41
|
+
combinerMediaQuery: false,
|
42
|
+
cssVariableReplacement: false,
|
43
|
+
selectorWeight: false,
|
44
|
+
minifier: false,
|
45
|
+
composeMinification: false
|
46
|
+
};
|
47
|
+
|
48
|
+
function deprecationSupport(options, disableDeprecationWarning) {
|
49
|
+
if (disableDeprecationWarning) {
|
50
|
+
/* eslint-disable no-empty-function */
|
51
|
+
deprecateMessage = () => {};
|
52
|
+
|
53
|
+
deprecateOption = () => {};
|
54
|
+
|
55
|
+
deprecationLoggerEnd = () => {};
|
56
|
+
/* eslint-enable no-empty-function */
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
options.app.plugins = options.app.plugins || defaultPostCssPluginOptions;
|
61
|
+
options.docs.plugins = options.docs.plugins || defaultPostCssPluginOptions;
|
62
|
+
options.css.plugins = options.css.plugins || defaultPostCssPluginOptions; // if (selectn(options, ".app.hasRTL") === true) {
|
63
|
+
|
64
|
+
if (options.app.hasRTL === true) {
|
65
|
+
deprecateOption('app.hasRTL', 'app.plugins.hasRTL');
|
66
|
+
options.app.plugins.hasRTL = true;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (options.docs.hasRTL === true) {
|
70
|
+
deprecateOption('docs.hasRTL', 'docs.plugins.hasRTL');
|
71
|
+
options.docs.plugins.hasRTL = true;
|
72
|
+
}
|
73
|
+
|
74
|
+
if (options.app.selectorReplace !== null && options.app.plugins && (options.app.plugins.selectorReplace === null || options.app.plugins.selectorReplace === undefined)) {
|
75
|
+
deprecateMessage('when you use app.selectorReplace mention enable or disable app.plugins.selectorReplace by setting value to true or false');
|
76
|
+
options.app.plugins.selectorReplace = true;
|
77
|
+
}
|
78
|
+
|
79
|
+
if (options.docs.selectorReplace !== null && options.docs.plugins && (options.docs.plugins.selectorReplace === null || options.docs.plugins.selectorReplace === undefined)) {
|
80
|
+
deprecateMessage('when you use docs.selectorReplace mention enable or disable docs.plugins.selectorReplace by setting value to true or false');
|
81
|
+
options.docs.plugins.selectorReplace = true;
|
82
|
+
}
|
83
|
+
|
84
|
+
if (options.css.valueReplacer !== null && options.css.plugins && (options.app.plugins.valueReplacer === null || options.app.plugins.valueReplacer === undefined)) {
|
85
|
+
deprecateMessage('when you use app.valueReplacer mention enable or disable app.plugins.valueReplacer by setting value to true or false');
|
86
|
+
options.app.plugins.valueReplacer = true;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (!options.app.patterns) {
|
90
|
+
options.app.patterns = {};
|
91
|
+
}
|
92
|
+
|
93
|
+
function handleRTL(rtlExclude, rtl, hasRTL, type) {
|
94
|
+
if (rtlExclude && rtlExclude.length > 0) {
|
95
|
+
options[type].patterns.hasRTL = modifyCssArr(rtlExclude);
|
96
|
+
deprecateOption(`${type}.rtlExclude`, `${type}.patterns.hasRTL`);
|
97
|
+
}
|
98
|
+
|
99
|
+
if (rtl && rtl.length > 0) {
|
100
|
+
options[type].patterns.hasRTL = modifyCssArr(rtl);
|
101
|
+
deprecateOption(`${type}.exclude.rtl`, `${type}.patterns.hasRTL`);
|
102
|
+
}
|
103
|
+
|
104
|
+
if (hasRTL && hasRTL.length > 0) {
|
105
|
+
options[type].patterns.hasRTL = modifyCssArr(hasRTL);
|
106
|
+
deprecateOption(`${type}.exclude.hasRTL`, `${type}.patterns.hasRTL`);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
function addExcludesToPattern(patterns, exclude, type) {
|
111
|
+
Object.keys(defaultPostCssPluginOptions).forEach(key => {
|
112
|
+
if (exclude[key] && patterns[key].length === 0) {
|
113
|
+
deprecateOption(`${type}.exclude.${key}`, `${type}.patterns.${key}`);
|
114
|
+
let tempArr = exclude[key];
|
115
|
+
tempArr = tempArr.map(x => _path.default.join('!**', x, '**')); // Since patterns[key] is empty we need to wildcard for allow all others.
|
116
|
+
|
117
|
+
tempArr.unshift('*');
|
118
|
+
patterns[key] = tempArr;
|
119
|
+
}
|
120
|
+
});
|
121
|
+
}
|
122
|
+
|
123
|
+
handleRTL(options.app.rtlExclude, options.app.exclude.rtl, options.app.exclude.hasRTL, 'app');
|
124
|
+
handleRTL(options.docs.rtlExclude, options.docs.exclude.rtl, options.docs.exclude.hasRTL, 'docs');
|
125
|
+
addExcludesToPattern(options.app.patterns, options.app.exclude, 'app');
|
126
|
+
addExcludesToPattern(options.docs.patterns, options.docs.exclude, 'docs');
|
127
|
+
deprecationLoggerEnd();
|
128
|
+
}
|
package/lib/utils/getOptions.js
CHANGED
@@ -7,14 +7,20 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _child_process = require("child_process");
|
9
9
|
|
10
|
-
var _fs =
|
10
|
+
var _fs = _interopRequireWildcard(require("fs"));
|
11
11
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
13
13
|
|
14
14
|
var _schemas = _interopRequireDefault(require("../schemas"));
|
15
15
|
|
16
|
+
var _deprecationSupport = require("./deprecationSupport");
|
17
|
+
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
19
|
|
20
|
+
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); }
|
21
|
+
|
22
|
+
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; }
|
23
|
+
|
18
24
|
// import { argv } from 'process';
|
19
25
|
const args = process.argv.slice(2); // console.log('argv', argv);
|
20
26
|
|
@@ -122,105 +128,39 @@ const defaulter = (target, source) => {
|
|
122
128
|
return defaultObject;
|
123
129
|
};
|
124
130
|
|
125
|
-
global.reactCLIOptions = null;
|
126
|
-
// let temp = obj;
|
127
|
-
// let keys = key.split('.');
|
128
|
-
// for (let i = 0; i < keys.length; i++) {
|
129
|
-
// const element = keys[i];
|
130
|
-
// temp = temp && temp[element];
|
131
|
-
// }
|
132
|
-
// return temp;
|
133
|
-
// }
|
134
|
-
|
135
|
-
function deprecationSupport(options) {
|
136
|
-
// if (selectn(options, ".app.hasRTL") === true) {
|
137
|
-
if (options.app.hasRTL === true) {
|
138
|
-
options.app.plugins.hasRTL = true;
|
139
|
-
}
|
140
|
-
|
141
|
-
if (options.docs.hasRTL === true) {
|
142
|
-
options.docs.plugins.hasRTL = true;
|
143
|
-
}
|
144
|
-
|
145
|
-
if (options.app.rtlExclude.length > 0) {
|
146
|
-
options.app.exclude.rtl = options.app.rtlExclude;
|
147
|
-
}
|
131
|
+
global.reactCLIOptions = null;
|
148
132
|
|
149
|
-
|
150
|
-
|
151
|
-
}
|
133
|
+
const getOptionsFromConfigFile = (appPath, configFileName) => {
|
134
|
+
const fileName = configFileName || 'build.config.js';
|
152
135
|
|
153
|
-
|
154
|
-
options.app.plugins.selectorReplace = true;
|
155
|
-
}
|
136
|
+
const packagePath = _path.default.join(appPath, fileName);
|
156
137
|
|
157
|
-
if (
|
158
|
-
|
138
|
+
if ((0, _fs.existsSync)(packagePath)) {
|
139
|
+
return require(packagePath).config;
|
159
140
|
}
|
160
141
|
|
161
|
-
|
162
|
-
|
163
|
-
}
|
164
|
-
|
165
|
-
options.app.exclude.hasRTL = options.app.exclude.rtl;
|
166
|
-
|
167
|
-
if (!options.app.patterns) {
|
168
|
-
options.app.patterns = {};
|
169
|
-
}
|
170
|
-
|
171
|
-
if (options.app.patterns.valueReplacer.length === 0) {
|
172
|
-
options.app.patterns.valueReplacer = ['*'];
|
173
|
-
}
|
174
|
-
|
175
|
-
if (options.app.patterns.selectorReplace.length === 0) {
|
176
|
-
options.app.patterns.selectorReplace = ['*'];
|
177
|
-
}
|
178
|
-
|
179
|
-
if (options.docs.patterns.selectorReplace.length === 0) {
|
180
|
-
options.docs.patterns.selectorReplace = ['*'];
|
181
|
-
}
|
182
|
-
|
183
|
-
Object.keys(options.app.patterns).forEach(key => {
|
184
|
-
if (options.app.exclude[key] && options.app.patterns[key].length === 0) {
|
185
|
-
let tempArr = options.app.exclude[key];
|
186
|
-
tempArr = tempArr.map(x => {
|
187
|
-
x = x.replace(/\//gi, _path.default.sep);
|
188
|
-
return `!**${x[0] === _path.default.sep || x[0] === '@' ? '' : _path.default.sep}${x}${x[x.length - 1] === _path.default.sep ? '' : _path.default.sep}**`;
|
189
|
-
});
|
190
|
-
options.app.patterns[key] = tempArr;
|
191
|
-
}
|
192
|
-
});
|
193
|
-
Object.keys(options.docs.patterns).forEach(key => {
|
194
|
-
if (options.docs.exclude[key] && options.docs.patterns[key].length === 0) {
|
195
|
-
let tempArr = options.docs.exclude[key];
|
196
|
-
tempArr = tempArr.map(x => {
|
197
|
-
x = x.replace(/\//gi, _path.default.sep);
|
198
|
-
return `!**${x[0] === _path.default.sep || x[0] === '@' ? '' : _path.default.sep}${x}${x[x.length - 1] === _path.default.sep ? '' : _path.default.sep}**`;
|
199
|
-
});
|
200
|
-
options.docs.patterns[key] = tempArr;
|
201
|
-
}
|
202
|
-
});
|
203
|
-
}
|
142
|
+
return null;
|
143
|
+
};
|
204
144
|
|
205
|
-
const getOptions =
|
145
|
+
const getOptions = fromRoot => {
|
206
146
|
if (global.reactCLIOptions) {
|
207
147
|
return global.reactCLIOptions;
|
208
148
|
}
|
209
149
|
|
210
150
|
const appPath = process.cwd();
|
211
|
-
let userSchemas;
|
151
|
+
let userSchemas = getOptionsFromConfigFile(appPath, processEnv.config_file);
|
212
152
|
|
213
153
|
const packagePath = _path.default.join(appPath, 'package.json');
|
214
154
|
|
215
155
|
if (_fs.default.existsSync(packagePath)) {
|
216
|
-
userSchemas = require(packagePath)['react-cli'] || {};
|
156
|
+
userSchemas = userSchemas || require(packagePath)['react-cli'] || {};
|
217
157
|
}
|
218
158
|
|
219
159
|
const options = defaulter(_schemas.default, userSchemas || {}); // for future may be for npm 8 edge cases
|
220
160
|
|
221
161
|
options.npmVersion = getNpmVersion();
|
222
162
|
options.cwd = getCWD();
|
223
|
-
deprecationSupport(options);
|
163
|
+
(0, _deprecationSupport.deprecationSupport)(options, options.disableDeprecationWarning || !fromRoot);
|
224
164
|
options.packageVersion = process.env.npm_package_version;
|
225
165
|
global.reactCLIOptions = options;
|
226
166
|
return options;
|
package/lib/utils/index.js
CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
var _exportNames = {
|
7
|
-
log: true,
|
8
7
|
writeFile: true,
|
9
8
|
makeDir: true,
|
10
9
|
getInfoFromPublicPaths: true,
|
11
10
|
getLibraryConflict: true,
|
11
|
+
log: true,
|
12
12
|
getOptions: true,
|
13
13
|
createEventStream: true,
|
14
14
|
getServerURL: true,
|
@@ -64,7 +64,13 @@ Object.defineProperty(exports, "jsonHelper", {
|
|
64
64
|
return _jsonHelper.default;
|
65
65
|
}
|
66
66
|
});
|
67
|
-
exports
|
67
|
+
Object.defineProperty(exports, "log", {
|
68
|
+
enumerable: true,
|
69
|
+
get: function () {
|
70
|
+
return _log.log;
|
71
|
+
}
|
72
|
+
});
|
73
|
+
exports.makeDir = void 0;
|
68
74
|
Object.defineProperty(exports, "pullOrigin", {
|
69
75
|
enumerable: true,
|
70
76
|
get: function () {
|
@@ -95,6 +101,8 @@ var _stream = require("stream");
|
|
95
101
|
|
96
102
|
var _fs = _interopRequireDefault(require("fs"));
|
97
103
|
|
104
|
+
var _log = require("./log");
|
105
|
+
|
98
106
|
var _getOptions = _interopRequireDefault(require("./getOptions"));
|
99
107
|
|
100
108
|
var _createEventStream = _interopRequireDefault(require("./createEventStream"));
|
@@ -161,13 +169,7 @@ var _ssTestHack = _interopRequireDefault(require("./ssTestHack"));
|
|
161
169
|
|
162
170
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
163
171
|
|
164
|
-
|
165
|
-
let print = console;
|
166
|
-
print.log(...info);
|
167
|
-
};
|
168
|
-
|
169
|
-
exports.log = log;
|
170
|
-
|
172
|
+
// eslint-disable-next-line no-duplicate-imports
|
171
173
|
let writeFile = (outputPath, src, isPath = false) => new Promise((resolve, reject) => {
|
172
174
|
let inStr;
|
173
175
|
|
@@ -314,9 +316,9 @@ let getLibraryConflict = (moduleObject, impactObj, changesOnly) => {
|
|
314
316
|
whichLibrary = "No component file changes!";
|
315
317
|
}
|
316
318
|
|
317
|
-
log('\n');
|
318
|
-
log('You can see the HTML out at coverageTest/impactLibrary.html!');
|
319
|
-
log('\x1b[33m%s\x1b[0m', '************************************************************ \n ');
|
319
|
+
(0, _log.log)('\n');
|
320
|
+
(0, _log.log)('You can see the HTML out at coverageTest/impactLibrary.html!');
|
321
|
+
(0, _log.log)('\x1b[33m%s\x1b[0m', '************************************************************ \n ');
|
320
322
|
return {
|
321
323
|
response: allImpactArray,
|
322
324
|
result: {
|
@@ -11,7 +11,7 @@ var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
|
12
12
|
var _child_process = require("child_process");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _log = require("./log");
|
15
15
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
17
|
|
@@ -38,7 +38,7 @@ let copyEslintConfig = rootDir => {
|
|
38
38
|
|
39
39
|
_fs.default.writeFileSync(targetPath, src);
|
40
40
|
|
41
|
-
(0,
|
41
|
+
(0, _log.log)('Eslint config added in project root path');
|
42
42
|
}
|
43
43
|
};
|
44
44
|
|
@@ -58,7 +58,7 @@ let initPreCommitHook = (forReactCLI = false) => {
|
|
58
58
|
|
59
59
|
_fs.default.writeFileSync(targetPath, precommit);
|
60
60
|
|
61
|
-
(0,
|
61
|
+
(0, _log.log)('pre-commit hook added');
|
62
62
|
}
|
63
63
|
|
64
64
|
let packagePath = _path.default.join(process.cwd(), 'package.json');
|
@@ -71,10 +71,10 @@ let initPreCommitHook = (forReactCLI = false) => {
|
|
71
71
|
|
72
72
|
_fs.default.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
|
73
73
|
|
74
|
-
(0,
|
74
|
+
(0, _log.log)('lint script added in your package.json');
|
75
75
|
}
|
76
76
|
} catch (e) {
|
77
|
-
(0,
|
77
|
+
(0, _log.log)('package.json not found');
|
78
78
|
}
|
79
79
|
}
|
80
80
|
};
|