@kevlns/xlmerge 2.0.3 → 2.0.5
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/AGENTS.md +25 -169
- package/LICENSE +21 -21
- package/README.md +111 -111
- package/bin/xlmerge.js +152 -152
- package/package.json +3 -2
- package/python/xlsx_merge_engine/__init__.py +2 -2
- package/python/xlsx_merge_engine/xlsx_git_merge_bridge.py +1614 -1614
- package/python/xlsx_resolver/__init__.py +2 -2
- package/python/xlsx_resolver/__main__.py +4 -4
- package/python/xlsx_resolver/formula_values.py +677 -660
- package/python/xlsx_resolver/merge_server.py +24 -0
- package/python/xlsx_resolver/merge_ui.html +1635 -1634
- package/python/xlsx_resolver/recalculate_workbook.ps1 +140 -141
- package/python/xlsx_resolver/resolve_xlsx_conflict.py +9 -0
- package/python/xlsx_resolver/session.py +49 -0
- package/python/xlsx_resolver/xlsx_conflict.py +2381 -2317
- package/skills/xlmerge/SKILL.md +8 -0
- package/skills/xlmerge/references/project.md +171 -0
- package/v-cli.plugin.json +305 -248
package/bin/xlmerge.js
CHANGED
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* xlmerge 启动垫片:定位可用 Python 解释器后透传参数给包内 CLI。
|
|
4
|
-
* - 解释器优先级:XLMERGE_PYTHON > python3 > python > py -3(需 >= 3.9)
|
|
5
|
-
* - 系统解释器已有 openpyxl/bottle 时直接使用;否则在 ~/.xlmerge/venv
|
|
6
|
-
* 创建用户级 venv 并安装固定版本依赖
|
|
7
|
-
* - 所有诊断信息输出到 stderr,保证 stdout 只有 Python CLI 的 JSON 结果
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
"use strict";
|
|
11
|
-
|
|
12
|
-
const { spawnSync, spawn } = require("child_process");
|
|
13
|
-
const fs = require("fs");
|
|
14
|
-
const os = require("os");
|
|
15
|
-
const path = require("path");
|
|
16
|
-
|
|
17
|
-
const PKG_ROOT = path.resolve(__dirname, "..");
|
|
18
|
-
const ENTRY = path.join(PKG_ROOT, "python", "xlsx_resolver", "resolve_xlsx_conflict.py");
|
|
19
|
-
const PY_ROOT = path.join(PKG_ROOT, "python");
|
|
20
|
-
const VENV_DIR = process.env.XLMERGE_VENV || path.join(os.homedir(), ".xlmerge", "venv");
|
|
21
|
-
const DEPS = ["openpyxl==3.1.5", "bottle==0.13.4"];
|
|
22
|
-
|
|
23
|
-
function log(msg) {
|
|
24
|
-
process.stderr.write(`[xlmerge] ${msg}\n`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** 候选解释器命令(数组形式,兼容 "py -3") */
|
|
28
|
-
function candidates() {
|
|
29
|
-
const list = [];
|
|
30
|
-
if (process.env.XLMERGE_PYTHON) list.push([process.env.XLMERGE_PYTHON]);
|
|
31
|
-
if (process.platform !== "win32") list.push(["python3"]);
|
|
32
|
-
list.push(["python"]);
|
|
33
|
-
if (process.platform === "win32") list.push(["py", "-3"]);
|
|
34
|
-
// 去重
|
|
35
|
-
const seen = new Set();
|
|
36
|
-
return list.filter((c) => {
|
|
37
|
-
const key = c.join(" ");
|
|
38
|
-
if (seen.has(key)) return false;
|
|
39
|
-
seen.add(key);
|
|
40
|
-
return true;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** 探测候选解释器,返回 { cmd, version } 或 null */
|
|
45
|
-
function probeInterpreter() {
|
|
46
|
-
for (const cmd of candidates()) {
|
|
47
|
-
let result;
|
|
48
|
-
try {
|
|
49
|
-
result = spawnSync(cmd[0], [...cmd.slice(1), "-c", "import sys; print(sys.version_info >= (3, 9))"], {
|
|
50
|
-
encoding: "utf-8",
|
|
51
|
-
timeout: 20000,
|
|
52
|
-
});
|
|
53
|
-
} catch {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (result.error || result.status !== 0) continue;
|
|
57
|
-
if (result.stdout.trim() === "True") {
|
|
58
|
-
return cmd;
|
|
59
|
-
}
|
|
60
|
-
if (result.stdout.trim() === "False") {
|
|
61
|
-
log(`跳过 ${cmd.join(" ")}:Python 版本低于 3.9`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function venvPython(venvDir) {
|
|
68
|
-
return process.platform === "win32"
|
|
69
|
-
? path.join(venvDir, "Scripts", "python.exe")
|
|
70
|
-
: path.join(venvDir, "bin", "python");
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function hasDeps(cmd) {
|
|
74
|
-
const result = spawnSync(cmd[0], [...cmd.slice(1), "-c", "import openpyxl, bottle"], {
|
|
75
|
-
encoding: "utf-8",
|
|
76
|
-
timeout: 20000,
|
|
77
|
-
});
|
|
78
|
-
return result.status === 0 && !result.error;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/** 确保依赖可用:优先系统解释器,其次用户级 venv;返回解释器命令 */
|
|
82
|
-
function ensureInterpreter() {
|
|
83
|
-
const system = probeInterpreter();
|
|
84
|
-
if (!system) {
|
|
85
|
-
log("未找到可用的 Python >= 3.9,请安装 Python 或设置 XLMERGE_PYTHON 指向解释器路径。");
|
|
86
|
-
process.exit(1);
|
|
87
|
-
}
|
|
88
|
-
if (hasDeps(system)) return system;
|
|
89
|
-
|
|
90
|
-
const vpy = venvPython(VENV_DIR);
|
|
91
|
-
if (fs.existsSync(vpy)) {
|
|
92
|
-
if (hasDeps([vpy])) return [vpy];
|
|
93
|
-
log("已有 venv 缺少依赖,重新安装...");
|
|
94
|
-
} else {
|
|
95
|
-
log(`系统 Python 缺少 openpyxl/bottle,创建用户级 venv:${VENV_DIR}`);
|
|
96
|
-
const created = spawnSync(system[0], [...system.slice(1), "-m", "venv", VENV_DIR], {
|
|
97
|
-
stdio: ["ignore", "ignore", "inherit"],
|
|
98
|
-
timeout: 180000,
|
|
99
|
-
});
|
|
100
|
-
if (created.status !== 0) {
|
|
101
|
-
log("venv 创建失败,请手动执行:python -m venv \"" + VENV_DIR + '" 并 pip 安装 ' + DEPS.join(" "));
|
|
102
|
-
process.exit(1);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const installed = spawnSync(vpy, ["-m", "pip", "install", "--quiet", ...DEPS], {
|
|
106
|
-
stdio: ["ignore", "ignore", "inherit"],
|
|
107
|
-
timeout: 600000,
|
|
108
|
-
});
|
|
109
|
-
if (installed.status !== 0) {
|
|
110
|
-
log(`pip 安装失败(${DEPS.join(" ")}),请检查网络或手动安装。`);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
}
|
|
113
|
-
return [vpy];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function main() {
|
|
117
|
-
if (!fs.existsSync(ENTRY)) {
|
|
118
|
-
log(`找不到入口脚本:${ENTRY}`);
|
|
119
|
-
process.exit(1);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
if (process.argv.includes("--selfcheck")) {
|
|
123
|
-
const system = probeInterpreter();
|
|
124
|
-
const cmd = system ? ensureInterpreter() : null;
|
|
125
|
-
process.stdout.write(
|
|
126
|
-
JSON.stringify(
|
|
127
|
-
{
|
|
128
|
-
ok: Boolean(cmd),
|
|
129
|
-
entry: ENTRY,
|
|
130
|
-
python: cmd ? cmd.join(" ") : null,
|
|
131
|
-
venv: fs.existsSync(venvPython(VENV_DIR)) ? VENV_DIR : null,
|
|
132
|
-
},
|
|
133
|
-
null,
|
|
134
|
-
2,
|
|
135
|
-
) + "\n",
|
|
136
|
-
);
|
|
137
|
-
process.exit(cmd ? 0 : 1);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const cmd = ensureInterpreter();
|
|
141
|
-
const child = spawn(cmd[0], [...cmd.slice(1), ENTRY, ...process.argv.slice(2)], {
|
|
142
|
-
stdio: "inherit",
|
|
143
|
-
env: process.env,
|
|
144
|
-
});
|
|
145
|
-
child.on("error", (err) => {
|
|
146
|
-
log(`启动失败:${err.message}`);
|
|
147
|
-
process.exit(1);
|
|
148
|
-
});
|
|
149
|
-
child.on("exit", (code) => process.exit(code === null ? 1 : code));
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
main();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* xlmerge 启动垫片:定位可用 Python 解释器后透传参数给包内 CLI。
|
|
4
|
+
* - 解释器优先级:XLMERGE_PYTHON > python3 > python > py -3(需 >= 3.9)
|
|
5
|
+
* - 系统解释器已有 openpyxl/bottle 时直接使用;否则在 ~/.xlmerge/venv
|
|
6
|
+
* 创建用户级 venv 并安装固定版本依赖
|
|
7
|
+
* - 所有诊断信息输出到 stderr,保证 stdout 只有 Python CLI 的 JSON 结果
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
const { spawnSync, spawn } = require("child_process");
|
|
13
|
+
const fs = require("fs");
|
|
14
|
+
const os = require("os");
|
|
15
|
+
const path = require("path");
|
|
16
|
+
|
|
17
|
+
const PKG_ROOT = path.resolve(__dirname, "..");
|
|
18
|
+
const ENTRY = path.join(PKG_ROOT, "python", "xlsx_resolver", "resolve_xlsx_conflict.py");
|
|
19
|
+
const PY_ROOT = path.join(PKG_ROOT, "python");
|
|
20
|
+
const VENV_DIR = process.env.XLMERGE_VENV || path.join(os.homedir(), ".xlmerge", "venv");
|
|
21
|
+
const DEPS = ["openpyxl==3.1.5", "bottle==0.13.4"];
|
|
22
|
+
|
|
23
|
+
function log(msg) {
|
|
24
|
+
process.stderr.write(`[xlmerge] ${msg}\n`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 候选解释器命令(数组形式,兼容 "py -3") */
|
|
28
|
+
function candidates() {
|
|
29
|
+
const list = [];
|
|
30
|
+
if (process.env.XLMERGE_PYTHON) list.push([process.env.XLMERGE_PYTHON]);
|
|
31
|
+
if (process.platform !== "win32") list.push(["python3"]);
|
|
32
|
+
list.push(["python"]);
|
|
33
|
+
if (process.platform === "win32") list.push(["py", "-3"]);
|
|
34
|
+
// 去重
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
return list.filter((c) => {
|
|
37
|
+
const key = c.join(" ");
|
|
38
|
+
if (seen.has(key)) return false;
|
|
39
|
+
seen.add(key);
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 探测候选解释器,返回 { cmd, version } 或 null */
|
|
45
|
+
function probeInterpreter() {
|
|
46
|
+
for (const cmd of candidates()) {
|
|
47
|
+
let result;
|
|
48
|
+
try {
|
|
49
|
+
result = spawnSync(cmd[0], [...cmd.slice(1), "-c", "import sys; print(sys.version_info >= (3, 9))"], {
|
|
50
|
+
encoding: "utf-8",
|
|
51
|
+
timeout: 20000,
|
|
52
|
+
});
|
|
53
|
+
} catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (result.error || result.status !== 0) continue;
|
|
57
|
+
if (result.stdout.trim() === "True") {
|
|
58
|
+
return cmd;
|
|
59
|
+
}
|
|
60
|
+
if (result.stdout.trim() === "False") {
|
|
61
|
+
log(`跳过 ${cmd.join(" ")}:Python 版本低于 3.9`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function venvPython(venvDir) {
|
|
68
|
+
return process.platform === "win32"
|
|
69
|
+
? path.join(venvDir, "Scripts", "python.exe")
|
|
70
|
+
: path.join(venvDir, "bin", "python");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function hasDeps(cmd) {
|
|
74
|
+
const result = spawnSync(cmd[0], [...cmd.slice(1), "-c", "import openpyxl, bottle"], {
|
|
75
|
+
encoding: "utf-8",
|
|
76
|
+
timeout: 20000,
|
|
77
|
+
});
|
|
78
|
+
return result.status === 0 && !result.error;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** 确保依赖可用:优先系统解释器,其次用户级 venv;返回解释器命令 */
|
|
82
|
+
function ensureInterpreter() {
|
|
83
|
+
const system = probeInterpreter();
|
|
84
|
+
if (!system) {
|
|
85
|
+
log("未找到可用的 Python >= 3.9,请安装 Python 或设置 XLMERGE_PYTHON 指向解释器路径。");
|
|
86
|
+
process.exit(1);
|
|
87
|
+
}
|
|
88
|
+
if (hasDeps(system)) return system;
|
|
89
|
+
|
|
90
|
+
const vpy = venvPython(VENV_DIR);
|
|
91
|
+
if (fs.existsSync(vpy)) {
|
|
92
|
+
if (hasDeps([vpy])) return [vpy];
|
|
93
|
+
log("已有 venv 缺少依赖,重新安装...");
|
|
94
|
+
} else {
|
|
95
|
+
log(`系统 Python 缺少 openpyxl/bottle,创建用户级 venv:${VENV_DIR}`);
|
|
96
|
+
const created = spawnSync(system[0], [...system.slice(1), "-m", "venv", VENV_DIR], {
|
|
97
|
+
stdio: ["ignore", "ignore", "inherit"],
|
|
98
|
+
timeout: 180000,
|
|
99
|
+
});
|
|
100
|
+
if (created.status !== 0) {
|
|
101
|
+
log("venv 创建失败,请手动执行:python -m venv \"" + VENV_DIR + '" 并 pip 安装 ' + DEPS.join(" "));
|
|
102
|
+
process.exit(1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const installed = spawnSync(vpy, ["-m", "pip", "install", "--quiet", ...DEPS], {
|
|
106
|
+
stdio: ["ignore", "ignore", "inherit"],
|
|
107
|
+
timeout: 600000,
|
|
108
|
+
});
|
|
109
|
+
if (installed.status !== 0) {
|
|
110
|
+
log(`pip 安装失败(${DEPS.join(" ")}),请检查网络或手动安装。`);
|
|
111
|
+
process.exit(1);
|
|
112
|
+
}
|
|
113
|
+
return [vpy];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function main() {
|
|
117
|
+
if (!fs.existsSync(ENTRY)) {
|
|
118
|
+
log(`找不到入口脚本:${ENTRY}`);
|
|
119
|
+
process.exit(1);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (process.argv.includes("--selfcheck")) {
|
|
123
|
+
const system = probeInterpreter();
|
|
124
|
+
const cmd = system ? ensureInterpreter() : null;
|
|
125
|
+
process.stdout.write(
|
|
126
|
+
JSON.stringify(
|
|
127
|
+
{
|
|
128
|
+
ok: Boolean(cmd),
|
|
129
|
+
entry: ENTRY,
|
|
130
|
+
python: cmd ? cmd.join(" ") : null,
|
|
131
|
+
venv: fs.existsSync(venvPython(VENV_DIR)) ? VENV_DIR : null,
|
|
132
|
+
},
|
|
133
|
+
null,
|
|
134
|
+
2,
|
|
135
|
+
) + "\n",
|
|
136
|
+
);
|
|
137
|
+
process.exit(cmd ? 0 : 1);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const cmd = ensureInterpreter();
|
|
141
|
+
const child = spawn(cmd[0], [...cmd.slice(1), ENTRY, ...process.argv.slice(2)], {
|
|
142
|
+
stdio: "inherit",
|
|
143
|
+
env: process.env,
|
|
144
|
+
});
|
|
145
|
+
child.on("error", (err) => {
|
|
146
|
+
log(`启动失败:${err.message}`);
|
|
147
|
+
process.exit(1);
|
|
148
|
+
});
|
|
149
|
+
child.on("exit", (code) => process.exit(code === null ? 1 : code));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kevlns/xlmerge",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "在浏览器中审阅 Git 冲突工作簿的三方差异,校验后写回并提交合并结果。",
|
|
5
5
|
"bin": {
|
|
6
6
|
"xlmerge": "bin/xlmerge.js"
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"python/xlsx_resolver/",
|
|
12
12
|
"v-cli.plugin.json",
|
|
13
13
|
"AGENTS.md",
|
|
14
|
-
"docs/"
|
|
14
|
+
"docs/",
|
|
15
|
+
"skills/"
|
|
15
16
|
],
|
|
16
17
|
"vCli": {
|
|
17
18
|
"manifest": "v-cli.plugin.json"
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""XLSX/XLSM 三方结构化差异引擎(源自 XlsxGitMergeBridge)。"""
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""XLSX/XLSM 三方结构化差异引擎(源自 XlsxGitMergeBridge)。"""
|