tazuna 0.16.0 → 0.18.0
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 +17 -13
- package/dist/commands/apply.js +9 -3
- package/dist/commands/build.js +1 -1
- package/dist/commands/init.js +6 -2
- package/dist/commands/pack-io.js +125 -4
- package/dist/commands/pack.js +71 -39
- package/dist/commands/vbproj-register.js +39 -27
- package/dist/core/applier.js +42 -8
- package/dist/core/encoding.js +2 -2
- package/dist/core/new-file-style.js +9 -5
- package/dist/core/report.js +26 -0
- package/dist/core/sjis.js +34 -0
- package/dist/core/vbproj.js +22 -6
- package/dist/infra/vbproj.js +19 -11
- package/dist/pack/assets/procedure.js +80 -7
- package/dist/pack/handoff.js +10 -0
- package/dist/pack/includePlanner.js +610 -0
- package/dist/pack/initConfig.js +131 -12
- package/dist/pack/initProject.js +51 -22
- package/dist/pack/logicalTreeBuilder.js +1 -1
- package/dist/pack/procedureFile.js +1 -0
- package/dist/pack/projectLanguage.js +67 -0
- package/dist/pack/services/designerSummary.js +270 -2
- package/dist/pack/services/environmentSummary.js +146 -3
- package/dist/pack/services/extraRootsCollector.js +46 -2
- package/dist/pack/services/repomixExporter.js +66 -18
- package/dist/pack/slnParser.js +12 -8
- package/dist/pack/slnmixConfig.js +49 -6
- package/dist/pack/targetResolver.js +17 -13
- package/dist/pack/types.js +0 -5
- package/dist/pack/vbprojParser.js +52 -18
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* create した .vb の旧スタイル .vbproj への自動登録 (設計書 §11.1 P1-a
|
|
3
|
-
*
|
|
2
|
+
* create した .vb / .cs の旧スタイル .vbproj / .csproj への自動登録 (設計書 §11.1 P1-a。C# は
|
|
3
|
+
* tazuna 0.17.0 から) — apply の結線部。判定・挿入は core/vbproj.ts、探索は infra/vbproj.ts。
|
|
4
|
+
* .vb は最寄りの .vbproj、.cs は最寄りの .csproj に登録する (最寄りのプロジェクトが別の言語なら登録しない)。
|
|
4
5
|
*
|
|
5
6
|
* - 登録の失敗は create 自体の成否に影響しない (レポートに載せるだけ)
|
|
6
7
|
* - 同じ changes.md が .vbproj 自体を変更する場合は、その変更後の内容に対して登録する
|
|
@@ -9,21 +10,32 @@
|
|
|
9
10
|
import { existsSync } from "node:fs";
|
|
10
11
|
import { basename, dirname, join } from "node:path";
|
|
11
12
|
import { EncodingError, decodeFile, encodeDocument, findUnencodable, } from "../core/encoding.js";
|
|
13
|
+
import { describeChars } from "../core/sjis.js";
|
|
12
14
|
import { designerParentName, detectSubType, registerCompileItem, toIncludePath, } from "../core/vbproj.js";
|
|
13
15
|
import { isInsideRoot, readFileState } from "../infra/files.js";
|
|
14
16
|
import { findNearestVbproj } from "../infra/vbproj.js";
|
|
15
17
|
const EMPTY = { writes: new Map(), registrations: [], notes: [] };
|
|
18
|
+
/** 作ったファイルの言語に対応するプロジェクトファイル */
|
|
19
|
+
function projectKindOf(file) {
|
|
20
|
+
return /\.cs$/i.test(file)
|
|
21
|
+
? { language: "cs", extension: ".csproj", label: "csproj" }
|
|
22
|
+
: { language: "vb", extension: ".vbproj", label: "vbproj" };
|
|
23
|
+
}
|
|
24
|
+
/** プロジェクトファイルのパスの見出し ("vbproj" / "csproj") */
|
|
25
|
+
function labelOfProject(path) {
|
|
26
|
+
return /\.csproj$/i.test(path) ? "csproj" : "vbproj";
|
|
27
|
+
}
|
|
16
28
|
function relDirOf(path) {
|
|
17
29
|
const d = dirname(path);
|
|
18
30
|
return d === "." ? "" : d;
|
|
19
31
|
}
|
|
20
32
|
/**
|
|
21
|
-
* 書き込み対象 (applicable) の outcomes から create された .vb を拾い、登録計画を立てる。
|
|
33
|
+
* 書き込み対象 (applicable) の outcomes から create された .vb / .cs を拾い、登録計画を立てる。
|
|
22
34
|
* 書き込みは行わない。
|
|
23
35
|
*/
|
|
24
36
|
export function planVbprojRegistrations(root, applicable) {
|
|
25
37
|
const creates = applicable
|
|
26
|
-
.filter((o) => o.change.op === "create" && /\.vb$/i.test(o.change.path))
|
|
38
|
+
.filter((o) => o.change.op === "create" && /\.(vb|cs)$/i.test(o.change.path))
|
|
27
39
|
// X.vb を X.Designer.vb より先に登録する (VS の並びに合わせる。安定ソート)
|
|
28
40
|
.map((o, i) => ({ o, i, designer: designerParentName(basename(o.change.path)) !== null }))
|
|
29
41
|
.sort((a, b) => Number(a.designer) - Number(b.designer) || a.i - b.i)
|
|
@@ -43,21 +55,26 @@ export function planVbprojRegistrations(root, applicable) {
|
|
|
43
55
|
};
|
|
44
56
|
for (const o of creates) {
|
|
45
57
|
const file = o.change.path;
|
|
46
|
-
const
|
|
58
|
+
const kind = projectKindOf(file);
|
|
59
|
+
const note = (message) => {
|
|
60
|
+
plan.notes.push({ file, message, label: kind.label });
|
|
61
|
+
};
|
|
62
|
+
const lookup = findNearestVbproj(root, relDirOf(file), kind.extension);
|
|
47
63
|
if (lookup.kind === "none") {
|
|
48
|
-
|
|
64
|
+
note(`${kind.label} が見つからないため未登録`);
|
|
49
65
|
continue;
|
|
50
66
|
}
|
|
51
67
|
if (lookup.kind === "multiple") {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
68
|
+
note(`${lookup.dir} に複数の ${kind.extension} があるため未登録 (${lookup.names.join(", ")})。手動で登録してください`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (lookup.kind === "other-language") {
|
|
72
|
+
note(`最寄りのプロジェクト ${lookup.path} は ${kind.extension} ではないため未登録`);
|
|
56
73
|
continue;
|
|
57
74
|
}
|
|
58
75
|
const target = load(lookup.path);
|
|
59
76
|
if ("error" in target) {
|
|
60
|
-
|
|
77
|
+
note(`${lookup.path} に未登録 (${target.error})`);
|
|
61
78
|
continue;
|
|
62
79
|
}
|
|
63
80
|
const include = toIncludePath(relDirOf(lookup.path), file);
|
|
@@ -71,32 +88,26 @@ export function planVbprojRegistrations(root, applicable) {
|
|
|
71
88
|
}
|
|
72
89
|
}
|
|
73
90
|
else if (o.change.op === "create") {
|
|
74
|
-
const subType = detectSubType(o.change.content);
|
|
91
|
+
const subType = detectSubType(o.change.content, kind.language);
|
|
75
92
|
if (subType !== undefined)
|
|
76
93
|
opts.subType = subType;
|
|
77
94
|
}
|
|
78
95
|
const r = registerCompileItem(target.lines.map((l) => l.text), include, opts);
|
|
79
96
|
if (r.status === "registered") {
|
|
80
|
-
|
|
97
|
+
note(`${lookup.path} に登録済み (変更なし)`);
|
|
81
98
|
continue;
|
|
82
99
|
}
|
|
83
100
|
if (r.status === "sdk-style") {
|
|
84
|
-
|
|
101
|
+
note(`${lookup.path} は SDK スタイルのため登録不要`);
|
|
85
102
|
continue;
|
|
86
103
|
}
|
|
87
104
|
if (r.status === "unsupported") {
|
|
88
|
-
|
|
89
|
-
file,
|
|
90
|
-
message: `${lookup.path} は登録できない形式のため未登録 (${r.reason})。手動で登録してください`,
|
|
91
|
-
});
|
|
105
|
+
note(`${lookup.path} は登録できない形式のため未登録 (${r.reason})。手動で登録してください`);
|
|
92
106
|
continue;
|
|
93
107
|
}
|
|
94
108
|
const bad = findUnencodable(r.inserted.join("\n"), target.doc.encoding);
|
|
95
109
|
if (bad.length > 0) {
|
|
96
|
-
|
|
97
|
-
file,
|
|
98
|
-
message: `${lookup.path} (Shift_JIS) に変換できない文字がパスに含まれるため未登録: ${bad.join(" ")}`,
|
|
99
|
-
});
|
|
110
|
+
note(`${lookup.path} (Shift_JIS) に変換できない文字がパスに含まれるため未登録: ${describeChars(bad)}`);
|
|
100
111
|
continue;
|
|
101
112
|
}
|
|
102
113
|
const inserted = r.inserted.map((text) => ({ text, raw: null, eol: null }));
|
|
@@ -115,13 +126,14 @@ export function planVbprojRegistrations(root, applicable) {
|
|
|
115
126
|
}
|
|
116
127
|
return plan;
|
|
117
128
|
}
|
|
118
|
-
/**
|
|
129
|
+
/** プロジェクトファイルの現在の内容 (changes.md が同じファイルを変更するならその変更後) を読む */
|
|
119
130
|
function loadVbproj(root, vbproj, applicable) {
|
|
120
131
|
const own = applicable.find((o) => o.change.path === vbproj);
|
|
121
132
|
let bytes;
|
|
122
133
|
if (own !== undefined) {
|
|
123
|
-
if (own.change.op === "delete")
|
|
124
|
-
return { error:
|
|
134
|
+
if (own.change.op === "delete") {
|
|
135
|
+
return { error: `changes.md がこの ${/\.csproj$/i.test(vbproj) ? ".csproj" : ".vbproj"} を削除するため` };
|
|
136
|
+
}
|
|
125
137
|
bytes = own.afterBytes;
|
|
126
138
|
}
|
|
127
139
|
else {
|
|
@@ -151,9 +163,9 @@ export function formatVbprojPlan(plan) {
|
|
|
151
163
|
r.subType !== undefined ? `SubType: ${r.subType}` : null,
|
|
152
164
|
r.dependentUpon !== undefined ? `DependentUpon: ${r.dependentUpon}` : null,
|
|
153
165
|
].filter((x) => x !== null);
|
|
154
|
-
lines.push(` vbproj に登録: ${r.vbproj} ← ${r.file}${extra.length > 0 ? ` (${extra.join(", ")})` : ""}`);
|
|
166
|
+
lines.push(` ${labelOfProject(r.vbproj)} に登録: ${r.vbproj} ← ${r.file}${extra.length > 0 ? ` (${extra.join(", ")})` : ""}`);
|
|
155
167
|
}
|
|
156
168
|
for (const n of plan.notes)
|
|
157
|
-
lines.push(`
|
|
169
|
+
lines.push(` ${n.label}: ${n.file} — ${n.message}`);
|
|
158
170
|
return lines;
|
|
159
171
|
}
|
package/dist/core/applier.js
CHANGED
|
@@ -8,6 +8,7 @@ import { EncodingError, decodeFile, encodeDocument, findUnencodable, makeDocumen
|
|
|
8
8
|
import { STAGE_LABEL, contentEqualsStage, findContentStage, findInsertionPresenceStage, matchBlock, } from "./matcher.js";
|
|
9
9
|
import { MASK_TOKEN, hasMaskToken, maskLinesForDisplay, maskedValueCounts, maskedViews, restoreMaskedLines, } from "./mask.js";
|
|
10
10
|
import { analyzeNearest } from "./nearest.js";
|
|
11
|
+
import { describeChars, foldToCp932 } from "./sjis.js";
|
|
11
12
|
/** Windows の予約デバイス名 (拡張子付きも不可) */
|
|
12
13
|
const WINDOWS_RESERVED = /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(\..+)?$/i;
|
|
13
14
|
/** §9: プロジェクトルート相対のみ。絶対パス・`..`・`~`・Windows 特殊パスを拒否 */
|
|
@@ -75,6 +76,21 @@ function maskFailureMessage(prefix, r, options = {}) {
|
|
|
75
76
|
`伏せ字を含む行は SEARCH にも REPLACE にもそのまま写してください。${move}伏せ字を含む行を書き換える・新しく足す・` +
|
|
76
77
|
`コメントなどに ${MASK_TOKEN} と書く変更はできません (その行は変えずに残し、利用者に手で直してもらうよう説明してください)`);
|
|
77
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Shift_JIS のファイルに当てる行の「〜」(U+301C) などを、Windows の Shift_JIS (CP932) の対応する文字
|
|
81
|
+
* (「~」U+FF5E など。sjis.ts の CP932_EQUIVALENTS) にそろえる。Shift_JIS のファイルをデコードした行には
|
|
82
|
+
* キーの側の文字は現れず、書くときもキーの側の文字は変換できないため、そろえても一致・書き込みの結果が
|
|
83
|
+
* 悪くなることはない (そろえなければ SEARCH は一致せず、REPLACE は変換できないエラーになる)
|
|
84
|
+
*/
|
|
85
|
+
function foldLinesToCp932(lines) {
|
|
86
|
+
const folded = [];
|
|
87
|
+
const out = lines.map((line) => {
|
|
88
|
+
const r = foldToCp932(line);
|
|
89
|
+
folded.push(...r.folded);
|
|
90
|
+
return r.text;
|
|
91
|
+
});
|
|
92
|
+
return { lines: out, folded };
|
|
93
|
+
}
|
|
78
94
|
/**
|
|
79
95
|
* 抜粋の行のうち「複数行にまたがる値を伏せた範囲にかかる行」に印を付ける。伏せ字のある SEARCH は伏せた
|
|
80
96
|
* 表示で照合し、その範囲の行を含む一致は採らない (伏せ字のない SEARCH は実ファイルで照合するので一致する)。
|
|
@@ -151,6 +167,17 @@ function planReplace(change, state, fallbackEol, options) {
|
|
|
151
167
|
const failures = [];
|
|
152
168
|
const applied = [];
|
|
153
169
|
const already = [];
|
|
170
|
+
// Shift_JIS のファイルでは SEARCH / REPLACE の「〜」などを CP932 の文字にそろえる (照合・書き込みとも)
|
|
171
|
+
const sjisTarget = doc.encoding === "shift_jis";
|
|
172
|
+
const blocks = change.blocks.map((original) => {
|
|
173
|
+
if (!sjisTarget)
|
|
174
|
+
return { block: original, folded: [] };
|
|
175
|
+
const search = foldLinesToCp932(original.search);
|
|
176
|
+
const replace = foldLinesToCp932(original.replace);
|
|
177
|
+
if (search.folded.length === 0 && replace.folded.length === 0)
|
|
178
|
+
return { block: original, folded: [] };
|
|
179
|
+
return { block: { ...original, search: search.lines, replace: replace.lines }, folded: replace.folded };
|
|
180
|
+
});
|
|
154
181
|
let docLines = doc.lines;
|
|
155
182
|
let textLines = docLines.map((l) => l.text);
|
|
156
183
|
const original = textLines;
|
|
@@ -203,7 +230,7 @@ function planReplace(change, state, fallbackEol, options) {
|
|
|
203
230
|
}
|
|
204
231
|
return sets.size;
|
|
205
232
|
};
|
|
206
|
-
for (const block of
|
|
233
|
+
for (const { block, folded } of blocks) {
|
|
207
234
|
let m = matchBlock(textLines, block);
|
|
208
235
|
if (block.search.some(hasMaskToken) && (m.ok || m.reason === "not-found")) {
|
|
209
236
|
// SEARCH の [MASKED] は伏せた表示となら一致する (パックから写した行)。実ファイルで
|
|
@@ -338,7 +365,7 @@ function planReplace(change, state, fallbackEol, options) {
|
|
|
338
365
|
failures.push({
|
|
339
366
|
path: change.path,
|
|
340
367
|
kind: "unencodable",
|
|
341
|
-
message: `ブロック ${block.index}: REPLACE 側に Shift_JIS へ変換できない文字が含まれています: ${bad
|
|
368
|
+
message: `ブロック ${block.index}: REPLACE 側に Shift_JIS へ変換できない文字が含まれています: ${describeChars(bad)}`,
|
|
342
369
|
block,
|
|
343
370
|
});
|
|
344
371
|
continue;
|
|
@@ -351,6 +378,7 @@ function planReplace(change, state, fallbackEol, options) {
|
|
|
351
378
|
inserted: replacement,
|
|
352
379
|
...(restoredMasks > 0 ? { restoredMasks } : {}),
|
|
353
380
|
...(literalMasks > 0 ? { literalMasks } : {}),
|
|
381
|
+
...(folded.length > 0 ? { sjisFolded: folded } : {}),
|
|
354
382
|
});
|
|
355
383
|
// 書いた行の provenance: 元の値に戻した行は戻す元の行、SEARCH の範囲の行を (インデント以外)
|
|
356
384
|
// そのまま残した行はその行。どちらでもなければ新しい行
|
|
@@ -406,7 +434,8 @@ function planFile(change, state, newFile, options) {
|
|
|
406
434
|
if (state.bytes !== null) {
|
|
407
435
|
try {
|
|
408
436
|
const doc = decodeFile(state.bytes);
|
|
409
|
-
|
|
437
|
+
const expected = doc.encoding === "shift_jis" ? foldLinesToCp932(change.content).lines : change.content;
|
|
438
|
+
if (contentEqualsStage(doc.lines.map((l) => l.text), expected) !== null) {
|
|
410
439
|
return fileAlreadyApplied(change);
|
|
411
440
|
}
|
|
412
441
|
}
|
|
@@ -429,11 +458,12 @@ function planFile(change, state, newFile, options) {
|
|
|
429
458
|
return outcome;
|
|
430
459
|
}
|
|
431
460
|
const createLiteral = maskedContent.reduce((n, line) => n + line.split(MASK_TOKEN).length - 1, 0);
|
|
432
|
-
const
|
|
461
|
+
const created = newFile.encoding === "shift_jis" ? foldLinesToCp932(change.content) : { lines: change.content, folded: [] };
|
|
462
|
+
const bad = findUnencodable(created.lines.join("\n"), newFile.encoding);
|
|
433
463
|
if (bad.length > 0) {
|
|
434
|
-
return fileFailure(change, "unencodable", `新規ファイルの既定エンコーディング (${newFile.encoding}) に変換できない文字: ${bad
|
|
464
|
+
return fileFailure(change, "unencodable", `新規ファイルの既定エンコーディング (${newFile.encoding}) に変換できない文字: ${describeChars(bad)}`);
|
|
435
465
|
}
|
|
436
|
-
const doc = makeDocument(
|
|
466
|
+
const doc = makeDocument(created.lines, newFile);
|
|
437
467
|
return {
|
|
438
468
|
change,
|
|
439
469
|
failures: [],
|
|
@@ -443,6 +473,7 @@ function planFile(change, state, newFile, options) {
|
|
|
443
473
|
alreadyApplied: false,
|
|
444
474
|
totalBlocks: 0,
|
|
445
475
|
...(createLiteral > 0 ? { literalMasks: createLiteral } : {}),
|
|
476
|
+
...(created.folded.length > 0 ? { sjisFolded: created.folded } : {}),
|
|
446
477
|
};
|
|
447
478
|
}
|
|
448
479
|
case "rewrite": {
|
|
@@ -457,7 +488,9 @@ function planFile(change, state, newFile, options) {
|
|
|
457
488
|
return fileFailure(change, "undecodable", e instanceof EncodingError ? e.message : String(e));
|
|
458
489
|
}
|
|
459
490
|
const current = doc.lines.map((l) => l.text);
|
|
460
|
-
|
|
491
|
+
// Shift_JIS のファイルでは「〜」などを CP932 の文字にそろえる (planReplace と同じ)
|
|
492
|
+
const rewritten = doc.encoding === "shift_jis" ? foldLinesToCp932(change.content) : { lines: change.content, folded: [] };
|
|
493
|
+
let content = rewritten.lines;
|
|
461
494
|
let restoredMasks = 0;
|
|
462
495
|
let literalMasks = 0;
|
|
463
496
|
if (content.some(hasMaskToken)) {
|
|
@@ -484,7 +517,7 @@ function planFile(change, state, newFile, options) {
|
|
|
484
517
|
}
|
|
485
518
|
const bad = findUnencodable(content.join("\n"), doc.encoding);
|
|
486
519
|
if (bad.length > 0) {
|
|
487
|
-
return fileFailure(change, "unencodable", `Shift_JIS へ変換できない文字が含まれています: ${bad
|
|
520
|
+
return fileFailure(change, "unencodable", `Shift_JIS へ変換できない文字が含まれています: ${describeChars(bad)}`);
|
|
488
521
|
}
|
|
489
522
|
// 既存のエンコーディング・BOM・支配的 EOL・末尾改行の有無を維持して全文を差し替える (§8)
|
|
490
523
|
const lines = content.map((text) => ({ text, raw: null, eol: null }));
|
|
@@ -499,6 +532,7 @@ function planFile(change, state, newFile, options) {
|
|
|
499
532
|
totalBlocks: 0,
|
|
500
533
|
...(restoredMasks > 0 ? { restoredMasks } : {}),
|
|
501
534
|
...(literalMasks > 0 ? { literalMasks } : {}),
|
|
535
|
+
...(rewritten.folded.length > 0 ? { sjisFolded: rewritten.folded } : {}),
|
|
502
536
|
};
|
|
503
537
|
}
|
|
504
538
|
case "delete": {
|
package/dist/core/encoding.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* これにより Shift_JIS の重複マッピング (NEC/IBM 拡張等) があっても、
|
|
7
7
|
* 触っていない行のバイト列は原理的に変わらない。再エンコードは変更行のみ。
|
|
8
8
|
*/
|
|
9
|
-
import { sjisEncode } from "./sjis.js";
|
|
9
|
+
import { describeChars, sjisEncode } from "./sjis.js";
|
|
10
10
|
export class EncodingError extends Error {
|
|
11
11
|
}
|
|
12
12
|
const BOM = Uint8Array.of(0xef, 0xbb, 0xbf);
|
|
@@ -120,7 +120,7 @@ function encodeText(text, encoding) {
|
|
|
120
120
|
return new TextEncoder().encode(text);
|
|
121
121
|
const { bytes, unencodable } = sjisEncode(text);
|
|
122
122
|
if (unencodable.length > 0) {
|
|
123
|
-
throw new EncodingError(`Shift_JIS に変換できない文字が含まれています: ${unencodable
|
|
123
|
+
throw new EncodingError(`Shift_JIS に変換できない文字が含まれています: ${describeChars(unencodable)}`);
|
|
124
124
|
}
|
|
125
125
|
return bytes;
|
|
126
126
|
}
|
|
@@ -27,25 +27,29 @@ function describe(c) {
|
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* 作成先に近いディレクトリから順に手本を探し、最初に見つかったディレクトリの多数決で決める。
|
|
30
|
-
* 手本がなければ拡張子別の既定 (.vb → utf8 + BOM + crlf
|
|
30
|
+
* 手本がなければ拡張子別の既定 (.vb / .cs → utf8 + BOM + crlf (Visual Studio の新規ファイルと同じ)、
|
|
31
|
+
* それ以外 → utf8 / BOM なし / lf)。
|
|
31
32
|
* .vb で utf8 かつ BOM なしになった場合は BOM を付ける (BOM なし UTF-8 の日本語は vbc で化ける。
|
|
32
|
-
* ASCII のみの Shift_JIS ファイルが UTF-8 判定される既知の限界への対処でもある)
|
|
33
|
+
* ASCII のみの Shift_JIS ファイルが UTF-8 判定される既知の限界への対処でもある)。.cs は手本に従う
|
|
34
|
+
* (C# のコンパイラは BOM なしの UTF-8 を読める。.NET の SDK スタイルのリポジトリは BOM なしが多い)。
|
|
33
35
|
*/
|
|
34
36
|
export function resolveNewFileStyle(path, setting, groups) {
|
|
35
37
|
if (setting.encoding !== "auto")
|
|
36
38
|
return { config: fixedNewFile(setting), basis: null };
|
|
37
39
|
const ext = extensionOf(path);
|
|
38
40
|
const isVb = ext === ".vb";
|
|
41
|
+
/** Visual Studio が UTF-8 (BOM あり) / CRLF で新規ファイルを作る言語 */
|
|
42
|
+
const isVsSource = isVb || ext === ".cs";
|
|
39
43
|
let config;
|
|
40
44
|
let basis;
|
|
41
45
|
const found = groups
|
|
42
46
|
.map((g) => ({ g, samples: g.sameExt.length > 0 ? g.sameExt : g.others, same: g.sameExt.length > 0 }))
|
|
43
47
|
.find((x) => x.samples.length > 0);
|
|
44
48
|
if (found === undefined) {
|
|
45
|
-
config =
|
|
49
|
+
config = isVsSource
|
|
46
50
|
? { encoding: "utf8", bom: true, eol: "crlf" }
|
|
47
51
|
: { encoding: "utf8", bom: false, eol: "lf" };
|
|
48
|
-
basis = `手本となる既存ファイルなし → ${
|
|
52
|
+
basis = `手本となる既存ファイルなし → ${isVsSource ? ext : "拡張子"} の既定`;
|
|
49
53
|
}
|
|
50
54
|
else {
|
|
51
55
|
const { g, samples, same } = found;
|
|
@@ -53,7 +57,7 @@ export function resolveNewFileStyle(path, setting, groups) {
|
|
|
53
57
|
const utf8Samples = samples.filter((s) => s.encoding === "utf8");
|
|
54
58
|
const bom = encoding === "utf8" ? majority(utf8Samples.map((s) => s.bom), true) : false;
|
|
55
59
|
const eols = samples.map((s) => s.eol).filter((e) => e !== null);
|
|
56
|
-
const eol = eols.length > 0 ? majority(eols, "crlf") :
|
|
60
|
+
const eol = eols.length > 0 ? majority(eols, "crlf") : isVsSource ? "crlf" : "lf";
|
|
57
61
|
config = { encoding, bom, eol };
|
|
58
62
|
const what = same
|
|
59
63
|
? `${ext === "" ? "拡張子なし" : ext} ${samples.length} ファイル`
|
package/dist/core/report.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { TOOL_NAME } from "../brand.js";
|
|
13
13
|
import { STAGE_LABEL } from "./matcher.js";
|
|
14
14
|
import { renderNearest, renderNearestReplace } from "./nearest.js";
|
|
15
|
+
import { CP932_EQUIVALENTS, describeChars } from "./sjis.js";
|
|
15
16
|
const MATCH_SPEC_NOTE = [
|
|
16
17
|
`## ${TOOL_NAME} の照合仕様 (SEARCH を修正する前に必ず読んでください)`,
|
|
17
18
|
"",
|
|
@@ -158,6 +159,31 @@ export function buildBlankInsensitiveNote(outcomes) {
|
|
|
158
159
|
return null;
|
|
159
160
|
return `注: ${count} 件のブロックは空行の差を吸収して適用しました (git diff で空行の並びを確認してください)`;
|
|
160
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Shift_JIS のファイルに「〜」(U+301C) などを、Windows の Shift_JIS (CP932) の対応する文字 (「~」U+FF5E など)
|
|
164
|
+
* にして書いたときの注記。changes.md と違う文字が書かれることを dry-run と適用サマリの末尾で知らせる。
|
|
165
|
+
* 該当が無ければ null。
|
|
166
|
+
*/
|
|
167
|
+
export function buildSjisFoldNote(outcomes, written) {
|
|
168
|
+
const counts = new Map();
|
|
169
|
+
const add = (chars) => {
|
|
170
|
+
for (const ch of chars ?? [])
|
|
171
|
+
counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
172
|
+
};
|
|
173
|
+
for (const o of outcomes) {
|
|
174
|
+
add(o.sjisFolded);
|
|
175
|
+
for (const b of o.appliedBlocks)
|
|
176
|
+
add(b.sjisFolded);
|
|
177
|
+
}
|
|
178
|
+
if (counts.size === 0)
|
|
179
|
+
return null;
|
|
180
|
+
const pairs = [...counts.entries()].map(([ch, n]) => {
|
|
181
|
+
const to = CP932_EQUIVALENTS.get(ch) ?? ch;
|
|
182
|
+
return `${describeChars([ch])} → ${describeChars([to])}${n > 1 ? ` × ${n}` : ""}`;
|
|
183
|
+
});
|
|
184
|
+
return (`注: Shift_JIS のファイルのため、次の文字を Windows の Shift_JIS で対応する文字にして` +
|
|
185
|
+
`${written ? "書き込みました" : "書き込みます"}: ${pairs.join("、")}`);
|
|
186
|
+
}
|
|
161
187
|
/**
|
|
162
188
|
* 伏せ字 [MASKED] を元の値に戻して適用したブロックがあるときの注記。
|
|
163
189
|
* 伏せ字の行を照合・書き込みしたことを dry-run と適用サマリの末尾で知らせる。
|
package/dist/core/sjis.js
CHANGED
|
@@ -80,3 +80,37 @@ export function sjisEncode(text) {
|
|
|
80
80
|
export function sjisUnencodable(text) {
|
|
81
81
|
return sjisEncode(text).unencodable;
|
|
82
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* JIS X 0208 の同じ文字に、Unicode への対応表によって別のコードポイントが当てられているもの。
|
|
85
|
+
* キーは JIS の対応表 (macOS・JIS X 0213・EUC-JP の多くの実装など) の側、値は Windows の Shift_JIS (CP932)
|
|
86
|
+
* の側で、TextDecoder("shift_jis") のデコード結果は値の側になる。AI は「〜」(U+301C) のようにキーの側を
|
|
87
|
+
* 書くことが多く、そのままでは Shift_JIS へ変換できない。Shift_JIS のファイルに書く文字・照合する文字は
|
|
88
|
+
* 値の側にそろえる (foldToCp932)。sjisEncode 自体は変換しない (ファイル名を .vbproj に書くときなど、
|
|
89
|
+
* 実際の名前と違う文字にしてはいけない所があるため)。
|
|
90
|
+
* 0x815F (U+005C と U+FF3C) は ASCII のバックスラッシュのため対象外
|
|
91
|
+
*/
|
|
92
|
+
export const CP932_EQUIVALENTS = new Map([
|
|
93
|
+
["\u301c", "\uff5e"], // 〜 WAVE DASH → ~ FULLWIDTH TILDE (0x8160)
|
|
94
|
+
["\u2016", "\u2225"], // ‖ DOUBLE VERTICAL LINE → ∥ PARALLEL TO (0x8161)
|
|
95
|
+
["\u2212", "\uff0d"], // − MINUS SIGN → - FULLWIDTH HYPHEN-MINUS (0x817C)
|
|
96
|
+
["\u00a2", "\uffe0"], // ¢ CENT SIGN → ¢ FULLWIDTH CENT SIGN (0x8191)
|
|
97
|
+
["\u00a3", "\uffe1"], // £ POUND SIGN → £ FULLWIDTH POUND SIGN (0x8192)
|
|
98
|
+
["\u00ac", "\uffe2"], // ¬ NOT SIGN → ¬ FULLWIDTH NOT SIGN (0x81CA)
|
|
99
|
+
["\u2014", "\u2015"], // — EM DASH → ― HORIZONTAL BAR (0x815C)
|
|
100
|
+
]);
|
|
101
|
+
const CP932_FOLD_PATTERN = new RegExp(`[${[...CP932_EQUIVALENTS.keys()].join("")}]`, "gu");
|
|
102
|
+
/** CP932_EQUIVALENTS のキーの文字を値の文字にする。変えた文字 (元の文字。出現ごと) も返す */
|
|
103
|
+
export function foldToCp932(text) {
|
|
104
|
+
const folded = [];
|
|
105
|
+
const out = text.replace(CP932_FOLD_PATTERN, (ch) => {
|
|
106
|
+
folded.push(ch);
|
|
107
|
+
return CP932_EQUIVALENTS.get(ch) ?? ch;
|
|
108
|
+
});
|
|
109
|
+
return { text: out, folded };
|
|
110
|
+
}
|
|
111
|
+
/** 文字の一覧を「– (U+2013)」の形で並べる (見分けにくい文字を AI にも利用者にも特定できるように) */
|
|
112
|
+
export function describeChars(chars) {
|
|
113
|
+
return chars
|
|
114
|
+
.map((ch) => `${ch} (U+${(ch.codePointAt(0) ?? 0).toString(16).toUpperCase().padStart(4, "0")})`)
|
|
115
|
+
.join(" ");
|
|
116
|
+
}
|
package/dist/core/vbproj.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 旧スタイル .vbproj への Compile 項目登録 (設計書 §11.1 P1-a)
|
|
2
|
+
* 旧スタイル .vbproj への Compile 項目登録 (設計書 §11.1 P1-a)。旧スタイル .csproj (C#) も同じ形式のため
|
|
3
|
+
* 同じ処理で登録する (tazuna 0.17.0)。
|
|
3
4
|
*
|
|
4
5
|
* 旧スタイル .vbproj は <Compile Include> に載っていないファイルをコンパイルしない。
|
|
5
6
|
* AI にこれをやらせるとパックに .vbproj 本体がなく SEARCH が一致しないため、
|
|
@@ -202,8 +203,20 @@ export function applyInsertion(lines, result) {
|
|
|
202
203
|
return [...lines.slice(0, result.at), ...result.inserted, ...lines.slice(result.at)];
|
|
203
204
|
}
|
|
204
205
|
const RE_INHERITS = /^\s*Inherits\s+(?:(?:System\.)?Windows\.Forms\.)?(Form|UserControl)\s*(?:'.*)?$/i;
|
|
205
|
-
/**
|
|
206
|
-
|
|
206
|
+
/**
|
|
207
|
+
* C# のクラス宣言の基底が Form / UserControl か (`partial class X : Form`、`: System.Windows.Forms.UserControl, IFoo`)。
|
|
208
|
+
* 基底を次の行に書く形もあるため、行をまたいで探す。C# は大文字小文字を区別する
|
|
209
|
+
*/
|
|
210
|
+
const RE_CS_FORM_BASE = /\bclass\s+[A-Za-z_]\w*(?:\s*<[^>]*>)?\s*:\s*(?:global::)?(?:(?:System\.)?Windows\.Forms\.)?(Form|UserControl)\b(?!\s*[.<])/;
|
|
211
|
+
/**
|
|
212
|
+
* 新規 .vb / .cs の内容から <SubType> を推定する (VB: Inherits Form / UserControl、
|
|
213
|
+
* C#: class X : Form / UserControl)。該当なしは undefined
|
|
214
|
+
*/
|
|
215
|
+
export function detectSubType(contentLines, language = "vb") {
|
|
216
|
+
if (language === "cs") {
|
|
217
|
+
const m = RE_CS_FORM_BASE.exec(contentLines.join("\n"));
|
|
218
|
+
return m === null ? undefined : m[1];
|
|
219
|
+
}
|
|
207
220
|
for (const line of contentLines) {
|
|
208
221
|
const m = RE_INHERITS.exec(line);
|
|
209
222
|
if (m === null)
|
|
@@ -213,10 +226,13 @@ export function detectSubType(contentLines) {
|
|
|
213
226
|
}
|
|
214
227
|
return undefined;
|
|
215
228
|
}
|
|
216
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* `X.Designer.vb` なら親ファイル名 `X.vb`、`X.Designer.cs` なら `X.cs` を返す (大文字小文字は区別しない)。
|
|
231
|
+
* それ以外は null
|
|
232
|
+
*/
|
|
217
233
|
export function designerParentName(fileName) {
|
|
218
|
-
const m = /^(.+)\.designer\.vb$/i.exec(fileName);
|
|
219
|
-
return m === null ? null : `${m[1]}.
|
|
234
|
+
const m = /^(.+)\.designer\.(vb|cs)$/i.exec(fileName);
|
|
235
|
+
return m === null ? null : `${m[1]}.${m[2].toLowerCase()}`;
|
|
220
236
|
}
|
|
221
237
|
/** ルート相対パス (/ 区切り) を .vbproj のディレクトリからの相対 Include (\ 区切り) にする */
|
|
222
238
|
export function toIncludePath(vbprojDir, filePath) {
|
package/dist/infra/vbproj.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 最寄りのプロジェクトファイル (.vbproj / .csproj) の探索 (設計書 §11.1)。ファイル I/O のみ。
|
|
3
|
+
* 判定・挿入は core/vbproj.ts。
|
|
3
4
|
*/
|
|
4
5
|
import { readdirSync } from "node:fs";
|
|
5
6
|
import { dirname, join } from "node:path";
|
|
6
|
-
|
|
7
|
+
const PROJECT_FILE = /\.(vbproj|csproj)$/i;
|
|
8
|
+
function listProjectFiles(absDir) {
|
|
7
9
|
try {
|
|
8
10
|
return readdirSync(absDir, { withFileTypes: true })
|
|
9
11
|
// 書き込み対象になるため symlink は除外する (Dirent 判定・§9)
|
|
10
|
-
.filter((e) => e.isFile() &&
|
|
12
|
+
.filter((e) => e.isFile() && PROJECT_FILE.test(e.name))
|
|
11
13
|
.map((e) => e.name)
|
|
12
14
|
.sort();
|
|
13
15
|
}
|
|
@@ -16,18 +18,24 @@ function listVbproj(absDir) {
|
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
/**
|
|
19
|
-
* ルート相対ディレクトリ relDir
|
|
20
|
-
*
|
|
21
|
+
* ルート相対ディレクトリ relDir から上へ辿り、プロジェクトルートまでの間で最寄りのプロジェクトファイル
|
|
22
|
+
* (.vbproj / .csproj) のあるディレクトリを探し、その中から拡張子 extension (".vbproj" / ".csproj") のものを返す。
|
|
23
|
+
* 最寄りのディレクトリに別の言語のプロジェクトファイルしかなければ other-language (それより上は探さない。
|
|
24
|
+
* そのプロジェクトの配下のファイルを、上にある別のプロジェクトに登録しないため)。ルートの外には出ない。
|
|
21
25
|
*/
|
|
22
|
-
export function findNearestVbproj(root, relDir) {
|
|
26
|
+
export function findNearestVbproj(root, relDir, extension = ".vbproj") {
|
|
23
27
|
let dir = relDir === "." ? "" : relDir;
|
|
24
28
|
for (;;) {
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
|
|
29
|
+
const all = listProjectFiles(dir === "" ? root : join(root, dir));
|
|
30
|
+
if (all !== null && all.length > 0) {
|
|
31
|
+
const names = all.filter((name) => name.toLowerCase().endsWith(extension.toLowerCase()));
|
|
32
|
+
const at = (name) => (dir === "" ? name : `${dir}/${name}`);
|
|
33
|
+
if (names.length === 1)
|
|
34
|
+
return { kind: "found", path: at(names[0]) };
|
|
35
|
+
if (names.length > 1)
|
|
36
|
+
return { kind: "multiple", dir: dir === "" ? "." : dir, names };
|
|
37
|
+
return { kind: "other-language", path: at(all[0]) };
|
|
28
38
|
}
|
|
29
|
-
if (names !== null && names.length > 1)
|
|
30
|
-
return { kind: "multiple", dir: dir === "" ? "." : dir, names };
|
|
31
39
|
if (dir === "")
|
|
32
40
|
return { kind: "none" };
|
|
33
41
|
const parent = dirname(dir);
|