zen-gitsync 2.12.2 → 2.12.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.
Files changed (47) hide show
  1. package/LICENSE +190 -21
  2. package/index.js +25 -11
  3. package/package.json +2 -2
  4. package/scripts/convert-colors-to-vars.cjs +286 -272
  5. package/scripts/convert-fontsize-to-vars.cjs +221 -207
  6. package/scripts/convert-spacing-to-vars.cjs +256 -242
  7. package/scripts/convert-to-standard-vars.cjs +282 -268
  8. package/scripts/release.js +599 -585
  9. package/src/config.js +350 -336
  10. package/src/gitCommit.js +455 -440
  11. package/src/ui/public/assets/EditorView-CbqSI9nw.css +1 -0
  12. package/src/ui/public/assets/{EditorView-bnJmBq-i.js → EditorView-GS5cmh99.js} +2 -2
  13. package/src/ui/public/assets/SourceMapView-DyMK80hS.css +1 -0
  14. package/src/ui/public/assets/{SourceMapView-Rz5SD0A0.js → SourceMapView-_YRtzmZZ.js} +3 -3
  15. package/src/ui/public/assets/{index-bOs5P8fz.css → index-ML5Y-5lO.css} +1 -1
  16. package/src/ui/public/assets/{index-Bo3tntQh.js → index-yky0Sd13.js} +11 -11
  17. package/src/ui/public/index.html +2 -2
  18. package/src/ui/server/index.js +410 -396
  19. package/src/ui/server/middleware/requestLogger.js +51 -37
  20. package/src/ui/server/routes/branchStatus.js +101 -87
  21. package/src/ui/server/routes/code.js +110 -96
  22. package/src/ui/server/routes/codeAnalysis.js +995 -981
  23. package/src/ui/server/routes/config.js +1172 -1158
  24. package/src/ui/server/routes/exec.js +272 -258
  25. package/src/ui/server/routes/fileOpen.js +279 -265
  26. package/src/ui/server/routes/fs.js +701 -687
  27. package/src/ui/server/routes/git/diff.js +352 -338
  28. package/src/ui/server/routes/git/diffUtils.js +128 -114
  29. package/src/ui/server/routes/git/stash.js +552 -538
  30. package/src/ui/server/routes/git/tags.js +172 -158
  31. package/src/ui/server/routes/git.js +190 -176
  32. package/src/ui/server/routes/gitOps.js +1179 -1165
  33. package/src/ui/server/routes/instances.js +14 -0
  34. package/src/ui/server/routes/npm.js +1023 -1009
  35. package/src/ui/server/routes/process.js +82 -68
  36. package/src/ui/server/routes/status.js +67 -53
  37. package/src/ui/server/routes/terminal.js +319 -305
  38. package/src/ui/server/socket/registerUiSocketHandlers.js +226 -212
  39. package/src/ui/server/utils/createSavePortToFile.js +46 -32
  40. package/src/ui/server/utils/instanceRegistry.js +14 -0
  41. package/src/ui/server/utils/pathGuard.js +14 -0
  42. package/src/ui/server/utils/pathGuard.test.js +14 -0
  43. package/src/ui/server/utils/randomStartPort.js +14 -0
  44. package/src/ui/server/utils/startServerOnAvailablePort.js +101 -87
  45. package/src/utils/index.js +14 -0
  46. package/src/ui/public/assets/EditorView-CHBjgiZc.css +0 -1
  47. package/src/ui/public/assets/SourceMapView-DhQX0K7t.css +0 -1
