@yarn-tool/static-file 3.0.19 → 3.0.21

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 (81) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +110 -3
  3. package/file/npmignore +31 -0
  4. package/file/test/__root-core.cjs +1 -1
  5. package/file/test/__root-core.mjs +1 -1
  6. package/file/test/__root.js.map +1 -0
  7. package/file/test/__root.ts +9 -2
  8. package/file/test/temp.js.map +1 -0
  9. package/file/test/tsconfig.json.tpl +7 -0
  10. package/file/tsconfig.esm.json.tpl +9 -1
  11. package/file/tsconfig.json.tpl +9 -1
  12. package/file/tsconfig.tsdx.json.tpl +4 -0
  13. package/file/tsdx/index.cjs.map +1 -0
  14. package/file/ws-root/__root_ws.js.map +1 -0
  15. package/lib/const.js +120 -27
  16. package/lib/const.js.map +1 -1
  17. package/lib/copyStaticFiles.d.ts +62 -2
  18. package/lib/copyStaticFiles.js +156 -9
  19. package/lib/copyStaticFiles.js.map +1 -1
  20. package/lib/copyStaticFilesEntry.d.ts +72 -25
  21. package/lib/copyStaticFilesEntry.js +133 -34
  22. package/lib/copyStaticFilesEntry.js.map +1 -1
  23. package/lib/mergeIgnoreFiles.d.ts +52 -0
  24. package/lib/mergeIgnoreFiles.js +146 -0
  25. package/lib/mergeIgnoreFiles.js.map +1 -0
  26. package/lib/parseStaticMap.js +16 -3
  27. package/lib/parseStaticMap.js.map +1 -1
  28. package/lib/reMapStaticFilesMapArray.js +26 -5
  29. package/lib/reMapStaticFilesMapArray.js.map +1 -1
  30. package/lib/root/getRootCopyStaticFiles.js +17 -2
  31. package/lib/root/getRootCopyStaticFiles.js.map +1 -1
  32. package/lib/types.d.ts +71 -0
  33. package/lib/types.js.map +1 -1
  34. package/package.json +22 -5
  35. package/test/__root-core.cjs +1 -0
  36. package/test/__root-core.d.cts +1 -0
  37. package/test/__root-core.d.mts +1 -0
  38. package/test/__root-core.d.ts +1 -0
  39. package/test/__root-core.mjs +8 -0
  40. package/test/__root.d.ts +32 -0
  41. package/test/__root.js +54 -0
  42. package/test/__root.js.map +1 -0
  43. package/test/copyStaticFiles.test.js.map +1 -0
  44. package/test/copyStaticFiles.test.ts.snapshot +439 -0
  45. package/test/fixtures/out/gitignore +242 -0
  46. package/test/fixtures/out/npmignore +216 -0
  47. package/test/fixtures/split/git/00-header.txt +2 -0
  48. package/test/fixtures/split/git/10-project.txt +24 -0
  49. package/test/fixtures/split/git/20-test.txt +9 -0
  50. package/test/fixtures/split/git/40-env.txt +10 -0
  51. package/test/fixtures/split/git/90-misc.txt +6 -0
  52. package/test/fixtures/split/git/99-whitelist.txt +40 -0
  53. package/test/fixtures/split/npm/01-hidden.txt +2 -0
  54. package/test/fixtures/split/npm/05-source.txt +7 -0
  55. package/test/fixtures/split/npm/10-project.txt +31 -0
  56. package/test/fixtures/split/npm/20-test.txt +20 -0
  57. package/test/fixtures/split/npm/30-ide.txt +2 -0
  58. package/test/fixtures/split/npm/40-env.txt +2 -0
  59. package/test/fixtures/split/npm/90-misc.txt +4 -0
  60. package/test/fixtures/split/other/90-duplicates.txt +33 -0
  61. package/test/fixtures/split/shared/10-project.txt +38 -0
  62. package/test/fixtures/split/shared/20-test.txt +7 -0
  63. package/test/fixtures/split/shared/30-ide.txt +8 -0
  64. package/test/fixtures/split/shared/40-env.txt +6 -0
  65. package/test/fixtures/split/shared/90-misc.txt +10 -0
  66. package/test/scripts/compose-split-ignore-files.d.ts +1 -0
  67. package/test/scripts/compose-split-ignore-files.js +80 -0
  68. package/test/scripts/compose-split-ignore-files.js.map +1 -0
  69. package/test/scripts/lib/ignore-split.d.ts +205 -0
  70. package/test/scripts/lib/ignore-split.js +286 -0
  71. package/test/scripts/lib/ignore-split.js.map +1 -0
  72. package/test/scripts/split-ignore-files.d.ts +1 -0
  73. package/test/scripts/split-ignore-files.js +454 -0
  74. package/test/scripts/split-ignore-files.js.map +1 -0
  75. package/test/scripts/update-npmignore-static-files.d.ts +1 -0
  76. package/test/scripts/update-npmignore-static-files.js +121 -0
  77. package/test/scripts/update-npmignore-static-files.js.map +1 -0
  78. package/test/temp.d.ts +3 -0
  79. package/test/temp.js +5 -0
  80. package/test/temp.js.map +1 -0
  81. package/test/tsconfig.json.tpl +13 -0
