@zohodesk/client_build_tool 0.0.11-exp.16.0 → 0.0.11-exp.17.0

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 (220) hide show
  1. package/README.md +102 -0
  2. package/README_backup.md +102 -0
  3. package/lib/allCommandsConfigs.js +7 -2
  4. package/lib/commands/build/commandExecutor.js +5 -1
  5. package/lib/commands/build/config.js +3 -2
  6. package/lib/commands/build/optionsProcessor.js +5 -2
  7. package/lib/commands/build/preProcessor.js +2 -0
  8. package/lib/commands/buildEs/commandExecutor.js +5 -0
  9. package/lib/commands/buildEs/config.js +3 -2
  10. package/lib/commands/buildEs/preProcessor.js +2 -0
  11. package/lib/commands/buildLib/commandExecutor.js +5 -0
  12. package/lib/commands/buildLib/config.js +3 -2
  13. package/lib/commands/buildLib/preProcessor.js +2 -0
  14. package/lib/commands/mockserver/commandExecutor.js +9 -2
  15. package/lib/commands/mockserver/config.js +3 -2
  16. package/lib/commands/pre_process/commandExecutor.js +2 -0
  17. package/lib/commands/pre_process/config.js +3 -2
  18. package/lib/commands/start/commandExecutor.js +2 -0
  19. package/lib/commands/start/config.js +3 -2
  20. package/lib/commands/start/optionsProcessor.js +4 -2
  21. package/lib/commands/start/preProcessor.js +2 -0
  22. package/lib/commands/template/commandExecutor.js +7 -0
  23. package/lib/commands/template/config.js +3 -2
  24. package/lib/commands/version/commandExecutor.js +3 -0
  25. package/lib/commands/version/config.js +3 -2
  26. package/lib/commandsRouter.js +21 -5
  27. package/lib/index.js +2 -0
  28. package/lib/logger.js +5 -0
  29. package/lib/schemas/applyValuesToSchema/index.js +8 -0
  30. package/lib/schemas/applyValuesToSchema/isObject.js +1 -0
  31. package/lib/schemas/applyValuesToSchema/isValid.js +2 -0
  32. package/lib/schemas/cliArgsToObject.js +6 -2
  33. package/lib/schemas/defaultConfigValues.js +17 -4
  34. package/lib/schemas/defaultConfigValuesOnly.js +33 -4
  35. package/lib/schemas/deprecatedOptionsHandler.js +16 -7
  36. package/lib/schemas/getNpmVersion.js +5 -0
  37. package/lib/schemas/giveDefaultValue.js +3 -0
  38. package/lib/schemas/npmConfigToObject.js +5 -2
  39. package/lib/schemas/readOptions.js +30 -10
  40. package/lib/schemas/readOptionsForConfigFile.js +12 -2
  41. package/lib/shared/babel/addDefaultPlugins.js +2 -0
  42. package/lib/shared/babel/babelWebConfig.js +10 -1
  43. package/lib/shared/babel/babel_plugins/removeAttributesPlugin.js +4 -0
  44. package/lib/shared/babel/getBabelPlugin.js +7 -2
  45. package/lib/shared/babel/runBabelForJSFile.js +4 -1
  46. package/lib/shared/babel/runBabelForTsFile.js +5 -1
  47. package/lib/shared/bundler/webpack/common/decidePublicPath.js +5 -0
  48. package/lib/shared/bundler/webpack/common/libAlias.js +3 -3
  49. package/lib/shared/bundler/webpack/common/modeUtils.js +5 -0
  50. package/lib/shared/bundler/webpack/common/nameTemplates.js +18 -11
  51. package/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +3 -2
  52. package/lib/shared/bundler/webpack/configCustomLoaders.js +1 -0
  53. package/lib/shared/bundler/webpack/cssLoaders.js +2 -0
  54. package/lib/shared/bundler/webpack/custom_plugins/BundleIntegrityReport/index.js +20 -1
  55. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/index.js +25 -20
  56. package/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin/webpackCustomJsUrlLoader.js +9 -4
  57. package/lib/shared/bundler/webpack/custom_plugins/CustomScriptLoadingPlugin.js +23 -3
  58. package/lib/shared/bundler/webpack/custom_plugins/EFCTemplatePlugin.js +19 -8
  59. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +61 -37
  60. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +33 -15
  61. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +108 -60
  62. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +26 -20
  63. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nFilesEmitPlugin.js +26 -5
  64. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +16 -13
  65. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nRuntimeDealerPlugin.js +53 -19
  66. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/LocaleChunkAssetsStore.js +17 -2
  67. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ModulesI18nKeysStore.js +13 -0
  68. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +21 -11
  69. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +4 -0
  70. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +14 -4
  71. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +13 -3
  72. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/iterateModulesInChunk.js +12 -3
  73. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +7 -2
  74. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +2 -0
  75. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +3 -2
  76. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +4 -2
  77. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +13 -8
  78. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +14 -2
  79. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/getChunkModules.js +1 -0
  80. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +3 -1
  81. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +4 -0
  82. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +25 -5
  83. package/lib/shared/bundler/webpack/custom_plugins/InitialHtmlPlugin.js +10 -3
  84. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/addFilesNamesToManifestJson.js +6 -1
  85. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createInitialEntries.js +6 -1
  86. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/createManifestJson.js +6 -0
  87. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/findInitialFileNames.js +1 -0
  88. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/index.js +7 -0
  89. package/lib/shared/bundler/webpack/custom_plugins/ManifestJsonPlugin/removeHashFromFileName.js +1 -0
  90. package/lib/shared/bundler/webpack/custom_plugins/ResourceHintsPlugin.js +17 -13
  91. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +15 -6
  92. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +13 -4
  93. package/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +6 -4
  94. package/lib/shared/bundler/webpack/custom_plugins/RuntimeResourceCleanup/index.js +10 -0
  95. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/classHandling.js +3 -0
  96. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/index.js +20 -4
  97. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/selectorWeightPrefixAdder.js +12 -10
  98. package/lib/shared/bundler/webpack/custom_plugins/SelectorWeightPlugin/windowsModification.js +3 -2
  99. package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +20 -7
  100. package/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPluginUtils.js +1 -0
  101. package/lib/shared/bundler/webpack/custom_plugins/SourceMapPlugin/index.js +10 -7
  102. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/addHashToFilePath.js +6 -1
  103. package/lib/shared/bundler/webpack/custom_plugins/TPHashMappingPlugin/index.js +16 -1
  104. package/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin/index.js.js +11 -4
  105. package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/ErrorHandler.js +10 -3
  106. package/lib/shared/bundler/webpack/custom_plugins/VariableConversionCollector/index.js +62 -27
  107. package/lib/shared/bundler/webpack/custom_plugins/custom_attribute_plugin/index.js +15 -3
  108. package/lib/shared/bundler/webpack/custom_plugins/emitAsset.js +1 -0
  109. package/lib/shared/bundler/webpack/custom_plugins/getInitialAssetsFuncTemplate.js +12 -2
  110. package/lib/shared/bundler/webpack/custom_plugins/getInitialI18nAssetsArrayStr.js +7 -2
  111. package/lib/shared/bundler/webpack/defaultVendorPatternList.js +6 -2
  112. package/lib/shared/bundler/webpack/devtoolConfig.js +1 -0
  113. package/lib/shared/bundler/webpack/entryConfig.js +4 -0
  114. package/lib/shared/bundler/webpack/externals.js +1 -0
  115. package/lib/shared/bundler/webpack/getCSSLoaders.js +6 -1
  116. package/lib/shared/bundler/webpack/getFilenameFromModule.js +5 -1
  117. package/lib/shared/bundler/webpack/jsLoaders.js +10 -6
  118. package/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +2 -0
  119. package/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +3 -2
  120. package/lib/shared/bundler/webpack/loaderConfigs/checkIsPatternsMatchFilename.js +12 -3
  121. package/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +1 -0
  122. package/lib/shared/bundler/webpack/loaderConfigs/configPostCssLoader.js +10 -2
  123. package/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +2 -0
  124. package/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +12 -0
  125. package/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +15 -1
  126. package/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +4 -1
  127. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +16 -8
  128. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +29 -22
  129. package/lib/shared/bundler/webpack/loaders/miniCssFallBackLoader.js +2 -2
  130. package/lib/shared/bundler/webpack/loaders/workerLoader.js +19 -8
  131. package/lib/shared/bundler/webpack/optimizationConfig.js +13 -5
  132. package/lib/shared/bundler/webpack/outputConfig.js +9 -1
  133. package/lib/shared/bundler/webpack/pluginConfigs/configBundleAnalyzer.js +9 -5
  134. package/lib/shared/bundler/webpack/pluginConfigs/configBundleIntegrityReport.js +5 -0
  135. package/lib/shared/bundler/webpack/pluginConfigs/configCSSMinifierPlugin.js +9 -4
  136. package/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +8 -3
  137. package/lib/shared/bundler/webpack/pluginConfigs/configCopyPublicFolders.js +16 -1
  138. package/lib/shared/bundler/webpack/pluginConfigs/configCustomAttributesPlugin.js +4 -0
  139. package/lib/shared/bundler/webpack/pluginConfigs/configCustomScriptLoadingStrategyPlugin.js +16 -0
  140. package/lib/shared/bundler/webpack/pluginConfigs/configEFCTemplatePlugin.js +5 -0
  141. package/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +5 -0
  142. package/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +8 -2
  143. package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +9 -5
  144. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +25 -19
  145. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +26 -12
  146. package/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +9 -3
  147. package/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +2 -0
  148. package/lib/shared/bundler/webpack/pluginConfigs/configManifestJsonPlugin.js +7 -0
  149. package/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +7 -3
  150. package/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +5 -1
  151. package/lib/shared/bundler/webpack/pluginConfigs/configResourceHintsPlugin.js +4 -1
  152. package/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +4 -0
  153. package/lib/shared/bundler/webpack/pluginConfigs/configRuntimeResourceCleanup.js +8 -3
  154. package/lib/shared/bundler/webpack/pluginConfigs/configSelectorWeightPlugin.js +6 -1
  155. package/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +8 -3
  156. package/lib/shared/bundler/webpack/pluginConfigs/configSourceMapPlugin.js +4 -0
  157. package/lib/shared/bundler/webpack/pluginConfigs/configTPHashMappingPlugin.js +8 -1
  158. package/lib/shared/bundler/webpack/pluginConfigs/configVariableConversionPlugin.js +6 -1
  159. package/lib/shared/bundler/webpack/plugins.js +24 -1
  160. package/lib/shared/bundler/webpack/resolvers.js +17 -3
  161. package/lib/shared/bundler/webpack/splitChunksConfig.js +15 -2
  162. package/lib/shared/bundler/webpack/statsConfig.js +5 -2
  163. package/lib/shared/bundler/webpack/tsLoaders.js +4 -2
  164. package/lib/shared/bundler/webpack/utils/index.js +12 -1
  165. package/lib/shared/bundler/webpack/utils/object-manipulation.js +16 -2
  166. package/lib/shared/bundler/webpack/utils/updateArrayWithDefault.js +7 -0
  167. package/lib/shared/bundler/webpack/webpackBuild.js +8 -1
  168. package/lib/shared/bundler/webpack/webpackConfig.js +17 -0
  169. package/lib/shared/commands-utils/doBasicRequirementCheck.js +3 -0
  170. package/lib/shared/commands-utils/getCliPath.js +9 -5
  171. package/lib/shared/commands-utils/index.js +3 -0
  172. package/lib/shared/commands-utils/log.js +2 -0
  173. package/lib/shared/commands-utils/readArgsFormCommandLine.js +1 -0
  174. package/lib/shared/commands-utils/readOptionFormCommandLine.js +1 -0
  175. package/lib/shared/commands-utils/spawnSyncIO.js +13 -5
  176. package/lib/shared/constants.js +29 -9
  177. package/lib/shared/fileUtils/copyFile.js +8 -1
  178. package/lib/shared/fileUtils/directoryIterator.js +4 -0
  179. package/lib/shared/fileUtils/watchRun.js +24 -3
  180. package/lib/shared/postcss/custom_postcss_plugins/EmptyPlugin.js +6 -1
  181. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/constants.js +3 -2
  182. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/handleIgnores.js +13 -6
  183. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/index.js +26 -6
  184. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/insertBefore.js +9 -6
  185. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/isPreviouslyProcessed.js +3 -0
  186. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/replaceUtils.js +7 -2
  187. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/separateHoveredSelectorAndNormalSelector.js +2 -0
  188. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/specialCases.js +9 -4
  189. package/lib/shared/postcss/custom_postcss_plugins/HoverActivePlugin/typeCheckUtils.js +10 -0
  190. package/lib/shared/postcss/custom_postcss_plugins/RTLSplitPlugin.js +29 -16
  191. package/lib/shared/postcss/custom_postcss_plugins/SelectorReplace.js +17 -0
  192. package/lib/shared/postcss/custom_postcss_plugins/ValueReplacer.js +9 -4
  193. package/lib/shared/postcss/custom_postcss_plugins/VariableModificationPlugin/index.js +63 -27
  194. package/lib/shared/postcss/filterPluginsAllowedForSpecficFile.js +13 -5
  195. package/lib/shared/postcss/getAllowedPostCssPlugins.js +3 -0
  196. package/lib/shared/postcss/getSpecificPostCssPlugin.js +17 -7
  197. package/lib/shared/postcss/runPostCssForCssFile.js +9 -1
  198. package/lib/shared/pre_process/runPreProcess.js +11 -0
  199. package/lib/shared/server/configWebpackDevMiddleware.js +8 -1
  200. package/lib/shared/server/corsHandling.js +6 -2
  201. package/lib/shared/server/getIp.js +7 -1
  202. package/lib/shared/server/getServerURL.js +6 -0
  203. package/lib/shared/server/httpsOptions.js +11 -0
  204. package/lib/shared/server/initExpressApp.js +4 -1
  205. package/lib/shared/server/initialHTMLHandling.js +16 -7
  206. package/lib/shared/server/mockApiHandler.js +16 -8
  207. package/lib/shared/server/mockServer.js +7 -0
  208. package/lib/shared/server/serveContextFiles.js +5 -1
  209. package/lib/shared/server/serverBywebpackDevMiddleware.js +9 -4
  210. package/lib/shared/server/startHttpServer.js +3 -0
  211. package/lib/shared/server/startHttpsServer.js +9 -1
  212. package/lib/shared/server/unwanted/addHttp2Server.js +7 -2
  213. package/lib/shared/server/unwanted/configWebpackDevMiddleware.js +8 -1
  214. package/lib/shared/server/unwanted/mockApiSupport.js +2 -0
  215. package/lib/shared/server/unwanted/websocketMockSetup.js +7 -1
  216. package/lib/shared/server/urlConcat.js +8 -3
  217. package/lib/shared/utils/requireLocalOrGlobal.js +25 -10
  218. package/lib/shared/utils/versionPrint.js +6 -1
  219. package/npm-shrinkwrap.json +2 -2
  220. package/package.json +1 -1
