@zohodesk/react-cli 0.0.1-exp.175.1 → 0.0.1-exp.176.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. package/README.md +35 -40
  2. package/docs/SelectorWeight.md +6 -0
  3. package/docs/VariableConversion.md +33 -1
  4. package/lib/babel/cmjs-plugins-presets.js +4 -0
  5. package/lib/babel/es-plugins-presets.js +4 -0
  6. package/lib/common/getEntries.js +10 -0
  7. package/lib/common/getPublicPathConfig.js +6 -0
  8. package/lib/common/index.js +5 -0
  9. package/lib/common/splitChunks.js +13 -2
  10. package/lib/common/sslcertUpdater.js +17 -6
  11. package/lib/common/templateParameters.js +2 -0
  12. package/lib/common/testPattern.js +21 -10
  13. package/lib/common/valueReplacer.js +15 -0
  14. package/lib/configs/jest.config.js +9 -0
  15. package/lib/configs/libAlias.js +2 -4
  16. package/lib/configs/webpack.component.umd.config.js +5 -0
  17. package/lib/configs/webpack.css.umd.config.js +13 -5
  18. package/lib/configs/webpack.dev.config.js +36 -2
  19. package/lib/configs/webpack.docs.config.js +21 -1
  20. package/lib/configs/webpack.impact.config.js +19 -1
  21. package/lib/configs/webpack.prod.config.js +37 -3
  22. package/lib/hooks/docsProptypeHook.js +7 -3
  23. package/lib/jest/commitedFilesResult.js +45 -3
  24. package/lib/jest/coverageCollector.js +11 -0
  25. package/lib/jest/jsonMaker.js +6 -0
  26. package/lib/jest/preProcessors/cssPreprocessor.js +8 -0
  27. package/lib/jest/preProcessors/jsPreprocessor.js +2 -0
  28. package/lib/jest/preProcessors/otherFilesPreprocessor.js +3 -0
  29. package/lib/jest/result.js +22 -0
  30. package/lib/jest/run.js +17 -6
  31. package/lib/jest/setup.js +57 -5
  32. package/lib/loaderUtils/configsAssetsLoaders.js +11 -1
  33. package/lib/loaderUtils/getCSSLoaders.js +35 -20
  34. package/lib/loaderUtils/getDevJsLoaders.js +8 -0
  35. package/lib/loaderUtils/index.js +3 -0
  36. package/lib/loaderUtils/windowsModification.js +11 -0
  37. package/lib/loaders/docsLoader.js +7 -0
  38. package/lib/loaders/docsPropsLoader.js +7 -3
  39. package/lib/loaders/fileBountryLoader.js +2 -0
  40. package/lib/loaders/fileLoader.js +22 -11
  41. package/lib/loaders/scriptInstrumentLoader.js +13 -5
  42. package/lib/loaders/selectorMappingLoader.js +25 -7
  43. package/lib/loaders/workerLoader.js +20 -4
  44. package/lib/middlewares/HMRMiddleware.js +26 -13
  45. package/lib/middlewares/SSTMiddleware.js +3 -0
  46. package/lib/pluginUtils/configHtmlWebpackPlugins.js +9 -3
  47. package/lib/pluginUtils/getDevPlugins.js +63 -17
  48. package/lib/pluginUtils/getDocsPlugins.js +10 -1
  49. package/lib/pluginUtils/getLibraryImactPlugins.js +5 -4
  50. package/lib/pluginUtils/getLibraryPlugins.js +5 -0
  51. package/lib/pluginUtils/getProdPlugins.js +72 -23
  52. package/lib/pluginUtils/getServerPlugins.js +5 -0
  53. package/lib/pluginUtils/getUMDCSSPlugins.js +7 -0
  54. package/lib/pluginUtils/getUMDComponentPlugins.js +7 -0
  55. package/lib/pluginUtils/index.js +8 -0
  56. package/lib/plugins/CdnChangePlugin.js +14 -0
  57. package/lib/plugins/CleanupStatsPlugin.js +5 -0
  58. package/lib/plugins/EFCPlugin.js +34 -23
  59. package/lib/plugins/EFCTemplatePlugin.js +32 -23
  60. package/lib/plugins/I18NInjectIntoIndexPlugin.js +34 -8
  61. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +17 -12
  62. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +10 -4
  63. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +39 -8
  64. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +29 -14
  65. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +22 -13
  66. package/lib/plugins/I18nSplitPlugin/index.js +23 -13
  67. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +12 -2
  68. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +1 -0
  69. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +5 -0
  70. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +6 -0
  71. package/lib/plugins/I18nSplitPlugin/utils/index.js +4 -0
  72. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +20 -2
  73. package/lib/plugins/ManifestPlugin.js +17 -0
  74. package/lib/plugins/ModuleStatsPlugin.js +23 -0
  75. package/lib/plugins/OptimizeJSPlugin.js +7 -0
  76. package/lib/plugins/PublicPathCallbackPlugin.js +10 -0
  77. package/lib/plugins/PublicPathChangePlugin.js +36 -4
  78. package/lib/plugins/ReportGeneratePlugin.js +30 -4
  79. package/lib/plugins/RequireVariablePublicPlugin.js +6 -0
  80. package/lib/plugins/ResourceHintsPlugin.js +10 -3
  81. package/lib/plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +17 -12
  82. package/lib/plugins/RtlSplitPlugin/RtlCssPlugin.js +16 -9
  83. package/lib/plugins/RtlSplitPlugin/replaceCssDirTemplate.js +5 -2
  84. package/lib/plugins/ScriptInstrumentPlugin.js +7 -0
  85. package/lib/plugins/SelectorPlugin.js +97 -0
  86. package/lib/plugins/ServiceWorkerPlugin.js +20 -4
  87. package/lib/plugins/ShadowDOMSupportPlugin.js +40 -3
  88. package/lib/plugins/SourceMapHookPlugin.js +9 -0
  89. package/lib/plugins/TPHashMappingPlugin.js +15 -1
  90. package/lib/plugins/UglifyCSSPlugin.js +9 -0
  91. package/lib/plugins/UnusedFilesFindPlugin.js +35 -2
  92. package/lib/plugins/VariableConversionCollector.js +252 -0
  93. package/lib/plugins/composeCommonPlugin.js +30 -0
  94. package/lib/plugins/index.js +19 -0
  95. package/lib/plugins/libraryImpactPlugin.js +32 -0
  96. package/lib/plugins/webpackwatchrunplugin.js +5 -0
  97. package/lib/postcss-plugins/ExcludePlugin.js +4 -0
  98. package/lib/postcss-plugins/RTLSplitPlugin.js +27 -14
  99. package/lib/postcss-plugins/ValueReplacer.js +6 -9
  100. package/lib/postcss-plugins/__test__/hoverActivePlugin.spec.js +3 -0
  101. package/lib/postcss-plugins/hoverActivePlugin.js +66 -30
  102. package/lib/postcss-plugins/variableModificationPlugin/ErrorHandler.js +40 -13
  103. package/lib/postcss-plugins/variableModificationPlugin/index.js +215 -141
  104. package/lib/postcss-plugins/variableModifier.js +20 -13
  105. package/lib/schemas/index.js +23 -4
  106. package/lib/servers/clusterHubServer.js +10 -0
  107. package/lib/servers/devBuild.js +24 -13
  108. package/lib/servers/docsServer.js +2 -0
  109. package/lib/servers/docsServerCore.js +21 -0
  110. package/lib/servers/getCliPath.js +9 -0
  111. package/lib/servers/helpServer.js +5 -0
  112. package/lib/servers/httpsOptions.js +4 -0
  113. package/lib/servers/impactServer.js +34 -2
  114. package/lib/servers/mockserver.js +9 -0
  115. package/lib/servers/nowatchserver.js +34 -12
  116. package/lib/servers/scrServer.js +20 -13
  117. package/lib/servers/server.js +35 -7
  118. package/lib/servers/ssServer.js +16 -0
  119. package/lib/templates/CoverageScriptTemplate.js +14 -0
  120. package/lib/templates/WMSTemplate.js +12 -6
  121. package/lib/utils/babelPresets.js +2 -0
  122. package/lib/utils/clean.js +8 -2
  123. package/lib/utils/copy.js +6 -0
  124. package/lib/utils/copyTimezones.js +8 -0
  125. package/lib/utils/createEventStream.js +4 -0
  126. package/lib/utils/cssClassNameGenerate.js +19 -3
  127. package/lib/utils/cssURLReplacer.js +50 -38
  128. package/lib/utils/dependencyPostPublish.js +9 -0
  129. package/lib/utils/fileUtils.js +26 -0
  130. package/lib/utils/folderIterator.js +10 -0
  131. package/lib/utils/getComponents.js +21 -0
  132. package/lib/utils/getCurrentBranch.js +5 -0
  133. package/lib/utils/getDependenciesImpactList.js +21 -0
  134. package/lib/utils/getFileType.js +49 -0
  135. package/lib/utils/getHash.js +7 -0
  136. package/lib/utils/getIp.js +2 -0
  137. package/lib/utils/getOptions.js +39 -14
  138. package/lib/utils/getServerURL.js +7 -0
  139. package/lib/utils/index.js +47 -2
  140. package/lib/utils/init.js +1 -0
  141. package/lib/utils/initPreCommitHook.js +29 -6
  142. package/lib/utils/jsonHelper.js +19 -2
  143. package/lib/utils/libraryImpactConfig.js +2 -0
  144. package/lib/utils/lint/addScripts.js +5 -2
  145. package/lib/utils/lint/checkExistingConfig.js +12 -3
  146. package/lib/utils/lint/copyConfigs.js +3 -0
  147. package/lib/utils/lint/index.js +9 -0
  148. package/lib/utils/lint/lintScripts.js +1 -0
  149. package/lib/utils/lint/lintSetup.js +4 -3
  150. package/lib/utils/lint/lintStagedPreCommitHook.js +1 -0
  151. package/lib/utils/lint/question.js +7 -0
  152. package/lib/utils/lintReporter.js +20 -0
  153. package/lib/utils/mailSender.js +7 -0
  154. package/lib/utils/pullOrigin.js +4 -0
  155. package/lib/utils/reinstallDependencies.js +28 -0
  156. package/lib/utils/removeAttributes.js +7 -0
  157. package/lib/utils/repoClone.js +27 -2
  158. package/lib/utils/request.js +12 -0
  159. package/lib/utils/rtl.js +16 -4
  160. package/lib/utils/setEnvVariables.js +2 -0
  161. package/lib/utils/ssTestHack.js +10 -0
  162. package/lib/utils/switchBranch.js +4 -0
  163. package/lib/utils/urlConcat.js +4 -0
  164. package/lib/utils/useExitCleanup.js +10 -9
  165. package/package.json +10 -9