@@ -1,176 +1,190 @@
1
- import express from 'express';
2
-
3
- export function registerGitRoutes({
4
- app,
5
- execGitCommand,
6
- clearBranchCache
7
- }) {
8
- // 获取所有分支
9
- app.get('/api/branches', async (req, res) => {
10
- try {
11
- // 获取本地分支 - 使用简单的git branch命令
12
- const { stdout: localBranches } = await execGitCommand('git branch');
13
-
14
- // 获取远程分支
15
- const { stdout: remoteBranches } = await execGitCommand('git branch -r');
16
-
17
- // 处理本地分支 - 正确解析git branch的标准输出格式
18
- const localBranchList = localBranches.split('\n')
19
- .filter(Boolean)
20
- .map(b => b.trim())
21
- .map(b => b.startsWith('* ') ? b.substring(2) : b); // 移除星号并保留分支名
22
-
23
- // 处理远程分支,保留完整的远程分支名称
24
- const remoteBranchList = remoteBranches.split('\n')
25
- .filter(Boolean)
26
- .map(b => b.trim())
27
- .filter(b => b !== 'origin' && !b.includes('HEAD')); // 过滤掉单纯的origin和HEAD引用
28
-
29
- // 合并分支列表
30
- const allBranches = [
31
- ...localBranchList,
32
- ...remoteBranchList
33
- ];
34
-
35
- res.json({ branches: allBranches });
36
- } catch (error) {
37
- console.error('获取分支列表失败:', error);
38
- res.status(500).json({ error: error.message });
39
- }
40
- });
41
-
42
- // 创建新分支
43
- app.post('/api/create-branch', express.json(), async (req, res) => {
44
- try {
45
- const { newBranchName, baseBranch } = req.body;
46
-
47
- if (!newBranchName) {
48
- return res.status(400).json({ success: false, error: '分支名称不能为空' });
49
- }
50
-
51
- // 构建创建分支的命令
52
- let command = `git branch ${newBranchName}`;
53
-
54
- // 如果指定了基础分支,则基于该分支创建
55
- if (baseBranch) {
56
- command = `git branch ${newBranchName} ${baseBranch}`;
57
- }
58
-
59
- // 执行创建分支命令
60
- await execGitCommand(command);
61
-
62
- // 切换到新创建的分支
63
- await execGitCommand(`git checkout ${newBranchName}`);
64
-
65
- // 清除分支缓存,因为分支已切换
66
- clearBranchCache();
67
-
68
- res.json({ success: true, branch: newBranchName });
69
- } catch (error) {
70
- console.error('创建分支失败:', error);
71
- res.status(500).json({ success: false, error: error.message });
72
- }
73
- });
74
-
75
- // 切换分支
76
- app.post('/api/checkout', async (req, res) => {
77
- try {
78
- const { branch } = req.body;
79
- if (!branch) {
80
- return res.status(400).json({ success: false, error: '分支名称不能为空' });
81
- }
82
-
83
- // 执行分支切换
84
- await execGitCommand(`git checkout ${branch}`);
85
-
86
- // 清除分支缓存,因为分支已切换
87
- clearBranchCache();
88
-
89
- res.json({ success: true });
90
- } catch (error) {
91
- console.error('切换分支失败:', error);
92
- res.status(500).json({ success: false, error: error.message });
93
- }
94
- });
95
-
96
- // 合并分支
97
- app.post('/api/merge', async (req, res) => {
98
- try {
99
- const { branch, noCommit, noFf, squash, message } = req.body;
100
-
101
- if (!branch) {
102
- return res.status(400).json({ success: false, error: '分支名称不能为空' });
103
- }
104
-
105
- // 构建Git合并命令 - 直接使用传入的分支名(可能包含origin/前缀)
106
- let command = `git merge ${branch}`;
107
-
108
- // 添加可选参数
109
- if (noCommit) {
110
- command += ' --no-commit';
111
- }
112
-
113
- if (noFf) {
114
- command += ' --no-ff';
115
- }
116
-
117
- if (squash) {
118
- command += ' --squash';
119
- }
120
-
121
- if (message) {
122
- command += ` -m "${message}"`;
123
- }
124
-
125
- try {
126
- // 执行合并命令
127
- const { stdout } = await execGitCommand(command);
128
-
129
- res.json({
130
- success: true,
131
- message: '分支合并成功',
132
- output: stdout
133
- });
134
- } catch (error) {
135
- // 检查是否有合并冲突
136
- const errorMsg = error.message || '';
137
- const hasConflicts = errorMsg.includes('CONFLICT') ||
138
- errorMsg.includes('Automatic merge failed');
139
-
140
- if (hasConflicts) {
141
- res.status(409).json({
142
- success: false,
143
- hasConflicts: true,
144
- error: '合并过程中发生冲突,需要手动解决',
145
- details: errorMsg
146
- });
147
- } else {
148
- throw error;
149
- }
150
- }
151
- } catch (error) {
152
- console.error('合并分支失败:', error);
153
- res.status(500).json({
154
- success: false,
155
- error: `合并分支失败: ${error.message}`
156
- });
157
- }
158
- });
159
-
160
- // 获取Git用户配置信息
161
- app.get('/api/user-info', async (req, res) => {
162
- try {
163
- // 获取全局用户名
164
- const { stdout: userName } = await execGitCommand('git config --global user.name');
165
- // 获取全局用户邮箱
166
- const { stdout: userEmail } = await execGitCommand('git config --global user.email');
167
-
168
- res.json({
169
- name: userName.trim(),
170
- email: userEmail.trim()
171
- });
172
- } catch (error) {
173
- res.status(500).json({ error: error.message });
174
- }
175
- });
176
- }
1
+ // Copyright 2026 xz333221
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ import express from 'express';
16
+
17
+ export function registerGitRoutes({
18
+ app,
19
+ execGitCommand,
20
+ clearBranchCache
21
+ }) {
22
+ // 获取所有分支
23
+ app.get('/api/branches', async (req, res) => {
24
+ try {
25
+ // 获取本地分支 - 使用简单的git branch命令
26
+ const { stdout: localBranches } = await execGitCommand('git branch');
27
+
28
+ // 获取远程分支
29
+ const { stdout: remoteBranches } = await execGitCommand('git branch -r');
30
+
31
+ // 处理本地分支 - 正确解析git branch的标准输出格式
32
+ const localBranchList = localBranches.split('\n')
33
+ .filter(Boolean)
34
+ .map(b => b.trim())
35
+ .map(b => b.startsWith('* ') ? b.substring(2) : b); // 移除星号并保留分支名
36
+
37
+ // 处理远程分支,保留完整的远程分支名称
38
+ const remoteBranchList = remoteBranches.split('\n')
39
+ .filter(Boolean)
40
+ .map(b => b.trim())
41
+ .filter(b => b !== 'origin' && !b.includes('HEAD')); // 过滤掉单纯的origin和HEAD引用
42
+
43
+ // 合并分支列表
44
+ const allBranches = [
45
+ ...localBranchList,
46
+ ...remoteBranchList
47
+ ];
48
+
49
+ res.json({ branches: allBranches });
50
+ } catch (error) {
51
+ console.error('获取分支列表失败:', error);
52
+ res.status(500).json({ error: error.message });
53
+ }
54
+ });
55
+
56
+ // 创建新分支
57
+ app.post('/api/create-branch', express.json(), async (req, res) => {
58
+ try {
59
+ const { newBranchName, baseBranch } = req.body;
60
+
61
+ if (!newBranchName) {
62
+ return res.status(400).json({ success: false, error: '分支名称不能为空' });
63
+ }
64
+
65
+ // 构建创建分支的命令
66
+ let command = `git branch ${newBranchName}`;
67
+
68
+ // 如果指定了基础分支,则基于该分支创建
69
+ if (baseBranch) {
70
+ command = `git branch ${newBranchName} ${baseBranch}`;
71
+ }
72
+
73
+ // 执行创建分支命令
74
+ await execGitCommand(command);
75
+
76
+ // 切换到新创建的分支
77
+ await execGitCommand(`git checkout ${newBranchName}`);
78
+
79
+ // 清除分支缓存,因为分支已切换
80
+ clearBranchCache();
81
+
82
+ res.json({ success: true, branch: newBranchName });
83
+ } catch (error) {
84
+ console.error('创建分支失败:', error);
85
+ res.status(500).json({ success: false, error: error.message });
86
+ }
87
+ });
88
+
89
+ // 切换分支
90
+ app.post('/api/checkout', async (req, res) => {
91
+ try {
92
+ const { branch } = req.body;
93
+ if (!branch) {
94
+ return res.status(400).json({ success: false, error: '分支名称不能为空' });
95
+ }
96
+
97
+ // 执行分支切换
98
+ await execGitCommand(`git checkout ${branch}`);
99
+
100
+ // 清除分支缓存,因为分支已切换
101
+ clearBranchCache();
102
+
103
+ res.json({ success: true });
104
+ } catch (error) {
105
+ console.error('切换分支失败:', error);
106
+ res.status(500).json({ success: false, error: error.message });
107
+ }
108
+ });
109
+
110
+ // 合并分支
111
+ app.post('/api/merge', async (req, res) => {
112
+ try {
113
+ const { branch, noCommit, noFf, squash, message } = req.body;
114
+
115
+ if (!branch) {
116
+ return res.status(400).json({ success: false, error: '分支名称不能为空' });
117
+ }
118
+
119
+ // 构建Git合并命令 - 直接使用传入的分支名(可能包含origin/前缀)
120
+ let command = `git merge ${branch}`;
121
+
122
+ // 添加可选参数
123
+ if (noCommit) {
124
+ command += ' --no-commit';
125
+ }
126
+
127
+ if (noFf) {
128
+ command += ' --no-ff';
129
+ }
130
+
131
+ if (squash) {
132
+ command += ' --squash';
133
+ }
134
+
135
+ if (message) {
136
+ command += ` -m "${message}"`;
137
+ }
138
+
139
+ try {
140
+ // 执行合并命令
141
+ const { stdout } = await execGitCommand(command);
142
+
143
+ res.json({
144
+ success: true,
145
+ message: '分支合并成功',
146
+ output: stdout
147
+ });
148
+ } catch (error) {
149
+ // 检查是否有合并冲突
150
+ const errorMsg = error.message || '';
151
+ const hasConflicts = errorMsg.includes('CONFLICT') ||
152
+ errorMsg.includes('Automatic merge failed');
153
+
154
+ if (hasConflicts) {
155
+ res.status(409).json({
156
+ success: false,
157
+ hasConflicts: true,
158
+ error: '合并过程中发生冲突,需要手动解决',
159
+ details: errorMsg
160
+ });
161
+ } else {
162
+ throw error;
163
+ }
164
+ }
165
+ } catch (error) {
166
+ console.error('合并分支失败:', error);
167
+ res.status(500).json({
168
+ success: false,
169
+ error: `合并分支失败: ${error.message}`
170
+ });
171
+ }
172
+ });
173
+
174
+ // 获取Git用户配置信息
175
+ app.get('/api/user-info', async (req, res) => {
176
+ try {
177
+ // 获取全局用户名
178
+ const { stdout: userName } = await execGitCommand('git config --global user.name');
179
+ // 获取全局用户邮箱
180
+ const { stdout: userEmail } = await execGitCommand('git config --global user.email');
181
+
182
+ res.json({
183
+ name: userName.trim(),
184
+ email: userEmail.trim()
185
+ });
186
+ } catch (error) {
187
+ res.status(500).json({ error: error.message });
188
+ }
189
+ });
190
+ }