@@ -4,12 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+
7
8
  var _utils = require("./utils");
9
+
8
10
  var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
9
- /* eslint-disable max-classes-per-file */
10
11
 
12
+ /* eslint-disable max-classes-per-file */
11
13
  const pluginName = 'I18nKeysIdentifier';
12
-
13
14
  /**
14
15
  * this plugin search the i18 keys and make it as I18nDependency.
15
16
  * how it works?
@@ -19,6 +20,7 @@ const pluginName = 'I18nKeysIdentifier';
19
20
  * after the walk of AST we get some I18n keys
20
21
  * then we make it as I18nDependency.
21
22
  */
23
+
22
24
  class I18nKeysIdentifer {
23
25
  constructor({
24
26
  jsResourceI18nKeys
@@ -26,9 +28,9 @@ class I18nKeysIdentifer {
26
28
  this.jsResourceI18nKeys = jsResourceI18nKeys;
27
29
  this.store = new _LocaleChunkAssetsStore.LocaleChunkAssetsStore();
28
30
  }
31
+
29
32
  apply(compiler) {
30
33
  // const { splitChunks } = compiler.options.optimization;
31
-
32
34
  // if (splitChunks) {
33
35
  // if (splitChunks.defaultSizeTypes.includes('...')) {
34
36
  // splitChunks.defaultSizeTypes.push(MODULE_TYPE);
@@ -44,30 +46,31 @@ class I18nKeysIdentifer {
44
46
  parser.hooks.program.tap(pluginName, (ast, comments) => {
45
47
  const {
46
48
  module
47
- } = parser.state;
48
- //
49
+ } = parser.state; //
50
+
49
51
  if (!(module && /\.jsx?$/.test(module.resource))) {
50
52
  return;
51
- }
52
- // i18n grep proper contract regex
53
+ } // i18n grep proper contract regex
54
+
55
+
53
56
  let i18nKeys = (0, _utils.collectI18nKeysfromAST)(ast, this.jsResourceI18nKeys);
54
- i18nKeys = i18nKeys.concat(
55
- // i18n grep proper contract regex
57
+ i18nKeys = i18nKeys.concat( // i18n grep proper contract regex
56
58
  (0, _utils.collectI18nKeysfromComments)(comments, this.jsResourceI18nKeys));
59
+
57
60
  if (i18nKeys.length) {
58
61
  // console.log('i18nKeys.length', module.resource, i18nKeys);
59
62
  this.store.updateModuleI18nKeys(module.resource, i18nKeys);
60
63
  }
61
64
  });
62
- };
63
-
64
- // this below hook was tapped for collect I18n Key from files and add as Dependency
65
-
65
+ }; // this below hook was tapped for collect I18n Key from files and add as Dependency
66
66
  // const factory = params.normalModuleFactory;
67
67
 
68
+
68
69
  factory.hooks.parser.for('javascript/auto').tap(pluginName, handler);
69
70
  factory.hooks.parser.for('javascript/dynamic').tap(pluginName, handler);
70
71
  });
