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,114 +1,128 @@
1
- export function createDiffHelpers({ execGitCommand }) {
2
- /**
3
- * 检查文件是否应该跳过diff显示(参考GitLab策略)
4
- * @param {string} filePath - 文件路径
5
- * @param {string} diffCommand - 要执行的git diff命令
6
- * @returns {Promise<{shouldSkip: boolean, reason?: string, stats?: object}>}
7
- */
8
- async function checkShouldSkipDiff(filePath, diffCommand) {
9
- // 1. 检查文件扩展名 - 编译/压缩/二进制文件
10
- const skipExtensions = /\.(min\.js|umd\.cjs|bundle\.js|dist\.js|prod\.js|map|wasm|exe|dll|so|dylib|bin|zip|tar|gz|rar|7z|jar|war|ear|pdf|doc|docx|xls|xlsx|ppt|pptx|jpg|jpeg|png|gif|bmp|ico|mp3|mp4|avi|mov|wmv|flv|webm|mkv|ttf|woff|woff2|eot|otf)$/i;
11
- if (skipExtensions.test(filePath)) {
12
- return {
13
- shouldSkip: true,
14
- reason: '⚠️ 检测到编译/打包/二进制文件,diff已跳过显示。\n\n提示:这类文件通常是自动生成的或二进制文件,不适合查看diff。\n如需查看,请使用命令行。'
15
- };
16
- }
17
-
18
- // 2. 使用 --numstat 快速检查变更量(不获取实际内容,速度快)
19
- try {
20
- const numstatCommand = diffCommand.replace(/git (diff|show)/, 'git $1 --numstat');
21
- const { stdout: numstat } = await execGitCommand(numstatCommand, { log: false });
22
-
23
- if (numstat.trim()) {
24
- const lines = numstat.trim().split('\n');
25
- for (const line of lines) {
26
- const parts = line.split('\t');
27
- if (parts.length >= 3) {
28
- const added = parts[0];
29
- const deleted = parts[1];
30
-
31
- // 检查是否是二进制文件(显示为 - -)
32
- if (added === '-' && deleted === '-') {
33
- return {
34
- shouldSkip: true,
35
- reason: '⚠️ 检测到二进制文件,diff已跳过显示。\n\n提示:二进制文件无法以文本形式显示diff。'
36
- };
37
- }
38
-
39
- // 检查变更行数是否过多(超过3000行)
40
- const totalChanges = parseInt(added) + parseInt(deleted);
41
- if (!isNaN(totalChanges) && totalChanges > 3000) {
42
- return {
43
- shouldSkip: true,
44
- reason: `⚠️ 变更内容过大 (${totalChanges.toLocaleString()} 行变更),diff已跳过显示以避免浏览器卡顿。\n\n提示:建议使用命令行或专业diff工具查看大文件变更。\n增加:${parseInt(added).toLocaleString()} 行\n删除:${parseInt(deleted).toLocaleString()} 行`,
45
- stats: { added: parseInt(added), deleted: parseInt(deleted), total: totalChanges }
46
- };
47
- }
48
- }
49
- }
50
- }
51
- } catch (error) {
52
- // numstat失败不影响后续流程
53
- console.log('numstat检查失败,继续执行:', error.message);
54
- }
55
-
56
- // 3. 通过了初步检查
57
- return { shouldSkip: false };
58
- }
59
-
60
- /**
61
- * 检查diff内容大小,如果过大则跳过
62
- * @param {string} diffContent - diff内容
63
- * @param {number} maxSizeKB - 最大大小(KB),默认500KB
64
- * @returns {object|null} - 如果需要跳过返回提示对象,否则返回null
65
- */
66
- function checkDiffSize(diffContent, maxSizeKB = 500) {
67
- const diffSizeKB = Buffer.byteLength(diffContent, 'utf8') / 1024;
68
- if (diffSizeKB > maxSizeKB) {
69
- return {
70
- diff: `⚠️ Diff内容过大 (${diffSizeKB.toFixed(1)} KB),已跳过显示以避免浏览器卡顿。\n\n提示:建议使用命令行查看大文件diff。`,
71
- isLargeFile: true,
72
- size: diffSizeKB
73
- };
74
- }
75
- return null;
76
- }
77
-
78
- /**
79
- * 从 diff 内容中统计增加和删除行数
80
- * @param {string} diffContent - diff内容
81
- * @returns {object} - {added, deleted}
82
- */
83
- function getDiffStats(diffContent) {
84
- if (!diffContent) return { added: 0, deleted: 0 };
85
-
86
- const lines = diffContent.split('\n');
87
- let added = 0;
88
- let deleted = 0;
89
-
90
- for (const line of lines) {
91
- // 跳过diff头部信息
92
- if (line.startsWith('diff ') || line.startsWith('index ') ||
93
- line.startsWith('--- ') || line.startsWith('+++ ') ||
94
- line.startsWith('@@ ')) {
95
- continue;
96
- }
97
-
98
- // 统计增加和删除的行
99
- if (line.startsWith('+')) {
100
- added++;
101
- } else if (line.startsWith('-')) {
102
- deleted++;
103
- }
104
- }
105
-
106
- return { added, deleted };
107
- }
108
-
109
- return {
110
- checkShouldSkipDiff,
111
- checkDiffSize,
112
- getDiffStats
113
- };
114
- }
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
+ export function createDiffHelpers({ execGitCommand }) {
16
+ /**
17
+ * 检查文件是否应该跳过diff显示(参考GitLab策略)
18
+ * @param {string} filePath - 文件路径
19
+ * @param {string} diffCommand - 要执行的git diff命令
20
+ * @returns {Promise<{shouldSkip: boolean, reason?: string, stats?: object}>}
21
+ */
22
+ async function checkShouldSkipDiff(filePath, diffCommand) {
23
+ // 1. 检查文件扩展名 - 编译/压缩/二进制文件
24
+ const skipExtensions = /\.(min\.js|umd\.cjs|bundle\.js|dist\.js|prod\.js|map|wasm|exe|dll|so|dylib|bin|zip|tar|gz|rar|7z|jar|war|ear|pdf|doc|docx|xls|xlsx|ppt|pptx|jpg|jpeg|png|gif|bmp|ico|mp3|mp4|avi|mov|wmv|flv|webm|mkv|ttf|woff|woff2|eot|otf)$/i;
25
+ if (skipExtensions.test(filePath)) {
26
+ return {
27
+ shouldSkip: true,
28
+ reason: '⚠️ 检测到编译/打包/二进制文件,diff已跳过显示。\n\n提示:这类文件通常是自动生成的或二进制文件,不适合查看diff。\n如需查看,请使用命令行。'
29
+ };
30
+ }
31
+
32
+ // 2. 使用 --numstat 快速检查变更量(不获取实际内容,速度快)
33
+ try {
34
+ const numstatCommand = diffCommand.replace(/git (diff|show)/, 'git $1 --numstat');
35
+ const { stdout: numstat } = await execGitCommand(numstatCommand, { log: false });
36
+
37
+ if (numstat.trim()) {
38
+ const lines = numstat.trim().split('\n');
39
+ for (const line of lines) {
40
+ const parts = line.split('\t');
41
+ if (parts.length >= 3) {
42
+ const added = parts[0];
43
+ const deleted = parts[1];
44
+
45
+ // 检查是否是二进制文件(显示为 - -)
46
+ if (added === '-' && deleted === '-') {
47
+ return {
48
+ shouldSkip: true,
49
+ reason: '⚠️ 检测到二进制文件,diff已跳过显示。\n\n提示:二进制文件无法以文本形式显示diff。'
50
+ };
51
+ }
52
+
53
+ // 检查变更行数是否过多(超过3000行)
54
+ const totalChanges = parseInt(added) + parseInt(deleted);
55
+ if (!isNaN(totalChanges) && totalChanges > 3000) {
56
+ return {
57
+ shouldSkip: true,
58
+ reason: `⚠️ 变更内容过大 (${totalChanges.toLocaleString()} 行变更),diff已跳过显示以避免浏览器卡顿。\n\n提示:建议使用命令行或专业diff工具查看大文件变更。\n增加:${parseInt(added).toLocaleString()} 行\n删除:${parseInt(deleted).toLocaleString()} 行`,
59
+ stats: { added: parseInt(added), deleted: parseInt(deleted), total: totalChanges }
60
+ };
61
+ }
62
+ }
63
+ }
64
+ }
65
+ } catch (error) {
66
+ // numstat失败不影响后续流程
67
+ console.log('numstat检查失败,继续执行:', error.message);
68
+ }
69
+
70
+ // 3. 通过了初步检查
71
+ return { shouldSkip: false };
72
+ }
73
+
74
+ /**
75
+ * 检查diff内容大小,如果过大则跳过
76
+ * @param {string} diffContent - diff内容
77
+ * @param {number} maxSizeKB - 最大大小(KB),默认500KB
78
+ * @returns {object|null} - 如果需要跳过返回提示对象,否则返回null
79
+ */
80
+ function checkDiffSize(diffContent, maxSizeKB = 500) {
81
+ const diffSizeKB = Buffer.byteLength(diffContent, 'utf8') / 1024;
82
+ if (diffSizeKB > maxSizeKB) {
83
+ return {
84
+ diff: `⚠️ Diff内容过大 (${diffSizeKB.toFixed(1)} KB),已跳过显示以避免浏览器卡顿。\n\n提示:建议使用命令行查看大文件diff。`,
85
+ isLargeFile: true,
86
+ size: diffSizeKB
87
+ };
88
+ }
89
+ return null;
90
+ }
91
+
92
+ /**
93
+ * diff 内容中统计增加和删除行数
94
+ * @param {string} diffContent - diff内容
95
+ * @returns {object} - {added, deleted}
96
+ */
97
+ function getDiffStats(diffContent) {
98
+ if (!diffContent) return { added: 0, deleted: 0 };
99
+
100
+ const lines = diffContent.split('\n');
101
+ let added = 0;
102
+ let deleted = 0;
103
+
104
+ for (const line of lines) {
105
+ // 跳过diff头部信息
106
+ if (line.startsWith('diff ') || line.startsWith('index ') ||
107
+ line.startsWith('--- ') || line.startsWith('+++ ') ||
108
+ line.startsWith('@@ ')) {
109
+ continue;
110
+ }
111
+
112
+ // 统计增加和删除的行
113
+ if (line.startsWith('+')) {
114
+ added++;
115
+ } else if (line.startsWith('-')) {
116
+ deleted++;
117
+ }
118
+ }
119
+
120
+ return { added, deleted };
121
+ }
122
+
123
+ return {
124
+ checkShouldSkipDiff,
125
+ checkDiffSize,
126
+ getDiffStats
127
+ };
128
+ }