@@ -0,0 +1,454 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * 將 file/gitignore / file/npmignore 分割為 test/fixtures/split/ 的分類片段
5
+ * Split file/gitignore & file/npmignore into classified fragments under test/fixtures/split/
6
+ *
7
+ * 單一事實來源:主題({@link TOPICS})、分類 ↔ 檔名({@link IGNORE_SPLIT_TARGETS})、
8
+ * 共用輔助區塊({@link IGNORE_SPLIT_GENERATORS})與片段路徑慣例({@link getSplitFragmentPath})
9
+ * 皆引用 ./lib/ignore-split;本檔只保留分類邏輯本身。
10
+ *
11
+ * Single source of truth: topics ({@link TOPICS}), bucket ↔ file name
12
+ * ({@link IGNORE_SPLIT_TARGETS}), shared generated blocks
13
+ * ({@link IGNORE_SPLIT_GENERATORS}), and the fragment path convention
14
+ * ({@link getSplitFragmentPath}) all come from ./lib/ignore-split; this script
15
+ * only owns the classification logic itself.
16
+ *
17
+ * 分類流程:比對主題 → 命中共用輔助的重複語法改寫為佔位行 → 同檔重複與冗餘規則
18
+ * 捨棄(寫入 other/)→ 段落註解併入下一個規則行的主題 → 依分類與主題寫出片段。
19
+ *
20
+ * Classification flow: match the topic → replace repeated matrices covered by a
21
+ * shared generator with a placeholder line → drop same-file duplicates and
22
+ * redundant rules (recorded in other/) → attach each section comment to the
23
+ * topic of the following rule line → write out fragments by bucket and topic.
24
+ *
25
+ * 規格語意(必須保留):`x/` 只針對目錄、`/x` 只錨定根目錄,兩者與 `x` 皆為
26
+ * 不同規則;本檔所有比對(共用判定、同檔重複、輔助產生、冗餘判定)都以完整
27
+ * 字串進行,不做任何正規化;冗餘表只允許「廣義規則的匹配集合嚴格包含該行」。
28
+ *
29
+ * Pattern semantics (must be preserved): `x/` targets directories only and `/x`
30
+ * anchors to the root, so both differ from `x`; every comparison in this script
31
+ * (shared detection, same-file duplicates, generator matching, redundancy) uses
32
+ * the full string with no normalization, and the redundancy table only allows a
33
+ * broader rule whose match set strictly contains the line.
34
+ *
35
+ * 執行 / run: tsx packages/@yarn-tool/static-file/test/scripts/split-ignore-files.ts
36
+ * 輸出 / output: test/fixtures/split/{git,npm,shared,other}/*.txt
37
+ */
38
+ const fs_1 = require("fs");
39
+ const path_1 = require("path");
40
+ const __root_1 = require("../__root");
41
+ const ignore_split_1 = require("./lib/ignore-split");
42
+ /**
43
+ * 片段檔標頭中的分類名稱(僅輸出分類需要標頭;other 有固定檔頭不經此表)
44
+ * Bucket names shown in fragment headers (only emitted buckets need a header;
45
+ * other has its own fixed header and does not use this table)
46
+ */
47
+ const BUCKET_LABEL = {
48
+ git: 'git 專用 / git only',
49
+ npm: 'npm 發布專用 / npm publish only',
50
+ shared: '兩類共用 / shared',
51
+ };
52
+ /**
53
+ * 冗餘規則:已被更廣泛的規則涵蓋,不輸出到組合結果,僅記錄於 other/ 供稽核
54
+ * Redundant rules: covered by a broader rule, never emitted into the composed
55
+ * output, only recorded in other/ for auditing
56
+ *
57
+ * 鍵為 `<分類>:<規則>`;只有該分類專屬(非共用)的行才會比對。
58
+ * Keyed as `<bucket>:<rule>`; only bucket-specific (non-shared) lines are matched.
59
+ *
60
+ * 「涵蓋」指語意上的匹配集合包含(例:`coverage` 匹配任意層級,故包含只針對
61
+ * 根目錄的 `/coverage`),絕非字串相同或正規化後相同;`x/`(只針對目錄)與
62
+ * `/x`(只錨定根目錄)都是獨立規則,每條的廣義規則必須仍然存在於同一份來源
63
+ * 檔,否則該條不得列為冗餘。
64
+ * "Covered" means semantic containment of the match sets (e.g. `coverage`
65
+ * matches any depth and therefore contains root-anchored `/coverage`), never
66
+ * string equality or equality after normalization; `x/` (directories only) and
67
+ * `/x` (root-anchored only) are rules in their own right, and each broader rule
68
+ * must still exist in the same source file or the entry must not be listed.
69
+ */
70
+ const REDUNDANT = {
71
+ 'git:/coverage': '已被 `coverage` 涵蓋 / covered by `coverage`',
72
+ 'git:/.next/': '已被 `.next` 涵蓋 / covered by `.next`',
73
+ 'git:/out/': '已被 `/out` 涵蓋 / covered by `/out`',
74
+ 'git:**/node_modules': '已被 `node_modules` 涵蓋 / covered by `node_modules`',
75
+ 'git:test/temp*/': '已被輔助產生的 `test/temp*` 涵蓋 / covered by generated `test/temp*`',
76
+ 'npm:/node_modules/': '已被 `node_modules` 涵蓋 / covered by `node_modules`',
77
+ 'npm:**/node_modules/': '已被 `node_modules` 涵蓋 / covered by `node_modules`',
78
+ 'npm:jest.config.js': '已被 `jest.config.*` 涵蓋 / covered by `jest.config.*`',
79
+ };
80
+ /**
81
+ * 每個目標分類的「另一份」來源分類;共用規則即以「同時出現在另一份」判定
82
+ * The complementary source bucket of each target; a rule counts as shared when
83
+ * it also appears in that other source
84
+ */
85
+ const COMPLEMENT = {
86
+ git: 'npm',
87
+ npm: 'git',
88
+ };
89
+ /**
90
+ * 主題分類規則(依序比對,第一個符合者勝出)
91
+ * Topic rules (checked in order; the first match wins)
92
+ */
93
+ const RULES = [
94
+ [/^!\*\.d\.(ts|mts|cts)$/, '05-source'],
95
+ [/^!\/src\/\*\*/, '05-source'],
96
+ [/^!\/(README|CHANGELOG)\.md$/, '10-project'],
97
+ /**
98
+ * `!.github` 必須排在「巢狀 .github 排除規則」(原檔 163 < 201)之前,
99
+ * 否則嵌套 .github 會被白名單重新放行;`!/.github`(202)維持 99。
100
+ * `!.github` must stay before the nested-.github exclusion rule (original
101
+ * line 163 < 201) so nested .github remains re-excluded; `!/.github` (202)
102
+ * stays in 99.
103
+ */
104
+ [/^!\.github$/, '10-project'],
105
+ [/^!/, '99-whitelist'],
106
+ /**
107
+ * 根目錄隱藏檔規則須早於 `!*.d.ts`(原檔 17 < 26),
108
+ * 否則根目錄的 *.d.ts 會被後置的 `/.*` 重新排除。
109
+ * The root hidden-file rule must precede `!*.d.ts` (original line 17 < 26),
110
+ * otherwise root *.d.ts files get re-excluded by the later `/.*`.
111
+ */
112
+ [/^\/\.\*$/, '01-hidden'],
113
+ [/^\*\.ts$/, '05-source'],
114
+ [/^\/bin\//, '05-source'],
115
+ /**
116
+ * 環境與 IDE 規則須早於測試規則:`.env.test.local` 含 `.test.` 但並非測試檔
117
+ * Environment and IDE rules must precede the test rules: `.env.test.local`
118
+ * contains `.test.` but is not a test file
119
+ */
120
+ [/^\.env/, '40-env'],
121
+ [/^\/certificates$/, '40-env'],
122
+ [/\.pem$/, '40-env'],
123
+ [/vercel|\.nowignore|^\/?now\.json$/, '40-env'],
124
+ [/^\.?nvmrc$|^\.node-version$/, '40-env'],
125
+ [/^\.?(idea|vscode)$/, '30-ide'],
126
+ [/\.(suo|ntvs\*|njsproj|sln|sw\?)$/, '30-ide'],
127
+ [/^(clinerules|kilocode|cline|junie|gemini|copilot|claude|agents|aiassistant)$/, '30-ide'],
128
+ [/intellij/, '30-ide'],
129
+ [/^(tests?|__tests?__|__mocks__|__snapshots__|__fixtures__|__file_snapshots__)$/, '20-test'],
130
+ [/^\/?(tests?|__tests?__|__mocks__|__snapshots__|__fixtures__|fixture)\//, '20-test'],
131
+ [/\/test\//, '20-test'],
132
+ [/\.(spec|test|node-spec|node-test|stories)\./, '20-test'],
133
+ [/^\.gitkeep$/, '20-test'],
134
+ [/jest|karma|mocha|nyc|coverage/i, '20-test'],
135
+ [/\.snap(shot)?$/, '20-test'],
136
+ [/\/stories\//, '20-test'],
137
+ [/^\.DS_Store$/, '90-misc'],
138
+ [/^~ci\.|^\/~\*/, '90-misc'],
139
+ [/\.stackdump$|^\*\.bak$|^\*\.old$/, '90-misc'],
140
+ [/^\.opt-(in|out)$|^\*\.stat$|^\.codenomad$|^\.logs$|^\.agentbridge$|^openspec\/$|^cz-adapter$/, '90-misc'],
141
+ [/.*/, '10-project'],
142
+ ];
143
+ /**
144
+ * 每個輔助區塊涵蓋的規則集合(排除空行與說明註解),
145
+ * 用於在來源檔中找出該以佔位行取代的重複行
146
+ * The rule set covered by each generator (blank lines and description comments
147
+ * excluded), used to find the repeated source lines that a placeholder replaces
148
+ */
149
+ const GENERATOR_RULE_SETS = Object.fromEntries(Object.entries(ignore_split_1.IGNORE_SPLIT_GENERATORS).map(([name, { generate }]) => [
150
+ name,
151
+ new Set(generate().filter(line => line !== '' && !line.startsWith('#'))),
152
+ ]));
153
+ const report = {
154
+ fragments: {},
155
+ gen: {},
156
+ dropped: {
157
+ redundant: [],
158
+ dup: [],
159
+ },
160
+ };
161
+ /**
162
+ * 行指派的種類:以 enum 取代字串聯合,避免字串筆誤;
163
+ * 字串值與原字面值一致,report 與 JSON 輸出不受影響
164
+ * The kind of a line assignment: an enum instead of a string union, so a typo
165
+ * cannot slip in; the string values match the previous literals, keeping the
166
+ * report and JSON output unchanged
167
+ */
168
+ var EnumIgnoreSplitLineKind;
169
+ (function (EnumIgnoreSplitLineKind) {
170
+ EnumIgnoreSplitLineKind["Comment"] = "comment";
171
+ EnumIgnoreSplitLineKind["Gen"] = "gen";
172
+ EnumIgnoreSplitLineKind["Dropped"] = "dropped";
173
+ EnumIgnoreSplitLineKind["Fragment"] = "fragment";
174
+ })(EnumIgnoreSplitLineKind || (EnumIgnoreSplitLineKind = {}));
175
+ /**
176
+ * 判斷單一規則行所屬的主題
177
+ * Decide which topic a single rule line belongs to
178
+ */
179
+ function classifyTopic(line) {
180
+ for (const [re, topic] of RULES) {
181
+ if (re.test(line)) {
182
+ return topic;
183
+ }
184
+ }
185
+ return '10-project';
186
+ }
187
+ /**
188
+ * 讀取來源檔並去除結尾空行 / Read a source file and strip its trailing blank lines
189
+ */
190
+ function readLines(path) {
191
+ const lines = (0, fs_1.readFileSync)(path, 'utf8').split(/\r?\n/);
192
+ while (lines.length > 0 && lines[lines.length - 1] === '') {
193
+ lines.pop();
194
+ }
195
+ return lines;
196
+ }
197
+ /**
198
+ * 判斷單一來源檔每一行的分類與主題
199
+ * Decide the bucket and topic of every line in one source file
200
+ *
201
+ * @param file - 來源所屬的目標分類 / The target bucket of the source file
202
+ * @param lines - 來源檔的所有行 / Every line of the source file
203
+ * @param otherSet - 另一份來源檔的非空行集合(共用判定基準)/ The non-blank line set of the complementary source (the shared-bucket basis)
204
+ */
205
+ function processFile(file, lines, otherSet) {
206
+ const seen = new Set();
207
+ const assign = new Array(lines.length).fill(null);
208
+ for (let i = 0; i < lines.length; i++) {
209
+ const line = lines[i];
210
+ if (line === '') {
211
+ continue;
212
+ }
213
+ /**
214
+ * 段落註解為「# 後接空白」的形式;`#jest.config.js` 這類被註解掉的規則
215
+ * 不符合此形式,仍視為規則行走一般分類
216
+ * A section comment is `#` followed by whitespace; a commented-out rule
217
+ * like `#jest.config.js` does not match and is classified as a rule line
218
+ */
219
+ if (/^#\s/.test(line)) {
220
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Comment };
221
+ continue;
222
+ }
223
+ /**
224
+ * 規則行:同時出現在另一份來源檔即為共用分類
225
+ * A rule line that also appears in the other source belongs to the shared bucket
226
+ */
227
+ const bucket = otherSet.has(line) ? 'shared' : file;
228
+ /**
229
+ * 1. 命中共用輔助的重複語法 → 以佔位行取代
230
+ * 1. A repeated matrix covered by a shared generator → replaced by a placeholder
231
+ */
232
+ let genName;
233
+ if (bucket === file) {
234
+ for (const [name, ruleSet] of Object.entries(GENERATOR_RULE_SETS)) {
235
+ const generator = ignore_split_1.IGNORE_SPLIT_GENERATORS[name];
236
+ if (generator.bucket === file && ruleSet.has(line)) {
237
+ genName = name;
238
+ break;
239
+ }
240
+ }
241
+ }
242
+ if (genName) {
243
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Gen, bucket: file, topic: ignore_split_1.IGNORE_SPLIT_GENERATORS[genName].topic, genName };
244
+ report.gen[genName] = (report.gen[genName] || 0) + 1;
245
+ continue;
246
+ }
247
+ const topic = classifyTopic(line);
248
+ /**
249
+ * 2. 同檔內重複出現 → other
250
+ * 2. Repeated within the same file → other
251
+ */
252
+ if (seen.has(line)) {
253
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Dropped, topic };
254
+ report.dropped.dup.push({ bucket: file, line });
255
+ continue;
256
+ }
257
+ seen.add(line);
258
+ /**
259
+ * 3. 冗餘(已被更廣泛的規則涵蓋)→ other
260
+ * 3. Redundant (covered by a broader rule) → other
261
+ */
262
+ const redundantNote = REDUNDANT[`${file}:${line}`];
263
+ if (bucket === file && redundantNote) {
264
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Dropped, topic };
265
+ report.dropped.redundant.push({ bucket: file, line, note: redundantNote });
266
+ continue;
267
+ }
268
+ /**
269
+ * 4. 一般規則 → 分類到 fragment
270
+ * 4. An ordinary rule → classified into a fragment
271
+ */
272
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Fragment, bucket, topic };
273
+ }
274
+ /**
275
+ * 段落註解:主題採用下一個規則行的主題;分類採用同主題且會輸出的規則行。
276
+ * 規則行被佔位或丟棄時,繼續向後找同主題的下一個輸出行。
277
+ * A section comment adopts the topic of the next rule line and the bucket of
278
+ * an emitted line of that topic; when that line is dropped or replaced by a
279
+ * placeholder, it keeps scanning forward for the next emitted line of the
280
+ * same topic.
281
+ */
282
+ for (let i = 0; i < lines.length; i++) {
283
+ const current = assign[i];
284
+ if (!current || current.kind !== EnumIgnoreSplitLineKind.Comment) {
285
+ continue;
286
+ }
287
+ /**
288
+ * git 檔案首行的官方說明保留為 00-header 片段
289
+ * The official note on line 1 of the gitignore becomes the 00-header fragment
290
+ */
291
+ if (i === 0 && file === 'git') {
292
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Fragment, bucket: 'git', topic: '00-header' };
293
+ continue;
294
+ }
295
+ let topic;
296
+ for (let j = i + 1; j < lines.length; j++) {
297
+ const next = assign[j];
298
+ if (!next || next.kind === EnumIgnoreSplitLineKind.Comment) {
299
+ continue;
300
+ }
301
+ topic = next.topic;
302
+ break;
303
+ }
304
+ const resolvedTopic = topic !== null && topic !== void 0 ? topic : '90-misc';
305
+ let bucket = file;
306
+ for (let j = i + 1; j < lines.length; j++) {
307
+ const next = assign[j];
308
+ if (!next || next.kind !== EnumIgnoreSplitLineKind.Fragment || next.topic !== resolvedTopic) {
309
+ continue;
310
+ }
311
+ bucket = next.bucket;
312
+ break;
313
+ }
314
+ assign[i] = { kind: EnumIgnoreSplitLineKind.Fragment, bucket, topic: resolvedTopic };
315
+ }
316
+ return { lines, assign: assign };
317
+ }
318
+ /**
319
+ * 依分類取出被丟棄的規則行(供 other/ 片段分段列出)
320
+ * Collect the dropped rule lines of one bucket (for the sections of other/)
321
+ */
322
+ function droppedLines(entries, bucket) {
323
+ return entries.filter(entry => entry.bucket === bucket).map(entry => entry.line);
324
+ }
325
+ /**
326
+ * 腳本進入點:分割兩份來源檔並寫出分類片段
327
+ * Script entry: split both source files and write out the classified fragments
328
+ */
329
+ function main() {
330
+ /**
331
+ * 讀取兩份來源檔(檔名來自 {@link IGNORE_SPLIT_TARGETS})
332
+ * Read both source files (file names come from {@link IGNORE_SPLIT_TARGETS})
333
+ */
334
+ const files = {};
335
+ for (const { bucket, fileName } of ignore_split_1.IGNORE_SPLIT_TARGETS) {
336
+ files[bucket] = readLines((0, path_1.join)(__root_1.__ROOT, 'file', fileName));
337
+ }
338
+ const ruleLineSets = {};
339
+ for (const { bucket } of ignore_split_1.IGNORE_SPLIT_TARGETS) {
340
+ ruleLineSets[bucket] = new Set(files[bucket].filter(line => line !== ''));
341
+ }
342
+ const results = {};
343
+ for (const { bucket } of ignore_split_1.IGNORE_SPLIT_TARGETS) {
344
+ results[bucket] = processFile(bucket, files[bucket], ruleLineSets[COMPLEMENT[bucket]]);
345
+ }
346
+ /**
347
+ * 建立 groups[分類][主題] = 行陣列(依原始順序)
348
+ * Build groups[bucket][topic] = line arrays (in original order)
349
+ */
350
+ const groups = {};
351
+ for (const bucket of ignore_split_1.EMITTED_BUCKETS) {
352
+ groups[bucket] = Object.fromEntries(ignore_split_1.TOPICS.map(({ id }) => [id, []]));
353
+ }
354
+ const emittedGen = new Set();
355
+ for (const { bucket: file } of ignore_split_1.IGNORE_SPLIT_TARGETS) {
356
+ const { lines, assign } = results[file];
357
+ for (let i = 0; i < lines.length; i++) {
358
+ const current = assign[i];
359
+ if (!current || current.kind === EnumIgnoreSplitLineKind.Dropped) {
360
+ continue;
361
+ }
362
+ /**
363
+ * 共用規則只在 git 通過時寫入(避免 git / npm 各推一次造成重複)
364
+ * Shared rules are written only during the git pass (to avoid pushing once per source file)
365
+ */
366
+ if (current.bucket === 'shared' && file === 'npm') {
367
+ continue;
368
+ }
369
+ if (current.kind === EnumIgnoreSplitLineKind.Gen) {
370
+ const key = `${current.bucket}|${current.topic}|${current.genName}`;
371
+ if (emittedGen.has(key)) {
372
+ continue;
373
+ }
374
+ emittedGen.add(key);
375
+ groups[current.bucket][current.topic].push(`# %gen:${current.genName}%`);
376
+ continue;
377
+ }
378
+ groups[current.bucket][current.topic].push(lines[i]);
379
+ }
380
+ }
381
+ const written = new Set();
382
+ for (const bucket of ignore_split_1.EMITTED_BUCKETS) {
383
+ for (const { id: topic, zh, en } of ignore_split_1.TOPICS) {
384
+ const content = groups[bucket][topic];
385
+ const path = (0, ignore_split_1.getSplitFragmentPath)(bucket, topic);
386
+ if (content.length === 0) {
387
+ /**
388
+ * 該分類 × 主題已無內容:刪除舊檔,避免組合腳本讀到過期片段
389
+ * This bucket × topic is now empty: remove the stale file so the compose script cannot read outdated content
390
+ */
391
+ if ((0, fs_1.existsSync)(path)) {
392
+ (0, fs_1.unlinkSync)(path);
393
+ }
394
+ continue;
395
+ }
396
+ const header = `# ${zh} / ${en} · ${BUCKET_LABEL[bucket]}`;
397
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true });
398
+ (0, fs_1.writeFileSync)(path, [header, ...content].join('\n') + '\n', 'utf8');
399
+ written.add(path);
400
+ report.fragments[`${bucket}/${topic}`] = content.length;
401
+ }
402
+ }
403
+ /**
404
+ * other:不輸出的冗餘與重複規則,僅留存供稽核
405
+ * other: duplicated and redundant rules, kept for auditing only
406
+ */
407
+ {
408
+ const content = [
409
+ '# 其他:不輸出的重複與冗餘規則 / other: duplicated & redundant rules (never emitted)',
410
+ '# 本目錄規則不會進入 out/gitignore 或 out/npmignore;僅留存供稽核 / these rules are never emitted into out/gitignore or out/npmignore; kept for auditing only',
411
+ '# 重複語法(測試矩陣、*.map…)改由共用輔助產生,見 test/scripts/lib/ignore-split.ts / repetitive matrices are generated by the shared helper, see test/scripts/lib/ignore-split.ts',
412
+ '',
413
+ '# git 專用檔:已被更廣泛的規則涵蓋 / gitignore source: covered by a broader rule',
414
+ ...droppedLines(report.dropped.redundant, 'git'),
415
+ '',
416
+ '# npm 發布專用檔:已被更廣泛的規則涵蓋 / npmignore source: covered by a broader rule',
417
+ ...droppedLines(report.dropped.redundant, 'npm'),
418
+ '',
419
+ '# git 專用檔中重複出現 / duplicated in the gitignore source',
420
+ ...droppedLines(report.dropped.dup, 'git'),
421
+ '',
422
+ '# npm 發布專用檔中重複出現 / duplicated in the npmignore source',
423
+ ...droppedLines(report.dropped.dup, 'npm'),
424
+ ];
425
+ const path = (0, ignore_split_1.getSplitFragmentPath)('other', '90-duplicates');
426
+ (0, fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true });
427
+ (0, fs_1.writeFileSync)(path, content.join('\n') + '\n', 'utf8');
428
+ written.add(path);
429
+ }
430
+ /**
431
+ * 清理未重寫的片段檔(主題改名或刪除後的殘留),
432
+ * 以逐檔 unlink 取代整目錄刪除,避免破壞性操作
433
+ * Remove fragment files not rewritten by this run (leftovers after a topic
434
+ * rename or removal); per-file unlink instead of a destructive directory wipe
435
+ */
436
+ for (const bucket of [...ignore_split_1.EMITTED_BUCKETS, 'other']) {
437
+ const dir = (0, path_1.join)(ignore_split_1.SPLIT_ROOT, bucket);
438
+ if (!(0, fs_1.existsSync)(dir)) {
439
+ continue;
440
+ }
441
+ for (const entry of (0, fs_1.readdirSync)(dir)) {
442
+ if (!entry.endsWith('.txt')) {
443
+ continue;
444
+ }
445
+ const path = (0, path_1.join)(dir, entry);
446
+ if (!written.has(path)) {
447
+ (0, fs_1.unlinkSync)(path);
448
+ }
449
+ }
450
+ }
451
+ console.log(JSON.stringify({ fragments: report.fragments, gen: report.gen, dropped: report.dropped }, null, 2));
452
+ }
453
+ main();
454
+ //# sourceMappingURL=split-ignore-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split-ignore-files.js","sourceRoot":"","sources":["split-ignore-files.ts"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,2BAAiG;AACjG,+BAAqC;AACrC,sCAAmC;AAMnC,qDAO4B;AAE5B;;;;GAIG;AACH,MAAM,YAAY,GAA8C;IAC/D,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,6BAA6B;IAClC,MAAM,EAAE,eAAe;CACvB,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,SAAS,GAA2B;IACzC,eAAe,EAAE,0CAA0C;IAC3D,aAAa,EAAE,oCAAoC;IACnD,WAAW,EAAE,kCAAkC;IAC/C,qBAAqB,EAAE,kDAAkD;IACzE,iBAAiB,EAAE,6DAA6D;IAChF,oBAAoB,EAAE,kDAAkD;IACxE,sBAAsB,EAAE,kDAAkD;IAC1E,oBAAoB,EAAE,oDAAoD;CAC1E,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,GAA+D;IAC9E,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;CACV,CAAC;AAEF;;;GAGG;AACH,MAAM,KAAK,GAAoC;IAC9C,CAAC,wBAAwB,EAAE,WAAW,CAAC;IACvC,CAAC,eAAe,EAAE,WAAW,CAAC;IAC9B,CAAC,6BAA6B,EAAE,YAAY,CAAC;IAC7C;;;;;;OAMG;IACH,CAAC,aAAa,EAAE,YAAY,CAAC;IAC7B,CAAC,IAAI,EAAE,cAAc,CAAC;IACtB;;;;;OAKG;IACH,CAAC,UAAU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pC,CAAC;YACA,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAC3B,CAAC;gBACA,SAAS;YACV,CAAC;YAED,MAAM,IAAI,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YAE9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EACtB,CAAC;gBACA,IAAA,eAAU,EAAC,IAAI,CAAC,CAAC;YAClB,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACjH,CAAC;AAED,IAAI,EAAE,CAAC","sourcesContent":["/**\n * 將 file/gitignore / file/npmignore 分割為 test/fixtures/split/ 的分類片段\n * Split file/gitignore & file/npmignore into classified fragments under test/fixtures/split/\n *\n * 單一事實來源:主題({@link TOPICS})、分類 ↔ 檔名({@link IGNORE_SPLIT_TARGETS})、\n * 共用輔助區塊({@link IGNORE_SPLIT_GENERATORS})與片段路徑慣例({@link getSplitFragmentPath})\n * 皆引用 ./lib/ignore-split;本檔只保留分類邏輯本身。\n *\n * Single source of truth: topics ({@link TOPICS}), bucket ↔ file name\n * ({@link IGNORE_SPLIT_TARGETS}), shared generated blocks\n * ({@link IGNORE_SPLIT_GENERATORS}), and the fragment path convention\n * ({@link getSplitFragmentPath}) all come from ./lib/ignore-split; this script\n * only owns the classification logic itself.\n *\n * 分類流程:比對主題 → 命中共用輔助的重複語法改寫為佔位行 → 同檔重複與冗餘規則\n * 捨棄(寫入 other/)→ 段落註解併入下一個規則行的主題 → 依分類與主題寫出片段。\n *\n * Classification flow: match the topic → replace repeated matrices covered by a\n * shared generator with a placeholder line → drop same-file duplicates and\n * redundant rules (recorded in other/) → attach each section comment to the\n * topic of the following rule line → write out fragments by bucket and topic.\n *\n * 規格語意(必須保留):`x/` 只針對目錄、`/x` 只錨定根目錄,兩者與 `x` 皆為\n * 不同規則;本檔所有比對(共用判定、同檔重複、輔助產生、冗餘判定)都以完整\n * 字串進行,不做任何正規化;冗餘表只允許「廣義規則的匹配集合嚴格包含該行」。\n *\n * Pattern semantics (must be preserved): `x/` targets directories only and `/x`\n * anchors to the root, so both differ from `x`; every comparison in this script\n * (shared detection, same-file duplicates, generator matching, redundancy) uses\n * the full string with no normalization, and the redundancy table only allows a\n * broader rule whose match set strictly contains the line.\n *\n * 執行 / run: tsx packages/@yarn-tool/static-file/test/scripts/split-ignore-files.ts\n * 輸出 / output: test/fixtures/split/{git,npm,shared,other}/*.txt\n */\nimport { existsSync, mkdirSync, readFileSync, readdirSync, unlinkSync, writeFileSync } from 'fs';\nimport { dirname, join } from 'path';\nimport { __ROOT } from '../__root';\nimport type {\n\tIIgnoreSplitEmittedBucket,\n\tIIgnoreSplitTargetBucket,\n\tIIgnoreSplitTopicId,\n} from './lib/ignore-split';\nimport {\n\tEMITTED_BUCKETS,\n\tIGNORE_SPLIT_GENERATORS,\n\tIGNORE_SPLIT_TARGETS,\n\tSPLIT_ROOT,\n\tTOPICS,\n\tgetSplitFragmentPath,\n} from './lib/ignore-split';\n\n/**\n * 片段檔標頭中的分類名稱(僅輸出分類需要標頭;other 有固定檔頭不經此表)\n * Bucket names shown in fragment headers (only emitted buckets need a header;\n * other has its own fixed header and does not use this table)\n */\nconst BUCKET_LABEL: Record<IIgnoreSplitEmittedBucket, string> = {\n\tgit: 'git 專用 / git only',\n\tnpm: 'npm 發布專用 / npm publish only',\n\tshared: '兩類共用 / shared',\n};\n\n/**\n * 冗餘規則:已被更廣泛的規則涵蓋,不輸出到組合結果,僅記錄於 other/ 供稽核\n * Redundant rules: covered by a broader rule, never emitted into the composed\n * output, only recorded in other/ for auditing\n *\n * 鍵為 `<分類>:<規則>`;只有該分類專屬(非共用)的行才會比對。\n * Keyed as `<bucket>:<rule>`; only bucket-specific (non-shared) lines are matched.\n *\n * 「涵蓋」指語意上的匹配集合包含(例:`coverage` 匹配任意層級,故包含只針對\n * 根目錄的 `/coverage`),絕非字串相同或正規化後相同;`x/`(只針對目錄)與\n * `/x`(只錨定根目錄)都是獨立規則,每條的廣義規則必須仍然存在於同一份來源\n * 檔,否則該條不得列為冗餘。\n * \"Covered\" means semantic containment of the match sets (e.g. `coverage`\n * matches any depth and therefore contains root-anchored `/coverage`), never\n * string equality or equality after normalization; `x/` (directories only) and\n * `/x` (root-anchored only) are rules in their own right, and each broader rule\n * must still exist in the same source file or the entry must not be listed.\n */\nconst REDUNDANT: Record<string, string> = {\n\t'git:/coverage': '已被 `coverage` 涵蓋 / covered by `coverage`',\n\t'git:/.next/': '已被 `.next` 涵蓋 / covered by `.next`',\n\t'git:/out/': '已被 `/out` 涵蓋 / covered by `/out`',\n\t'git:**/node_modules': '已被 `node_modules` 涵蓋 / covered by `node_modules`',\n\t'git:test/temp*/': '已被輔助產生的 `test/temp*` 涵蓋 / covered by generated `test/temp*`',\n\t'npm:/node_modules/': '已被 `node_modules` 涵蓋 / covered by `node_modules`',\n\t'npm:**/node_modules/': '已被 `node_modules` 涵蓋 / covered by `node_modules`',\n\t'npm:jest.config.js': '已被 `jest.config.*` 涵蓋 / covered by `jest.config.*`',\n};\n\n/**\n * 每個目標分類的「另一份」來源分類;共用規則即以「同時出現在另一份」判定\n * The complementary source bucket of each target; a rule counts as shared when\n * it also appears in that other source\n */\nconst COMPLEMENT: Record<IIgnoreSplitTargetBucket, IIgnoreSplitTargetBucket> = {\n\tgit: 'npm',\n\tnpm: 'git',\n};\n\n/**\n * 主題分類規則(依序比對,第一個符合者勝出)\n * Topic rules (checked in order; the first match wins)\n */\nconst RULES: [RegExp, IIgnoreSplitTopicId][] = [\n\t[/^!\\*\\.d\\.(ts|mts|cts)$/, '05-source'],\n\t[/^!\\/src\\/\\*\\*/, '05-source'],\n\t[/^!\\/(README|CHANGELOG)\\.md$/, '10-project'],\n\t/**\n\t * `!.github` 必須排在「巢狀 .github 排除規則」(原檔 163 < 201)之前,\n\t * 否則嵌套 .github 會被白名單重新放行;`!/.github`(202)維持 99。\n\t * `!.github` must stay before the nested-.github exclusion rule (original\n\t * line 163 < 201) so nested .github remains re-excluded; `!/.github` (202)\n\t * stays in 99.\n\t */\n\t[/^!\\.github$/, '10-project'],\n\t[/^!/, '99-whitelist'],\n\t/**\n\t * 根目錄隱藏檔規則須早於 `!*.d.ts`(原檔 17 < 26),\n\t * 否則根目錄的 *.d.ts 會被後置的 `/.*` 重新排除。\n\t * The root hidden-file rule must precede `!*.d.ts` (original line 17 < 26),\n\t * otherwise root *.d.ts files get re-excluded by the later `/.*`.\n\t */\n\t[/^\\/\\.\\*$/, '01-hidden'],\n\t[/^\\*\\.ts$/, '05-source'],\n\t[/^\\/bin\\//, '05-source'],\n\t/**\n\t * 環境與 IDE 規則須早於測試規則:`.env.test.local` 含 `.test.` 但並非測試檔\n\t * Environment and IDE rules must precede the test rules: `.env.test.local`\n\t * contains `.test.` but is not a test file\n\t */\n\t[/^\\.env/, '40-env'],\n\t[/^\\/certificates$/, '40-env'],\n\t[/\\.pem$/, '40-env'],\n\t[/vercel|\\.nowignore|^\\/?now\\.json$/, '40-env'],\n\t[/^\\.?nvmrc$|^\\.node-version$/, '40-env'],\n\t[/^\\.?(idea|vscode)$/, '30-ide'],\n\t[/\\.(suo|ntvs\\*|njsproj|sln|sw\\?)$/, '30-ide'],\n\t[/^(clinerules|kilocode|cline|junie|gemini|copilot|claude|agents|aiassistant)$/, '30-ide'],\n\t[/intellij/, '30-ide'],\n\t[/^(tests?|__tests?__|__mocks__|__snapshots__|__fixtures__|__file_snapshots__)$/, '20-test'],\n\t[/^\\/?(tests?|__tests?__|__mocks__|__snapshots__|__fixtures__|fixture)\\//, '20-test'],\n\t[/\\/test\\//, '20-test'],\n\t[/\\.(spec|test|node-spec|node-test|stories)\\./, '20-test'],\n\t[/^\\.gitkeep$/, '20-test'],\n\t[/jest|karma|mocha|nyc|coverage/i, '20-test'],\n\t[/\\.snap(shot)?$/, '20-test'],\n\t[/\\/stories\\//, '20-test'],\n\t[/^\\.DS_Store$/, '90-misc'],\n\t[/^~ci\\.|^\\/~\\*/, '90-misc'],\n\t[/\\.stackdump$|^\\*\\.bak$|^\\*\\.old$/, '90-misc'],\n\t[/^\\.opt-(in|out)$|^\\*\\.stat$|^\\.codenomad$|^\\.logs$|^\\.agentbridge$|^openspec\\/$|^cz-adapter$/, '90-misc'],\n\t[/.*/, '10-project'],\n];\n\n/**\n * 每個輔助區塊涵蓋的規則集合(排除空行與說明註解),\n * 用於在來源檔中找出該以佔位行取代的重複行\n * The rule set covered by each generator (blank lines and description comments\n * excluded), used to find the repeated source lines that a placeholder replaces\n */\nconst GENERATOR_RULE_SETS: Record<string, ReadonlySet<string>> = Object.fromEntries(\n\tObject.entries(IGNORE_SPLIT_GENERATORS).map(([name, { generate }]) => [\n\t\tname,\n\t\tnew Set(generate().filter(line => line !== '' && !line.startsWith('#'))),\n\t]),\n);\n\n/**\n * 分割統計,僅供執行結束時輸出 / Split statistics, printed at the end of a run\n */\ninterface ISplitReport\n{\n\tfragments: Record<string, number>;\n\tgen: Record<string, number>;\n\tdropped: {\n\t\tredundant: { bucket: IIgnoreSplitTargetBucket; line: string; note: string }[];\n\t\tdup: { bucket: IIgnoreSplitTargetBucket; line: string }[];\n\t};\n}\n\nconst report: ISplitReport = {\n\tfragments: {},\n\tgen: {},\n\tdropped: {\n\t\tredundant: [],\n\t\tdup: [],\n\t},\n};\n\n/**\n * 行指派的種類:以 enum 取代字串聯合,避免字串筆誤;\n * 字串值與原字面值一致,report 與 JSON 輸出不受影響\n * The kind of a line assignment: an enum instead of a string union, so a typo\n * cannot slip in; the string values match the previous literals, keeping the\n * report and JSON output unchanged\n */\nenum EnumIgnoreSplitLineKind\n{\n\tComment = 'comment',\n\tGen = 'gen',\n\tDropped = 'dropped',\n\tFragment = 'fragment',\n}\n\n/**\n * 單一行的分類指派(判別聯合,依 {@link EnumIgnoreSplitLineKind} 收斂)\n * The classification assigned to a single line (a discriminated union narrowed by {@link EnumIgnoreSplitLineKind})\n */\ntype ILineAssignment =\n\t| { kind: EnumIgnoreSplitLineKind.Comment }\n\t| { kind: EnumIgnoreSplitLineKind.Gen; bucket: IIgnoreSplitTargetBucket; topic: IIgnoreSplitTopicId; genName: string }\n\t| { kind: EnumIgnoreSplitLineKind.Dropped; topic: IIgnoreSplitTopicId }\n\t| { kind: EnumIgnoreSplitLineKind.Fragment; bucket: IIgnoreSplitEmittedBucket; topic: IIgnoreSplitTopicId };\n\n/**\n * 已解析的行指派:第二輪會把每個段落註解改為 Fragment,\n * 故回傳型別不再包含 Comment,後續只會遇到 Gen / Dropped / Fragment\n * Resolved line assignment: the second pass converts every section comment into\n * a Fragment, so the returned type no longer includes Comment and later stages\n * only see Gen / Dropped / Fragment\n */\ntype IResolvedAssignment = Exclude<ILineAssignment, { kind: EnumIgnoreSplitLineKind.Comment }>;\n\n/**\n * 判斷單一規則行所屬的主題\n * Decide which topic a single rule line belongs to\n */\nfunction classifyTopic(line: string): IIgnoreSplitTopicId\n{\n\tfor (const [re, topic] of RULES)\n\t{\n\t\tif (re.test(line))\n\t\t{\n\t\t\treturn topic;\n\t\t}\n\t}\n\n\treturn '10-project';\n}\n\n/**\n * 讀取來源檔並去除結尾空行 / Read a source file and strip its trailing blank lines\n */\nfunction readLines(path: string): string[]\n{\n\tconst lines = readFileSync(path, 'utf8').split(/\\r?\\n/);\n\n\twhile (lines.length > 0 && lines[lines.length - 1] === '')\n\t{\n\t\tlines.pop();\n\t}\n\n\treturn lines;\n}\n\n/**\n * 判斷單一來源檔每一行的分類與主題\n * Decide the bucket and topic of every line in one source file\n *\n * @param file - 來源所屬的目標分類 / The target bucket of the source file\n * @param lines - 來源檔的所有行 / Every line of the source file\n * @param otherSet - 另一份來源檔的非空行集合(共用判定基準)/ The non-blank line set of the complementary source (the shared-bucket basis)\n */\nfunction processFile(\n\tfile: IIgnoreSplitTargetBucket,\n\tlines: string[],\n\totherSet: ReadonlySet<string>,\n): { lines: string[]; assign: (IResolvedAssignment | null)[] }\n{\n\tconst seen = new Set<string>();\n\tconst assign = new Array<ILineAssignment | null>(lines.length).fill(null);\n\n\tfor (let i = 0; i < lines.length; i++)\n\t{\n\t\tconst line = lines[i];\n\n\t\tif (line === '')\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\t/**\n\t\t * 段落註解為「# 後接空白」的形式;`#jest.config.js` 這類被註解掉的規則\n\t\t * 不符合此形式,仍視為規則行走一般分類\n\t\t * A section comment is `#` followed by whitespace; a commented-out rule\n\t\t * like `#jest.config.js` does not match and is classified as a rule line\n\t\t */\n\t\tif (/^#\\s/.test(line))\n\t\t{\n\t\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Comment };\n\t\t\tcontinue;\n\t\t}\n\n\t\t/**\n\t\t * 規則行:同時出現在另一份來源檔即為共用分類\n\t\t * A rule line that also appears in the other source belongs to the shared bucket\n\t\t */\n\t\tconst bucket: IIgnoreSplitEmittedBucket = otherSet.has(line) ? 'shared' : file;\n\n\t\t/**\n\t\t * 1. 命中共用輔助的重複語法 → 以佔位行取代\n\t\t * 1. A repeated matrix covered by a shared generator → replaced by a placeholder\n\t\t */\n\t\tlet genName: string | undefined;\n\n\t\tif (bucket === file)\n\t\t{\n\t\t\tfor (const [name, ruleSet] of Object.entries(GENERATOR_RULE_SETS))\n\t\t\t{\n\t\t\t\tconst generator = IGNORE_SPLIT_GENERATORS[name];\n\n\t\t\t\tif (generator.bucket === file && ruleSet.has(line))\n\t\t\t\t{\n\t\t\t\t\tgenName = name;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (genName)\n\t\t{\n\t\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Gen, bucket: file, topic: IGNORE_SPLIT_GENERATORS[genName].topic, genName };\n\t\t\treport.gen[genName] = (report.gen[genName] || 0) + 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst topic = classifyTopic(line);\n\n\t\t/**\n\t\t * 2. 同檔內重複出現 → other\n\t\t * 2. Repeated within the same file → other\n\t\t */\n\t\tif (seen.has(line))\n\t\t{\n\t\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Dropped, topic };\n\t\t\treport.dropped.dup.push({ bucket: file, line });\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(line);\n\n\t\t/**\n\t\t * 3. 冗餘(已被更廣泛的規則涵蓋)→ other\n\t\t * 3. Redundant (covered by a broader rule) → other\n\t\t */\n\t\tconst redundantNote = REDUNDANT[`${file}:${line}`];\n\n\t\tif (bucket === file && redundantNote)\n\t\t{\n\t\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Dropped, topic };\n\t\t\treport.dropped.redundant.push({ bucket: file, line, note: redundantNote });\n\t\t\tcontinue;\n\t\t}\n\n\t\t/**\n\t\t * 4. 一般規則 → 分類到 fragment\n\t\t * 4. An ordinary rule → classified into a fragment\n\t\t */\n\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Fragment, bucket, topic };\n\t}\n\n\t/**\n\t * 段落註解:主題採用下一個規則行的主題;分類採用同主題且會輸出的規則行。\n\t * 規則行被佔位或丟棄時,繼續向後找同主題的下一個輸出行。\n\t * A section comment adopts the topic of the next rule line and the bucket of\n\t * an emitted line of that topic; when that line is dropped or replaced by a\n\t * placeholder, it keeps scanning forward for the next emitted line of the\n\t * same topic.\n\t */\n\tfor (let i = 0; i < lines.length; i++)\n\t{\n\t\tconst current = assign[i];\n\n\t\tif (!current || current.kind !== EnumIgnoreSplitLineKind.Comment)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\t/**\n\t\t * git 檔案首行的官方說明保留為 00-header 片段\n\t\t * The official note on line 1 of the gitignore becomes the 00-header fragment\n\t\t */\n\t\tif (i === 0 && file === 'git')\n\t\t{\n\t\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Fragment, bucket: 'git', topic: '00-header' };\n\t\t\tcontinue;\n\t\t}\n\n\t\tlet topic: IIgnoreSplitTopicId | undefined;\n\n\t\tfor (let j = i + 1; j < lines.length; j++)\n\t\t{\n\t\t\tconst next = assign[j];\n\n\t\t\tif (!next || next.kind === EnumIgnoreSplitLineKind.Comment)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\ttopic = next.topic;\n\t\t\tbreak;\n\t\t}\n\n\t\tconst resolvedTopic = topic ?? '90-misc';\n\t\tlet bucket: IIgnoreSplitEmittedBucket = file;\n\n\t\tfor (let j = i + 1; j < lines.length; j++)\n\t\t{\n\t\t\tconst next = assign[j];\n\n\t\t\tif (!next || next.kind !== EnumIgnoreSplitLineKind.Fragment || next.topic !== resolvedTopic)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tbucket = next.bucket;\n\t\t\tbreak;\n\t\t}\n\n\t\tassign[i] = { kind: EnumIgnoreSplitLineKind.Fragment, bucket, topic: resolvedTopic };\n\t}\n\n\treturn { lines, assign: assign as (IResolvedAssignment | null)[] };\n}\n\n/**\n * 依分類取出被丟棄的規則行(供 other/ 片段分段列出)\n * Collect the dropped rule lines of one bucket (for the sections of other/)\n */\nfunction droppedLines(\n\tentries: readonly { bucket: IIgnoreSplitTargetBucket; line: string }[],\n\tbucket: IIgnoreSplitTargetBucket,\n): string[]\n{\n\treturn entries.filter(entry => entry.bucket === bucket).map(entry => entry.line);\n}\n\n/**\n * 腳本進入點:分割兩份來源檔並寫出分類片段\n * Script entry: split both source files and write out the classified fragments\n */\nfunction main(): void\n{\n\t/**\n\t * 讀取兩份來源檔(檔名來自 {@link IGNORE_SPLIT_TARGETS})\n\t * Read both source files (file names come from {@link IGNORE_SPLIT_TARGETS})\n\t */\n\tconst files = {} as Record<IIgnoreSplitTargetBucket, string[]>;\n\n\tfor (const { bucket, fileName } of IGNORE_SPLIT_TARGETS)\n\t{\n\t\tfiles[bucket] = readLines(join(__ROOT, 'file', fileName));\n\t}\n\n\tconst ruleLineSets = {} as Record<IIgnoreSplitTargetBucket, ReadonlySet<string>>;\n\n\tfor (const { bucket } of IGNORE_SPLIT_TARGETS)\n\t{\n\t\truleLineSets[bucket] = new Set(files[bucket].filter(line => line !== ''));\n\t}\n\n\tconst results = {} as Record<IIgnoreSplitTargetBucket, ReturnType<typeof processFile>>;\n\n\tfor (const { bucket } of IGNORE_SPLIT_TARGETS)\n\t{\n\t\tresults[bucket] = processFile(bucket, files[bucket], ruleLineSets[COMPLEMENT[bucket]]);\n\t}\n\n\t/**\n\t * 建立 groups[分類][主題] = 行陣列(依原始順序)\n\t * Build groups[bucket][topic] = line arrays (in original order)\n\t */\n\tconst groups = {} as Record<IIgnoreSplitEmittedBucket, Record<IIgnoreSplitTopicId, string[]>>;\n\n\tfor (const bucket of EMITTED_BUCKETS)\n\t{\n\t\tgroups[bucket] = Object.fromEntries(TOPICS.map(({ id }) => [id, [] as string[]])) as Record<IIgnoreSplitTopicId, string[]>;\n\t}\n\n\tconst emittedGen = new Set<string>();\n\n\tfor (const { bucket: file } of IGNORE_SPLIT_TARGETS)\n\t{\n\t\tconst { lines, assign } = results[file];\n\n\t\tfor (let i = 0; i < lines.length; i++)\n\t\t{\n\t\t\tconst current = assign[i];\n\n\t\t\tif (!current || current.kind === EnumIgnoreSplitLineKind.Dropped)\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t/**\n\t\t\t * 共用規則只在 git 通過時寫入(避免 git / npm 各推一次造成重複)\n\t\t\t * Shared rules are written only during the git pass (to avoid pushing once per source file)\n\t\t\t */\n\t\t\tif (current.bucket === 'shared' && file === 'npm')\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (current.kind === EnumIgnoreSplitLineKind.Gen)\n\t\t\t{\n\t\t\t\tconst key = `${current.bucket}|${current.topic}|${current.genName}`;\n\n\t\t\t\tif (emittedGen.has(key))\n\t\t\t\t{\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\temittedGen.add(key);\n\t\t\t\tgroups[current.bucket][current.topic].push(`# %gen:${current.genName}%`);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tgroups[current.bucket][current.topic].push(lines[i]);\n\t\t}\n\t}\n\n\tconst written = new Set<string>();\n\n\tfor (const bucket of EMITTED_BUCKETS)\n\t{\n\t\tfor (const { id: topic, zh, en } of TOPICS)\n\t\t{\n\t\t\tconst content = groups[bucket][topic];\n\t\t\tconst path = getSplitFragmentPath(bucket, topic);\n\n\t\t\tif (content.length === 0)\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * 該分類 × 主題已無內容:刪除舊檔,避免組合腳本讀到過期片段\n\t\t\t\t * This bucket × topic is now empty: remove the stale file so the compose script cannot read outdated content\n\t\t\t\t */\n\t\t\t\tif (existsSync(path))\n\t\t\t\t{\n\t\t\t\t\tunlinkSync(path);\n\t\t\t\t}\n\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst header = `# ${zh} / ${en} · ${BUCKET_LABEL[bucket]}`;\n\n\t\t\tmkdirSync(dirname(path), { recursive: true });\n\t\t\twriteFileSync(path, [header, ...content].join('\\n') + '\\n', 'utf8');\n\n\t\t\twritten.add(path);\n\t\t\treport.fragments[`${bucket}/${topic}`] = content.length;\n\t\t}\n\t}\n\n\t/**\n\t * other:不輸出的冗餘與重複規則,僅留存供稽核\n\t * other: duplicated and redundant rules, kept for auditing only\n\t */\n\t{\n\t\tconst content = [\n\t\t\t'# 其他:不輸出的重複與冗餘規則 / other: duplicated & redundant rules (never emitted)',\n\t\t\t'# 本目錄規則不會進入 out/gitignore 或 out/npmignore;僅留存供稽核 / these rules are never emitted into out/gitignore or out/npmignore; kept for auditing only',\n\t\t\t'# 重複語法(測試矩陣、*.map…)改由共用輔助產生,見 test/scripts/lib/ignore-split.ts / repetitive matrices are generated by the shared helper, see test/scripts/lib/ignore-split.ts',\n\t\t\t'',\n\t\t\t'# git 專用檔:已被更廣泛的規則涵蓋 / gitignore source: covered by a broader rule',\n\t\t\t...droppedLines(report.dropped.redundant, 'git'),\n\t\t\t'',\n\t\t\t'# npm 發布專用檔:已被更廣泛的規則涵蓋 / npmignore source: covered by a broader rule',\n\t\t\t...droppedLines(report.dropped.redundant, 'npm'),\n\t\t\t'',\n\t\t\t'# git 專用檔中重複出現 / duplicated in the gitignore source',\n\t\t\t...droppedLines(report.dropped.dup, 'git'),\n\t\t\t'',\n\t\t\t'# npm 發布專用檔中重複出現 / duplicated in the npmignore source',\n\t\t\t...droppedLines(report.dropped.dup, 'npm'),\n\t\t];\n\n\t\tconst path = getSplitFragmentPath('other', '90-duplicates');\n\n\t\tmkdirSync(dirname(path), { recursive: true });\n\t\twriteFileSync(path, content.join('\\n') + '\\n', 'utf8');\n\n\t\twritten.add(path);\n\t}\n\n\t/**\n\t * 清理未重寫的片段檔(主題改名或刪除後的殘留),\n\t * 以逐檔 unlink 取代整目錄刪除,避免破壞性操作\n\t * Remove fragment files not rewritten by this run (leftovers after a topic\n\t * rename or removal); per-file unlink instead of a destructive directory wipe\n\t */\n\tfor (const bucket of [...EMITTED_BUCKETS, 'other'])\n\t{\n\t\tconst dir = join(SPLIT_ROOT, bucket);\n\n\t\tif (!existsSync(dir))\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const entry of readdirSync(dir))\n\t\t{\n\t\t\tif (!entry.endsWith('.txt'))\n\t\t\t{\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst path = join(dir, entry);\n\n\t\t\tif (!written.has(path))\n\t\t\t{\n\t\t\t\tunlinkSync(path);\n\t\t\t}\n\t\t}\n\t}\n\n\tconsole.log(JSON.stringify({ fragments: report.fragments, gen: report.gen, dropped: report.dropped }, null, 2));\n}\n\nmain();\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /**
5
+ * Script to extract staticFile values from const.ts
6
+ * and add them as !<file> entries to .npmignore and .gitignore
7
+ *
8
+ * 腳本從 const.ts 提取 staticFile 值
9
+ * 並將它們作為 !<file> 條目加入 .npmignore 和 .gitignore
10
+ *
11
+ * 讀取與保存皆透過 IgnoreFile(行陣列模型:支援陣列內容,EOF 換行自動還原)
12
+ * Reading and saving both go through IgnoreFile (the line model: array content
13
+ * is supported and the EOF newline is restored automatically)
14
+ */
15
+ const path = tslib_1.__importStar(require("path"));
16
+ const IgnoreFile_1 = require("@yarn-tool/ignore/lib/IgnoreFile");
17
+ const __root_1 = require("../__root");
18
+ const const_1 = require("../../lib/const");
19
+ /**
20
+ * 生成區段的起始標記,用於識別並替換上一次產生的內容
21
+ * Start marker of the generated section, used to locate and replace the previous run's output
22
+ */
23
+ const HEADER = '# Static files from const.ts';
24
+ /**
25
+ * 生成區段的結束標記
26
+ * End marker of the generated section
27
+ */
28
+ const FOOTER = '# END Static files from const.ts';
29
+ /**
30
+ * 收集三份清單中所有不重複的 staticFile 來源路徑
31
+ * Collect every unique staticFile source path across the three lists
32
+ *
33
+ * 以 includes 去重,確保 ignore 檔中同一來源只出現一次
34
+ * Dedupe with includes so each source appears only once in the ignore file
35
+ *
36
+ * @returns 靜態樣板的來源路徑陣列 / Array of static template source paths
37
+ */
38
+ function extractStaticFiles() {
39
+ const staticFiles = [];
40
+ /**
41
+ * 三份清單的內容可能重疊(例如同一樣板被不同情境引用),
42
+ * 合併後再統一去重
43
+ * The three lists may overlap (e.g. one template referenced by different scenarios),
44
+ * so merge first and dedupe afterwards
45
+ */
46
+ const allArrays = [
47
+ ...const_1.defaultCopyStaticFiles,
48
+ ...const_1.defaultCopyStaticFilesRootOnly,
49
+ ...const_1.defaultCopyStaticFilesWsRootOnly,
50
+ ];
51
+ for (const entry of allArrays) {
52
+ const staticFile = entry[1];
53
+ /**
54
+ * 已存在則跳過,避免 ignore 檔重複列出
55
+ * Skip when already collected to avoid duplicate entries in the ignore file
56
+ */
57
+ if (!staticFiles.includes(staticFile)) {
58
+ staticFiles.push(staticFile);
59
+ }
60
+ }
61
+ return staticFiles;
62
+ }
63
+ /**
64
+ * 重寫 ignore 檔中的生成區段
65
+ * Rewrite the generated section of an ignore file
66
+ *
67
+ * 先移除舊的 `!file/` 條目與標記區段,再重新寫入,
68
+ * 使腳本可重複執行(Idempotent)而不會不斷累加
69
+ * Old `!file/` entries and the marked section are removed before rewriting,
70
+ * so the script stays idempotent instead of appending forever
71
+ *
72
+ * @param filePath - .npmignore 或 .gitignore 的路徑 / Path to .npmignore or .gitignore
73
+ * @param staticFiles - 要排除的靜態樣板路徑 / Static template paths to whitelist
74
+ */
75
+ function updateIgnoreFile(filePath, staticFiles) {
76
+ /**
77
+ * 以 IgnoreFile 讀取:內容統一為行陣列,結尾空白行已由建構處理
78
+ * Read via IgnoreFile: content is normalized into a line array, with the trailing blanks already handled at construction
79
+ */
80
+ const ignoreFile = IgnoreFile_1.IgnoreFile.from(filePath, {
81
+ endCount: true,
82
+ });
83
+ const lines = [];
84
+ lines.push('');
85
+ lines.push(HEADER);
86
+ lines.push(...staticFiles);
87
+ lines.push(FOOTER);
88
+ lines.push('');
89
+ ignoreFile.addList(lines, true);
90
+ ignoreFile.outputFile(filePath);
91
+ }
92
+ /**
93
+ * 腳本進入點:擷取清單並更新 .npmignore 與 .gitignore
94
+ * Script entry: extract the list and update .npmignore and .gitignore
95
+ */
96
+ function main() {
97
+ console.log('Extracting static files from imported module...');
98
+ const staticFiles = extractStaticFiles();
99
+ staticFiles.push('test/fixtures/out/');
100
+ staticFiles.push('test/fixtures/split/');
101
+ staticFiles.push('test/fixtures/out/**');
102
+ staticFiles.push('test/fixtures/split/**');
103
+ console.log(`Found ${staticFiles.length} static files:`);
104
+ const entries = staticFiles.sort().map(f => {
105
+ const entry = `!${f}`;
106
+ console.log(` ${entry}`);
107
+ return entry;
108
+ });
109
+ const npmIgnore = path.join(__root_1.__ROOT, '.npmignore');
110
+ const gitIgnore = path.join(__root_1.__ROOT, '.gitignore');
111
+ /**
112
+ * 兩個檔案採用同一套生成規則,先 npmignore 再 gitignore
113
+ * Both files share the same generated rules, npmignore first then gitignore
114
+ */
115
+ updateIgnoreFile(npmIgnore, entries);
116
+ console.log(`\nUpdated ${npmIgnore}`);
117
+ updateIgnoreFile(gitIgnore, entries);
118
+ console.log(`Updated ${gitIgnore}`);
119
+ }
120
+ main();
121
+ //# sourceMappingURL=update-npmignore-static-files.js.map