@zohodesk/react-cli 1.1.17 → 1.1.18-exp.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +13 -0
  2. package/lib/babel/babel-option-utils/babel-preset-react-option.js +22 -0
  3. package/lib/babel/cmjs-plugins-presets.js +7 -1
  4. package/lib/babel/es-plugins-presets.js +7 -1
  5. package/lib/configs/webpack.dev.config.js +7 -2
  6. package/lib/configs/webpack.prod.config.js +9 -2
  7. package/lib/loaderUtils/getDevJsLoaders.js +5 -1
  8. package/lib/schemas/index.js +4 -0
  9. package/npm-shrinkwrap.json +31 -5
  10. package/package.json +1 -1
  11. package/packages/client_build_tool/lib/allCommandsConfigs.js +23 -0
  12. package/packages/client_build_tool/lib/buildToolLoggers.js +32 -0
  13. package/packages/client_build_tool/lib/commands/build/commandExecutor.js +21 -0
  14. package/packages/client_build_tool/lib/commands/build/config.js +12 -0
  15. package/packages/client_build_tool/lib/commands/build/errorHander.js +10 -0
  16. package/packages/client_build_tool/lib/commands/build/index.js +35 -0
  17. package/packages/client_build_tool/lib/commands/build/optionsProcesser.js +40 -0
  18. package/packages/client_build_tool/lib/commands/buildEs/commandExecutor.js +17 -0
  19. package/packages/client_build_tool/lib/commands/buildEs/config.js +12 -0
  20. package/packages/client_build_tool/lib/commands/buildLib/commandExecutor.js +17 -0
  21. package/packages/client_build_tool/lib/commands/buildLib/config.js +12 -0
  22. package/packages/client_build_tool/lib/commands/start/commandExecutor.js +13 -0
  23. package/packages/client_build_tool/lib/commands/start/config.js +12 -0
  24. package/packages/client_build_tool/lib/commands/start/deprecationHandler.js +10 -0
  25. package/packages/client_build_tool/lib/commands/start/errorHander.js +10 -0
  26. package/packages/client_build_tool/lib/commands/start/optionsProcesser.js +36 -0
  27. package/packages/client_build_tool/lib/commands/start/postProcesser.js +10 -0
  28. package/packages/client_build_tool/lib/commands/start/preProcesser.js +10 -0
  29. package/packages/client_build_tool/lib/commandsRouter.js +71 -0
  30. package/packages/client_build_tool/lib/shared/bundler/webpack/common/decidePublicPath.js +44 -0
  31. package/packages/client_build_tool/lib/shared/bundler/webpack/common/libAlias.js +31 -0
  32. package/packages/client_build_tool/lib/shared/bundler/webpack/common/nameTemplates.js +51 -0
  33. package/packages/client_build_tool/lib/shared/bundler/webpack/common/resourceBasedPublicPath.js +21 -0
  34. package/packages/client_build_tool/lib/shared/bundler/webpack/cssLoaders.js +16 -0
  35. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/CdnChangePlugin.js +111 -0
  36. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/EFCPlugin.js +1 -0
  37. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/ContributionGuide.md +11 -0
  38. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nKeysIdentifer.js +136 -0
  39. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/I18nSplit.md +95 -0
  40. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/README.md +25 -0
  41. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/constants.js +29 -0
  42. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/createHash.js +24 -0
  43. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nDependency.js +99 -0
  44. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nLoadingRuntimeModule.js +81 -0
  45. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/getI18nModule.js +201 -0
  46. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/index.js +401 -0
  47. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/optionsHandler.js +67 -0
  48. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/pathCreator.js +23 -0
  49. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/readI18nValues.js +29 -0
  50. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateFileName.js +49 -0
  51. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/templateHashHelpers.js +77 -0
  52. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectI18nKeys.js +63 -0
  53. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/hashUtils.js +19 -0
  54. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/index.js +31 -0
  55. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +127 -0
  56. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RTLSplitPlugin.js +1 -0
  57. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/OverwriteCssPathForRTL.js +63 -0
  58. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtlCssPlugin.js +89 -0
  59. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/RtrSplit.md +34 -0
  60. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/RtlSplitPlugin/replaceCssDirTemplate.js +15 -0
  61. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/ServiceWorkerPlugin.js +155 -0
  62. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_plugins/UglifyCSSPlugin.js +49 -0
  63. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_postcss_loaders/ExcludePlugin.js +58 -0
  64. package/packages/client_build_tool/lib/shared/bundler/webpack/custom_postcss_loaders/RTLSplitPlugin.js +139 -0
  65. package/packages/client_build_tool/lib/shared/bundler/webpack/devServerConfig.js +34 -0
  66. package/packages/client_build_tool/lib/shared/bundler/webpack/getCSSLoaders.js +30 -0
  67. package/packages/client_build_tool/lib/shared/bundler/webpack/jsLoaders.js +17 -0
  68. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/assetLoaders.js +14 -0
  69. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/babelLoaderConfig.js +24 -0
  70. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configHtmlTemplateLoader.js +18 -0
  71. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configWebWorkerLoader.js +21 -0
  72. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/configsAssetsLoaders.js +138 -0
  73. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/cssClassNameGenerate.js +83 -0
  74. package/packages/client_build_tool/lib/shared/bundler/webpack/loaderConfigs/getCssLoaderOptions.js +23 -0
  75. package/packages/client_build_tool/lib/shared/bundler/webpack/loaders/workerLoader.js +133 -0
  76. package/packages/client_build_tool/lib/shared/bundler/webpack/optimizationConfig.js +39 -0
  77. package/packages/client_build_tool/lib/shared/bundler/webpack/outputConfig.js +28 -0
  78. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configCdnChangePlugin.js +18 -0
  79. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configCopyThirdpartyFile.js +38 -0
  80. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configEnvVariables.js +24 -0
  81. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configHtmlWebpackPlugin.js +28 -0
  82. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configI18nSplitPlugin.js +35 -0
  83. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configIgnorePlugin.js +16 -0
  84. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configMiniCSSExtractPlugin.js +23 -0
  85. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configProgressPlugin.js +19 -0
  86. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configRtlCssPlugin.js +27 -0
  87. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configServiceWorkerPlugin.js +18 -0
  88. package/packages/client_build_tool/lib/shared/bundler/webpack/pluginConfigs/configUglifyCSSPlugin.js +15 -0
  89. package/packages/client_build_tool/lib/shared/bundler/webpack/plugins.js +39 -0
  90. package/packages/client_build_tool/lib/shared/bundler/webpack/postcssPlugins.js +36 -0
  91. package/packages/client_build_tool/lib/shared/bundler/webpack/resolvers.js +42 -0
  92. package/packages/client_build_tool/lib/shared/bundler/webpack/splitChunksConfig.js +12 -0
  93. package/packages/client_build_tool/lib/shared/bundler/webpack/webpack.dev.config.js +17 -0
  94. package/packages/client_build_tool/lib/shared/bundler/webpack/webpackBuild.js +24 -0
  95. package/packages/client_build_tool/lib/shared/bundler/webpack/webpackConfig.js +50 -0
  96. package/packages/client_build_tool/lib/shared/commands-utlis/doBasicRequiermentCheck.js +16 -0
  97. package/packages/client_build_tool/lib/shared/commands-utlis/getCliPath.js +38 -0
  98. package/packages/client_build_tool/lib/shared/commands-utlis/index.js +29 -0
  99. package/packages/client_build_tool/lib/shared/commands-utlis/log.js +13 -0
  100. package/packages/client_build_tool/lib/shared/commands-utlis/readArgsFormCommandLine.js +11 -0
  101. package/packages/client_build_tool/lib/shared/commands-utlis/readOptionFormCommandLine.js +11 -0
  102. package/packages/client_build_tool/lib/shared/commands-utlis/spanSync.js +35 -0
  103. package/packages/client_build_tool/lib/shared/constants.js +33 -0
  104. package/packages/client_build_tool/lib/shared/schemas/applyValuesToShema.js +37 -0
  105. package/packages/client_build_tool/lib/shared/schemas/cliArgsToObject.js +37 -0
  106. package/packages/client_build_tool/lib/shared/schemas/defaultConfigValues.js +119 -0
  107. package/packages/client_build_tool/lib/shared/schemas/deprecatedOptionsHandler.js +65 -0
  108. package/packages/client_build_tool/lib/shared/schemas/getCWD.js +23 -0
  109. package/packages/client_build_tool/lib/shared/schemas/getNpmVersion.js +21 -0
  110. package/packages/client_build_tool/lib/shared/schemas/npmConfigToObject.js +32 -0
  111. package/packages/client_build_tool/lib/shared/schemas/oldDefaultConfigValues.js +480 -0
  112. package/packages/client_build_tool/lib/shared/schemas/readOptions.js +55 -0
  113. package/packages/client_build_tool/lib/shared/schemas/readOptionsForPackageJson.js +26 -0
  114. package/packages/client_build_tool/lib/shared/schemas/readOptionsOld.js +152 -0
  115. package/packages/client_build_tool/lib/shared/server/cert/Tsicsezwild-22-23.crt +37 -0
  116. package/packages/client_build_tool/lib/shared/server/cert/Tsicsezwild-22-23.key +27 -0
  117. package/packages/client_build_tool/lib/shared/server/configWebpackDevMiddleware.js +40 -0
  118. package/packages/client_build_tool/lib/shared/server/corsHandleing.js +28 -0
  119. package/packages/client_build_tool/lib/shared/server/getIp.js +30 -0
  120. package/packages/client_build_tool/lib/shared/server/getServerURL.js +29 -0
  121. package/packages/client_build_tool/lib/shared/server/httpsOptions.js +53 -0
  122. package/packages/client_build_tool/lib/shared/server/initExpressApp.js +19 -0
  123. package/packages/client_build_tool/lib/shared/server/initialHTMLHandling.js +66 -0
  124. package/packages/client_build_tool/lib/shared/server/serveContextFiles.js +24 -0
  125. package/packages/client_build_tool/lib/shared/server/serverBywebpackDevMiddleware.js +40 -0
  126. package/packages/client_build_tool/lib/shared/server/startHttpServer.js +26 -0
  127. package/packages/client_build_tool/lib/shared/server/startHttpsServer.js +34 -0
  128. package/packages/client_build_tool/lib/shared/server/unwanted/addHttp2Server.js +41 -0
  129. package/packages/client_build_tool/lib/shared/server/unwanted/configWebpackDevMiddleware.js +44 -0
  130. package/packages/client_build_tool/lib/shared/server/unwanted/devServerUtlis.js +1 -0
  131. package/packages/client_build_tool/lib/shared/server/unwanted/mockApiSupport.js +19 -0
  132. package/packages/client_build_tool/lib/shared/server/unwanted/webpackConfig.js +32 -0
  133. package/packages/client_build_tool/lib/shared/server/unwanted/websocketMockSetup.js +48 -0
  134. package/packages/client_build_tool/lib/shared/server/urlConcat.js +25 -0
  135. package/packages/client_build_tool/lib/shared/utils/utils.js +1 -0