71
72
  }
73
+
72
74
  }
75
+
73
76
  exports.default = I18nKeysIdentifer;
@@ -4,40 +4,56 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.I18nRuntimeDealerPlugin = void 0;
7
+
7
8
  var _webpack = require("webpack");
9
+
8
10
  var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
11
+
9
12
  var _constants = require("./constants");
13
+
10
14
  var _getI18nLoadingRuntimeModule = require("./getI18nLoadingRuntimeModule");
15
+
11
16
  var _templateFileName = require("./templateFileName");
17
+
12
18
  var _hashUtils = require("./utils/hashUtils");
19
+
13
20
  var _urlConcat = require("../../../../server/urlConcat");
21
+
14
22
  var _I18nFilesEmitPlugin = require("./I18nFilesEmitPlugin");
23
+
15
24
  var _LocaleChunkAssetsStore = require("./LocaleChunkAssetsStore");
25
+
16
26
  var _logger = require("../../../../../logger");
17
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
27
+
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
+
18
30
  const {
19
31
  RawSource
20
32
  } = _webpack.sources;
21
- const pluginName = 'I18nRuntimeDealerPlugin';
33
+ const pluginName = 'I18nRuntimeDealerPlugin'; // I18nExtractPlugin.loader = require.resolve('./loader');
22
34
 
