zen-gitsync 2.12.2 → 2.12.4
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/LICENSE +190 -21
- package/index.js +25 -11
- package/package.json +18 -5
- package/scripts/convert-colors-to-vars.cjs +286 -272
- package/scripts/convert-fontsize-to-vars.cjs +221 -207
- package/scripts/convert-spacing-to-vars.cjs +256 -242
- package/scripts/convert-to-standard-vars.cjs +282 -268
- package/scripts/release.js +599 -585
- package/src/config.js +350 -336
- package/src/gitCommit.js +455 -440
- package/src/ui/public/assets/{EditorView-bnJmBq-i.js → EditorView-BZaOzahT.js} +2 -2
- package/src/ui/public/assets/EditorView-CbqSI9nw.css +1 -0
- package/src/ui/public/assets/{SourceMapView-Rz5SD0A0.js → SourceMapView-D_8mnVt2.js} +3 -3
- package/src/ui/public/assets/SourceMapView-DyMK80hS.css +1 -0
- package/src/ui/public/assets/{index-Bo3tntQh.js → index-BgFwmXzV.js} +11 -11
- package/src/ui/public/assets/{index-bOs5P8fz.css → index-Dsi6tg7k.css} +1 -1
- package/src/ui/public/index.html +2 -2
- package/src/ui/server/index.js +410 -396
- package/src/ui/server/middleware/requestLogger.js +51 -37
- package/src/ui/server/routes/branchStatus.js +101 -87
- package/src/ui/server/routes/code.js +110 -96
- package/src/ui/server/routes/codeAnalysis.js +995 -981
- package/src/ui/server/routes/config.js +1190 -1158
- package/src/ui/server/routes/exec.js +272 -258
- package/src/ui/server/routes/fileOpen.js +279 -265
- package/src/ui/server/routes/fs.js +701 -687
- package/src/ui/server/routes/git/diff.js +352 -338
- package/src/ui/server/routes/git/diffUtils.js +128 -114
- package/src/ui/server/routes/git/stash.js +552 -538
- package/src/ui/server/routes/git/tags.js +172 -158
- package/src/ui/server/routes/git.js +190 -176
- package/src/ui/server/routes/gitOps.js +1179 -1165
- package/src/ui/server/routes/instances.js +14 -0
- package/src/ui/server/routes/npm.js +1023 -1009
- package/src/ui/server/routes/process.js +82 -68
- package/src/ui/server/routes/status.js +67 -53
- package/src/ui/server/routes/terminal.js +319 -305
- package/src/ui/server/socket/registerUiSocketHandlers.js +226 -212
- package/src/ui/server/utils/createSavePortToFile.js +46 -32
- package/src/ui/server/utils/instanceRegistry.js +14 -0
- package/src/ui/server/utils/pathGuard.js +14 -0
- package/src/ui/server/utils/pathGuard.test.js +14 -0
- package/src/ui/server/utils/randomStartPort.js +14 -0
- package/src/ui/server/utils/startServerOnAvailablePort.js +101 -87
- package/src/utils/index.js +14 -0
- package/src/ui/public/assets/EditorView-CHBjgiZc.css +0 -1
- package/src/ui/public/assets/SourceMapView-DhQX0K7t.css +0 -1
|
@@ -1,37 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
chalk.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 createRequestLogger({ chalk }) {
|
|
16
|
+
return (req, res, next) => {
|
|
17
|
+
const startTime = Date.now();
|
|
18
|
+
const requestTime = new Date().toLocaleString('zh-CN', { hour12: false });
|
|
19
|
+
|
|
20
|
+
res.on('finish', () => {
|
|
21
|
+
const duration = Date.now() - startTime;
|
|
22
|
+
const statusCode = res.statusCode;
|
|
23
|
+
|
|
24
|
+
let statusColor = chalk.green;
|
|
25
|
+
if (statusCode >= 400 && statusCode < 500) {
|
|
26
|
+
statusColor = chalk.yellow;
|
|
27
|
+
} else if (statusCode >= 500) {
|
|
28
|
+
statusColor = chalk.red;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let durationColor = chalk.gray;
|
|
32
|
+
if (duration > 1000) {
|
|
33
|
+
durationColor = chalk.red;
|
|
34
|
+
} else if (duration > 500) {
|
|
35
|
+
durationColor = chalk.yellow;
|
|
36
|
+
} else if (duration > 200) {
|
|
37
|
+
durationColor = chalk.cyan;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
console.log(
|
|
41
|
+
chalk.dim(`[${requestTime}]`),
|
|
42
|
+
chalk.bold(req.method),
|
|
43
|
+
req.url,
|
|
44
|
+
statusColor(`[${statusCode}]`),
|
|
45
|
+
durationColor(`${duration}ms`)
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
next();
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -1,87 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
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 registerBranchStatusRoutes({
|
|
16
|
+
app,
|
|
17
|
+
execGitCommand,
|
|
18
|
+
getIsGitRepo,
|
|
19
|
+
getBranchStatusCache,
|
|
20
|
+
setBranchStatusCache,
|
|
21
|
+
getRecentPushStatus,
|
|
22
|
+
setRecentPushStatus
|
|
23
|
+
}) {
|
|
24
|
+
// 获取当前分支 - 直接读取,不缓存(git symbolic-ref 极快,<5ms)
|
|
25
|
+
app.get('/api/branch', async (req, res) => {
|
|
26
|
+
try {
|
|
27
|
+
const { stdout } = await execGitCommand('git symbolic-ref --short HEAD');
|
|
28
|
+
res.json({ branch: stdout.trim() });
|
|
29
|
+
} catch (error) {
|
|
30
|
+
res.status(500).json({ error: error.message });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 获取分支与远程的差异状态(领先/落后提交数)
|
|
35
|
+
app.get('/api/branch-status', async (req, res) => {
|
|
36
|
+
try {
|
|
37
|
+
if (!getIsGitRepo()) {
|
|
38
|
+
return res.json({ hasUpstream: false, ahead: 0, behind: 0 });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
const forceRefresh = req.query.force === 'true';
|
|
43
|
+
|
|
44
|
+
const recentPushStatus = getRecentPushStatus();
|
|
45
|
+
const branchStatusCache = getBranchStatusCache();
|
|
46
|
+
|
|
47
|
+
// push 后10秒内直接返回同步状态
|
|
48
|
+
if (recentPushStatus.justPushed &&
|
|
49
|
+
(now - recentPushStatus.pushTime) < recentPushStatus.validDuration) {
|
|
50
|
+
console.log('检测到最近推送过,直接返回同步状态');
|
|
51
|
+
return res.json({
|
|
52
|
+
hasUpstream: true,
|
|
53
|
+
upstreamBranch: branchStatusCache.upstreamBranch || 'origin/main',
|
|
54
|
+
ahead: 0,
|
|
55
|
+
behind: 0
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 5秒缓存分支名,防止短时间内重复执行 git symbolic-ref / git rev-parse
|
|
60
|
+
const branchInfoCacheValid = !forceRefresh &&
|
|
61
|
+
branchStatusCache.currentBranch &&
|
|
62
|
+
branchStatusCache.upstreamBranch &&
|
|
63
|
+
(now - branchStatusCache.lastUpdate) < branchStatusCache.cacheTimeout;
|
|
64
|
+
|
|
65
|
+
let currentBranch, upstreamBranch;
|
|
66
|
+
|
|
67
|
+
if (branchInfoCacheValid) {
|
|
68
|
+
currentBranch = branchStatusCache.currentBranch;
|
|
69
|
+
upstreamBranch = branchStatusCache.upstreamBranch;
|
|
70
|
+
console.log(`使用5秒缓存的分支名: ${currentBranch} -> ${upstreamBranch}`);
|
|
71
|
+
} else {
|
|
72
|
+
// 直接读取,不再走5分钟长缓存
|
|
73
|
+
const { stdout: branchOut } = await execGitCommand('git symbolic-ref --short HEAD');
|
|
74
|
+
currentBranch = branchOut.trim();
|
|
75
|
+
|
|
76
|
+
const { stdout: upstreamOut } = await execGitCommand(
|
|
77
|
+
'git rev-parse --abbrev-ref --symbolic-full-name @{u}',
|
|
78
|
+
{ ignoreError: true }
|
|
79
|
+
);
|
|
80
|
+
upstreamBranch = upstreamOut.trim() || null;
|
|
81
|
+
|
|
82
|
+
if (!upstreamBranch) {
|
|
83
|
+
setBranchStatusCache({ currentBranch: null, upstreamBranch: null, lastUpdate: 0, cacheTimeout: 5000 });
|
|
84
|
+
return res.json({ hasUpstream: false, ahead: 0, behind: 0 });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
setBranchStatusCache({ currentBranch, upstreamBranch, lastUpdate: now, cacheTimeout: 5000 });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const { stdout: aheadBehindOutput } = await execGitCommand(
|
|
91
|
+
`git rev-list --left-right --count ${currentBranch}...${upstreamBranch}`
|
|
92
|
+
);
|
|
93
|
+
const [ahead, behind] = aheadBehindOutput.trim().split('\t').map(Number);
|
|
94
|
+
|
|
95
|
+
res.json({ hasUpstream: true, upstreamBranch, ahead, behind });
|
|
96
|
+
} catch (error) {
|
|
97
|
+
console.error('获取分支状态失败:', error);
|
|
98
|
+
res.status(500).json({ error: error.message });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
@@ -1,96 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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 * as vm from 'node:vm';
|
|
16
|
+
|
|
17
|
+
function isPlainObject(value) {
|
|
18
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function normalizeOutputs(outputs) {
|
|
22
|
+
if (!isPlainObject(outputs)) return {};
|
|
23
|
+
|
|
24
|
+
const result = {};
|
|
25
|
+
const entries = Object.entries(outputs);
|
|
26
|
+
|
|
27
|
+
for (const [key, val] of entries) {
|
|
28
|
+
const safeKey = String(key || '').trim();
|
|
29
|
+
if (!safeKey) continue;
|
|
30
|
+
if (safeKey.length > 64) continue;
|
|
31
|
+
|
|
32
|
+
if (val === undefined || val === null) {
|
|
33
|
+
result[safeKey] = '';
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof val === 'string') {
|
|
38
|
+
result[safeKey] = val;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof val === 'number' || typeof val === 'boolean') {
|
|
43
|
+
result[safeKey] = String(val);
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
result[safeKey] = JSON.stringify(val);
|
|
49
|
+
} catch {
|
|
50
|
+
result[safeKey] = String(val);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function registerCodeRoutes({ app }) {
|
|
58
|
+
app.post('/api/execute-code-node', async (req, res) => {
|
|
59
|
+
try {
|
|
60
|
+
const { script, input, param } = req.body || {};
|
|
61
|
+
|
|
62
|
+
if (!script || typeof script !== 'string' || !script.trim()) {
|
|
63
|
+
return res.status(400).json({ success: false, error: 'script 不能为空' });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const inputText = typeof input === 'string' ? input : (input === undefined || input === null ? '' : String(input));
|
|
67
|
+
|
|
68
|
+
const paramObj = (param && typeof param === 'object') ? param : undefined;
|
|
69
|
+
|
|
70
|
+
const wrapped = `"use strict";\n${script}\n`;
|
|
71
|
+
|
|
72
|
+
const sandbox = {
|
|
73
|
+
input: inputText,
|
|
74
|
+
param: paramObj,
|
|
75
|
+
main: undefined
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const context = vm.createContext(sandbox, {
|
|
79
|
+
name: 'code-node-sandbox'
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const vmScript = new vm.Script(wrapped, { filename: 'code-node.js' });
|
|
83
|
+
|
|
84
|
+
let result;
|
|
85
|
+
try {
|
|
86
|
+
result = vmScript.runInContext(context, { timeout: 800 });
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return res.status(400).json({ success: false, error: e?.message || String(e) });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const mainFn = context.main || sandbox.main;
|
|
92
|
+
if (typeof mainFn !== 'function') {
|
|
93
|
+
return res.status(400).json({ success: false, error: '未找到 main(param) 函数' });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let finalResult = result;
|
|
97
|
+
try {
|
|
98
|
+
finalResult = mainFn(paramObj || {});
|
|
99
|
+
} catch (e) {
|
|
100
|
+
return res.status(400).json({ success: false, error: e?.message || String(e) });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const outputs = normalizeOutputs(finalResult);
|
|
104
|
+
|
|
105
|
+
return res.json({ success: true, outputs });
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return res.status(500).json({ success: false, error: error?.message || String(error) });
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|