@zohodesk/react-cli 1.1.1 → 1.1.2-9.exp.3

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.
Files changed (78) hide show
  1. package/.vscode/settings.json +25 -0
  2. package/README.md +446 -35
  3. package/bin/cli.js +17 -52
  4. package/docs/CustomChunks.md +12 -9
  5. package/docs/MarkdownParser.md +18 -0
  6. package/docs/ReactLive.md +8 -0
  7. package/docs/ValueReplacer.md +27 -0
  8. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  9. package/lib/babel/cmjs-plugins-presets.js +36 -7
  10. package/lib/babel/es-plugins-presets.js +45 -16
  11. package/lib/common/runPreProcess.js +71 -0
  12. package/lib/common/splitChunks.js +65 -45
  13. package/lib/common/testPattern.js +9 -9
  14. package/lib/configs/jest.config.js +4 -4
  15. package/lib/configs/libAlias.js +36 -2
  16. package/lib/configs/resolvers.js +7 -4
  17. package/lib/configs/webpack.css.umd.config.js +3 -2
  18. package/lib/configs/webpack.dev.config.js +28 -8
  19. package/lib/configs/webpack.docs.config.js +10 -5
  20. package/lib/configs/webpack.impact.config.js +9 -4
  21. package/lib/configs/webpack.prod.config.js +32 -10
  22. package/lib/constants.js +3 -3
  23. package/lib/deprecationLogger.js +40 -0
  24. package/lib/jest/preProcessors/jsPreprocessor.js +27 -2
  25. package/lib/loaderUtils/configsAssetsLoaders.js +1 -1
  26. package/lib/loaderUtils/getCSSLoaders.js +32 -8
  27. package/lib/loaderUtils/getDevJsLoaders.js +8 -2
  28. package/lib/loaders/__test__/markdownLoader.spec.js +145 -0
  29. package/lib/loaders/composeLoader.js +140 -14
  30. package/lib/loaders/docsLoader.js +5 -2
  31. package/lib/loaders/enhancedReactLiveConverter.js +151 -0
  32. package/lib/loaders/markdownLoader.js +71 -0
  33. package/lib/loaders/workerLoader.js +37 -22
  34. package/lib/logger.js +7 -0
  35. package/lib/pluginUtils/configHtmlWebpackPlugins.js +62 -2
  36. package/lib/pluginUtils/getDevPlugins.js +24 -8
  37. package/lib/pluginUtils/getProdPlugins.js +34 -6
  38. package/lib/plugins/CssOrderControlPlugin.js +36 -0
  39. package/lib/plugins/CustomScriptLoadingStrategyPlugin.js +109 -0
  40. package/lib/plugins/EfcResourceCleanupPlugin.js +43 -0
  41. package/lib/plugins/EventsHandlingPlugin.js +34 -0
  42. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +5 -1
  43. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +4 -1
  44. package/lib/plugins/I18nSplitPlugin/utils/unicodeConversion.js +14 -0
  45. package/lib/plugins/ReportGeneratePlugin.js +8 -6
  46. package/lib/plugins/ResourceHintsPlugin.js +13 -3
  47. package/lib/plugins/StatsPlugin.js +82 -0
  48. package/lib/plugins/UnusedFilesFindPlugin.js +7 -5
  49. package/lib/plugins/utils/fileHandling.js +36 -51
  50. package/lib/plugins/variableConvertorUtils.js +4 -2
  51. package/lib/postcss-plugins/ValueReplacer.js +7 -17
  52. package/lib/postcss-plugins/__test__/valueReplacer.spec.js +43 -0
  53. package/lib/postcss-plugins/variableModificationPlugin/index.js +70 -18
  54. package/lib/schemas/index.js +67 -39
  55. package/lib/servers/getCliPath.js +3 -5
  56. package/lib/servers/requireLocalOrGlobal.js +1 -1
  57. package/lib/utils/cssClassNameGenerate.js +43 -5
  58. package/lib/utils/deprecationSupport.js +134 -0
  59. package/lib/utils/getFileType.js +1 -1
  60. package/lib/utils/getOptions.js +31 -69
  61. package/lib/utils/getServerURL.js +7 -2
  62. package/lib/utils/index.js +27 -11
  63. package/lib/utils/initPreCommitHook.js +5 -5
  64. package/lib/utils/log.js +11 -0
  65. package/lib/utils/object-manipulation.js +88 -0
  66. package/lib/utils/pullOrigin.js +3 -3
  67. package/lib/utils/reinstallDependencies.js +3 -3
  68. package/lib/utils/switchBranch.js +4 -2
  69. package/lib/utils/typeCheck.js +10 -0
  70. package/lib/utils/variableConverter.js +26 -11
  71. package/npm-shrinkwrap.json +929 -39
  72. package/package.json +12 -4
  73. package/templates/docs/all.html +1 -0
  74. package/templates/docs/component.html +1 -0
  75. package/templates/docs/components.html +1 -0
  76. package/templates/docs/css/markdown.css +202 -0
  77. package/templates/docs/css/style.css +136 -169
  78. package/templates/docs/index.html +796 -632
