Skip to content

Commit d82dc09

Browse files
committed
fix bundle error
1 parent 593c1e1 commit d82dc09

5 files changed

Lines changed: 183 additions & 13 deletions

File tree

webapp/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,5 @@
5454
"typescript-plugin-css-modules": "^5",
5555
"vitest": "^3"
5656
},
57-
"packageManager": "yarn@4.9.2",
58-
"dependencies": {
59-
"lz-string": "1.5.0"
60-
}
61-
}
57+
"packageManager": "yarn@4.9.2"
58+
}

webapp/packages/plugin-session-expiration/src/SessionExpireDialog/SessionExpiredDialogBootstrap.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ import { Bootstrap, injectable } from '@cloudbeaver/core-di';
1010
import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dialogs';
1111
import { ENotificationType, NotificationService } from '@cloudbeaver/core-events';
1212
import { SessionExpireService } from '@cloudbeaver/core-root';
13-
import { RouterService } from '@cloudbeaver/core-routing';
1413

1514
import { SessionExpiredDialog } from './SessionExpiredDialog.js';
1615

17-
@injectable(() => [RouterService, NotificationService, CommonDialogService, SessionExpireService])
16+
@injectable(() => [NotificationService, CommonDialogService, SessionExpireService])
1817
export class SessionExpiredDialogBootstrap extends Bootstrap {
1918
constructor(
20-
private readonly routerService: RouterService,
2119
private readonly notificationService: NotificationService,
2220
private readonly commonDialogService: CommonDialogService,
2321
private readonly sessionExpireService: SessionExpireService,
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/env node
2+
3+
import fs from 'fs';
4+
import path from 'path';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
// 需要临时修改的 tsconfig.json 文件路径(相对于 webapp 根目录)
11+
const WEBAPP_ROOT = path.resolve(__dirname, '../..');
12+
const TSCONFIG_PATHS = ['packages/plugin-data-viewer/tsconfig.json'];
13+
14+
// 需要临时移除的循环引用路径
15+
const CIRCULAR_REFERENCES = ['../plugin-sql-editor', '../plugin-sql-editor-navigation-tab'];
16+
17+
// 备份文件后缀
18+
const BACKUP_SUFFIX = '.backup-before-build';
19+
20+
/**
21+
* 备份并修改 tsconfig.json 文件,移除循环引用
22+
*/
23+
function removeCircularReferences() {
24+
console.log('🔧 正在移除循环引用...');
25+
26+
TSCONFIG_PATHS.forEach(tsconfigPath => {
27+
const fullPath = path.join(WEBAPP_ROOT, tsconfigPath);
28+
const backupPath = fullPath + BACKUP_SUFFIX;
29+
30+
try {
31+
// 检查是否已存在备份文件
32+
if (fs.existsSync(backupPath)) {
33+
console.log(`⚠️ 备份文件已存在: ${tsconfigPath}${BACKUP_SUFFIX}`);
34+
return;
35+
}
36+
37+
// 读取原始文件
38+
const originalContent = fs.readFileSync(fullPath, 'utf8');
39+
40+
// 创建备份
41+
fs.writeFileSync(backupPath, originalContent);
42+
console.log(`📝 已备份: ${tsconfigPath}`);
43+
44+
// 解析 JSON
45+
const tsconfig = JSON.parse(originalContent);
46+
47+
// 移除循环引用
48+
if (tsconfig.references) {
49+
const originalCount = tsconfig.references.length;
50+
tsconfig.references = tsconfig.references.filter(ref => !CIRCULAR_REFERENCES.includes(ref.path));
51+
const removedCount = originalCount - tsconfig.references.length;
52+
53+
if (removedCount > 0) {
54+
console.log(`🗑️ 已从 ${tsconfigPath} 移除 ${removedCount} 个循环引用`);
55+
56+
// 写入修改后的内容
57+
fs.writeFileSync(fullPath, JSON.stringify(tsconfig, null, 2) + '\n');
58+
} else {
59+
console.log(`ℹ️ ${tsconfigPath} 中未找到需要移除的循环引用`);
60+
}
61+
}
62+
} catch (error) {
63+
console.error(`❌ 处理 ${tsconfigPath} 时出错:`, error.message);
64+
throw error;
65+
}
66+
});
67+
}
68+
69+
/**
70+
* 恢复备份的 tsconfig.json 文件
71+
*/
72+
function restoreBackups() {
73+
console.log('🔄 正在恢复备份文件...');
74+
75+
TSCONFIG_PATHS.forEach(tsconfigPath => {
76+
const fullPath = path.join(WEBAPP_ROOT, tsconfigPath);
77+
const backupPath = fullPath + BACKUP_SUFFIX;
78+
79+
try {
80+
if (fs.existsSync(backupPath)) {
81+
// 恢复备份
82+
fs.copyFileSync(backupPath, fullPath);
83+
84+
// 删除备份文件
85+
fs.unlinkSync(backupPath);
86+
87+
console.log(`✅ 已恢复: ${tsconfigPath}`);
88+
} else {
89+
console.log(`ℹ️ 未找到备份文件: ${tsconfigPath}${BACKUP_SUFFIX}`);
90+
}
91+
} catch (error) {
92+
console.error(`❌ 恢复 ${tsconfigPath} 时出错:`, error.message);
93+
}
94+
});
95+
}
96+
97+
/**
98+
* 清理备份文件(用于异常情况)
99+
*/
100+
function cleanupBackups() {
101+
console.log('🧹 清理备份文件...');
102+
103+
TSCONFIG_PATHS.forEach(tsconfigPath => {
104+
const fullPath = path.join(WEBAPP_ROOT, tsconfigPath);
105+
const backupPath = fullPath + BACKUP_SUFFIX;
106+
107+
if (fs.existsSync(backupPath)) {
108+
fs.unlinkSync(backupPath);
109+
console.log(`🧹 已清理备份文件: ${tsconfigPath}${BACKUP_SUFFIX}`);
110+
}
111+
});
112+
}
113+
114+
// 处理进程中断信号
115+
process.on('SIGINT', () => {
116+
console.log('\n\n⚠️ 收到中断信号,正在清理...');
117+
restoreBackups();
118+
process.exit(0);
119+
});
120+
121+
process.on('SIGTERM', () => {
122+
console.log('\n\n⚠️ 收到终止信号,正在清理...');
123+
restoreBackups();
124+
process.exit(0);
125+
});
126+
127+
// 命令行参数处理
128+
const command = process.argv[2];
129+
130+
switch (command) {
131+
case 'remove':
132+
console.log('🚀 开始移除循环引用...\n');
133+
try {
134+
removeCircularReferences();
135+
console.log('\n✅ 循环引用移除完成!');
136+
} catch (error) {
137+
console.error('\n❌ 移除循环引用失败:', error.message);
138+
process.exit(1);
139+
}
140+
break;
141+
142+
case 'restore':
143+
console.log('🚀 开始恢复备份文件...\n');
144+
try {
145+
restoreBackups();
146+
console.log('\n✅ 备份恢复完成!');
147+
} catch (error) {
148+
console.error('\n❌ 恢复备份失败:', error.message);
149+
process.exit(1);
150+
}
151+
break;
152+
153+
case 'cleanup':
154+
cleanupBackups();
155+
console.log('✅ 清理完成!');
156+
break;
157+
158+
default:
159+
console.log(`
160+
用法: node cycle-fix.js <command>
161+
162+
命令:
163+
remove - 移除循环引用(创建备份)
164+
restore - 恢复备份文件
165+
cleanup - 清理备份文件
166+
167+
示例:
168+
node cycle-fix.js remove # 移除循环引用
169+
yarn build # 执行构建
170+
node cycle-fix.js restore # 恢复原始文件
171+
`);
172+
process.exit(1);
173+
}

webapp/packages/product-default/package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
"extends @cloudbeaver/browserslist-config"
2121
],
2222
"scripts": {
23-
"build": "rimraf --glob dist && yarn workspaces foreach -Ap --include '@cloudbeaver/core-sdk' run gql:gen && yarn tsc -b",
24-
"bundle": "yarn build && vite build --mode production",
23+
"build": "node cycle-fix.js remove && rimraf --glob dist && yarn workspaces foreach -Ap --include '@cloudbeaver/core-sdk' run gql:gen && yarn tsc -b && node cycle-fix.js restore",
24+
"bundle": "yarn build && node cycle-fix.js remove && vite build --mode production && node cycle-fix.js restore",
2525
"dev": "yarn build && concurrently -P -k \"yarn workspaces foreach -Ap --include '@cloudbeaver/core-sdk' run gql:gen:dev\" \"vite {@}\"",
2626
"lint": "eslint ./src/ --ext .ts,.tsx",
2727
"version:set": "yarn core-cli-set-version",
28-
"validate-dependencies": "core-cli-validate-dependencies"
28+
"validate-dependencies": "core-cli-validate-dependencies",
29+
"cycle-fix:remove": "node cycle-fix.js remove",
30+
"cycle-fix:restore": "node cycle-fix.js restore",
31+
"cycle-fix:cleanup": "node cycle-fix.js cleanup"
2932
},
3033
"dependencies": {
3134
"@cloudbeaver/core-browser": "workspace:*",
@@ -52,4 +55,4 @@
5255
"tailwindcss": "4.0.7",
5356
"typescript": "^5"
5457
}
55-
}
58+
}

webapp/yarn.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9448,7 +9448,6 @@ __metadata:
94489448
concurrently: "npm:^9"
94499449
eslint: "npm:^9.30.1"
94509450
happy-dom: "npm:^18"
9451-
lz-string: "npm:1.5.0"
94529451
mobx: "npm:^6"
94539452
mobx-react-lite: "npm:^4"
94549453
msw: "npm:^2"

0 commit comments

Comments
 (0)