23
- // I18nExtractPlugin.loader = require.resolve('./loader');
24
35
  class I18nRuntimeDealerPlugin {
25
36
  constructor(options) {
26
37
  this.options = options;
27
38
  }
39
+
28
40
  apply(compiler) {
29
41
  compiler.hooks.thisCompilation.tap(pluginName, compilation => {
30
42
  // Get store for cache
31
43
  this.store = (0, _LocaleChunkAssetsStore.getLocaleChunkAssetsStore)(compilation);
44
+
32
45
  if (!this.options.runtime) {
33
46
  return;
34
47
  }
48
+
35
49
  this.createI18nDownloadCodeInRuntimeFile(compilation);
36
50
  this.addI18nIntoInitialHtml(compilation);
37
51
  });
38
52
  }
53
+
39
54
  addI18nIntoInitialHtml(compilation) {
40
55
  const i18nStore = this.store;
56
+
41
57
  _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, hookOptions => {
42
58
  const {
43
59
  assets
@@ -47,8 +63,8 @@ class I18nRuntimeDealerPlugin {
47
63
  filename,
48
64
  publicPath = '',
49
65
  mainChunkName
50
- } = this.options;
51
- // const dummyContent = '// dummy comment';
66
+ } = this.options; // const dummyContent = '// dummy comment';
67
+
52
68
  const dummyContentHash = 'dummy0content0hashes';
53
69
  const entryPoint = compilation.entrypoints.get(mainChunkName);
54
70
  const initialChunks = Array.from(entryPoint.chunks).filter(c => c.canBeInitial() && c.id !== c.runtime);
@@ -63,17 +79,18 @@ class I18nRuntimeDealerPlugin {
63
79
  // So Dummy hash was being used it will not work just skip warnings
64
80
  contentHash: dummyContentHash
65
81
  });
82
+
66
83
  return (0, _urlConcat.urlConcat)(publicPath, data.filename);
67
84
  });
68
85
  const allJSAssets = [...initialI18nAssets, ...assets.js].map(url => url.replaceAll('[locale]', templateLabel).replaceAll('%5Blocale%5D', templateLabel));
69
86
  return {
70
- assets: {
71
- ...assets,
87
+ assets: { ...assets,
72
88
  js: allJSAssets
73
89
  }
74
90
  };
75
91
  });
76
92
  }