package/lib/logger.js CHANGED
@@ -5,8 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.errorLogger = errorLogger;
7
7
  exports.messageLogger = messageLogger;
8
+ exports.verboseLogger = verboseLogger;
8
9
  exports.warnLogger = warnLogger;
9
10
 
11
+ /* eslint-disable no-console */
10
12
  function messageLogger(...args) {
11
13
  console.log(...args);
12
14
  }
@@ -17,4 +19,9 @@ function errorLogger(...args) {
17
19
 
18
20
  function warnLogger(...args) {
19
21
  console.warn(...args);
22
+ }
23
+
24
+ function verboseLogger(...args) {
25
+ // TODO: need to be remove when publish happens
26
+ process.env.VERBOSE === 'true' && console.log('\x1b[33m [verbose] \x1b[0m', ...args);
20
27
  }
@@ -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
  }
@@ -19,6 +19,8 @@ var _I18nSplitPlugin = _interopRequireDefault(require("../plugins/I18nSplitPlugi
19
19
 
20
20
  var _RequireVariablePublicPlugin = _interopRequireDefault(require("../plugins/RequireVariablePublicPlugin"));
21
21
 
22
+ var _CssOrderControlPlugin = _interopRequireDefault(require("../plugins/CssOrderControlPlugin"));
23
+
22
24
  var _copyWebpackPlugin = _interopRequireDefault(require("copy-webpack-plugin"));
23
25
 
24
26
  var _webpack = _interopRequireDefault(require("webpack"));
@@ -35,12 +37,17 @@ var _SelectorPlugin = _interopRequireDefault(require("../plugins/SelectorPlugin"
35
37
 
36
38
  var _configHtmlWebpackPlugins = require("./configHtmlWebpackPlugins");
37
39
 
40
+ var _EfcResourceCleanupPlugin = _interopRequireDefault(require("../plugins/EfcResourceCleanupPlugin"));
41
+
42
+ var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
43
+
38
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
45
 
40
46
  // import { windowsModification } from '../loaderUtils/windowsModification';
41
47
  const getDevPlugins = (options, publicPath) => {
42
48
  const {
43
49
  app: {
50
+ generateHtml,
44
51
  tpFolder,
45
52
  folder,
46
53
  instrumentScript,
@@ -58,7 +65,8 @@ const getDevPlugins = (options, publicPath) => {
58
65
  mode
59
66
  },
60
67
  htmlTemplate: {
61
- inject
68
+ inject,
69
+ customScriptLoadingStrategey
62
70
  },
63
71
  crossorigin
64
72
  },
@@ -69,10 +77,12 @@ const getDevPlugins = (options, publicPath) => {
69
77
  localeAttr: efcLocaleAttr
70
78
  },
71
79
  css: {
72
- enableRTLSplit
80
+ enableRTLSplit,
81
+ cssOrderControler
73
82
  },
74
83
  i18n,
75
- unusedFiles
84
+ unusedFiles,
85
+ resourceHints
76
86
  } = options;
77
87
  const hasEFC = newOptionForEnableEFC || prevOptionForEnableEFC;
78
88
  const cssLTRFileNameTempalte = enableRTLSplit ? 'css/[name].ltr.css' : 'css/[name].css';
@@ -94,7 +104,7 @@ const getDevPlugins = (options, publicPath) => {
94
104
  filename: cssLTRFileNameTempalte,
95
105
  // ignoreOrder: true,
96
106
  chunkFilename: cssLTRFileNameTempalte
97
- }), new _plugins.ResourceHintsPlugin()];
107
+ }), new _plugins.ResourceHintsPlugin(resourceHints)];
98
108
 
