@zohodesk/react-cli 1.1.20 → 1.1.22-exp.1
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 +38 -1
- package/bin/cli.js +4 -0
- package/lib/babel/cmjs-plugins-presets.js +24 -9
- package/lib/babel/es-plugins-presets.js +33 -18
- package/lib/configs/jest.config.js +3 -3
- package/lib/configs/resolvers.js +1 -0
- package/lib/configs/webpack.dev.config.js +7 -2
- package/lib/configs/webpack.prod.config.js +12 -4
- package/lib/jest/preProcessors/jsPreprocessor.js +23 -2
- package/lib/loaderUtils/getDevJsLoaders.js +2 -1
- package/lib/loaders/workerLoader.js +39 -24
- package/lib/pluginUtils/configHtmlWebpackPlugins.js +57 -1
- package/lib/pluginUtils/getDevPlugins.js +9 -4
- package/lib/pluginUtils/getProdPlugins.js +6 -1
- package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +108 -0
- package/lib/plugins/EventsHandlingPlugin.js +34 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
- package/lib/schemas/index.js +12 -1
- package/lib/utils/index.js +14 -0
- package/lib/utils/typeCheck.js +10 -0
- package/npm-shrinkwrap.json +983 -27
- package/package.json +4 -1
@@ -0,0 +1,108 @@
|
|
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
|
+
}
|
20
|
+
|
21
|
+
getFileNameFromTagSrc(src) {
|
22
|
+
const fileNameArr = src.split('/');
|
23
|
+
return fileNameArr[fileNameArr.length - 1];
|
24
|
+
}
|
25
|
+
|
26
|
+
addAttributestToTag(tag, attributes) {
|
27
|
+
tag.attributes = Object.assign({}, tag.attributes, attributes);
|
28
|
+
}
|
29
|
+
|
30
|
+
matchFileName(tag, fileName) {
|
31
|
+
return fileName.test(this.getFileNameFromTagSrc(tag.attributes.src));
|
32
|
+
}
|
33
|
+
|
34
|
+
blockingStrategy(tag) {
|
35
|
+
delete tag.attributes.defer;
|
36
|
+
delete tag.attributes.async;
|
37
|
+
}
|
38
|
+
|
39
|
+
deferStrategy(tag) {
|
40
|
+
delete tag.attributes.async;
|
41
|
+
}
|
42
|
+
|
43
|
+
asyncStrategy(tag) {
|
44
|
+
delete tag.attributes.defer;
|
45
|
+
}
|
46
|
+
|
47
|
+
moduleStrategy(tag) {
|
48
|
+
this.deferStrategy(tag);
|
49
|
+
}
|
50
|
+
|
51
|
+
matchStrategy(scriptLoadingStrategy, tag) {
|
52
|
+
if (scriptLoadingStrategy === 'blocking') {
|
53
|
+
this.blockingStrategy(tag);
|
54
|
+
}
|
55
|
+
|
56
|
+
if (scriptLoadingStrategy === 'defer') {
|
57
|
+
this.deferStrategy(tag);
|
58
|
+
}
|
59
|
+
|
60
|
+
if (scriptLoadingStrategy === 'async') {
|
61
|
+
this.asyncStrategy(tag);
|
62
|
+
}
|
63
|
+
|
64
|
+
if (scriptLoadingStrategy === 'module') {
|
65
|
+
this.moduleStrategy(tag);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
matchAndApplyCustomLoadingStrategyToScripts(tags) {
|
70
|
+
Object.keys(this.scriptLoadingStrategy).forEach(scriptLoadingStrategy => {
|
71
|
+
const filesToMatch = this.scriptLoadingStrategy[scriptLoadingStrategy];
|
72
|
+
tags.forEach(tag => {
|
73
|
+
if (tag.attributes.src) {
|
74
|
+
const isFileMatch = filesToMatch.some(fileName => this.matchFileName(tag, fileName));
|
75
|
+
|
76
|
+
if (isFileMatch) {
|
77
|
+
this.matchStrategy(scriptLoadingStrategy, tag);
|
78
|
+
this.addAttributestToTag(tag, {
|
79
|
+
[scriptLoadingStrategy]: true
|
80
|
+
});
|
81
|
+
}
|
82
|
+
} // filesToMatch.forEach(fileName => {
|
83
|
+
// if (!this.matchFileName(tag, fileName)) {
|
84
|
+
// return;
|
85
|
+
// }
|
86
|
+
// this.matchStrategy(scriptLoadingStrategy, tag);
|
87
|
+
// this.addAttributestToTag(tag, fileName, {
|
88
|
+
// [scriptLoadingStrategy]: true
|
89
|
+
// });
|
90
|
+
// });
|
91
|
+
|
92
|
+
});
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
apply(compiler) {
|
97
|
+
compiler.hooks.compilation.tap(pluginName, compilation => {
|
98
|
+
_htmlWebpackPlugin.default.getHooks(compilation).alterAssetTagGroups.tapAsync(pluginName, (data, callback) => {
|
99
|
+
const tags = [...data.bodyTags, ...data.headTags];
|
100
|
+
this.matchAndApplyCustomLoadingStrategyToScripts(tags);
|
101
|
+
callback(null, data);
|
102
|
+
});
|
103
|
+
});
|
104
|
+
}
|
105
|
+
|
106
|
+
}
|
107
|
+
|
108
|
+
exports.default = CustomScriptLoadingStrategyPlugin;
|
@@ -0,0 +1,34 @@
|
|
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
|
+
// NOTE: we not using this, Reason currently this option is only need for EFC,
|
14
|
+
// So it do not needed.
|
15
|
+
compiler.hooks.thisCompilation.tap({
|
16
|
+
name: 'CustomAttributePlugin',
|
17
|
+
stage: 1,
|
18
|
+
fn: compilation => {
|
19
|
+
compilation.mainTemplate.hooks.requireEnsure.tap('CustomAttributePlugin', source => {
|
20
|
+
// const str = attributeSetTemplate(cssAttributes, 'linkTag');
|
21
|
+
const sourceStr = source.replace('linkTag.onerror = function(event) {', 'linkTag.onerror = function(event) { linkTag.onerror = linkTag.onload = null;');
|
22
|
+
const replacedSourceStr = sourceStr.replace('linkTag.onload = resolve', `linkTag.onload = () => {
|
23
|
+
linkTag.onerror = linkTag.onload = null;
|
24
|
+
resolve();
|
25
|
+
};`);
|
26
|
+
return replacedSourceStr;
|
27
|
+
});
|
28
|
+
}
|
29
|
+
});
|
30
|
+
}
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
exports.EventsHandlingPlugin = EventsHandlingPlugin;
|
@@ -228,8 +228,12 @@ class I18nDownlodLogic {
|
|
228
228
|
if(dataSrc === srcPath || dataSrc === fullsrcPath){ return resolve();}
|
229
229
|
}
|
230
230
|
var scriptTag = document.createElement("script");
|
231
|
-
scriptTag.onload =
|
231
|
+
scriptTag.onload = () => {
|
232
|
+
scriptTag.onerror = scriptTag.onload = null;
|
233
|
+
resolve();
|
234
|
+
};
|
232
235
|
scriptTag.onerror = function(event) {
|
236
|
+
scriptTag.onerror = scriptTag.onload = null;
|
233
237
|
var request = event && event.target && event.target.src || fullsrcPath;
|
234
238
|
var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + request + ")");
|
235
239
|
err.code = "I18N_CHUNK_LOAD_FAILED";
|
package/lib/schemas/index.js
CHANGED
@@ -322,7 +322,11 @@ var _default = {
|
|
322
322
|
},
|
323
323
|
htmlTemplate: {
|
324
324
|
minify: null,
|
325
|
-
inject: true
|
325
|
+
inject: true,
|
326
|
+
customScriptLoadingStrategey: {
|
327
|
+
enable: false,
|
328
|
+
options: null
|
329
|
+
}
|
326
330
|
},
|
327
331
|
removePropTypes: false,
|
328
332
|
customChunksBaseConfig: null,
|
@@ -738,6 +742,13 @@ var _default = {
|
|
738
742
|
fileName: null,
|
739
743
|
options: null,
|
740
744
|
excludeKeys: null
|
745
|
+
},
|
746
|
+
babelCustomizationForLibrary: {
|
747
|
+
babelPlugins: []
|
748
|
+
},
|
749
|
+
enableTypeScript: {
|
750
|
+
value: false,
|
751
|
+
cli: 'enable_typescript'
|
741
752
|
}
|
742
753
|
};
|
743
754
|
exports.default = _default;
|
package/lib/utils/index.js
CHANGED
@@ -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
|