93
+
77
94
  createI18nDownloadCodeInRuntimeFile(compilation) {
78
95
  const {
79
96
  chunkFilename,
@@ -81,11 +98,14 @@ class I18nRuntimeDealerPlugin {
81
98
  localeVarName
82
99
  } = this.options;
83
100
  const chunkFilenameHasContentHash = (0, _hashUtils.hasContentHash)(chunkFilename);
101
+
84
102
  const getI18nChunks = mainChunk => this.filterI18nUsedChunks(mainChunk.getAllAsyncChunks());
103
+
85
104
  const I18nLoadingRuntimeModule = (0, _getI18nLoadingRuntimeModule.getI18nLoadingRuntimeModule)({
86
105
  getI18nChunks
87
106
  });
88
107
  const enabledChunks = new WeakSet();
108
+
89
109
  const chunkFilenameUrlGenerator = (i18nChunks, locale) => (0, _templateFileName.templateFileName)({
90
110
  compilation,
91
111
  localeVarName,
@@ -93,20 +113,25 @@ class I18nRuntimeDealerPlugin {
93
113
  contentHashes: this.getContentHashes(locale),
94
114
  chunks: i18nChunks
95
115
  });
116
+
96
117
  const prefixFunc = () => _constants.I18N_CHUNK_NAME_GENERATION_SEGMENT;
118
+
97
119
  const handler = (entryRuntimeChunk, set) => {
98
120
  if (enabledChunks.has(entryRuntimeChunk)) {
99
121
  return;
100
122
  }
123
+
101
124
  enabledChunks.add(entryRuntimeChunk);
102
125
  const {
103
126
  chunkFilename,
104
127
  // filename: initialFilename,
105
128
  runtimeOptions
106
129
  } = this.options;
130
+
107
131
  if (typeof chunkFilename === 'string' && /\[(full)?hash(:\d+)?\]/.test(chunkFilename)) {
108
132
  set.add(_webpack.RuntimeGlobals.getFullHash);
109
133
  }
134
+
110
135
  set.add(_webpack.RuntimeGlobals.publicPath);
111
136
  compilation.addRuntimeModule(entryRuntimeChunk, new I18nLoadingRuntimeModule(set, {
112
137
  prefixFunc: chunkFilenameHasContentHash ? prefixFunc : chunkFilenameUrlGenerator,
@@ -114,15 +139,18 @@ class I18nRuntimeDealerPlugin {
114
139
  chunkFilename
115
140
  }));
116
141
  };
142
+
117
143
  compilation.hooks.runtimeRequirementInTree.for(_webpack.RuntimeGlobals.ensureChunkHandlers).tap(pluginName, handler);
144
+
118
145
  if (chunkFilenameHasContentHash) {
119
146
  compilation.hooks.processAssets.tap({
120
147
  name: pluginName,
121
- stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED
122
- // additionalAssets: true
148
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED // additionalAssets: true
149
+
123
150
  }, assets => {
124
151
  // eslint-disable-next-line no-underscore-dangle
125
152
  const entries = compilation._getChunkGraphEntries();
153
+
126
154
  function createRuntimeFilePerLocale({
127
155
  locale,
128
156
  runtimeFileName,
@@ -133,9 +161,9 @@ class I18nRuntimeDealerPlugin {
133
161
  const replaceText = chunkFilenameUrlGenerator(i18nChunks, locale);
134
162
  const replacedStr = runtimeFileSourceStr.replace(_constants.I18N_CHUNK_NAME_GENERATION_SEGMENT, replaceText);
135
163
  compilation.emitAsset(newRuntimeName, new RawSource(replacedStr));
136
- }
164
+ } // eslint-disable-next-line no-restricted-syntax
165
+
137
166
 
138
- // eslint-disable-next-line no-restricted-syntax
139
167
  for (const entryChunk of entries) {
140
168
  const i18nChunks = getI18nChunks(entryChunk);
141
169
  const runtimeFileName = [...entryChunk.files][0];
@@ -146,21 +174,22 @@ class I18nRuntimeDealerPlugin {
146
174
  runtimeFileName,
147
175
  runtimeFileSourceStr,
148
176
  i18nChunks
149
- }));
150
- // NOTE: we don't delete, Because of HTML plugin needs to add runtime file in html and efc
177
+ })); // NOTE: we don't delete, Because of HTML plugin needs to add runtime file in html and efc
151
178
  // compilation.deleteAsset(runtimeFileName);
152
179
  }
153
180
  });
154
181
  compilation.hooks.processAssets.tap({
155
182
  name: pluginName,
156
- stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
157
- // additionalAssets: true
183
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE // additionalAssets: true
184
+
158
185
  }, () => {
159
186
  // eslint-disable-next-line no-underscore-dangle
160
- const entries = compilation._getChunkGraphEntries();
161
- // eslint-disable-next-line no-restricted-syntax
187
+ const entries = compilation._getChunkGraphEntries(); // eslint-disable-next-line no-restricted-syntax
188
+
189
+
162
190
  for (const entryChunk of entries) {
163
191
  const runtimeFileName = [...entryChunk.files][0] || '';
192
+
164
193
  if (runtimeFileName.includes('runtime') && runtimeFileName.includes('[locale]')) {
165
194
  (0, _logger.verboseLogger)('deleteAsset', runtimeFileName);
166
195
  compilation.deleteAsset(runtimeFileName);
@@ -169,21 +198,26 @@ class I18nRuntimeDealerPlugin {
169
198
  });
170
199
  }
171
200
  }
201
+
172
202
  filterI18nUsedChunks(chunks) {
173
203
  const i18nStore = this.store;
174
204
  return Array.from(chunks).filter(c => i18nStore.isChunkHasI18n(c.id));
175
205
  }
206
+
176
207
  getContentHashes(locale) {
177
208
  const i18nStore = this.store;
178
209
  const contentHashes = {};
179
210
  i18nStore.forEachChunkId(chunkId => {
180
211
  const contentHash = i18nStore.getContentHash(chunkId, locale);
212
+
181
213
  if (contentHash) {
182
214
  contentHashes[chunkId] = contentHash;
183
215
  }
184
- });
185
- // console.log({ contentHashes });
216
+ }); // console.log({ contentHashes });
217
+
186
218
  return contentHashes;
187
219
  }
220
+
188
221
  }
222
+
189
223
  exports.I18nRuntimeDealerPlugin = I18nRuntimeDealerPlugin;
@@ -6,53 +6,68 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.LocaleChunkAssetsStore = void 0;
7
7
  exports.getLocaleChunkAssetsStore = getLocaleChunkAssetsStore;
8
8
  exports.setLocaleChunkAssetsStore = setLocaleChunkAssetsStore;
9
+
9
10
  var _ModulesI18nKeysStore = require("./ModulesI18nKeysStore");