99
109
  if (enableRTLSplit) {
100
110
  pluginsArr.push(new _RtlCssPlugin.RtlCssPlugin({
@@ -157,13 +167,14 @@ const getDevPlugins = (options, publicPath) => {
157
167
  collections: true,
158
168
  shorthands: true
159
169
  }));
160
- (0, _configHtmlWebpackPlugins.configHtmlWebpackPlugins)(pluginsArr, {
170
+ generateHtml && (0, _configHtmlWebpackPlugins.configHtmlWebpackPlugins)(pluginsArr, {
161
171
  enableChunkHash: false,
162
172
  folder,
163
173
  minify: false,
164
174
  inject,
165
175
  crossorigin,
166
- hasEFC
176
+ hasEFC,
177
+ customScriptLoadingStrategey
167
178
  });
168
179
 
169
180
  if (hasEFC) {
@@ -189,7 +200,11 @@ const getDevPlugins = (options, publicPath) => {
189
200
  mainChunkName: 'main'
190
201
  }));
191
202
  instrumentScript && pluginsArr.push(new _plugins.ScriptInstrumentPlugin());
203
+ cssOrderControler.enable && pluginsArr.push(new _CssOrderControlPlugin.default(cssOrderControler));
192
204
  customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
205
+ customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(Object.assign({}, customAttributes, {
206
+ globalCacheObj: context
207
+ })));
193
208
  hasShadowDOM && pluginsArr.push(new _plugins.ShadowDOMSupportPlugin());
194
209
 
195
210
  if (devCssFileBountry) {
@@ -211,12 +226,13 @@ const getDevPlugins = (options, publicPath) => {
211
226
  exclude: exclude.selectorWeight,
212
227
  patterns
213
228
  }));
214
- } // if (pluginObject.minifier) {
229
+ }
230
+
231
+ pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin()); // if (pluginObject.minifier) {
215
232
  // // console.log('minifier active');
216
233
  // pluginsArr.push(new MinifierPlugin());
217
234
  // }
218
235
 
219
-
220
236
  return pluginsArr.filter(Boolean);
221
237
  };
222
238
 
@@ -27,14 +27,22 @@ var _VariableConversionCollector = _interopRequireDefault(require("../plugins/Va
27
27
 
28
28
  var _SelectorPlugin = _interopRequireDefault(require("../plugins/SelectorPlugin"));
29
29
 
30
+ var _EventsHandlingPlugin = require("../plugins/EventsHandlingPlugin");
31
+
30
32
  var _plugins = require("../plugins");
31
33
 
32
34
  var _CustomAttributePlugin = require("../plugins/CustomAttributePlugin");
33
35
 
34
36
  var _RtlCssPlugin = require("../plugins/RtlSplitPlugin/RtlCssPlugin");
35
37
 
38
+ var _CssOrderControlPlugin = _interopRequireDefault(require("../plugins/CssOrderControlPlugin"));
39
+
36
40
  var _configHtmlWebpackPlugins = require("./configHtmlWebpackPlugins");
37
41
 
42
+ var _StatsPlugin = _interopRequireDefault(require("../plugins/StatsPlugin"));
43
+
44
+ var _EfcResourceCleanupPlugin = _interopRequireDefault(require("../plugins/EfcResourceCleanupPlugin"));
45
+
38
46
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
47
 
40
48
  // eslint-disable-next-line no-unused-vars
@@ -43,6 +51,7 @@ const getProdPlugins = (options, publicPath = '') => {
43
51
  enableChunkHash
44
52
  } = options.app;
45
53
  const {
54
+ generateHtml,
46
55
  manifestFileName,
47
56
  bundleAnalyze,
48
57
  optimize,
@@ -74,13 +83,15 @@ const getProdPlugins = (options, publicPath = '') => {
74
83
  } = options.app;
75
84
  const {
76
85
  inject,
77
- minify: minifyHtmlOptions
86
+ minify: minifyHtmlOptions,
87
+ customScriptLoadingStrategey
78
88
  } = htmlTemplate;
79
89
  const {
80
90
  i18n
81
91
  } = options;
82
92
  const {
83
- enableRTLSplit
93
+ enableRTLSplit,
94
+ cssOrderControler
84
95
  } = options.css;
85
96
  const {
86
97
  hasEFC: newOptionForEnableEFC,
@@ -88,6 +99,12 @@ const getProdPlugins = (options, publicPath = '') => {
88
99
  templateFilePath,
89
100
  localeAttr: efcLocaleAttr
90
101
  } = options.efc;
102
+ const {
103
+ enable: enableStats,
104
+ options: statsOptions,
105
+ excludeKeys: statsOutputExcludeKeys,
106
+ fileName: statsFileName
107
+ } = options.stats;
91
108
  const hasEFC = newOptionForEnableEFC || prevOptionForEnableEFC;
92
109
  const hashTempalate = enableChunkHash ? '.[chunkhash:20]_' : '';
93
110
  const cssLTRFileNameTempalte = `css/[name]${hashTempalate}${enableRTLSplit ? '.ltr' : ''}.css`;
@@ -107,7 +124,7 @@ const getProdPlugins = (options, publicPath = '') => {
107
124
  // ignoreOrder: true,
108
125
  filename: cssLTRFileNameTempalte,
109
126
  chunkFilename: cssLTRFileNameTempalte
110
- }), new _plugins.ResourceHintsPlugin(), new _plugins.MinifyPlugin()];
127
+ }), new _plugins.ResourceHintsPlugin(options.resourceHints), new _plugins.MinifyPlugin()];
111
128
 
