@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.
- package/README.md +18 -0
- package/lib/babel/cmjs-plugins-presets.js +5 -1
- package/lib/babel/es-plugins-presets.js +6 -2
- package/lib/configs/jest.config.js +1 -1
- package/lib/configs/libAlias.js +2 -2
- package/lib/configs/resolvers.js +2 -2
- package/lib/jest/preProcessors/jsPreprocessor.js +5 -1
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +3 -6
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +141 -77
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +60 -255
- package/lib/schemas/index.js +1 -0
- package/npm-shrinkwrap.json +355 -24
- package/package.json +3 -2
- package/lib/plugins/I18nSplitPlugin/utils/applyMetaManifest.js +0 -273
- package/lib/plugins/I18nSplitPlugin/utils/createMetaManifest.js +0 -70
- package/lib/plugins/I18nSplitPlugin/utils/createRegularManifest.js +0 -59
@@ -1,273 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.applyMetaManifest = applyMetaManifest;
|
7
|
-
|
8
|
-
var _fs = _interopRequireDefault(require("fs"));
|
9
|
-
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
-
|
12
|
-
function applyMetaManifest(compilation, plugin) {
|
13
|
-
const {
|
14
|
-
moduleIdMap
|
15
|
-
} = plugin;
|
16
|
-
const manifestPath = './metaManifest.json';
|
17
|
-
|
18
|
-
if (!plugin.detailedManifest || Object.keys(plugin.detailedManifest).length === 0) {
|
19
|
-
console.warn('No detailedManifest available, skipping manifest comparison');
|
20
|
-
return {
|
21
|
-
extraKeys: new Set(),
|
22
|
-
movedKeys: new Set(),
|
23
|
-
error: 'No detailedManifest available'
|
24
|
-
};
|
25
|
-
} // Track keys in current build
|
26
|
-
|
27
|
-
|
28
|
-
const currentBuildKeys = new Set();
|
29
|
-
const currentKeyToModule = new Map();
|
30
|
-
const currentModules = new Map();
|
31
|
-
const currentKeySets = new Map();
|
32
|
-
const moduleIdToName = new Map(); // Process current build modules with final IDs
|
33
|
-
|
34
|
-
for (const [resourcePath, chunkData] of Object.entries(plugin.detailedManifest)) {
|
35
|
-
// Get the final module ID if it exists in our mapping
|
36
|
-
const finalModuleId = moduleIdMap.get(resourcePath) || resourcePath;
|
37
|
-
const chunkName = chunkData.chunkName || `chunk_${chunkData.chunkId || "unknown"}`; // Store module name mapping for better logging
|
38
|
-
|
39
|
-
moduleIdToName.set(finalModuleId, chunkName);
|
40
|
-
const keys = Array.isArray(chunkData.keysUsed) ? chunkData.keysUsed : Array.from(chunkData.keysUsed); // Skip empty modules
|
41
|
-
|
42
|
-
if (keys.length === 0) continue; // Sort keys for consistent comparison
|
43
|
-
|
44
|
-
const sortedKeys = [...keys].sort();
|
45
|
-
const keySetString = sortedKeys.join(','); // Store module data using final IDs
|
46
|
-
|
47
|
-
currentModules.set(finalModuleId, {
|
48
|
-
id: finalModuleId,
|
49
|
-
resourcePath: resourcePath,
|
50
|
-
chunkId: chunkData.chunkId,
|
51
|
-
name: chunkName,
|
52
|
-
keys: sortedKeys
|
53
|
-
}); // Store key set for module fingerprinting
|
54
|
-
|
55
|
-
currentKeySets.set(keySetString, finalModuleId); // Store individual key mappings
|
56
|
-
|
57
|
-
keys.forEach(key => {
|
58
|
-
currentBuildKeys.add(key);
|
59
|
-
currentKeyToModule.set(key, finalModuleId);
|
60
|
-
});
|
61
|
-
}
|
62
|
-
|
63
|
-
const currentKeyCount = currentBuildKeys.size;
|
64
|
-
const currentModuleCount = currentModules.size;
|
65
|
-
console.log(`Current build: ${currentKeyCount} keys in ${currentModuleCount} modules`);
|
66
|
-
|
67
|
-
try {
|
68
|
-
// Read from specified manifest path
|
69
|
-
if (!_fs.default.existsSync(manifestPath)) {
|
70
|
-
console.warn(`Meta manifest not found at ${manifestPath}`);
|
71
|
-
return {
|
72
|
-
extraKeys: new Set(),
|
73
|
-
movedKeys: new Set(),
|
74
|
-
error: `Meta manifest not found at ${manifestPath}`
|
75
|
-
};
|
76
|
-
}
|
77
|
-
|
78
|
-
const fileContent = _fs.default.readFileSync(manifestPath, 'utf8');
|
79
|
-
|
80
|
-
const remoteMetaManifest = JSON.parse(fileContent); // Handle non-existent or invalid modules
|
81
|
-
|
82
|
-
if (!remoteMetaManifest.modules) {
|
83
|
-
console.warn('Meta manifest does not contain modules section');
|
84
|
-
return {
|
85
|
-
extraKeys: new Set(),
|
86
|
-
movedKeys: new Set(),
|
87
|
-
error: 'Meta manifest does not contain modules section'
|
88
|
-
};
|
89
|
-
} // Track all keys in remote manifest modules
|
90
|
-
|
91
|
-
|
92
|
-
const remoteModuleKeys = new Set();
|
93
|
-
const remoteKeyToModule = new Map();
|
94
|
-
const remoteModules = new Map();
|
95
|
-
const remoteKeySets = new Map();
|
96
|
-
const remoteModuleIdToName = new Map();
|
97
|
-
const moduleEquivalenceMap = new Map(); // Process remote manifest modules
|
98
|
-
|
99
|
-
for (const [moduleId, moduleData] of Object.entries(remoteMetaManifest.modules)) {
|
100
|
-
if (moduleData.keys && Array.isArray(moduleData.keys)) {
|
101
|
-
// Store module name for better logging
|
102
|
-
const moduleName = moduleId;
|
103
|
-
remoteModuleIdToName.set(moduleId, moduleName); // Skip empty modules
|
104
|
-
|
105
|
-
if (moduleData.keys.length === 0) continue; // Sort keys for consistent comparison
|
106
|
-
|
107
|
-
const sortedKeys = [...moduleData.keys].sort();
|
108
|
-
const keySetString = sortedKeys.join(','); // Store module data
|
109
|
-
|
110
|
-
remoteModules.set(moduleId, {
|
111
|
-
id: moduleData.id || moduleId,
|
112
|
-
name: moduleName,
|
113
|
-
keys: sortedKeys,
|
114
|
-
keyCount: moduleData.keys.length
|
115
|
-
}); // Store key set
|
116
|
-
|
117
|
-
remoteKeySets.set(keySetString, moduleId); // Store individual key mappings
|
118
|
-
|
119
|
-
moduleData.keys.forEach(key => {
|
120
|
-
remoteModuleKeys.add(key);
|
121
|
-
remoteKeyToModule.set(key, moduleId);
|
122
|
-
});
|
123
|
-
}
|
124
|
-
} // Get keys from the master chunk in the remote manifest (if it exists)
|
125
|
-
|
126
|
-
|
127
|
-
const remoteMasterKeys = new Set();
|
128
|
-
|
129
|
-
if (remoteMetaManifest.masterKeys && Array.isArray(remoteMetaManifest.masterKeys)) {
|
130
|
-
remoteMetaManifest.masterKeys.forEach(key => {
|
131
|
-
remoteMasterKeys.add(key);
|
132
|
-
});
|
133
|
-
} // Get all unique keys from the remote manifest (modules + master)
|
134
|
-
|
135
|
-
|
136
|
-
const remoteAllKeys = new Set([...remoteModuleKeys, ...remoteMasterKeys]);
|
137
|
-
const remoteKeyCount = remoteAllKeys.size;
|
138
|
-
const remoteModuleCount = remoteModules.size;
|
139
|
-
const remoteMasterKeyCount = remoteMasterKeys.size;
|
140
|
-
console.log(`Remote manifest: ${remoteKeyCount} keys in ${remoteModuleCount} modules, ${remoteMasterKeyCount} master keys`); // Find intersection and differences for keys
|
141
|
-
|
142
|
-
const inBothSets = new Set([...currentBuildKeys].filter(key => remoteAllKeys.has(key)));
|
143
|
-
const missingKeys = new Set([...remoteAllKeys].filter(key => !currentBuildKeys.has(key)));
|
144
|
-
const extraKeys = new Set([...currentBuildKeys].filter(key => !remoteAllKeys.has(key)));
|
145
|
-
console.log(`Key comparison: ${inBothSets.size} shared keys, ${missingKeys.size} missing, ${extraKeys.size} new`); // Enhanced multi-level module equivalence mapping
|
146
|
-
// 1. First pass: Match by module name
|
147
|
-
|
148
|
-
for (const [remoteId, remoteModule] of remoteModules.entries()) {
|
149
|
-
if (remoteModule.name) {
|
150
|
-
// Find a current module with matching name
|
151
|
-
for (const [currentId, currentModule] of currentModules.entries()) {
|
152
|
-
if (currentModule.name && currentModule.name === remoteModule.name) {
|
153
|
-
moduleEquivalenceMap.set(remoteId, currentId);
|
154
|
-
break;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
}
|
158
|
-
} // 2. Second pass: Match by resource path
|
159
|
-
|
160
|
-
|
161
|
-
const unmatchedRemote = [...remoteModules.keys()].filter(id => !moduleEquivalenceMap.has(id));
|
162
|
-
|
163
|
-
for (const remoteId of unmatchedRemote) {
|
164
|
-
for (const [resourcePath, currentModuleId] of moduleIdMap.entries()) {
|
165
|
-
if (resourcePath.includes(remoteId)) {
|
166
|
-
moduleEquivalenceMap.set(remoteId, currentModuleId);
|
167
|
-
break;
|
168
|
-
}
|
169
|
-
}
|
170
|
-
} // 3. Third pass: Match by key set fingerprint
|
171
|
-
|
172
|
-
|
173
|
-
const stillUnmatchedRemote = [...remoteModules.keys()].filter(id => !moduleEquivalenceMap.has(id));
|
174
|
-
|
175
|
-
for (const remoteId of stillUnmatchedRemote) {
|
176
|
-
const remoteModule = remoteModules.get(remoteId);
|
177
|
-
const keySetString = remoteModule.keys.join(',');
|
178
|
-
|
179
|
-
if (currentKeySets.has(keySetString)) {
|
180
|
-
moduleEquivalenceMap.set(remoteId, currentKeySets.get(keySetString));
|
181
|
-
}
|
182
|
-
} // Find moved keys based on enhanced module equivalence map
|
183
|
-
|
184
|
-
|
185
|
-
const trulyMovedKeys = new Set();
|
186
|
-
const keyMovementDetails = new Map();
|
187
|
-
|
188
|
-
for (const key of inBothSets) {
|
189
|
-
// Skip keys that are in the master chunk
|
190
|
-
if (remoteMasterKeys.has(key)) {
|
191
|
-
continue;
|
192
|
-
}
|
193
|
-
|
194
|
-
const remoteModuleId = remoteKeyToModule.get(key);
|
195
|
-
const currentModuleId = currentKeyToModule.get(key); // Normalize module names for comparison
|
196
|
-
|
197
|
-
const remoteModuleName = remoteModuleIdToName.get(remoteModuleId) || remoteModuleId;
|
198
|
-
const currentModuleName = moduleIdToName.get(currentModuleId) || currentModuleId; // Only consider a key moved if it's actually in a different module
|
199
|
-
|
200
|
-
const moduleNameComparison = remoteModuleName !== currentModuleName;
|
201
|
-
|
202
|
-
if (moduleNameComparison) {
|
203
|
-
trulyMovedKeys.add(key);
|
204
|
-
keyMovementDetails.set(key, {
|
205
|
-
from: remoteModuleId,
|
206
|
-
fromName: remoteModuleName,
|
207
|
-
to: currentModuleId,
|
208
|
-
toName: currentModuleName,
|
209
|
-
type: 'module_change'
|
210
|
-
});
|
211
|
-
}
|
212
|
-
} // Get keys from unmatched modules that exist in the current build
|
213
|
-
|
214
|
-
|
215
|
-
const unmatchedRemoteModules = [...remoteModules.keys()].filter(id => !moduleEquivalenceMap.has(id));
|
216
|
-
unmatchedRemoteModules.forEach(moduleId => {
|
217
|
-
const module = remoteModules.get(moduleId);
|
218
|
-
const moduleName = remoteModuleIdToName.get(moduleId) || moduleId;
|
219
|
-
module.keys.forEach(key => {
|
220
|
-
// Only add the key if it exists in the current build
|
221
|
-
if (currentBuildKeys.has(key)) {
|
222
|
-
const currentModuleId = currentKeyToModule.get(key);
|
223
|
-
const currentModuleName = moduleIdToName.get(currentModuleId) || currentModuleId; // Only add if actually in a different module
|
224
|
-
|
225
|
-
if (moduleName !== currentModuleName) {
|
226
|
-
trulyMovedKeys.add(key);
|
227
|
-
keyMovementDetails.set(key, {
|
228
|
-
from: moduleId,
|
229
|
-
fromName: moduleName,
|
230
|
-
to: currentModuleId,
|
231
|
-
toName: currentModuleName,
|
232
|
-
type: 'unmatched_module'
|
233
|
-
});
|
234
|
-
}
|
235
|
-
}
|
236
|
-
});
|
237
|
-
});
|
238
|
-
const movedKeyCount = trulyMovedKeys.size;
|
239
|
-
console.log(`Found ${extraKeys.size} new keys and ${movedKeyCount} moved keys`); // Add extra and moved keys to the plugin's tracking for master chunk inclusion
|
240
|
-
|
241
|
-
plugin.extraKeys = extraKeys;
|
242
|
-
plugin.movedKeys = trulyMovedKeys; // Store key counts for reference
|
243
|
-
|
244
|
-
plugin.keyStats = {
|
245
|
-
current: currentKeyCount,
|
246
|
-
remote: remoteKeyCount,
|
247
|
-
extra: extraKeys.size,
|
248
|
-
moved: movedKeyCount
|
249
|
-
}; // Update master keys in the generated meta manifest
|
250
|
-
|
251
|
-
if (plugin.generatedMetaManifest) {
|
252
|
-
// Only include extra (new) and moved keys in the master keys
|
253
|
-
const masterKeys = [...Array.from(extraKeys), ...Array.from(trulyMovedKeys)];
|
254
|
-
plugin.generatedMetaManifest.masterKeys = masterKeys;
|
255
|
-
}
|
256
|
-
|
257
|
-
return {
|
258
|
-
extraKeys,
|
259
|
-
movedKeys: trulyMovedKeys,
|
260
|
-
keyStats: plugin.keyStats
|
261
|
-
};
|
262
|
-
} catch (error) {
|
263
|
-
console.error(`Error during manifest comparison: ${error.message}`); // Return empty sets for keys if there was an error
|
264
|
-
|
265
|
-
plugin.extraKeys = new Set();
|
266
|
-
plugin.movedKeys = new Set();
|
267
|
-
return {
|
268
|
-
extraKeys: new Set(),
|
269
|
-
movedKeys: new Set(),
|
270
|
-
error: error.message
|
271
|
-
};
|
272
|
-
}
|
273
|
-
}
|
@@ -1,70 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createMetaManifest = createMetaManifest;
|
7
|
-
|
8
|
-
var _webpackSources = require("webpack-sources");
|
9
|
-
|
10
|
-
function createMetaManifest(compilation, plugin, skipEmit = false) {
|
11
|
-
const {
|
12
|
-
detailedManifest
|
13
|
-
} = plugin; // Use the plugin's filename property
|
14
|
-
|
15
|
-
const i18nMetaManifestFileName = plugin.i18nMetaManifestFileName;
|
16
|
-
|
17
|
-
if (!skipEmit) {
|
18
|
-
console.log('Generating meta manifest:', i18nMetaManifestFileName);
|
19
|
-
} // Initialize a streamlined meta manifest structure
|
20
|
-
|
21
|
-
|
22
|
-
const finalMetaManifest = {
|
23
|
-
modules: {}
|
24
|
-
}; // Process each chunk's keys into the modules section
|
25
|
-
|
26
|
-
for (const [chunkId, chunkData] of Object.entries(detailedManifest)) {
|
27
|
-
const chunkName = chunkData.chunkName || `chunk_${chunkId}`;
|
28
|
-
const keysArray = Array.isArray(chunkData.keysUsed) ? chunkData.keysUsed : Array.from(chunkData.keysUsed); // Only add modules that have i18n keys
|
29
|
-
|
30
|
-
if (keysArray.length > 0) {
|
31
|
-
finalMetaManifest.modules[chunkName] = {
|
32
|
-
id: chunkId,
|
33
|
-
keys: keysArray
|
34
|
-
};
|
35
|
-
}
|
36
|
-
} // Only include new or moved keys in the masterKeys section
|
37
|
-
|
38
|
-
|
39
|
-
if (plugin.extraKeys && plugin.movedKeys) {
|
40
|
-
// Combine extra (new) and moved keys
|
41
|
-
const masterKeysSet = new Set([...(Array.from(plugin.extraKeys) || []), ...(Array.from(plugin.movedKeys) || [])]); // Convert back to array for the manifest
|
42
|
-
|
43
|
-
finalMetaManifest.masterKeys = Array.from(masterKeysSet); // Log the keys being added to master chunk
|
44
|
-
|
45
|
-
if (finalMetaManifest.masterKeys.length > 0) {
|
46
|
-
console.log(`Extra and moved keys to add to master chunk: ${finalMetaManifest.masterKeys.length}`); // Print each key for clarity
|
47
|
-
|
48
|
-
finalMetaManifest.masterKeys.forEach(key => {
|
49
|
-
console.log(` - ${key}`);
|
50
|
-
});
|
51
|
-
}
|
52
|
-
} // Store the generated manifest for potential further use
|
53
|
-
|
54
|
-
|
55
|
-
plugin.generatedMetaManifest = finalMetaManifest; // Only emit if not skipped
|
56
|
-
|
57
|
-
if (!skipEmit) {
|
58
|
-
const metaManifestSource = new _webpackSources.RawSource(JSON.stringify(finalMetaManifest, null, 2));
|
59
|
-
|
60
|
-
if (!compilation.emitAsset) {
|
61
|
-
compilation.assets[i18nMetaManifestFileName] = metaManifestSource;
|
62
|
-
} else {
|
63
|
-
compilation.emitAsset(i18nMetaManifestFileName, metaManifestSource, {
|
64
|
-
desc: 'Streamlined chunk-module-i18nKeys mapping with optimized master keys'
|
65
|
-
});
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
return finalMetaManifest;
|
70
|
-
}
|
@@ -1,59 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createRegularManifest = createRegularManifest;
|
7
|
-
|
8
|
-
var _webpackSources = require("webpack-sources");
|
9
|
-
|
10
|
-
function createRegularManifest(compilation, plugin) {
|
11
|
-
const {
|
12
|
-
regularManifest,
|
13
|
-
// e.g., { chunkId: { localeA: pathA, localeB: pathB, ... }, ... }
|
14
|
-
locales,
|
15
|
-
// e.g., ['en_US', 'fr_FR', ...]
|
16
|
-
i18nManifestFileName,
|
17
|
-
// e.g., 'i18n-manifest.json'
|
18
|
-
deskI18nManifestFileName = 'desk-i18n-manifest.js'
|
19
|
-
} = plugin; // 1. Create the final manifest structure.
|
20
|
-
|
21
|
-
const finalManifest = {
|
22
|
-
locales: [...locales],
|
23
|
-
chunks: {},
|
24
|
-
basePath: 'i18n-chunk/[locale]/'
|
25
|
-
};
|
26
|
-
|
27
|
-
for (const chunkId of Object.keys(regularManifest)) {
|
28
|
-
const localePaths = regularManifest[chunkId];
|
29
|
-
if (!localePaths) continue;
|
30
|
-
const entries = Object.entries(localePaths);
|
31
|
-
if (!entries.length) continue;
|
32
|
-
const [someLocale, fullPath] = entries[0];
|
33
|
-
if (!fullPath) continue; // Remove the first two segments from the full path to get the basename.
|
34
|
-
|
35
|
-
const pathSegments = fullPath.split('/');
|
36
|
-
const basename = pathSegments.slice(2).join('/');
|
37
|
-
finalManifest.chunks[chunkId] = basename;
|
38
|
-
} // Convert the manifest object to a prettified JSON string.
|
39
|
-
|
40
|
-
|
41
|
-
const manifestStr = JSON.stringify(finalManifest, null, 2); // 2. Create the JSON asset (plain JSON, without any wrapping).
|
42
|
-
|
43
|
-
const jsonManifestSource = new _webpackSources.RawSource(manifestStr); // 3. Create the manifest code for window.desk_i18n_manifest.
|
44
|
-
|
45
|
-
const deskI18nManifestCode = `
|
46
|
-
(function() {
|
47
|
-
window.desk_i18n_manifest = ${manifestStr};
|
48
|
-
})();
|
49
|
-
`;
|
50
|
-
const deskI18nManifestSource = new _webpackSources.RawSource(deskI18nManifestCode); // 4. Emit the plain JSON manifest asset.
|
51
|
-
|
52
|
-
compilation.emitAsset(i18nManifestFileName, jsonManifestSource, {
|
53
|
-
desc: 'Emitted plain JSON i18n manifest'
|
54
|
-
}); // 5. Emit the desk i18n manifest asset.
|
55
|
-
|
56
|
-
compilation.emitAsset(deskI18nManifestFileName, deskI18nManifestSource, {
|
57
|
-
desc: 'Emitted manifest attached to window.desk_i18n_manifest'
|
58
|
-
});
|
59
|
-
}
|