11
+
10
12
  class LocaleChunkAssetsStore extends _ModulesI18nKeysStore.ModulesI18nKeysStore {
11
13
  constructor() {
12
14
  super();
13
15
  this.data = {};
14
16
  }
17
+
15
18
  clear() {
16
19
  this.data = {};
17
20
  }
21
+
18
22
  storeData(chunkId, locale, data) {
19
23
  if (!this.data[chunkId]) {
20
24
  this.data[chunkId] = {};
21
25
  }
26
+
22
27
  const chunkBasedData = this.data[chunkId];
23
- chunkBasedData[locale] = {
24
- ...(chunkBasedData[locale] || {}),
28
+ chunkBasedData[locale] = { ...(chunkBasedData[locale] || {}),
25
29
  ...data
26
30
  };
27
31
  }
32
+
28
33
  getChunkIdsWhichHasI18n() {
29
34
  return Object.keys(this.data);
30
35
  }
36
+
31
37
  forEachChunkId(cb) {
32
38
  // Object.keys(localeChunkAssestMap).forEach
33
39
  this.getChunkIdsWhichHasI18n().forEach(cb);
34
40
  }
41
+
35
42
  isChunkHasI18n(chunkId) {
36
43
  if (typeof chunkId === 'object') {
37
44
  return super.isChunkHasI18n(chunkId);
38
45
  }
46
+
39
47
  return !!this.data[chunkId];
40
48
  }
49
+
41
50
  getDate(chunkId, locale) {
42
51
  return this.data[chunkId]?.[locale];
43
52
  }
53
+
44
54
  getContent(chunkId, locale) {
45
55
  return this.data[chunkId]?.[locale]?.content;
46
56
  }
57
+
47
58
  getContentHash(chunkId, locale) {
48
59
  return this.data[chunkId]?.[locale]?.contentHash;
49
60
  }
61
+
50
62
  }
63
+
51
64
  exports.LocaleChunkAssetsStore = LocaleChunkAssetsStore;
52
65
  const storeCache = new WeakMap();
66
+
53
67
  function getLocaleChunkAssetsStore(compilation) {
54
68
  return storeCache.get(compilation);
55
69
  }
70
+
56
71
  function setLocaleChunkAssetsStore(compilation, store) {
57
72
  return storeCache.set(compilation, store);
58
73
  }
@@ -4,21 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ModulesI18nKeysStore = void 0;
7
+
7
8
  var _iterateModulesInChunk = require("./iterateModulesInChunk");
9
+
8
10
  class ModulesI18nKeysStore {
9
11
  constructor() {
10
12
  this.modulesI18nKeysMap = {};
11
13
  this.compilation = null;
12
14
  }
15
+
13
16
  updateCompilation(compilation) {
14
17
  this.compilation = compilation;
15
18
  }
19
+
16
20
  updateModuleI18nKeys(resource, i18nKeys) {
17
21
  this.modulesI18nKeysMap[resource] = i18nKeys;
18
22
  }
23
+
19
24
  getModuleI18nKeys(resource) {
20
25
  return this.modulesI18nKeysMap[resource];
21
26
  }
27
+
22
28
  isChunkHasI18n(chunk) {
23
29
  const {
24
30
  modulesI18nKeysMap,
@@ -34,6 +40,7 @@ class ModulesI18nKeysStore {
34
40
  }) => {
35
41
  if (mod.resource) {
36
42
  const keys = modulesI18nKeysMap[mod.resource];
43
+
37
44
  if (keys && keys.length > 0) {
38
45
  hasModuleI18n = true;
39
46
  stopLoop();
@@ -43,14 +50,17 @@ class ModulesI18nKeysStore {
43
50
  });
44
51
  return hasModuleI18n;
45
52
  }
53
+
46
54
  getI18nKeysForChunk(chunk) {
47
55
  const {
48
56
  modulesI18nKeysMap,
49
57
  compilation
50
58
  } = this;
51
59
  const i18nKeysMap = {};
60
+
52
61
  function updateI18nKeys(mod) {
53
62
  const keys = modulesI18nKeysMap[mod.resource];
63
+
54
64
  if (keys) {
55
65
  // eslint-disable-next-line no-restricted-syntax
56
66
  for (const key of keys) {
@@ -58,6 +68,7 @@ class ModulesI18nKeysStore {
58
68
  }
59
69
  }
60
70
  }
71
+
61
72
  (0, _iterateModulesInChunk.iterateModulesInChunk)({
62
73
  chunk,
63
74
  compilation,
@@ -71,5 +82,7 @@ class ModulesI18nKeysStore {
71
82
  });
72
83
  return Object.keys(i18nKeysMap);
73
84
  }
85
+
74
86
  }
87
+
75
88
  exports.ModulesI18nKeysStore = ModulesI18nKeysStore;
@@ -4,16 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.TYPES = exports.SINGLE_DOT_PATH_SEGMENT = exports.MODULE_TYPE = exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = exports.DEFAULT_FILENAME = exports.DEFAULT_CHUNK_FILENAME = exports.CODE_GENERATION_RESULT = exports.BASE_URI = exports.AUTO_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = void 0;
7
- const MODULE_TYPE = exports.MODULE_TYPE = 'i18n/mini-extract';
8
- const AUTO_PUBLIC_PATH = exports.AUTO_PUBLIC_PATH = '__mini_i18n_extract_plugin_public_path_auto__';
9
- const ABSOLUTE_PUBLIC_PATH = exports.ABSOLUTE_PUBLIC_PATH = 'webpack:///mini-i18n-extract-plugin/';
10
- const BASE_URI = exports.BASE_URI = 'webpack://';
11
- const SINGLE_DOT_PATH_SEGMENT = exports.SINGLE_DOT_PATH_SEGMENT = '__mini_i18n_extract_plugin_single_dot_path_segment__';
12
- const I18N_CHUNK_NAME_GENERATION_SEGMENT = exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = '__mini_i18n_extract_plugin_i18n_chunk_name_generation_segment__';
13
- const DEFAULT_FILENAME = exports.DEFAULT_FILENAME = 'i18n-chunks/[locale]/[name].[contenthash].i18n.js';
14
- const DEFAULT_CHUNK_FILENAME = exports.DEFAULT_CHUNK_FILENAME = 'i18n-chunks/[locale]/[id].[contenthash].i18n.js';
15
- const TYPES = exports.TYPES = new Set([MODULE_TYPE]);
16
- const CODE_GENERATION_RESULT = exports.CODE_GENERATION_RESULT = {
7
+ const MODULE_TYPE = 'i18n/mini-extract';
8
+ exports.MODULE_TYPE = MODULE_TYPE;
9
+ const AUTO_PUBLIC_PATH = '__mini_i18n_extract_plugin_public_path_auto__';
10
+ exports.AUTO_PUBLIC_PATH = AUTO_PUBLIC_PATH;
11
+ const ABSOLUTE_PUBLIC_PATH = 'webpack:///mini-i18n-extract-plugin/';
12
+ exports.ABSOLUTE_PUBLIC_PATH = ABSOLUTE_PUBLIC_PATH;
13
+ const BASE_URI = 'webpack://';
14
+ exports.BASE_URI = BASE_URI;
15
+ const SINGLE_DOT_PATH_SEGMENT = '__mini_i18n_extract_plugin_single_dot_path_segment__';
16
+ exports.SINGLE_DOT_PATH_SEGMENT = SINGLE_DOT_PATH_SEGMENT;
17
+ const I18N_CHUNK_NAME_GENERATION_SEGMENT = '__mini_i18n_extract_plugin_i18n_chunk_name_generation_segment__';
18
+ exports.I18N_CHUNK_NAME_GENERATION_SEGMENT = I18N_CHUNK_NAME_GENERATION_SEGMENT;
19
+ const DEFAULT_FILENAME = 'i18n-chunks/[locale]/[name].[contenthash].i18n.js';
20
+ exports.DEFAULT_FILENAME = DEFAULT_FILENAME;
21
+ const DEFAULT_CHUNK_FILENAME = 'i18n-chunks/[locale]/[id].[contenthash].i18n.js';
22
+ exports.DEFAULT_CHUNK_FILENAME = DEFAULT_CHUNK_FILENAME;
23
+ const TYPES = new Set([MODULE_TYPE]);
24
+ exports.TYPES = TYPES;
25
+ const CODE_GENERATION_RESULT = {
17
26
  sources: new Map(),
18
27
  runtimeRequirements: new Set()
19
- };
28
+ };
29
+ exports.CODE_GENERATION_RESULT = CODE_GENERATION_RESULT;
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createHash = createHash;
7
+
7
8
  var _webpack = require("webpack");
9
+
8
10
  function createHash({
9
11
  outputOptions,
10
12
  content
@@ -14,7 +16,9 @@ function createHash({
14
16
  hashDigest,
15
17
  hashDigestLength
16
18
  } = outputOptions;
19
+
17
20
  const hash = _webpack.util.createHash(hashFunction);
21
+
18
22
  hash.update(content);
19
23
  return hash.digest(hashDigest).substring(0, hashDigestLength);
20
24
  }
@@ -4,15 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getI18nLoadingRuntimeModule = getI18nLoadingRuntimeModule;
7
+
7
8
  var _webpack = require("webpack");
9
+
8
10
  /* eslint-disable no-restricted-syntax */
9
11
  const getChunksMapObject = i18nChunks => {
10
12
  const obj = {};
13
+
11
14
  for (const chunk of i18nChunks) {
12
15
  obj[chunk.id] = 1;
13
16
  }
17
+
14
18
  return obj;
15
19
  };
20
+
16
21
  function getI18nLoadingRuntimeModule({
17
22
  getI18nChunks
18
23
  }) {
@@ -26,6 +31,7 @@ function getI18nLoadingRuntimeModule({
26
31
  this.prefixFunc = prefixFunc;
27
32
  this.runtimeOptions = runtimeOptions;
28
33
  }
34
+
29
35
  generate() {
30
36
  const {
31
37
  chunk,
@@ -38,16 +44,17 @@ function getI18nLoadingRuntimeModule({
38
44
  outputOptions: {
39
45
  crossOriginLoading
40
46
  }
41
- } = compilation;
42
- // const i18nChunks = getI18nChunks(chunk, compilation);
43
-
47
+ } = compilation; // const i18nChunks = getI18nChunks(chunk, compilation);
44
48
  // REASON: we do it in here is in dev mode thing may change
45
49
  // const i18nChunks = getI18nChunks(entryRuntimeChunk);
50
+
46
51
  const i18nChunks = getI18nChunks(chunk);
47
52
  const withLoading = runtimeRequirements.has(_webpack.RuntimeGlobals.ensureChunkHandlers) && i18nChunks.length > 0;
53
+
48
54
  if (!withLoading) {
49
55
  return '// no i18n chunks loading';
50
56
  }
57
+
51
58
  const chunkMap = getChunksMapObject(i18nChunks);
52
59
  const {
53
60
  attributes,
@@ -58,9 +65,12 @@ function getI18nLoadingRuntimeModule({
58
65
  return _webpack.Template.asString([`${prefixFunc(i18nChunks)}`, `var createI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId, fullsrc, resolve, reject', ['var scriptTag = document.createElement("script");', attributes ? _webpack.Template.asString(Object.entries(attributes).map(entry => {
59
66
  const [key, value] = entry;
60
67
  return `scriptTag.setAttribute(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
61
- })) : '', '__webpack_require__.nc && scriptTag.setAttribute("nonce", __webpack_require__.nc)', scriptType ? `scriptTag.type = ${JSON.stringify(scriptType)};` : '', `var onScriptComplete = ${runtimeTemplate.basicFunction('event', ['// avoid mem leaks.', 'scriptTag.onerror = scriptTag.onload = null;', 'if (event.type === \'load\') {', _webpack.Template.indent(['resolve();']), '} else {', _webpack.Template.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src || fullsrc;', 'var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + realSrc + ")");', 'err.code = "I18N_CHUNK_LOAD_FAILED";', 'err.type = errorType;', 'err.request = realSrc;', 'scriptTag.parentNode.removeChild(scriptTag)', 'reject(err);']), '}'])}`, 'scriptTag.onerror = scriptTag.onload = onScriptComplete;', 'scriptTag.src = fullsrc;', crossOriginLoading ? _webpack.Template.asString(['if (scriptTag.src.indexOf(window.location.origin + \'/\') !== 0) {', _webpack.Template.indent(`scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', insertRoot && insertPlace || _webpack.Template.asString(['document.head.appendChild(scriptTag);']), 'return scriptTag;'])};`, `var findI18nScriptTag = ${runtimeTemplate.basicFunction('src, fullsrc', ['var existingScriptTags = document.getElementsByTagName("script");', 'for(var i = 0; i < existingScriptTags.length; i++) {', _webpack.Template.indent(['var tag = existingScriptTags[i];', 'var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");', 'if((dataSrc === src || dataSrc === fullsrc)) return tag;']), '}', 'var existingStyleTags = document.getElementsByTagName("style");', 'for(var i = 0; i < existingStyleTags.length; i++) {', _webpack.Template.indent(['var tag = existingStyleTags[i];', 'var dataSrc = tag.getAttribute("data-src");', 'if(dataSrc === src || dataSrc === fullsrc) return tag;']), '}'])};`, `var loadI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId', `return new Promise(${runtimeTemplate.basicFunction('resolve, reject', [`var src = ${_webpack.RuntimeGlobals.require}.miniI18nF(chunkId);`, `var fullsrc = ${_webpack.RuntimeGlobals.publicPath} + src;`, 'if(findI18nScriptTag(src, fullsrc)) return resolve();', 'createI18nScriptTag(chunkId, fullsrc, resolve, reject);'])});`)}`, '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(/** @type {string[]} */
68
+ })) : '', '__webpack_require__.nc && scriptTag.setAttribute("nonce", __webpack_require__.nc)', scriptType ? `scriptTag.type = ${JSON.stringify(scriptType)};` : '', `var onScriptComplete = ${runtimeTemplate.basicFunction('event', ['// avoid mem leaks.', 'scriptTag.onerror = scriptTag.onload = null;', 'if (event.type === \'load\') {', _webpack.Template.indent(['resolve();']), '} else {', _webpack.Template.indent(['var errorType = event && (event.type === \'load\' ? \'missing\' : event.type);', 'var realSrc = event && event.target && event.target.src || fullsrc;', 'var err = new Error("Loading I18N chunk " + chunkId + " failed.\\n(" + realSrc + ")");', 'err.code = "I18N_CHUNK_LOAD_FAILED";', 'err.type = errorType;', 'err.request = realSrc;', 'scriptTag.parentNode.removeChild(scriptTag)', 'reject(err);']), '}'])}`, 'scriptTag.onerror = scriptTag.onload = onScriptComplete;', 'scriptTag.src = fullsrc;', crossOriginLoading ? _webpack.Template.asString(['if (scriptTag.src.indexOf(window.location.origin + \'/\') !== 0) {', _webpack.Template.indent(`scriptTag.crossOrigin = ${JSON.stringify(crossOriginLoading)};`), '}']) : '', insertRoot && insertPlace || _webpack.Template.asString(['document.head.appendChild(scriptTag);']), 'return scriptTag;'])};`, `var findI18nScriptTag = ${runtimeTemplate.basicFunction('src, fullsrc', ['var existingScriptTags = document.getElementsByTagName("script");', 'for(var i = 0; i < existingScriptTags.length; i++) {', _webpack.Template.indent(['var tag = existingScriptTags[i];', 'var dataSrc = tag.getAttribute("data-src") || tag.getAttribute("src");', 'if((dataSrc === src || dataSrc === fullsrc)) return tag;']), '}', 'var existingStyleTags = document.getElementsByTagName("style");', 'for(var i = 0; i < existingStyleTags.length; i++) {', _webpack.Template.indent(['var tag = existingStyleTags[i];', 'var dataSrc = tag.getAttribute("data-src");', 'if(dataSrc === src || dataSrc === fullsrc) return tag;']), '}'])};`, `var loadI18nScriptTag = ${runtimeTemplate.basicFunction('chunkId', `return new Promise(${runtimeTemplate.basicFunction('resolve, reject', [`var src = ${_webpack.RuntimeGlobals.require}.miniI18nF(chunkId);`, `var fullsrc = ${_webpack.RuntimeGlobals.publicPath} + src;`, 'if(findI18nScriptTag(src, fullsrc)) return resolve();', 'createI18nScriptTag(chunkId, fullsrc, resolve, reject);'])});`)}`, '// object to store loaded I18N chunks', 'var installedI18nChunks = {', _webpack.Template.indent(
69
+ /** @type {string[]} */
62
70
  chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(',\n')), '};', '', `${_webpack.RuntimeGlobals.ensureChunkHandlers}.miniI18n = ${runtimeTemplate.basicFunction('chunkId, promises', [`var i18nChunks = ${JSON.stringify(chunkMap)};`, 'if(installedI18nChunks[chunkId]) promises.push(installedI18nChunks[chunkId]);', 'else if(installedI18nChunks[chunkId] !== 0 && i18nChunks[chunkId]) {', _webpack.Template.indent([`promises.push(installedI18nChunks[chunkId] = loadI18nScriptTag(chunkId).then(${runtimeTemplate.basicFunction('', 'installedI18nChunks[chunkId] = 0;')}, ${runtimeTemplate.basicFunction('e', ['delete installedI18nChunks[chunkId];', 'throw e;'])}));`]), '}'])};`, '']);
63
71
  }
72
+
64
73
  }
74
+
65
75
  return I18nLoadingRuntimeModule;
66
76
  }
@@ -4,26 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.pluginName = exports.default = void 0;
7
+
7
8
  var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
9
+
8
10
  var _optionsHandler = require("./optionsHandler");
11
+
9
12
  var _I18nFilesEmitPlugin = require("./I18nFilesEmitPlugin");
13
+
10
14
  var _I18nRuntimeDealerPlugin = require("./I18nRuntimeDealerPlugin");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- // import getI18nKeysFormModules from './utils/getI18nKeysFormModules';
13
15
 
14
- const pluginName = exports.pluginName = 'mini-i18n-extract-plugin';
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ // import getI18nKeysFormModules from './utils/getI18nKeysFormModules';
19
+ const pluginName = 'mini-i18n-extract-plugin';
20
+ exports.pluginName = pluginName;
15
21
  const pluginSymbol = Symbol(pluginName);
22
+
16
23
  class I18nExtractPlugin {
17
24
  constructor(options = {}) {
18
25
  // initialize options
19
26
  this.options = (0, _optionsHandler.optionsHandler)(options);
20
27
  }
28
+
21
29
  apply(compiler) {
22
30
  new _I18nKeysIdentifer.default(this.options).apply(compiler);
23
31
  new _I18nFilesEmitPlugin.I18nFilesEmitPlugin(this.options).apply(compiler);
24
32
  new _I18nRuntimeDealerPlugin.I18nRuntimeDealerPlugin(this.options).apply(compiler);
25
33
  }
34
+
26
35
  }
36
+
27
37
  exports.default = I18nExtractPlugin;
28
38
  I18nExtractPlugin.pluginName = pluginName;
29
39
  I18nExtractPlugin.pluginSymbol = pluginSymbol;
@@ -4,18 +4,24 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.iterateModulesInChunk = iterateModulesInChunk;
7
+
7
8
  var _ConcatenatedModule = _interopRequireDefault(require("webpack/lib/optimize/ConcatenatedModule"));
9
+
8
10
  var _getChunkModules = require("./utils/getChunkModules");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
10
14
  function iterateModulesInChunk({
11
15
  chunk,
12
16
  cb,
13
17
  compilation
14
18
  }) {
15
19
  let canStopLoop = false;
20
+
16
21
  function stopLoop() {
17
22
  canStopLoop = true;
18
23
  }
24
+
19
25
  function iterateNestedModules(mod) {
20
26
  if (mod.resource) {
21
27
  cb({
@@ -24,15 +30,18 @@ function iterateModulesInChunk({
24
30
  });
25
31
  return canStopLoop;
26
32
  }
33
+
27
34
  if (mod instanceof _ConcatenatedModule.default) {
28
35
  const {
29
36
  modules
30
37
  } = mod;
31
38
  return Array.from(modules).some(mod => iterateNestedModules(mod));
32
39
  }
40
+
33
41
  return canStopLoop;
34
- }
35
- // eslint-disable-next-line no-restricted-syntax
42
+ } // eslint-disable-next-line no-restricted-syntax
43
+
44
+
36
45
  for (const mod of (0, _getChunkModules.getChunkModules)(chunk, compilation)) {
37
46
  if (iterateNestedModules(mod)) {
38
47
  return;