112
129
  if (enableRTLSplit) {
113
130
  pluginsArr.push(new _RtlCssPlugin.RtlCssPlugin({
@@ -161,11 +178,12 @@ const getProdPlugins = (options, publicPath = '') => {
161
178
  to: `./${tpFolder}/`,
162
179
  toType: 'dir'
163
180
  }]));
164
- (0, _configHtmlWebpackPlugins.configHtmlWebpackPlugins)(pluginsArr, {
181
+ generateHtml && (0, _configHtmlWebpackPlugins.configHtmlWebpackPlugins)(pluginsArr, {
165
182
  enableChunkHash,
166
183
  folder,
167
184
  inject,
168
185
  minify: minifyHtmlOptions,
186
+ customScriptLoadingStrategey,
169
187
  crossorigin,
170
188
  hasEFC
171
189
  });
@@ -227,9 +245,9 @@ const getProdPlugins = (options, publicPath = '') => {
227
245
  if (bundleAnalyze) {
228
246
  pluginsArr.push(new _webpackBundleAnalyzer.BundleAnalyzerPlugin({
229
247
  analyzerMode: 'static',
230
- generateStatsFile: true,
248
+ generateStatsFile: false,
231
249
  openAnalyzer: false,
232
- statsOptions: {
250
+ statsOptions: enableStats ? null : {
233
251
  source: false,
234
252
  normal: true,
235
253
  chunks: false,
@@ -287,7 +305,17 @@ const getProdPlugins = (options, publicPath = '') => {
287
305
  } // plugins.push(new VariableConversionCollector({}));
288
306
 
289
307
 
308
+ cssOrderControler.enable && pluginsArr.push(new _CssOrderControlPlugin.default(cssOrderControler));
290
309
  customAttributes.enable && pluginsArr.push(new _CustomAttributePlugin.CustomAttributePlugin(customAttributes));
310
+ customAttributes.enable && pluginsArr.push(new _EfcResourceCleanupPlugin.default(Object.assign({}, customAttributes, {
311
+ globalCacheObj: context
312
+ })));
313
+ enableStats && pluginsArr.push(new _StatsPlugin.default({
314
+ statsOptions,
315
+ statsOutputExcludeKeys,
316
+ statsFileName
317
+ }));
318
+ pluginsArr.push(new _EventsHandlingPlugin.EventsHandlingPlugin());
291
319
  return pluginsArr;
292
320
  };
293
321
 
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ class CssOrderControlPlugin {
9
+ constructor(options) {
10
+ this.options = {
11
+ className: options.className
12
+ };
13
+ }
14
+
15
+ apply(compiler) {
16
+ // NOTE: we not using this, Reason currently this option is only need for EFC,
17
+ // So it do not needed.
18
+ const className = this.options.className;
19
+ compiler.hooks.thisCompilation.tap({
20
+ name: 'CssOrderControlPlugin',
21
+ stage: 1,
22
+ fn: compilation => {
23
+ compilation.mainTemplate.hooks.requireEnsure.tap('CssOrderControlPlugin', source => {
24
+ // const str = attributeSetTemplate(cssAttributes, 'linkTag');
25
+ const replacedStr = source.replace('head.appendChild(linkTag);', `var referenceTag = document.getElementById('${className}');
26
+ head.insertBefore(linkTag, referenceTag);`); // console.log({ s: source, r: replacedStr });
27
+
28
+ return replacedStr;
29
+ });
30
+ }
31
+ });
32
+ }
33
+
34
+ }
35
+
36
+ exports.default = CssOrderControlPlugin;
@@ -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;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ const {
4
+ Template
5
+ } = require('webpack');
6
+
7
+ const plugInName = 'EFCResourceCleanup';
8
+ module.exports = class EfcResouceCleanupPlugin {
9
+ constructor(options) {
10
+ this.options = options;
11
+ }
12
+
13
+ apply(compiler) {
14
+ compiler.hooks.thisCompilation.tap(plugInName, ({
15
+ mainTemplate
16
+ }) => {
17
+ mainTemplate.hooks.afterStartup.tap(plugInName, source => {
18
+ const {
19
+ attributes,
20
+ globalCacheObj
21
+ } = this.options;
22
+ const attributesArr = Object.entries(attributes);
23
+ const [[attributekey, attributeValue]] = attributesArr;
24
+ const resourceSelector = `[${attributekey}="${attributeValue}"]`;
25
+ return Template.asString([source, Template.indent([` window['${globalCacheObj}Jsonp'].unInstall = function() {
26
+ Object.keys(installedModules).forEach(installedModulesKey => installedModules[installedModulesKey] = null);
27
+ Object.keys(modules).forEach(moduleKey => modules[moduleKey] = null);
28
+ `, `
29
+ installedModules = null;
30
+ modules = null;
31
+ __webpack_require__.m = null;
32
+ __webpack_require__.c = null;
33
+
34
+ `, attributekey && attributeValue ? `
35
+ const addedResources = document.querySelectorAll('${resourceSelector}');
36
+ addedResources.forEach(addedResource => addedResource.remove());
37
+ }
38
+ ` : ''])]);
39
+ });
40
+ });
41
+ }
42
+
43
+ };
@@ -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 = resolve;
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";
@@ -13,6 +13,8 @@ var _path = require("path");
13
13
 
14
14
  var _logger = require("../../../logger");
15
15
 
16
+ var _unicodeConversion = require("./unicodeConversion");
17
+
16
18
  function isComment(line) {
17
19
  return line[0] === '#';
18
20
  }
@@ -31,7 +33,8 @@ function getPropertiesAsJSON(filePath) {
31
33
 
32
34
  const ind = line.indexOf('=');
33
35
  const key = line.slice(0, ind).replace(/\\ /g, ' ');
34
- const value = line.slice(ind + 1);
36
+ let value = line.slice(ind + 1);
37
+ value = (0, _unicodeConversion.convertUnicode)(value);
35
38
 
36
39
  if (key && value) {
37
40
  i18nObj[key] = value;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.convertUnicode = convertUnicode;
7
+
8
+ function convertUnicode(str) {
9
+ const unicodeRegex = /\\u([a-fA-F0-9]{4})/g;
10
+ const converted = str.replace(unicodeRegex, (match, hex) => {
11
+ return String.fromCharCode(parseInt(hex, 16));
12
+ });
13
+ return converted;
14
+ }
@@ -13,6 +13,8 @@ var _redis = _interopRequireDefault(require("redis"));
13
13
 
14
14
  var _utils = require("../utils");
15
15
 
16
+ var _log = require("../utils/log");
17
+
16
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
19
 
18
20
  let options = (0, _utils.getOptions)();
@@ -68,10 +70,10 @@ class reportGeneratePlugin {
68
70
  let client = _redis.default.createClient(redisPort, redisHost);
69
71
 
70
72
  client.on('connect', () => {
71
- (0, _utils.log)('Redis client connected');
73
+ (0, _log.log)('Redis client connected');
72
74
  });
73
75
  client.on('error', err => {
74
- (0, _utils.log)(`Something went wrong ${err}`);
76
+ (0, _log.log)(`Something went wrong ${err}`);
75
77
  });
76
78
 
77
79
  if (_fs.default.existsSync(_path.default.resolve(process.cwd(), 'build', 'stats.json'))) {
@@ -80,7 +82,7 @@ class reportGeneratePlugin {
80
82
  statsJSON = JSON.parse(statsJSON);
81
83
  let finalObj = {};
82
84
  let branchName = branch ? branch : (0, _utils.getCurrentBranch)();
83
- (0, _utils.log)(branchName);
85
+ (0, _log.log)(branchName);
84
86
  statsJSON.assets.forEach(assetObj => {
85
87
  let nameSplitList = assetObj.name.split('/')[assetObj.name.split('/').length - 1].split('.'); // eslint-disable-line
86
88
 
@@ -111,7 +113,7 @@ class reportGeneratePlugin {
111
113
  };
112
114
  client.get(branchName, (err, reply) => {
113
115
  if (err) {
114
- (0, _utils.log)(err);
116
+ (0, _log.log)(err);
115
117
  } else {
116
118
  reply = JSON.parse(reply); // eslint-disable-line
117
119
 
@@ -147,7 +149,7 @@ class reportGeneratePlugin {
147
149
  throw err;
148
150
  }
149
151
 
150
- (0, _utils.log)('Stats Json generated!');
152
+ (0, _log.log)('Stats Json generated!');
151
153
  });
152
154
  }
153
155
  });
@@ -169,7 +171,7 @@ class reportGeneratePlugin {
169
171
  }
170
172
 
171
173
  if (err) {
172
- (0, _utils.log)(err);
174
+ (0, _log.log)(err);
173
175
  }
174
176
  });
175
177
  }