@@ -0,0 +1,401 @@
1
+ "use strict";
2
+
3
+ var _webpack = require("webpack");
4
+
5
+ var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
6
+
7
+ var _constants = require("./constants");
8
+
9
+ var _I18nKeysIdentifer = _interopRequireDefault(require("./I18nKeysIdentifer"));
10
+
11
+ var _getI18nModule = require("./getI18nModule");
12
+
13
+ var _getI18nDependency = require("./getI18nDependency");
14
+
15
+ var _optionsHandler = require("./optionsHandler");
16
+
17
+ var _getI18nLoadingRuntimeModule = require("./getI18nLoadingRuntimeModule");
18
+
19
+ var _createHash = require("./createHash");
20
+
21
+ var _pathCreator = require("./pathCreator");
22
+
23
+ var _templateFileName = require("./templateFileName");
24
+
25
+ var _hashUtils = require("./utils/hashUtils");
26
+
27
+ var _propertiesUtils = require("./utils/propertiesUtils");
28
+
29
+ var _urlConcat = require("../../../../server/urlConcat");
30
+
31
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
+
33
+ /* eslint-disable no-restricted-syntax */
34
+
35
+ /* eslint-disable no-nested-ternary */
36
+ // import getI18nKeysFormModules from './utils/getI18nKeysFormModules';
37
+ const pluginName = 'mini-i18n-extract-plugin';
38
+ const pluginSymbol = Symbol(pluginName);
39
+
40
+ function getChunkModules(chunk, chunkGraph) {
41
+ return typeof chunkGraph !== 'undefined' ? chunkGraph.getChunkModules(chunk) : chunk.modulesIterable;
42
+ }
43
+
44
+ class I18nExtractPlugin {
45
+ constructor(options = {}) {
46
+ // initialize options
47
+ this.options = (0, _optionsHandler.optionsHandler)(options);
48
+ }
49
+
50
+ getI18nKeysForChunk(chunk, chunkGraph) {
51
+ const {
52
+ modulesI18nKeysMap
53
+ } = this.i18nKeysIdentifer;
54
+ const i18nKeysMap = {};
55
+
56
+ for (const mod of getChunkModules(chunk, chunkGraph)) {
57
+ const keys = modulesI18nKeysMap[mod.resource];
58
+
59
+ if (keys) {
60
+ for (const key of keys) {
61
+ i18nKeysMap[key] = 1;
62
+ }
63
+ }
64
+ }
65
+
66
+ return Object.keys(i18nKeysMap);
67
+ }
68
+
69
+ getI18nContentForkeys(i18nKeys, locale) {
70
+ const {
71
+ allI18nObject
72
+ } = this.options;
73
+ const data = {};
74
+
75
+ for (const key of i18nKeys) {
76
+ data[key] = allI18nObject[locale][key];
77
+ }
78
+
79
+ return data;
80
+ }
81
+
82
+ getI18nChunkFileContent(i18nKeys, loc) {
83
+ const {
84
+ jsonpFunc
85
+ } = this.options;
86
+ const data = this.getI18nContentForkeys(i18nKeys, loc);
87
+ return `${jsonpFunc}(${(0, _propertiesUtils.jsonToString)(data)})`;
88
+ }
89
+
90
+ filterI18nUsedChunks(chunks) {
91
+ const {
92
+ localeChunkAssestMap
93
+ } = this;
94
+ return Array.from(chunks).filter(c => localeChunkAssestMap[c.id]);
95
+ }
96
+
97
+ getContentHashes(locale) {
98
+ const {
99
+ localeChunkAssestMap
100
+ } = this;
101
+ const contentHashes = {};
102
+ Object.keys(localeChunkAssestMap).forEach(chunkId => {
103
+ if (localeChunkAssestMap[chunkId] && localeChunkAssestMap[chunkId][locale] && localeChunkAssestMap[chunkId][locale].contentHash) {
104
+ contentHashes[chunkId] = localeChunkAssestMap[chunkId][locale].contentHash;
105
+ } // console.log(localeChunkAssestMap[chunkId][locale]);
106
+
107
+ }); // console.log({ contentHashes });
108
+
109
+ return contentHashes;
110
+ }
111
+
112
+ apply(compiler) {
113
+ const {
114
+ webpack
115
+ } = compiler;
116
+ this.addToDefaultTypes(compiler);
117
+ const I18nModule = (0, _getI18nModule.getI18nModule)(webpack);
118
+ const I18nDependency = (0, _getI18nDependency.getI18nDependency)(webpack); // initialize base data's and plugis
119
+
120
+ this.i18nKeysIdentifer = new _I18nKeysIdentifer.default(this.options, {
121
+ I18nModule,
122
+ I18nDependency
123
+ });
124
+ this.i18nKeysIdentifer.apply(compiler);
125
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
126
+ this.localeChunkAssestMap = {};
127
+ compilation.hooks.beforeHash.tap(pluginName, () => {
128
+ const {
129
+ locales
130
+ } = this.options;
131
+ const {
132
+ chunks
133
+ } = compilation;
134
+ this.localeChunkAssestMap = {};
135
+ const {
136
+ localeChunkAssestMap
137
+ } = this;
138
+
139
+ for (const chunk of chunks) {
140
+ const {
141
+ chunkGraph
142
+ } = compilation;
143
+ const i18nKeys = this.getI18nKeysForChunk(chunk, chunkGraph);
144
+
145
+ if (i18nKeys.length) {
146
+ localeChunkAssestMap[chunk.id] = {};
147
+
148
+ for (const loc of locales) {
149
+ const content = this.getI18nChunkFileContent(i18nKeys, loc);
150
+ localeChunkAssestMap[chunk.id][loc] = {
151
+ content
152
+ };
153
+ }
154
+ }
155
+ }
156
+ });
157
+ compilation.hooks.chunkHash.tap(pluginName, (chunk, hash) => {
158
+ const {
159
+ localeChunkAssestMap
160
+ } = this;
161
+ const {
162
+ locales
163
+ } = this.options;
164
+
165
+ if (localeChunkAssestMap[chunk.id]) {
166
+ for (const loc of locales) {
167
+ const {
168
+ content
169
+ } = localeChunkAssestMap[chunk.id][loc];
170
+ hash.update(content);
171
+ }
172
+ }
173
+ });
174
+
175
+ function createFilenameWithHash({
176
+ fileNameTemplate,
177
+ chunk,
178
+ locale,
179
+ content
180
+ }) {
181
+ const fileName = fileNameTemplate.replaceAll('[locale]', locale);
182
+ const contentHash = (0, _createHash.createHash)({
183
+ compiler,
184
+ outputOptions: compilation.outputOptions,
185
+ content
186
+ });
187
+ const filename = (0, _pathCreator.pathCreator)(fileName, compilation, {
188
+ hash: compilation.hash,
189
+ chunkId: chunk.id,
190
+ chunkHash: chunk.hash,
191
+ contentHash
192
+ });
193
+ return {
194
+ contentHash,
195
+ filename
196
+ };
197
+ }
198
+
199
+ compilation.hooks.contentHash.tap(pluginName, chunk => {
200
+ const {
201
+ RawSource
202
+ } = webpack.sources;
203
+ const {
204
+ locales,
205
+ chunkFilename,
206
+ filename
207
+ } = this.options;
208
+ const fileNameTemplate = chunk.canBeInitial() ? filename : chunkFilename; // const { chunks } = compilation;
209
+
210
+ const {
211
+ localeChunkAssestMap
212
+ } = this; // function filterI18nUsedChunks(chunks) {
213
+ // return Array.from(chunks).filter(c => localeChunkAssestMap[c.id]);
214
+ // }
215
+ // for (const chunk of chunks) {
216
+
217
+ if (localeChunkAssestMap[chunk.id]) {
218
+ for (const locale of locales) {
219
+ const localObject = localeChunkAssestMap[chunk.id][locale];
220
+ const {
221
+ content
222
+ } = localObject;
223
+ const {
224
+ contentHash,
225
+ filename
226
+ } = createFilenameWithHash({
227
+ fileNameTemplate,
228
+ chunk,
229
+ locale,
230
+ content
231
+ });
232
+ localObject.contentHash = contentHash;
233
+ localObject.filename = filename;
234
+ compilation.emitAsset(filename, new RawSource(content));
235
+ }
236
+ }
237
+ });
238
+
239
+ if (!this.options.runtime) {
240
+ return;
241
+ }
242
+
243
+ this.createI18nDownloadCodeInRuntimeFile(webpack, compilation, compiler); // ## compilation.hooks.runtimeRequirementInTree
244
+ // ## .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
245
+ // ## .tap(pluginName, handler);
246
+
247
+ _htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, hookOptions => {
248
+ const {
249
+ assets
250
+ } = hookOptions;
251
+ const {
252
+ templateLabel,
253
+ filename,
254
+ publicPath = ''
255
+ } = this.options;
256
+ const dummyContent = '// dummy comment';
257
+ const initialChunks = compilation.chunks.filter(c => c.canBeInitial() && c.id !== c.runtime);
258
+ const initialI18nAssets = initialChunks.map(c => {
259
+ const data = createFilenameWithHash({
260
+ fileNameTemplate: filename,
261
+ chunk: c,
262
+ locale: templateLabel,
263
+ content: dummyContent
264
+ });
265
+ return (0, _urlConcat.urlConcat)(publicPath, data.filename);
266
+ });
267
+ const allJSAssets = [...initialI18nAssets, ...assets.js].map(url => url.replaceAll('[locale]', templateLabel).replaceAll('%5Blocale%5D', templateLabel));
268
+ console.log('HtmlWebpackPluginallJSAssets', {
269
+ assets,
270
+ filename,
271
+ allJSAssets
272
+ });
273
+ return {
274
+ assets: { ...assets,
275
+ js: allJSAssets
276
+ }
277
+ };
278
+ });
279
+ });
280
+ }
281
+
282
+ createI18nDownloadCodeInRuntimeFile(webpack, compilation, compiler) {
283
+ const {
284
+ RuntimeGlobals
285
+ } = webpack;
286
+ const {
287
+ RawSource
288
+ } = webpack.sources;
289
+ const {
290
+ chunkFilename,
291
+ locales
292
+ } = this.options;
293
+ const chunkFilenameHasContentHash = (0, _hashUtils.hasContentHash)(chunkFilename);
294
+
295
+ const getI18nChunks = mainChunk => this.filterI18nUsedChunks(mainChunk.getAllAsyncChunks());
296
+
297
+ const I18nLoadingRuntimeModule = (0, _getI18nLoadingRuntimeModule.getI18nLoadingRuntimeModule)({
298
+ getI18nChunks,
299
+ webpack
300
+ });
301
+ const enabledChunks = new WeakSet();
302
+
303
+ const chunkFilenameUrlgenerator = (i18nChunks, locale) => (0, _templateFileName.templateFileName)({
304
+ compiler,
305
+ compilation,
306
+ locale,
307
+ dynamicFilename: chunkFilename,
308
+ contentHashes: this.getContentHashes(locale),
309
+ chunks: i18nChunks
310
+ });
311
+
312
+ const prefixFunc = () => _constants.I18N_CHUNK_NAME_GENERATION_SEGMENT;
313
+
314
+ const handler = (entryRuntimeChunk, set) => {
315
+ if (enabledChunks.has(entryRuntimeChunk)) {
316
+ return;
317
+ }
318
+
319
+ enabledChunks.add(entryRuntimeChunk);
320
+ const {
321
+ chunkFilename,
322
+ // filename: initialFilename,
323
+ runtimeOptions
324
+ } = this.options;
325
+
326
+ if (typeof chunkFilename === 'string' && /\[(full)?hash(:\d+)?\]/.test(chunkFilename)) {
327
+ set.add(RuntimeGlobals.getFullHash);
328
+ }
329
+
330
+ set.add(RuntimeGlobals.publicPath);
331
+ compilation.addRuntimeModule(entryRuntimeChunk, new I18nLoadingRuntimeModule(set, {
332
+ prefixFunc: chunkFilenameHasContentHash ? prefixFunc : chunkFilenameUrlgenerator,
333
+ compiler,
334
+ runtimeOptions,
335
+ chunkFilename
336
+ }));
337
+ };
338
+
339
+ compilation.hooks.runtimeRequirementInTree.for(RuntimeGlobals.ensureChunkHandlers).tap(pluginName, handler);
340
+
341
+ if (chunkFilenameHasContentHash) {
342
+ compilation.hooks.processAssets.tap({
343
+ name: pluginName,
344
+ stage: _webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVED // additionalAssets: true
345
+
346
+ }, assets => {
347
+ // eslint-disable-next-line no-underscore-dangle
348
+ const entries = compilation._getChunkGraphEntries();
349
+
350
+ function createRuntimeFilePerLocale({
351
+ locale,
352
+ runtimeFileName,
353
+ runtimeFileSourceStr,
354
+ i18nChunks
355
+ }) {
356
+ const newRuntimeName = runtimeFileName.replaceAll('[locale]', locale);
357
+ const replaceText = chunkFilenameUrlgenerator(i18nChunks, locale);
358
+ const replacedStr = runtimeFileSourceStr.replace(_constants.I18N_CHUNK_NAME_GENERATION_SEGMENT, replaceText);
359
+ compilation.emitAsset(newRuntimeName, new RawSource(replacedStr));
360
+ }
361
+
362
+ for (const entryChunk of entries) {
363
+ const i18nChunks = getI18nChunks(entryChunk);
364
+ const runtimeFileName = entryChunk.files[0];
365
+ const runtimeFileSourceStr = assets[runtimeFileName].source();
366
+ locales.forEach(locale => createRuntimeFilePerLocale({
367
+ locale,
368
+ entryChunk,
369
+ runtimeFileName,
370
+ runtimeFileSourceStr,
371
+ i18nChunks
372
+ })); // NOTE: we don't delete, Because of HTML plugin needs to add runtime file in html
373
+ // compilation.deleteAsset(runtimeFileName);
374
+ }
375
+ });
376
+ }
377
+ } // eslint-disable-next-line class-methods-use-this
378
+
379
+
380
+ addToDefaultTypes(compiler) {
381
+ const {
382
+ splitChunks
383
+ } = compiler.options.optimization;
384
+
385
+ if (splitChunks) {
386
+ if (splitChunks.defaultSizeTypes.includes('...')) {
387
+ splitChunks.defaultSizeTypes.push(_constants.MODULE_TYPE);
388
+ }
389
+ }
390
+ }
391
+
392
+ }
393
+
394
+ I18nExtractPlugin.pluginName = pluginName;
395
+ I18nExtractPlugin.pluginSymbol = pluginSymbol; // I18nExtractPlugin.loader = require.resolve('./loader');
396
+
397
+ module.exports = I18nExtractPlugin;
398
+ /**
399
+ * TODO:
400
+ * move `localeChunkAssestMap` as separate module or file or class
401
+ */
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.optionsHandler = optionsHandler;
7
+
8
+ var _constants = require("./constants");
9
+
10
+ var _readI18nValues = require("./readI18nValues");
11
+
12
+ /* eslint-disable no-use-before-define */
13
+ function optionsHandler(options) {
14
+ const {
15
+ disableDefault,
16
+ jsResource,
17
+ propertiesFolder
18
+ } = options;
19
+ const {
20
+ jsResourceI18nKeys,
21
+ allI18nObject,
22
+ locales
23
+ } = (0, _readI18nValues.readI18nValues)({
24
+ jsResource,
25
+ propertiesFolder,
26
+ disableDefault
27
+ });
28
+ return {
29
+ filename: options.filename || _constants.DEFAULT_FILENAME,
30
+ chunkFilename: options.chunkFilename || chunkNameDecider(options.filename),
31
+ templateLabel: options.templateLabel,
32
+ publicPath: options.publicPath,
33
+ disableDefault: options.disableDefault,
34
+ i18nManifestFileName: options.i18nManifestFileName,
35
+ jsonpFunc: options.jsonpFunc,
36
+ localeVarName: options.localeVarName,
37
+ jsResource: options.jsResource,
38
+ propertiesFolder: options.propertiesFolder,
39
+ jsResourceI18nKeys,
40
+ allI18nObject,
41
+ locales,
42
+ // template: (object, locale) => `window.loadI18n(${JSON.stringify(object)}, ${JSON.stringify(locale)})`,
43
+ runtime: true,
44
+ runtimeOptions: {
45
+ insert: options.insert,
46
+ scriptType: typeof options.scriptType === 'boolean' && options.scriptType === true || typeof options.scriptType === 'undefined' ? 'text/javascript' : options.scriptType,
47
+ attributes: options.attributes
48
+ }
49
+ };
50
+ }
51
+
52
+ function chunkNameDecider(filename) {
53
+ if (typeof filename !== 'function') {
54
+ const hasName = filename.includes('[name]');
55
+ const hasId = filename.includes('[id]');
56
+ const hasChunkHash = filename.includes('[chunkhash]');
57
+ const hasContentHash = filename.includes('[contenthash]');
58
+
59
+ if (hasChunkHash || hasContentHash || hasName || hasId) {
60
+ return filename;
61
+ }
62
+
63
+ return filename.replace(/(^|\/)([^/]*(?:\?|$))/, '$1[id].$2');
64
+ }
65
+
66
+ return _constants.DEFAULT_CHUNK_FILENAME;
67
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.pathCreator = pathCreator;
7
+
8
+ var _constants = require("./constants");
9
+
10
+ function pathCreator(filenameTemplate, compilation, data) {
11
+ return compilation.getAssetPath(filenameTemplate.replace(/\[locale\]/gi, data.locale), {
12
+ hash: data.hash,
13
+ chunk: {
14
+ id: data.chunkId,
15
+ hash: data.chunkHash,
16
+ contentHash: {
17
+ [_constants.MODULE_TYPE]: data.contentHash
18
+ },
19
+ name: data.chunkName
20
+ },
21
+ contentHashType: _constants.MODULE_TYPE
22
+ });
23
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.readI18nValues = readI18nValues;
7
+
8
+ var _propertiesUtils = require("./utils/propertiesUtils");
9
+
10
+ // gethere i18n keys and values
11
+ function readI18nValues({
12
+ jsResource,
13
+ propertiesFolder,
14
+ disableDefault
15
+ }) {
16
+ const jsResourceI18nKeys = jsResource ? (0, _propertiesUtils.getPropertiesAsJSON)(jsResource) : {};
17
+ const allI18nObject = (0, _propertiesUtils.getAllI18n)({
18
+ folderPath: propertiesFolder,
19
+ disableDefault,
20
+ jsResourceI18nKeys
21
+ }); // initialize base data's and plugis
22
+
23
+ const locales = Object.keys(allI18nObject);
24
+ return {
25
+ jsResourceI18nKeys,
26
+ allI18nObject,
27
+ locales
28
+ };
29
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.templateFileName = templateFileName;
7
+
8
+ var _templateHashHelpers = require("./templateHashHelpers");
9
+
10
+ function templateFileName({
11
+ compiler,
12
+ compilation,
13
+ dynamicFilename,
14
+ locale,
15
+ chunks,
16
+ contentHashes
17
+ }) {
18
+ const {
19
+ webpack
20
+ } = compiler;
21
+ const {
22
+ Template,
23
+ RuntimeGlobals
24
+ } = webpack;
25
+ const MODULE_TYPE = 'text/mini-i18n';
26
+ const {
27
+ mapExpr,
28
+ mapExprWithLength
29
+ } = (0, _templateHashHelpers.templateHashHelpers)(chunks); // "i18n-chunk/[locale]/[name].[chunkhash].js"
30
+
31
+ const i18nURLPathTemplate = compilation.getPath(JSON.stringify(dynamicFilename).replace(/\[locale\]/gi, '"+ locale +"'), {
32
+ hash: `" + ${RuntimeGlobals.getFullHash}() + "`,
33
+ hashWithLength: length => `" + ${RuntimeGlobals.getFullHash}().slice(0, ${length}) + "`,
34
+ chunk: {
35
+ id: '" + chunkId + "',
36
+ hash: mapExpr(c => c.renderedHash),
37
+ hashWithLength: mapExprWithLength(c => c.renderedHash),
38
+ name: mapExpr(c => c.name || c.id),
39
+ contentHash: {
40
+ [MODULE_TYPE]: mapExpr(c => contentHashes[c.id])
41
+ },
42
+ contentHashWithLength: {
43
+ [MODULE_TYPE]: mapExprWithLength(c => contentHashes[c.id])
44
+ }
45
+ },
46
+ contentHashType: MODULE_TYPE
47
+ });
48
+ return Template.asString([`var locale = ${JSON.stringify(locale)};`, `${RuntimeGlobals.require}.miniI18nF = function(chunkId){return (${i18nURLPathTemplate})}`]);
49
+ }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.templateHashHelpers = templateHashHelpers;
7
+
8
+ /**
9
+ * this function will be used for chunk name, chunk hash, contentHash
10
+ * in these, sometime chunk name and chunk id same for some chunkss so below logic has little towek
11
+ * @param {Chunk} chunks
12
+ * @returns { mapExpr, mapExprWithLength }
13
+ */
14
+ function templateHashHelpers(chunks) {
15
+ /**
16
+ * @param {function(Chunk): string | number} fn function from chunk to value
17
+ * @returns {string} code with static mapping of results of fn
18
+ */
19
+ const createMap = fn => {
20
+ const obj = {};
21
+ let useId = false;
22
+ let lastKey;
23
+ let entries = 0; // eslint-disable-next-line no-restricted-syntax
24
+
25
+ for (const c of chunks) {
26
+ const value = fn(c);
27
+
28
+ if (value === c.id) {
29
+ useId = true;
30
+ } else {
31
+ obj[c.id] = value;
32
+ lastKey = c.id;
33
+ entries++;
34
+ }
35
+ }
36
+
37
+ if (entries === 0) {
38
+ return 'chunkId';
39
+ }
40
+
41
+ if (entries === 1) {
42
+ return useId ? `(chunkId === ${JSON.stringify(lastKey)} ? ${JSON.stringify(obj[lastKey])} : chunkId)` : JSON.stringify(obj[lastKey]);
43
+ }
44
+
45
+ return useId ? `(${JSON.stringify(obj)}[chunkId] || chunkId)` : `${JSON.stringify(obj)}[chunkId]`;
46
+ };
47
+ /**
48
+ * @param {function(Chunk): string | number} fn function from chunk to value
49
+ * @returns {string} code with static mapping of results of fn for including in quoted string
50
+ */
51
+
52
+
53
+ const mapExpr = fn => `" + ${createMap(fn)} + "`;
54
+ /**
55
+ * @param {function(Chunk): string | number} fn function from chunk to value
56
+ * @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length
57
+ */
58
+
59
+
60
+ const mapExprWithLength = fn => length => // console.log('called with lentch', length),
61
+ `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
62
+
63
+ return {
64
+ mapExpr,
65
+ mapExprWithLength
66
+ };
67
+ }
68
+ /**
69
+ function mapExpr(fn) {
70
+ const obj = {};
71
+ // eslint-disable-next-line no-restricted-syntax
72
+ for (const c of chunks) {
73
+ obj[c.id] = fn(c);
74
+ }
75
+ return `(${JSON.stringify(obj)})[chunkId]`;
76
+ }
77
+ */