encoding-aware-fs 0.1.5 → 0.1.6
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/README.md +21 -1
- package/dist/index.js +14 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,8 +11,9 @@ AI 编码助手默认所有文件都是 UTF-8 编码,在读写 GB18030/GBK/GB2
|
|
|
11
11
|
- **自动编码检测** — 读取文件时自动识别原始编码(GB18030/GBK/GB2312),返回 UTF-8 给 AI 工具
|
|
12
12
|
- **透明回写** — 写入时自动将 UTF-8 内容转换回文件的原始编码
|
|
13
13
|
- **行尾保持** — 检测并保持文件原有的 CRLF/LF 行尾格式,编辑后不会改变
|
|
14
|
+
- **目录级编码规则** — 通过 glob 模式为不同目录指定不同编码(如 `openspec/**` 用 UTF-8,`legacy/**` 用 GBK)
|
|
14
15
|
- **三个 MCP 工具**:`read_file`、`write_file`、`edit_file` — 替代内置文件操作工具
|
|
15
|
-
- **一键安装/卸载** — 支持 Claude Code 和 OpenCode
|
|
16
|
+
- **一键安装/卸载** — 支持 Claude Code 和 OpenCode,交互式配置编码规则
|
|
16
17
|
|
|
17
18
|
## 安装
|
|
18
19
|
|
|
@@ -41,6 +42,25 @@ npx encoding-aware-fs uninstall
|
|
|
41
42
|
1. **读取时**:通过 BOM 和启发式算法检测文件编码,解码为 UTF-8 返回
|
|
42
43
|
2. **写入/编辑时**:先读取原文件检测编码和行尾风格,在 UTF-8 下完成操作,写入前转回原编码并还原行尾格式
|
|
43
44
|
|
|
45
|
+
## 项目配置
|
|
46
|
+
|
|
47
|
+
项目根目录的 `.encoding-converter.json` 控制编码行为:
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"sourceEncoding": "GB18030",
|
|
52
|
+
"confidenceThreshold": 0.8,
|
|
53
|
+
"overrides": [
|
|
54
|
+
{ "pattern": "openspec/**", "sourceEncoding": "UTF-8" },
|
|
55
|
+
{ "pattern": "legacy/**", "sourceEncoding": "GBK" }
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- `sourceEncoding`:检测不确定时的默认编码,也用于新建文件
|
|
61
|
+
- `confidenceThreshold`:自动检测的最小置信度(0-1)
|
|
62
|
+
- `overrides`:可选的目录级编码规则数组,每条规则包含 `pattern`(glob 模式)和 `sourceEncoding`;多个规则匹配时,最具体的模式优先
|
|
63
|
+
|
|
44
64
|
## 开发
|
|
45
65
|
|
|
46
66
|
```bash
|
package/dist/index.js
CHANGED
|
@@ -29978,8 +29978,9 @@ overrides: ${existingConfig.overrides.length} rule(s)` : ""}`,
|
|
|
29978
29978
|
confidenceThreshold = existingConfig.confidenceThreshold ?? 0.8;
|
|
29979
29979
|
overrides = existingConfig.overrides ?? [];
|
|
29980
29980
|
} else {
|
|
29981
|
-
sourceEncoding = await clack2.
|
|
29981
|
+
sourceEncoding = await clack2.autocomplete({
|
|
29982
29982
|
message: "Default source encoding",
|
|
29983
|
+
options: ENCODING_OPTIONS,
|
|
29983
29984
|
initialValue: "GB18030"
|
|
29984
29985
|
});
|
|
29985
29986
|
if (clack2.isCancel(sourceEncoding)) {
|
|
@@ -30019,8 +30020,9 @@ overrides: ${existingConfig.overrides.length} rule(s)` : ""}`,
|
|
|
30019
30020
|
clack2.cancel("Cancelled");
|
|
30020
30021
|
process.exit(0);
|
|
30021
30022
|
}
|
|
30022
|
-
const encoding = await clack2.
|
|
30023
|
+
const encoding = await clack2.autocomplete({
|
|
30023
30024
|
message: `Source encoding for ${pattern}`,
|
|
30025
|
+
options: ENCODING_OPTIONS,
|
|
30024
30026
|
initialValue: "UTF-8"
|
|
30025
30027
|
});
|
|
30026
30028
|
if (clack2.isCancel(encoding)) {
|
|
@@ -30104,7 +30106,7 @@ async function runInstaller() {
|
|
|
30104
30106
|
await promptEncodingConfig(cwd);
|
|
30105
30107
|
clack2.outro("\u5B89\u88C5\u5B8C\u6210\uFF01\u8BF7\u91CD\u542F Claude Code / OpenCode \u4EE5\u751F\u6548");
|
|
30106
30108
|
}
|
|
30107
|
-
var fs10, path6, import_child_process2, import_util6, clack2, execFileAsync;
|
|
30109
|
+
var fs10, path6, import_child_process2, import_util6, clack2, ENCODING_OPTIONS, execFileAsync;
|
|
30108
30110
|
var init_installer = __esm({
|
|
30109
30111
|
"src/installer.ts"() {
|
|
30110
30112
|
"use strict";
|
|
@@ -30114,6 +30116,15 @@ var init_installer = __esm({
|
|
|
30114
30116
|
import_util6 = require("util");
|
|
30115
30117
|
clack2 = __toESM(require("@clack/prompts"));
|
|
30116
30118
|
init_config_io();
|
|
30119
|
+
ENCODING_OPTIONS = [
|
|
30120
|
+
{ value: "GB18030", label: "GB18030 (\u4E2D\u6587\u9ED8\u8BA4)" },
|
|
30121
|
+
{ value: "GBK", label: "GBK" },
|
|
30122
|
+
{ value: "GB2312", label: "GB2312" },
|
|
30123
|
+
{ value: "UTF-8", label: "UTF-8" },
|
|
30124
|
+
{ value: "Big5", label: "Big5 (\u7E41\u4F53\u4E2D\u6587)" },
|
|
30125
|
+
{ value: "Shift_JIS", label: "Shift_JIS (\u65E5\u6587)" },
|
|
30126
|
+
{ value: "EUC-KR", label: "EUC-KR (\u97E9\u6587)" }
|
|
30127
|
+
];
|
|
30117
30128
|
execFileAsync = (0, import_util6.promisify)(import_child_process2.execFile);
|
|
30118
30129
|
}
|
|
30119
30130
|
});
|