@@ -4,20 +4,25 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  class CleanUpStatsPlugin {
8
9
  shouldPickStatChild(child) {
9
10
  return child.name.indexOf('mini-css-extract-plugin') !== 0;
10
11
  }
12
+
11
13
  apply(compiler) {
12
14
  compiler.hooks.done.tap('CleanUpStatsPlugin', stats => {
13
15
  const {
14
16
  children
15
17
  } = stats.compilation;
18
+
16
19
  if (Array.isArray(children)) {
17
20
  // eslint-disable-next-line no-param-reassign
18
21
  stats.compilation.children = children.filter(child => this.shouldPickStatChild(child));
19
22
  }
20
23
  });
21
24
  }
25
+
22
26
  }
27
+
23
28
  exports.default = CleanUpStatsPlugin;
@@ -4,16 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _webpackSources = require("webpack-sources");
9
+
8
10
  var _utils = require("../utils");
11
+
9
12
  var _path = _interopRequireDefault(require("path"));
13
+
10
14
  var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
15
+
11
16
  var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
17
+
12
18
  var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
19
+
13
20
  var _EFCTemplatePlugin = _interopRequireDefault(require("./EFCTemplatePlugin"));
21
+
14
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- // import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
16
23
 
24
+ // import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
17
25
  const cliOptions = (0, _utils.getOptions)();
