mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
dbeaver/pro#5599 refactor: simplify manualChunks function by removing async and circular dependency check
This commit is contained in:
@@ -20,65 +20,7 @@ export const manualChunks = (): PluginOption => [
|
||||
...config.build?.rollupOptions,
|
||||
output: {
|
||||
...config.build?.rollupOptions?.output,
|
||||
manualChunks(id, { getModuleInfo }) {
|
||||
function isModuleSync(moduleId: string) {
|
||||
// Use a non-recursive approach to detect circular dependencies
|
||||
const visited = new Set<string>();
|
||||
const queue = [moduleId];
|
||||
|
||||
// Track which modules we've already determined to be sync
|
||||
const syncModules = new Set<string>();
|
||||
|
||||
while (queue.length > 0) {
|
||||
const currentId = queue.shift()!;
|
||||
|
||||
// Skip if we've already processed this module in this traversal
|
||||
if (visited.has(currentId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
visited.add(currentId);
|
||||
|
||||
const info = getModuleInfo(currentId);
|
||||
|
||||
// No module info available, assume it's sync as a fallback
|
||||
if (!info) {
|
||||
syncModules.add(currentId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Entry modules are always sync
|
||||
if (info.isEntry) {
|
||||
syncModules.add(currentId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If there are no importers at all, it might be dynamically imported somewhere
|
||||
if (!info.importers || info.importers.length === 0) {
|
||||
// Not marking as sync
|
||||
continue;
|
||||
}
|
||||
|
||||
// If dynamicImporters is undefined or not an array, handle safely
|
||||
const dynamicImports = Array.isArray(info.dynamicImporters) ? info.dynamicImporters : [];
|
||||
|
||||
// Check if any importer imports this module statically
|
||||
let hasStaticImporter = false;
|
||||
for (const importer of info.importers) {
|
||||
if (!dynamicImports.includes(importer)) {
|
||||
hasStaticImporter = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasStaticImporter) {
|
||||
syncModules.add(currentId);
|
||||
}
|
||||
}
|
||||
|
||||
return syncModules.has(moduleId);
|
||||
}
|
||||
|
||||
manualChunks(id) {
|
||||
const langMatch = /[\\/]locales[\\/](\w+)\.js/.exec(id);
|
||||
if (langMatch) {
|
||||
const language = langMatch[1]; // e.g. "en"
|
||||
@@ -86,37 +28,22 @@ export const manualChunks = (): PluginOption => [
|
||||
}
|
||||
|
||||
if (id.includes('packages/core-')) {
|
||||
if (!isModuleSync(id)) {
|
||||
return 'core-async';
|
||||
}
|
||||
return 'core';
|
||||
}
|
||||
|
||||
if (id.includes('packages/plugin-')) {
|
||||
if (!isModuleSync(id)) {
|
||||
return 'plugins-async';
|
||||
}
|
||||
return 'plugins';
|
||||
}
|
||||
|
||||
if (id.includes('packages/product-')) {
|
||||
if (!isModuleSync(id)) {
|
||||
return 'products-async';
|
||||
}
|
||||
return 'products';
|
||||
}
|
||||
|
||||
if (id.includes('@dbeaver/')) {
|
||||
if (!isModuleSync(id)) {
|
||||
return 'dbeaver-async';
|
||||
}
|
||||
return 'dbeaver';
|
||||
}
|
||||
|
||||
if (id.includes('node_modules')) {
|
||||
if (!isModuleSync(id)) {
|
||||
return 'vendor-async';
|
||||
}
|
||||
return 'vendor';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user