@zohodesk/react-cli 1.1.29-exp.1 → 1.1.29-exp.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,12 +11,6 @@ var _utils = require("./utils");
11
11
 
12
12
  var _getI18nKeysFormModules = _interopRequireDefault(require("./utils/getI18nKeysFormModules"));
13
13
 
14
- var _createRegularManifest = require("./utils/createRegularManifest");
15
-
16
- var _createMetaManifest = require("./utils/createMetaManifest");
17
-
18
- var _applyMetaManifest = require("./utils/applyMetaManifest");
19
-
20
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
15
 
22
16
  /**
@@ -34,65 +28,42 @@ class I18nFilesEmitter {
34
28
  i18nManifestFileName,
35
29
  filenameTemplate,
36
30
  locales,
37
- jsonpFunc,
38
- i18nMetaManifestFileName,
39
- entryPointNames = ['main'],
40
- masterChunkFileName = 'master.i18n.js',
41
- publicPath
31
+ jsonpFunc
42
32
  }) {
43
33
  this.locales = locales;
44
34
  this.allI18nObject = allI18nObject;
45
- this.filenameTemplate = filenameTemplate;
35
+ this.filenameTemplate = filenameTemplate; // this.filenameTemplate = "i18n-chunk/[locale]/[name].js"
36
+
46
37
  this.jsonpFunc = jsonpFunc;
47
38
  this.prevHashes = {};
48
39
  this.i18nManifestFileName = i18nManifestFileName;
49
- this.i18nMetaManifestFileName = i18nMetaManifestFileName || 'metaManifest.json';
50
- this.regularManifest = {};
51
- this.detailedManifest = {};
52
- this.entryPointNames = Array.isArray(entryPointNames) ? entryPointNames : [entryPointNames];
53
- this.masterChunkFileName = masterChunkFileName;
54
- this.generatedMetaManifest = {
55
- modules: {},
56
- masterKeys: []
57
- };
58
- this.extraKeys = new Set();
59
- this.movedKeys = new Set();
60
- this.entryPointKeys = new Set();
61
- this.combinedChunks = {};
62
- this.publicPath = publicPath; // Add a map to store module ID mappings
63
-
64
- this.moduleIdMap = new Map(); // Map to track which modules belong to which chunks
65
-
66
- this.moduleToChunks = new Map(); // Store original resource paths for stable identification
67
-
68
- this.resourceToModule = new Map();
69
- console.log(`I18nFilesEmitter initialized with publicPath: "${this.publicPath}"`);
70
40
  }
71
41
 
72
42
  emitAsset(compilation, filename, source, info) {
43
+ // NOTE: info support available since webpack v4.40.0 https://webpack.js.org/api/stats/#asset-objects
73
44
  if (!compilation.emitAsset) {
74
45
  compilation.assets[filename] = source;
75
46
  } else {
76
47
  compilation.emitAsset(filename, source, info);
77
48
  }
78
- }
49
+ } // this method for create object and assign value for i18nkeys
50
+
79
51
 
80
52
  getI18nObjectByLocale(i18nKeys, locale) {
81
53
  const data = {};
82
54
  i18nKeys.forEach(key => {
83
- if (this.allI18nObject[locale] && this.allI18nObject[locale][key] !== undefined) {
84
- data[key] = this.allI18nObject[locale][key];
85
- }
55
+ data[key] = this.allI18nObject[locale][key];
86
56
  });
87
57
  return data;
88
58
  }
89
59
 
90
60
  getTemplateString(i18nKeys, locale) {
91
- const i18nObject = this.getI18nObjectByLocale(i18nKeys, locale);
92
- return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`;
61
+ let i18nObject = this.getI18nObjectByLocale(i18nKeys, locale);
62
+ return `${this.jsonpFunc}(${(0, _utils.jsonToString)(i18nObject)});`; // return `${this.jsonpFunc}(JSON.parse(${JSON.stringify(jsonToString(i18nObject))}));`;
93
63
  }
94
64
 
95
65
  renderI18nLocaleChunk(chunk, locale, i18nKeys) {
66
+ // renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation) {
96
67
  const filenameTemplate = this.filenameTemplate.replace(/\[locale\]/g, locale);
97
68
  const pathOptions = {
98
69
  chunk,
@@ -105,53 +76,6 @@ class I18nFilesEmitter {
105
76
  identifier: `${pluginName}.${chunk.id}.${locale}`,
106
77
  hash: chunk.contentHash[i18ntype(locale)]
107
78
  };
108
- } // Capture final module IDs from compilation
109
-
110
-
111
- captureModuleIds(compilation) {
112
- console.log('Capturing final module IDs from compilation...');
113
- this.moduleIdMap.clear();
114
- this.resourceToModule.clear();
115
- this.moduleToChunks.clear(); // Process all modules to build our mapping
116
-
117
- compilation.modules.forEach(module => {
118
- // Skip modules without resources
119
- if (!module.resource) return;
120
- const originalId = module.resource;
121
- const finalId = module.id; // Map resource path to final module ID
122
-
123
- this.moduleIdMap.set(originalId, finalId); // Map resource path to module object
124
-
125
- this.resourceToModule.set(originalId, module); // Build chunk membership for each module
126
-
127
- const chunkIds = Array.from(module.chunksIterable || []).map(chunk => chunk.id).filter(Boolean);
128
-
129
- if (chunkIds.length > 0) {
130
- this.moduleToChunks.set(originalId, chunkIds);
131
- }
132
- });
133
- console.log(`Captured ${this.moduleIdMap.size} module ID mappings`);
134
- } // Modified to use stable resource identifiers
135
-
136
-
137
- gatherModuleDetails(chunk, i18nKeys) {
138
- if (!i18nKeys.length) return; // Get stable identifiers for each module in the chunk
139
-
140
- const stableModuleIds = Array.from(chunk.modulesIterable).map(module => module.resource).filter(Boolean); // If no stable IDs found, fallback to chunk ID
141
-
142
- const moduleKey = stableModuleIds.length ? stableModuleIds[0] : `chunk_${chunk.id}`;
143
-
144
- if (!this.detailedManifest[moduleKey]) {
145
- this.detailedManifest[moduleKey] = {
146
- chunkId: chunk.id,
147
- chunkName: chunk.name || `chunk_${chunk.id}`,
148
- keysUsed: new Set()
149
- };
150
- }
151
-
152
- i18nKeys.forEach(key => {
153
- this.detailedManifest[moduleKey].keysUsed.add(key);
154
- });
155
79
  }
156
80
 
157
81
  emitI18nFilesForChunk(chunk, compilation) {
@@ -163,20 +87,14 @@ class I18nFilesEmitter {
163
87
  };
164
88
 
165
89
  if (!i18nKeys.length) {
90
+ // why it is not checked as 0
166
91
  return manifestForChunk;
167
92
  }
168
93
 
169
- this.gatherModuleDetails(chunk, i18nKeys);
170
- manifestForChunk.hasI18n = true; // Check if this is an entry point chunk
171
-
172
- const isEntryPoint = this.isPartOfEntryPoint(chunk, compilation); // If it's an entry point, add its keys to our tracking set
173
-
174
- if (isEntryPoint) {
175
- i18nKeys.forEach(key => this.entryPointKeys.add(key));
176
- }
94
+ manifestForChunk.hasI18n = true; // const locales = ['en_US'];
177
95
 
178
96
  this.locales.forEach(locale => {
179
- const result = this.renderI18nLocaleChunk(chunk, locale, i18nKeys);
97
+ const result = this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation);
180
98
  const {
181
99
  filenameTemplate,
182
100
  pathOptions,
@@ -192,186 +110,73 @@ class I18nFilesEmitter {
192
110
  }
193
111
 
194
112
  manifestForChunk.hasChanges = true;
195
- this.prevHashes[identifier] = hash; // Get the rendered content
196
-
197
- const renderedContent = render().source(); // Emit the asset
198
-
199
- this.emitAsset(compilation, filePath, new _webpackSources.RawSource(renderedContent), {
113
+ this.prevHashes[identifier] = hash;
114
+ this.emitAsset(compilation, filePath, render(), {
200
115
  locale,
201
116
  chunkId: chunk.id,
202
117
  chunkName: chunk.name
203
- }); // Store chunk content for later reference
204
-
205
- if (!this.combinedChunks[locale]) {
206
- this.combinedChunks[locale] = [];
207
- }
208
-
209
- this.combinedChunks[locale].push({
210
- path: filePath,
211
- content: renderedContent,
212
- data: this.getI18nObjectByLocale(i18nKeys, locale),
213
- isEntryPoint: isEntryPoint
214
- });
118
+ }); // compilation.assets[filePath] = render();
215
119
  });
216
120
  return manifestForChunk;
217
- } // Check if a chunk is part of an entry point we're interested in
218
-
219
-
220
- isPartOfEntryPoint(chunk, compilation) {
221
- let isEntryChunk = false;
222
- this.entryPointNames.forEach(entryName => {
223
- const entryPoint = compilation.entrypoints.get(entryName);
224
-
225
- if (entryPoint && entryPoint.chunks.includes(chunk)) {
226
- isEntryChunk = true;
227
- }
228
- });
229
- return isEntryChunk;
230
- } // Create meta manifest with final module IDs
231
-
232
-
233
- createMetaManifestWithFinalIds(compilation) {
234
- console.log('Creating meta manifest with final module IDs...'); // Initialize meta manifest structure
235
-
236
- const finalMetaManifest = {
237
- modules: {},
238
- masterKeys: []
239
- }; // Process each module with its final ID
240
-
241
- for (const [resourcePath, moduleData] of Object.entries(this.detailedManifest)) {
242
- // Get the final module ID if available
243
- const finalId = this.moduleIdMap.get(resourcePath) || resourcePath;
244
- const chunkName = moduleData.chunkName || `chunk_${finalId}`;
245
- const keysArray = Array.isArray(moduleData.keysUsed) ? moduleData.keysUsed : Array.from(moduleData.keysUsed); // Only add modules that have i18n keys
246
-
247
- if (keysArray.length > 0) {
248
- finalMetaManifest.modules[chunkName] = {
249
- id: moduleData.chunkId,
250
- finalId: finalId,
251
- resourcePath: resourcePath,
252
- keys: keysArray
253
- };
254
- }
255
- } // Store the generated manifest
256
-
257
-
258
- this.generatedMetaManifest = finalMetaManifest;
259
- console.log(`Created meta manifest with ${Object.keys(finalMetaManifest.modules).length} modules`);
260
- } // Compare the remote meta manifest with current build
261
-
262
-
263
- compareWithRemoteManifest(compilation) {
264
- // Use the imported applyMetaManifest function with our updated module ID maps
265
- (0, _applyMetaManifest.applyMetaManifest)(compilation, this);
266
- } // Create and emit the combined master chunk for each locale
267
-
268
-
269
- emitMasterChunks(compilation) {
270
- // Combine all the keys we need in the master chunk
271
- const combinedKeys = new Set([...this.extraKeys, ...this.movedKeys, ...(this.generatedMetaManifest.masterKeys || [])]);
272
- console.log(`Extra and moved keys to add to master chunk: ${combinedKeys.size}`);
273
- console.log(`Entry point keys: ${this.entryPointKeys.size}`); // Add entry point keys to the master keys in meta manifest
274
-
275
- if (this.generatedMetaManifest) {
276
- this.generatedMetaManifest.masterKeys = [...this.generatedMetaManifest.masterKeys, ...Array.from(this.entryPointKeys)];
277
- } // Create a master object that contains all needed keys
278
-
279
-
280
- const allMasterKeys = new Set([...combinedKeys, ...this.entryPointKeys]);
281
- console.log(`Creating master chunks with ${allMasterKeys.size} total keys`);
282
-
283
- for (const locale of this.locales) {
284
- try {
285
- // console.log(`\n========== Processing master chunk for locale: ${locale} ==========`);
286
- // Create the master i18n object with all required keys
287
- const masterI18nObject = this.getI18nObjectByLocale([...allMasterKeys], locale);
288
- console.log(`Master i18n object has ${Object.keys(masterI18nObject).length} keys`); // Create the final JSONP content
289
-
290
- const finalContent = `${this.jsonpFunc}(${(0, _utils.jsonToString)(masterI18nObject)});`;
291
- const outputPath = `i18n-chunk/${locale}/${this.masterChunkFileName}`; // Emit the combined master chunk
292
-
293
- this.emitAsset(compilation, outputPath, new _webpackSources.RawSource(finalContent), {
294
- locale,
295
- chunkName: 'master',
296
- desc: 'Combined master i18n chunk'
297
- }); // Add to manifest
298
-
299
- if (!this.regularManifest.master) {
300
- this.regularManifest.master = {};
301
- }
302
-
303
- this.regularManifest.master[locale] = outputPath; // console.log(`Emitted master chunk for locale ${locale}: ${outputPath} (${Object.keys(masterI18nObject).length} total keys)`);
304
- } catch (error) {
305
- console.error(`ERROR processing master chunk for locale ${locale}:`, error.message); // Emit a simplified version with just the master keys
306
-
307
- try {
308
- console.log(`Attempting to emit a fallback master chunk for locale ${locale}`); // Just use the moved and extra keys as fallback
309
-
310
- const fallbackI18nObject = this.getI18nObjectByLocale([...combinedKeys], locale);
311
- const fallbackContent = `${this.jsonpFunc}(${(0, _utils.jsonToString)(fallbackI18nObject)});`;
312
- const outputPath = `i18n-chunk/${locale}/${this.masterChunkFileName}`;
313
- this.emitAsset(compilation, outputPath, new _webpackSources.RawSource(fallbackContent), {
314
- locale,
315
- chunkName: 'master',
316
- desc: 'Fallback master i18n chunk (only moved/extra keys)'
317
- });
318
-
319
- if (!this.regularManifest.master) {
320
- this.regularManifest.master = {};
321
- }
322
-
323
- this.regularManifest.master[locale] = outputPath;
324
- console.log(`Emitted fallback master chunk for locale ${locale}: ${outputPath}`);
325
- } catch (fallbackError) {
326
- console.error(`Failed to emit fallback master chunk for locale ${locale}:`, fallbackError.message);
327
- }
328
- }
329
- }
330
121
  }
331
122
 
332
123
  emitI18nAssert(compilation) {
333
- console.log('Starting I18n asset emission process...'); // First, capture all final module IDs
334
-
335
- this.captureModuleIds(compilation); // Reset entry point keys for this build
336
-
337
- this.entryPointKeys = new Set(); // 1. Process chunks and collect keys
338
-
124
+ let manifest = {};
125
+ let needEmitManifest = false;
339
126
  compilation.chunks.forEach(chunk => {
340
127
  const manifestForChunk = this.emitI18nFilesForChunk(chunk, compilation);
341
128
 
342
129
  if (manifestForChunk.hasI18n) {
343
- this.regularManifest[chunk.id] = manifestForChunk.assets;
130
+ manifest[chunk.id] = manifestForChunk.assets;
131
+ needEmitManifest = needEmitManifest || manifestForChunk.hasChanges;
344
132
  }
345
- }); // 2. Create our meta manifest with final module IDs
346
-
347
- this.createMetaManifestWithFinalIds(compilation); // 3. Compare with remote manifest to find extra/moved keys
348
-
349
- this.compareWithRemoteManifest(compilation); // 4. Create and emit combined master chunks
350
-
351
- this.emitMasterChunks(compilation); // 5. Create the regular manifest
352
-
353
- (0, _createRegularManifest.createRegularManifest)(compilation, this); // 6. Emit the final meta manifest with updated master keys
354
-
355
- const metaManifestSource = new _webpackSources.RawSource(JSON.stringify(this.generatedMetaManifest, null, 2));
356
- this.emitAsset(compilation, this.i18nMetaManifestFileName, metaManifestSource, {
357
- desc: 'Updated meta manifest with master keys'
358
133
  });
359
- console.log('Completed I18n asset emission process');
134
+
135
+ if (needEmitManifest) {
136
+ const manifestSource = new _webpackSources.RawSource(JSON.stringify(manifest));
137
+ this.emitAsset(compilation, this.i18nManifestFileName, manifestSource, {
138
+ desc: 'this file is has chunks-locales-assets mapping'
139
+ });
140
+ }
360
141
  }
361
142
 
362
143
  apply(compiler) {
363
- // Use the afterCompile hook to capture module info after compilation
364
- compiler.hooks.afterCompile.tap(pluginName, compilation => {
365
- // console.log(`${pluginName}: Capturing compilation information after compile phase`);
366
- this.compilation = compilation;
367
- }); // Use the emit hook to generate the I18n assets with final module IDs
368
-
369
- compiler.hooks.emit.tapAsync(pluginName, (compilation, callback) => {
370
- // console.log(`${pluginName}: Emitting I18n assets with final module IDs`);
144
+ /*
145
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
146
+ compilation.mainTemplate.hooks.renderManifest.tap(
147
+ pluginName,
148
+ (result, { chunk }) => {
149
+ this.renderChunk(result, compilation, chunk);
150
+ }
151
+ );
152
+ compilation.chunkTemplate.hooks.renderManifest.tap(
153
+ pluginName,
154
+ (result, { chunk }) => {
155
+ this.renderChunk(result, compilation, chunk);
156
+ }
157
+ );
158
+ });
159
+ */
160
+ // this below hook was tapped for create asssets(file) for chunk specific i18nChunk Files
161
+ compiler.hooks.emit.tap(pluginName, compilation => {
371
162
  this.emitI18nAssert(compilation);
372
- callback();
373
163
  });
374
164
  }
165
+ /*
166
+ renderChunk(result, compilation, chunk) {
167
+ const i18nKeys = getI18nKeysFormModules(chunk.modulesIterable);
168
+ // TODO: need to discuss with vimal ji can we chose this place for add i18n locale files ????
169
+ // IDEA: we chose this place for add i18n locale files ????
170
+ if (i18nKeys.length > 0) {
171
+ Object.keys(this.allI18nObject).forEach(locale => {
172
+ result.push(
173
+ this.renderI18nLocaleChunk(chunk, locale, i18nKeys, compilation)
174
+ );
175
+ });
176
+ }
177
+ }
178
+ */
179
+
375
180
 
376
181
  }
377
182
 
@@ -232,6 +232,7 @@ var _default = {
232
232
  none: '(hover: none)'
233
233
  },
234
234
  disableES5Transpile: false,
235
+ disableES5Import: false,
235
236
  isReactMig: false,
236
237
  hasWidget: false,
237
238
  hasEFC: {