18
26
  const {
19
27
  app: {
@@ -31,18 +39,17 @@ const {
31
39
  createSDkFile,
32
40
  cdnStatement
33
41
  } = efcOptios;
42
+
34
43
  class EFCPlugin {
35
44
  constructor(options = {}) {
36
45
  this.isDevelopment = options.isDevelopment;
37
46
  this.templateFilePath = options.templateFilePath;
38
47
  this.serverUrl = options.serverUrl;
39
- this.i18nFileNameTemplate = options.i18nFileNameTemplate;
40
-
41
- // NOTE: this logic may be needed for i18n splited file name with contenthash cases
48
+ this.i18nFileNameTemplate = options.i18nFileNameTemplate; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
42
49
  // this.i18nManifestFileName = options.i18nManifestFileName;
43
-
44
50
  // IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
45
51
  // So when debugging consider this as well
52
+
46
53
  this.options = Object.assign({}, efcOptios, options);
47
54
  this.options.entryPointName = options.entryPointName || 'efc';
48
55
  this.options.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
@@ -51,8 +58,7 @@ class EFCPlugin {
51
58
  const cssDirAttr = this.options.cssDirAttr || 'data-efc-dir';
52
59
  const localeDefaultValue = this.options.localeDefaultValue || 'en_US';
53
60
  const cssDirDefaultValue = this.options.cssDirDefaultValue || 'ltr';
54
- this.options.localeStatement = options.localeStatement ||
55
- // Statment 1: return langEle && langEle.getAttribute('${localeAttr}') || 'en_US';
61
+ this.options.localeStatement = options.localeStatement || // Statment 1: return langEle && langEle.getAttribute('${localeAttr}') || 'en_US';
56
62
  // Statment 2: return langEle ? langEle.getAttribute('${localeAttr}') : 'en_US';
57
63
  // We are using statement1 not statment2,
58
64
  // Because even that attribute doesn't have value, We need default value
@@ -64,9 +70,7 @@ class EFCPlugin {
64
70
  let dirEle = document.querySelector('[${cssDirAttr}]');
65
71
  return dirEle && dirEle.getAttribute('${cssDirAttr}') || '${cssDirDefaultValue}';
66
72
  })();`;
67
- }
68
-
69
- // NOTE: this logic may be needed for i18n splited file name with contenthash cases
73
+ } // NOTE: this logic may be needed for i18n splited file name with contenthash cases
70
74
  // getI18nManifest(compilation) {
71
75
  // const i18nManifestFile =
72
76
  // compilation.assets[this.options.i18nManifestFileName];
@@ -77,11 +81,12 @@ class EFCPlugin {
77
81
  // return {};
78
82
  // }
79
83
 
84
+
80
85
  getI18nAssetsStr(entryPoint, compilation) {
81
86
  if (!chunkSplitEnable) {
82
87
  let i18nAsstes = {};
83
- let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1);
84
- //hook for i18n url contains i18n/ may cause problem
88
+ let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
89
+
85
90
  i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
86
91
  let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
87
92
  let splittedFileName = fileName.split('.');
@@ -90,9 +95,11 @@ class EFCPlugin {
90
95
  }, {});
91
96
  return `[${JSON.stringify(i18nAsstes)}[lang]]`;
92
97
  }
98
+
93
99
  let initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
94
100
  return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
95
101
  }
102
+
96
103
  createFileContent(compilation) {
97
104
  const {
98
105
  entryPointName,
@@ -104,19 +111,18 @@ class EFCPlugin {
104
111
  const {
105
112
  serverUrl
106
113
  } = this;
107
- const cssDirTemplate = '@dir@';
108
- // const i18nManifest = this.getI18nManifest(compilation);
109
- const entryPoint = compilation.entrypoints.get(entryPointName);
110
- // const chunk = compilation.namedChunks.get(entryPointName);
114
+ const cssDirTemplate = '@dir@'; // const i18nManifest = this.getI18nManifest(compilation);
115
+
116
+ const entryPoint = compilation.entrypoints.get(entryPointName); // const chunk = compilation.namedChunks.get(entryPointName);
117
+
111
118
  const [jsPath, cssPath,,, i18nJsPath] = !this.isDevelopment ? publicPaths : [];
112
119
  const initialFiles = entryPoint.getFiles();
113
- const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file));
114
-
115
- // const i18nAssets = getShortI18nAssets(
120
+ const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file)); // const i18nAssets = getShortI18nAssets(
116
121
  // entryPoint.chunks,
117
122
  // i18nManifest,
118
123
  // i18nJsPath
119
124
  // );
125
+
120
126
  const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, i18nJsPath);
121
127
  return `(() => {
122
128
  const lang = ${localeStatement};
@@ -195,12 +201,12 @@ class EFCPlugin {
195
201
  })();
196
202
  `;
197
203
  }
204
+
198
205
  apply(compiler) {
199
206
  if (!createSDkFile) {
200
207
  return;
201
- }
208
+ } //console.log('this.templateFilePath', this.templateFilePath, this.options);
202
209
 
203
- //console.log('this.templateFilePath', this.templateFilePath, this.options);
204
210
 
205
211
  if (this.templateFilePath) {
206
212
  new _EFCTemplatePlugin.default({
@@ -211,20 +217,25 @@ class EFCPlugin {
211
217
  }).apply(compiler);
212
218
  return;
213
219
  }
220
+
214
221
  compiler.hooks.emit.tap('EFCPlugin', compilation => {
215
222
  const {
216
223
  entryPointName,
217
224
  outputFile
218
225
  } = this.options;
219
226
  const entryPoint = compilation.entrypoints.get(entryPointName);
227
+
220
228
  if (!entryPoint) {
221
229
  return;
222
230
  }
231
+
223
232
  const source = new _webpackSources.RawSource(this.createFileContent(compilation));
224
- compilation.assets[outputFile] = source;
225
- // eslint-disable-next-line no-console
233
+ compilation.assets[outputFile] = source; // eslint-disable-next-line no-console
234
+
226
235
  console.log('The EFC embedded code was created successfully..!!!');
227
236
  });
228
237
  }
238
+
229
239
  }
240
+
230
241
  exports.default = EFCPlugin;
@@ -4,16 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _webpackSources = require("webpack-sources");
9
+
8
10
  var _utils = require("../utils");
11
+
9
12
  var _path = _interopRequireDefault(require("path"));
13
+
10
14
  var _fs = require("fs");
15
+
11
16
  var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
17
+
12
18
  var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nSplitPlugin/I18nKeysIdentifer"));
19
+
13
20
  var _replaceCssDirTemplate = require("./RtlSplitPlugin/replaceCssDirTemplate");
21
+
14
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- // import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
16
23
 
24
+ // import { getShortI18nAssets } from './I18nSplitPlugin/utils/hashUtils';
17
25
  const cliOptions = (0, _utils.getOptions)();
18
26
  const {
19
27
  i18n: {
@@ -26,32 +34,25 @@ const {
26
34
  } = cliOptions;
27
35
  const {
28
36
  createSDkFile
29
- } = efcOptios;
30
-
31
- // for smap relate changes
37
+ } = efcOptios; // for smap relate changes
32
38
  // CdnChangePlugin
33
39
  // SourceMapHookPlugin
34
40
 
35
41
  class EFCTemplatePlugin {
36
42
  constructor(options = {}) {
37
43
  // console.log(' templateFilePath ', process.cwd(), options.templateFilePath, templateFilePath);
38
- this.templateFilePath = _path.default.join(process.cwd(), options.templateFilePath);
39
- // console.log(' templateFilePath ', this.templateFilePath);
40
- this.i18nFileNameTemplate = options.i18nFileNameTemplate;
41
- this.publicPath = options.publicPath;
44
+ this.templateFilePath = _path.default.join(process.cwd(), options.templateFilePath); // console.log(' templateFilePath ', this.templateFilePath);
42
45
 
43
- // NOTE: this logic may be needed for i18n splited file name with contenthash cases
46
+ this.i18nFileNameTemplate = options.i18nFileNameTemplate;
47
+ this.publicPath = options.publicPath; // NOTE: this logic may be needed for i18n splited file name with contenthash cases
44
48
  // this.i18nManifestFileName = options.i18nManifestFileName;
45
-
46
49
  // IMPORTANT: here we mergeing optionds from pacakge.json and options via constructor
47
50
  // So when debugging consider this as well
48
51
  // this.options = Object.assign({}, efcOptios, options);
49
52
 
50
53
  this.entryPointName = options.entryPointName || 'efc';
51
54
  this.outputFile = efcOptios.outputFile.replace('[version]', efcOptios.version);
52
- }
53
-
54
- // NOTE: this logic may be needed for i18n splited file name with contenthash cases
55
+ } // NOTE: this logic may be needed for i18n splited file name with contenthash cases
55
56
  // getI18nManifest(compilation) {
56
57
  // const i18nManifestFile =
57
58
  // compilation.assets[this.options.i18nManifestFileName];
@@ -62,12 +63,13 @@ class EFCTemplatePlugin {
62
63
  // return {};
63
64
  // }
64
65
 
66
+
65
67
  getI18nAssetsStr(entryPoint, compilation) {
66
68
  // NOTE: we have used lang variable inside
67
69
  if (!chunkSplitEnable) {
68
70
  let i18nAsstes = {};
69
- let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1);
70
- //hook for i18n url contains i18n/ may cause problem
71
+ let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
72
+
71
73
  i18nAsstes = i18nFiles.reduce((res, i18nFilePath) => {
72
74
  let fileName = i18nFilePath.replace(`i18n${_path.default.sep}`, '');
73
75
  let splittedFileName = fileName.split('.');
@@ -76,30 +78,30 @@ class EFCTemplatePlugin {
76
78
  }, {});
77
79
  return `[${JSON.stringify(i18nAsstes)}[lang]]`;
78
80
  }
81
+
79
82
  let initalI18nAssets = entryPoint.chunks.filter(chunk => _I18nKeysIdentifer.default.isChunkHasI18n(chunk)).map(chunk => (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, '@locale@'));
80
83
  return `${JSON.stringify(initalI18nAssets)}.map(urlpath => urlpath.replace(/@locale@/g, lang))`;
81
84
  }
85
+
82
86
  templateReplacer(entryPoint, compilation) {
83
- const cssDirTemplate = '@dir@';
84
- // const i18nManifest = this.getI18nManifest(compilation);
87
+ const cssDirTemplate = '@dir@'; // const i18nManifest = this.getI18nManifest(compilation);
85
88
 
86
89
  const initialFiles = entryPoint.getFiles();
87
90
  const filteredInitialFiles = initialFiles.filter(file => /\.(css|js)$/.test(file));
88
91
  const initialJsFiles = filteredInitialFiles.filter(file => /\.js$/.test(file));
89
92
  let initialCssFiles = filteredInitialFiles.filter(file => /\.css$/.test(file));
93
+
90
94
  if (enableRTLSplit) {
91
95
  initialCssFiles = initialCssFiles.map(filePath => (0, _replaceCssDirTemplate.replaceCssDirTemplate)(filePath, cssDirTemplate));
92
- }
93
-
94
- // const i18nAssets = getShortI18nAssets(
96
+ } // const i18nAssets = getShortI18nAssets(
95
97
  // entryPoint.chunks,
96
98
  // i18nManifest,
97
99
  // '' // i18nJsPath
98
100
  // );
99
101
 
102
+
100
103
  const initalI18nAssets = this.getI18nAssetsStr(entryPoint, compilation, '' // i18nJsPath
101
104
  );
102
-
103
105
  let templateStr = (0, _fs.readFileSync)(this.templateFilePath).toString();
104
106
  return templateStr.replace('((\'getInitalAssets\'))', `function getInitalAssets(assetsType, lang) {
105
107
  if (assetsType === "js") {
@@ -114,29 +116,36 @@ class EFCTemplatePlugin {
114
116
  return [];
115
117
  }`).replace('((\'@dir@\'))', '\'@dir@\'').replace('((\'publicPath\'))', this.publicPath).replace('((\'@locale@\'))', '\'@locale@\'');
116
118
  }
119
+
117
120
  apply(compiler) {
118
121
  if (!createSDkFile) {
119
122
  return;
120
123
  }
124
+
121
125
  compiler.hooks.emit.tap('EFCTemplatePlugin', compilation => {
122
126
  const {
123
127
  entryPointName,
124
128
  outputFile
125
129
  } = this;
126
130
  const entryPoint = compilation.entrypoints.get(entryPointName);
131
+
127
132
  if (!entryPoint) {
128
133
  return;
129
134
  }
135
+
130
136
  if (!(0, _fs.existsSync)(this.templateFilePath)) {
131
137
  console.error(`EFC Template file not exists ${this.templateFilePath}`);
132
138
  return;
133
139
  }
140
+
134
141
  const source = new _webpackSources.RawSource(this.templateReplacer(entryPoint, compilation));
135
- compilation.assets[outputFile] = source;
136
- // console.log('EFCTemplatePlugin working');
142
+ compilation.assets[outputFile] = source; // console.log('EFCTemplatePlugin working');
137
143
  // eslint-disable-next-line no-console
144
+
138
145
  console.log('The EFC embedded code was created successfully..!!!');
139
146
  });
140
147
  }
148
+
141
149
  }
150
+
142
151
  exports.default = EFCTemplatePlugin;
@@ -4,22 +4,34 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
9
+
8
10
  var _utils = require("../utils");
11
+
9
12
  var _urlConcat = require("../utils/urlConcat");
13
+
10
14
  var _path = _interopRequireDefault(require("path"));
15
+
11
16
  var _webpackSources = require("webpack-sources");
17
+
12
18
  var _hashUtils = require("./I18nSplitPlugin/utils/hashUtils");
19
+
13
20
  var _getI18nFileUrlPathTemplate = require("./I18nSplitPlugin/utils/getI18nFileUrlPathTemplate");
21
+
14
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
+
15
24
  let i18nObj = null;
16
25
  let options = (0, _utils.getOptions)();
26
+
17
27
  function newAssign(target, data) {
18
28
  return Object.assign({}, target, data);
19
29
  }
30
+
20
31
  const {
21
32
  i18n
22
33
  } = options;
34
+
23
35
  class I18NInjectIntoIndexPlugin {
24
36
  constructor(options) {
25
37
  this.isDevelopment = options.isDevelopment;
@@ -29,30 +41,35 @@ class I18NInjectIntoIndexPlugin {
29
41
  this.i18nManifestFileName = options.i18nManifestFileName;
30
42
  this.entryPointName = options.mainChunkName;
31
43
  }
44
+
32
45
  getI18nFileUrlPath(chunk, compilation) {
33
46
  let urlpath = (0, _getI18nFileUrlPathTemplate.getI18nFileUrlPathTemplate)(compilation, chunk, this.i18nFileNameTemplate, this.templateLabel);
34
47
  return (0, _urlConcat.urlConcat)(this.publicPath, urlpath);
35
48
  }
49
+
36
50
  getI18nManifest(compilation) {
37
51
  const i18nManifestFile = compilation.assets[this.i18nManifestFileName];
52
+
38
53
  if (!i18nManifestFile) {
39
54
  return {};
40
55
  }
56
+
41
57
  const manifest = JSON.parse(i18nManifestFile.source());
42
58
  return manifest;
43
59
  }
60
+
44
61
  injectI18nURLsToHTML(compilation) {
45
62
  _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
46
63
  const {
47
64
  assets
48
- } = data;
49
- // Manipulate the content
65
+ } = data; // Manipulate the content
66
+
50
67
  const i18nManifest = this.getI18nManifest(compilation);
51
68
  const entryPoint = compilation.entrypoints.get(this.entryPointName);
52
- const i18nScriptURLs = entryPoint.chunks.filter(c => !!i18nManifest[c.id]).map(c => this.getI18nFileUrlPath(c, compilation));
53
- // .map(url => getI18nScriptTagObj(url));
69
+ const i18nScriptURLs = entryPoint.chunks.filter(c => !!i18nManifest[c.id]).map(c => this.getI18nFileUrlPath(c, compilation)); // .map(url => getI18nScriptTagObj(url));
54
70
  // .join('');
55
71
  // Tell webpack to move on
72
+
56
73
  cb(null, newAssign(data, {
57
74
  assets: newAssign(assets, {
58
75
  js: i18nScriptURLs.concat(assets.js)
@@ -60,6 +77,7 @@ class I18NInjectIntoIndexPlugin {
60
77
  }));
61
78
  });
62
79
  }
80
+
63
81
  withI18nSpitHandling(compiler) {
64
82
  compiler.hooks.make.tap('I18NInjectIntoIndexPlugin', compilation => {
65
83
  // let cdns = Object.keys(this.publicPaths);
@@ -68,17 +86,19 @@ class I18NInjectIntoIndexPlugin {
68
86
  this.injectI18nURLsToHTML(compilation);
69
87
  return;
70
88
  }
89
+
71
90
  _htmlWebpackPlugin.default.getHooks(compilation).beforeEmit.tapAsync('I18NInjectIntoIndexPlugin', (data, cb) => {
72
91
  // Manipulate the content
73
92
  const i18nManifest = this.getI18nManifest(compilation);
74
93
  const entryPoint = compilation.entrypoints.get(this.entryPointName);
75
94
  let i18nAssets = (0, _hashUtils.getShortI18nAssets)(entryPoint.chunks, i18nManifest, this.publicPath);
76
- data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets)));
77
- // Tell webpack to move on
95
+ data.html = data.html.replace(new RegExp('<!--I18nInfoToServer(.*?)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nAssets))); // Tell webpack to move on
96
+
78
97
  cb(null, data);
79
98
  });
80
99
  });
81
100
  }
101
+
82
102
  apply(compiler) {
83
103
  if (i18n.chunkSplitEnable) {
84
104
  this.withI18nSpitHandling(compiler);
@@ -86,12 +106,13 @@ class I18NInjectIntoIndexPlugin {
86
106
  this.withoutI18nSpitHandling(compiler);
87
107
  }
88
108
  }
109
+
89
110
  withoutI18nSpitHandling(compiler) {
90
111
  compiler.hooks.emit.tap('I18NInjectIntoIndexPlugin', compilation => {
91
112
  // let cdns = Object.keys(this.publicPaths);
92
113
  if (i18nObj === null) {
93
- let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1);
94
- //hook for i18n url contains i18n/ may cause problem
114
+ let i18nFiles = Object.keys(compilation.assets).filter(assert => assert.indexOf(`i18n${_path.default.sep}`) !== -1); //hook for i18n url contains i18n/ may cause problem
115
+
95
116
  i18nObj = i18nFiles.reduce((res, next) => {
96
117
  let fileName = next.replace(`i18n${_path.default.sep}`, '');
97
118
  let splittedFileName = fileName.split('.');
@@ -100,16 +121,21 @@ class I18NInjectIntoIndexPlugin {
100
121
  } else {
101
122
  res[splittedFileName[0]] = fileName;
102
123
  } */
124
+
103
125
  res[splittedFileName[0]] = `${this.publicPath}/i18n/${fileName}`;
104
126
  return res;
105
127
  }, {});
106
128
  }
129
+
107
130
  let [indexFile] = Object.keys(compilation.assets).filter(filename => /\.html$/g.test(filename));
131
+
108
132
  if (indexFile) {
109
133
  let source = compilation.assets[indexFile].source();
110
134
  compilation.assets[indexFile] = new _webpackSources.RawSource(source.replace(new RegExp('<!--I18nInfoToServer(.*)I18nInfoToServer-->', 'g'), (match, arg) => match.replace(arg, JSON.stringify(i18nObj))));
111
135
  }
112
136
  });
113
137
  }
138
+
114
139
  }
140
+
115
141
  exports.default = I18NInjectIntoIndexPlugin;
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _utils = require("./utils");
8
- const pluginName = 'I18nDebugPlugin';
9
- // this plugin only for debug related purpose
9
+
10
+ const pluginName = 'I18nDebugPlugin'; // this plugin only for debug related purpose
10
11
 
11
12
  class I18nDebugPlugin {
12
13
  constructor(jsResourceI18nKeys) {
13
14
  this.jsResourceI18nKeys = jsResourceI18nKeys;
14
15
  this.warnings = [];
15
16
  }
17
+
16
18
  apply(compiler) {
17
19
  compiler.hooks.thisCompilation.tap(pluginName, (compilation, compilationParams) => {
18
20
  // TEMP : only for debugging purpose
@@ -22,21 +24,22 @@ class I18nDebugPlugin {
22
24
  compiler.hooks.normalModuleFactory.tap(pluginName, factory => {
23
25
  if (!this.compilationParams || this.compilationParams.normalModuleFactory === factory) {
24
26
  return;
25
- }
26
- // console.log('skiped');
27
+ } // console.log('skiped');
28
+
29
+
27
30
  let handler = parser => {
28
31
  parser.hooks.program.tap(pluginName, (ast, commmets) => {
29
32
  const {
30
33
  module
31
- } = parser.state;
32
- //
34
+ } = parser.state; //
35
+
33
36
  if (!(module && /\.jsx?$/.test(module.resource))) {
34
37
  return;
35
- }
36
- // i18n grep proper contract regex
38
+ } // i18n grep proper contract regex
39
+
40
+
37
41
  let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
38
- i18nKeys = i18nKeys.concat(
39
- // i18n grep proper contract regex
42
+ i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
40
43
  (0, _utils.collectI18nKeysfromComments)(commmets, this.jsResourceI18nKeys));
41
44
  i18nKeys.length && this.warnings.push({
42
45
  message: 'skiped i18n keys',
@@ -46,10 +49,12 @@ class I18nDebugPlugin {
46
49
  });
47
50
  });
48
51
  };
52
+
49
53
  factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
50
- factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
51
- // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
54
+ factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler); // factory.hooks.parser.for('javascript/esm').tap(pluginName, handler);
52
55
  });
53
56
  }
57
+
54
58
  }
59
+
55
60
  exports.default = I18nDebugPlugin;
@@ -4,9 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.I18nDependencyTemplate = exports.I18nDependency = void 0;
7
+
7
8
  var _webpack = require("webpack");
8
- // const webpack = require('webpack');
9
9
 
10
+ // const webpack = require('webpack');
10
11
  class I18nDependency extends _webpack.Dependency {
11
12
  constructor({
12
13
  identifier,
@@ -18,21 +19,26 @@ class I18nDependency extends _webpack.Dependency {
18
19
  this.i18nKeys = i18nKeys;
19
20
  this.context = context;
20
21
  }
22
+
21
23
  getResourceIdentifier() {
22
24
  return `i18n-module-${this.identifier}-${this.identifierIndex}`;
23
25
  }
26
+
24
27
  }
28
+
25
29
  exports.I18nDependency = I18nDependency;
30
+
26
31
  class I18nDependencyTemplate {
27
32
  //eslint-disable-next-line no-empty-function
28
- apply() {}
29
- // apply(dep, source) {
33
+ apply() {} // apply(dep, source) {
30
34
  // if (typeof dep.range === "number") {
31
35
  // source.insert(0, `/* comment by I18nSplitPlugin , i18n keys = ${JSON.stringify(dep.i18nKeys)} */`);
32
36
  // return;
33
37
  // }
34
-
35
38
  // source.replace(dep.range[0], dep.range[1] - 1, dep.expression);
36
39
  // }
40
+
41
+
37
42
  }
43
+
38
44
  exports.I18nDependencyTemplate = I18nDependencyTemplate;