@yarn-tool/static-file 3.0.19 → 3.0.20

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 +56 -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
@@ -1,76 +1,175 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports._copyStaticFilesEntryCore = _copyStaticFilesEntryCore;
4
+ exports._copyStaticFilesEntryCoreCopy = _copyStaticFilesEntryCoreCopy;
3
5
  exports.copyStaticFilesEntry = copyStaticFilesEntry;
4
6
  const path_1 = require("path");
5
7
  const fs_extra_1 = require("fs-extra");
6
8
  const __root_1 = require("../__root");
7
9
  /**
8
- * Copy a single static file entry / 複製單個靜態檔案條目
10
+ * 解析單個靜態檔案條目的複製資訊 / Resolve copy info for a single static file entry
9
11
  *
10
- * Copies a single static file from the static root to the target directory.
11
- * 從靜態根目錄複製單個靜態檔案到目標目錄。
12
+ * 只做路徑解析與存在性檢查,不寫入任何檔案;真正的複製交給 _copyStaticFilesEntryCoreCopy。
13
+ * Only resolves paths and checks existence — nothing is written; the actual copy is done by _copyStaticFilesEntryCoreCopy.
12
14
  *
13
- * @param entry - The static file entry / 靜態檔案條目
14
- * @param entry.0 - targetFile: Target file path / 目標檔案路徑
15
- * @param entry.1 - staticFile: Source static file path / 來源靜態檔案路徑
16
- * @param entry.2 - detectFile: Optional file to check for existence / 可選的檢測檔案
15
+ * @param entry - 靜態檔案條目 / Static file entry
16
+ * @param entry.0 - targetFile:目標檔案路徑 / Target file path
17
+ * @param entry.1 - staticFile:來源靜態檔案路徑 / Source static file path
18
+ * @param entry.2 - detectFile:可選的檢測檔案 / Optional file to check for existence
17
19
  *
18
- * @param cwd - Current working directory / 當前工作目錄
19
- * @param staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)
20
- * @param overwrite - Whether to overwrite existing files (defaults to false) / 是否覆蓋已存在的檔案(預設為 false)
20
+ * @param cwd - 當前工作目錄 / Current working directory
21
+ * @param staticRoot - 靜態檔案根目錄(預設為套件根目錄)/ Root directory of static files (defaults to package root)
22
+ * @param overwrite - 是否覆蓋已存在的檔案(預設為 false)/ Whether to overwrite existing files (defaults to false)
21
23
  *
22
- * @returns true if file was copied, undefined if skipped (detect file exists) / 如果檔案已複製則返回 true,如果跳過(檢測檔案存在)則返回 undefined
23
- *
24
- * @throws {Error} When the source static file does not exist / 當來源靜態檔案不存在時
24
+ * @returns 解析後的複製資訊;被 detectFile 跳過時回傳 undefined / Resolved copy info, or undefined when skipped by detectFile
25
+ * @throws {Error} 當來源靜態檔案不存在時 / When the source static file does not exist
25
26
  *
26
27
  * @example
27
28
  * ```typescript
28
- * import { copyStaticFilesEntry } from '@yarn-tool/static-file';
29
+ * import { _copyStaticFilesEntryCore, _copyStaticFilesEntryCoreCopy } from '@yarn-tool/static-file/lib/copyStaticFilesEntry';
29
30
  *
30
- * // Copy a single file
31
- * // 複製單個檔案
32
- * const result = copyStaticFilesEntry(
31
+ * // 複製單個檔案 / Copy a single file
32
+ * const runtime = _copyStaticFilesEntryCore(
33
33
  * ['.gitignore', 'file/gitignore'],
34
34
  * '/path/to/project',
35
35
  * '/path/to/static/root',
36
- * false
36
+ * false,
37
37
  * );
38
38
  *
39
- * // With detect file - skips if detect file exists
40
- * // 使用檢測檔案 - 如果檢測檔案存在則跳過
41
- * const result = copyStaticFilesEntry(
39
+ * if (runtime)
40
+ * {
41
+ * _copyStaticFilesEntryCoreCopy(runtime);
42
+ * }
43
+ *
44
+ * // 使用檢測檔案:正式設定檔已存在時跳過 / With detect file: skip when the real config already exists
45
+ * _copyStaticFilesEntryCore(
42
46
  * ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],
43
- * '/path/to/project'
47
+ * '/path/to/project',
44
48
  * );
45
- * // Skips copy if tsconfig.json already exists in the project
46
- * // 如果 tsconfig.json 已存在於專案中則跳過複製
49
+ * // 專案已有 tsconfig.json 時回傳 undefined / Returns undefined when tsconfig.json already exists
47
50
  * ```
48
51
  */
49
- function copyStaticFilesEntry(entry, cwd, staticRoot = __root_1.__STATIC_ROOT, overwrite) {
52
+ function _copyStaticFilesEntryCore(entry, cwd, staticRoot = __root_1.__STATIC_ROOT, overwrite) {
50
53
  const [targetFile, staticFile, detectFile] = entry;
51
- // Check if detect file exists - skip copy if it does / 檢查檢測檔案是否存在 - 如果存在則跳過複製
54
+ /**
55
+ * 檢查檢測檔案 (detect file) 是否存在,存在即跳過複製
56
+ * Check if detect file exists - skip copy if it does
57
+ *
58
+ * 用於「範本檔」情境:專案已有正式設定檔時不應被樣板覆蓋
59
+ * For template scenarios: an existing real config file must not be overwritten by the template
60
+ */
52
61
  if (detectFile === null || detectFile === void 0 ? void 0 : detectFile.length) {
53
62
  const fc = (0, path_1.resolve)(cwd, detectFile);
54
63
  if ((0, fs_extra_1.existsSync)(fc)) {
55
64
  return;
56
65
  }
57
66
  }
58
- // Resolve source file path / 解析來源檔案路徑
67
+ /**
68
+ * 解析來源檔案路徑
69
+ * Resolve source file path
70
+ *
71
+ * 以靜態根目錄為基準,樣板路徑可為巢狀(如 file/test/…)
72
+ * Resolved against the static root; template paths may be nested (e.g. file/test/…)
73
+ */
59
74
  const fb = (0, path_1.resolve)(staticRoot, staticFile);
60
- // Verify source file exists / 驗證來源檔案是否存在
75
+ /**
76
+ * 驗證來源檔案是否存在
77
+ * Verify source file exists
78
+ *
79
+ * 來源缺失代表清單與 file/ 目錄不同步,應立即失敗而非複製出殘缺結果
80
+ * A missing source means the map is out of sync with file/; fail instead of producing a partial copy
81
+ */
61
82
  if (!(0, fs_extra_1.existsSync)(fb)) {
62
83
  throw new Error(`file not exists. ${fb}`);
63
84
  }
64
- // Resolve target file path / 解析目標檔案路徑
85
+ /**
86
+ * 解析目標檔案路徑
87
+ * Resolve target file path
88
+ */
65
89
  const fa = (0, path_1.resolve)(cwd, targetFile);
66
- // Ensure target directory exists / 確保目標目錄存在
67
- (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(fa));
68
- // Copy the file / 複製檔案
69
- (0, fs_extra_1.copySync)(fb, fa, {
90
+ return {
91
+ targetFile,
92
+ staticFile,
93
+ targetFileFull: fa,
94
+ staticFileFull: fb,
70
95
  overwrite: overwrite || false,
96
+ };
97
+ }
98
+ /**
99
+ * 執行單個靜態檔案的實際複製 / Perform the actual copy of a single static file entry
100
+ *
101
+ * @param runtime - _copyStaticFilesEntryCore 解析出的複製資訊 / Copy info resolved by _copyStaticFilesEntryCore
102
+ * @throws {TypeError} 當 runtime 為 undefined 時(detectFile 命中)/ When runtime is undefined (detectFile matched)
103
+ */
104
+ function _copyStaticFilesEntryCoreCopy(runtime) {
105
+ /**
106
+ * 確保目標目錄存在
107
+ * Ensure target directory exists
108
+ *
109
+ * 目標可能位於子目錄(如 .github/workflows/),需先建立
110
+ * Targets may live in subdirectories (e.g. .github/workflows/), which must be created first
111
+ */
112
+ (0, fs_extra_1.ensureDirSync)((0, path_1.dirname)(runtime.targetFileFull));
113
+ /**
114
+ * 複製檔案
115
+ * Copy the file
116
+ *
117
+ * overwrite 預設關閉並搭配 errorOnExist: false,讓已存在的目標維持原狀且不中斷批次
118
+ * overwrite defaults off with errorOnExist: false so existing targets stay untouched and the batch continues
119
+ */
120
+ (0, fs_extra_1.copySync)(runtime.staticFileFull, runtime.targetFileFull, {
121
+ overwrite: runtime.overwrite,
71
122
  preserveTimestamps: true,
72
123
  errorOnExist: false,
73
124
  });
74
- return true;
125
+ }
126
+ /**
127
+ * 複製單個靜態檔案到目標目錄 / Copy a single static file into the target directory
128
+ *
129
+ * 先解析再複製;被 detectFile 跳過時不會寫入任何檔案。
130
+ * Resolves first, then copies; nothing is written when detectFile skips the entry.
131
+ *
132
+ * @param entry - 靜態檔案條目 / Static file entry
133
+ * @param entry.0 - targetFile:目標檔案路徑 / Target file path
134
+ * @param entry.1 - staticFile:來源靜態檔案路徑 / Source static file path
135
+ * @param entry.2 - detectFile:可選的檢測檔案 / Optional file to check for existence
136
+ *
137
+ * @param cwd - 當前工作目錄 / Current working directory
138
+ * @param staticRoot - 靜態檔案根目錄(預設為套件根目錄)/ Root directory of static files (defaults to package root)
139
+ * @param overwrite - 是否覆蓋已存在的檔案(預設為 false)/ Whether to overwrite existing files (defaults to false)
140
+ *
141
+ * @returns 已複製時回傳 true;被 detectFile 跳過時回傳 undefined / Returns true when copied, undefined when skipped by detectFile
142
+ * @throws {Error} 當來源靜態檔案不存在時 / When the source static file does not exist
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * import { copyStaticFilesEntry } from '@yarn-tool/static-file/lib/copyStaticFilesEntry';
147
+ *
148
+ * // 複製單個檔案 / Copy a single file
149
+ * const copied = copyStaticFilesEntry(
150
+ * ['.gitignore', 'file/gitignore'],
151
+ * '/path/to/project',
152
+ * '/path/to/static/root',
153
+ * false,
154
+ * );
155
+ *
156
+ * // 使用檢測檔案:已存在則跳過 / With detect file: skip when it already exists
157
+ * const skipped = copyStaticFilesEntry(
158
+ * ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],
159
+ * '/path/to/project',
160
+ * );
161
+ * // 專案已有 tsconfig.json 時 skipped 為 undefined / skipped is undefined when tsconfig.json already exists
162
+ * ```
163
+ */
164
+ function copyStaticFilesEntry(entry, cwd, staticRoot = __root_1.__STATIC_ROOT, overwrite) {
165
+ const runtime = _copyStaticFilesEntryCore(entry, cwd, staticRoot, overwrite);
166
+ /**
167
+ * detectFile 命中時解析結果為 undefined,此時跳過複製並回傳 undefined
168
+ * When detectFile matched the resolution yields undefined, so the copy is skipped and undefined is returned
169
+ */
170
+ if (runtime) {
171
+ _copyStaticFilesEntryCoreCopy(runtime);
172
+ return true;
173
+ }
75
174
  }
76
175
  //# sourceMappingURL=copyStaticFilesEntry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copyStaticFilesEntry.js","sourceRoot":"","sources":["copyStaticFilesEntry.ts"],"names":[],"mappings":";;AAuDA,oDA0CC;AAxFD,+BAAwC;AACxC,uCAA+D;AAC/D,sCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,SAAgB,oBAAoB,CAAC,KAAwC,EAC5E,GAAW,EACX,aAAqB,sBAAa,EAClC,SAAmB;IAGnB,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;IAEnD,8EAA8E;IAC9E,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EACtB,CAAC;QACA,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEpC,IAAI,IAAA,qBAAU,EAAC,EAAE,CAAC,EAClB,CAAC;YACA,OAAO;QACR,CAAC;IACF,CAAC;IAED,sCAAsC;IACtC,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAE3C,yCAAyC;IACzC,IAAI,CAAC,IAAA,qBAAU,EAAC,EAAE,CAAC,EACnB,CAAC;QACA,MAAM,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED,sCAAsC;IACtC,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAEpC,4CAA4C;IAC5C,IAAA,wBAAa,EAAC,IAAA,cAAO,EAAC,EAAE,CAAC,CAAC,CAAA;IAE1B,uBAAuB;IACvB,IAAA,mBAAQ,EAAC,EAAE,EAAE,EAAE,EAAE;QAChB,SAAS,EAAE,SAAS,IAAI,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,YAAY,EAAE,KAAK;KACnB,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * Copy single static file entry / 複製單個靜態檔案條目\n *\n * This module provides the function for copying a single static file entry.\n * 此模組提供複製單個靜態檔案條目的函數。\n *\n * @module copyStaticFilesEntry\n */\nimport { IStaticFilesMapArrayEntry } from './types';\nimport { dirname, resolve } from 'path';\nimport { copySync, ensureDirSync, existsSync } from 'fs-extra';\nimport { __STATIC_ROOT } from '../__root';\n\n/**\n * Copy a single static file entry / 複製單個靜態檔案條目\n *\n * Copies a single static file from the static root to the target directory.\n * 從靜態根目錄複製單個靜態檔案到目標目錄。\n *\n * @param entry - The static file entry / 靜態檔案條目\n * @param entry.0 - targetFile: Target file path / 目標檔案路徑\n * @param entry.1 - staticFile: Source static file path / 來源靜態檔案路徑\n * @param entry.2 - detectFile: Optional file to check for existence / 可選的檢測檔案\n *\n * @param cwd - Current working directory / 當前工作目錄\n * @param staticRoot - Root directory of static files (defaults to package root) / 靜態檔案根目錄(預設為套件根目錄)\n * @param overwrite - Whether to overwrite existing files (defaults to false) / 是否覆蓋已存在的檔案(預設為 false)\n *\n * @returns true if file was copied, undefined if skipped (detect file exists) / 如果檔案已複製則返回 true,如果跳過(檢測檔案存在)則返回 undefined\n *\n * @throws {Error} When the source static file does not exist / 當來源靜態檔案不存在時\n *\n * @example\n * ```typescript\n * import { copyStaticFilesEntry } from '@yarn-tool/static-file';\n *\n * // Copy a single file\n * // 複製單個檔案\n * const result = copyStaticFilesEntry(\n * ['.gitignore', 'file/gitignore'],\n * '/path/to/project',\n * '/path/to/static/root',\n * false\n * );\n *\n * // With detect file - skips if detect file exists\n * // 使用檢測檔案 - 如果檢測檔案存在則跳過\n * const result = copyStaticFilesEntry(\n * ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],\n * '/path/to/project'\n * );\n * // Skips copy if tsconfig.json already exists in the project\n * // 如果 tsconfig.json 已存在於專案中則跳過複製\n * ```\n */\nexport function copyStaticFilesEntry(entry: IStaticFilesMapArrayEntry<string>,\n\tcwd: string,\n\tstaticRoot: string = __STATIC_ROOT,\n\toverwrite?: boolean,\n)\n{\n\tconst [targetFile, staticFile, detectFile] = entry;\n\n\t// Check if detect file exists - skip copy if it does / 檢查檢測檔案是否存在 - 如果存在則跳過複製\n\tif (detectFile?.length)\n\t{\n\t\tconst fc = resolve(cwd, detectFile);\n\n\t\tif (existsSync(fc))\n\t\t{\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Resolve source file path / 解析來源檔案路徑\n\tconst fb = resolve(staticRoot, staticFile);\n\n\t// Verify source file exists / 驗證來源檔案是否存在\n\tif (!existsSync(fb))\n\t{\n\t\tthrow new Error(`file not exists. ${fb}`)\n\t}\n\n\t// Resolve target file path / 解析目標檔案路徑\n\tconst fa = resolve(cwd, targetFile);\n\n\t// Ensure target directory exists / 確保目標目錄存在\n\tensureDirSync(dirname(fa))\n\n\t// Copy the file / 複製檔案\n\tcopySync(fb, fa, {\n\t\toverwrite: overwrite || false,\n\t\tpreserveTimestamps: true,\n\t\terrorOnExist: false,\n\t});\n\n\treturn true;\n}\n"]}
1
+ {"version":3,"file":"copyStaticFilesEntry.js","sourceRoot":"","sources":["copyStaticFilesEntry.ts"],"names":[],"mappings":";;AAwDA,8DA2DC;AAQD,sEAuBC;AAwCD,oDAkBC;AAnMD,+BAAwC;AACxC,uCAA+D;AAC/D,sCAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,SAAgB,yBAAyB,CAAmB,KAAmC,EAC9F,GAAW,EACX,aAAqB,sBAAa,EAClC,SAAmB;IAGnB,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC;IAEnD;;;;;;OAMG;IACH,IAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,EACtB,CAAC;QACA,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEpC,IAAI,IAAA,qBAAU,EAAC,EAAE,CAAC,EAClB,CAAC;YACA,OAAO;QACR,CAAC;IACF,CAAC;IAED;;;;;;OAMG;IACH,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAE3C;;;;;;OAMG;IACH,IAAI,CAAC,IAAA,qBAAU,EAAC,EAAE,CAAC,EACnB,CAAC;QACA,MAAM,IAAI,KAAK,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAA;IAC1C,CAAC;IAED;;;OAGG;IACH,MAAM,EAAE,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAEpC,OAAO;QACN,UAAU;QACV,UAAU;QACV,cAAc,EAAE,EAAE;QAClB,cAAc,EAAE,EAAE;QAClB,SAAS,EAAE,SAAS,IAAI,KAAK;KACpB,CAAC;AACZ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAmB,OAAoC;IAEnG;;;;;;OAMG;IACH,IAAA,wBAAa,EAAC,IAAA,cAAO,EAAC,OAAO,CAAC,cAAc,CAAC,CAAC,CAAA;IAE9C;;;;;;OAMG;IACH,IAAA,mBAAQ,EAAC,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC,cAAc,EAAE;QACxD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,kBAAkB,EAAE,IAAI;QACxB,YAAY,EAAE,KAAK;KACnB,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,SAAgB,oBAAoB,CAAmB,KAAmC,EACzF,GAAW,EACX,aAAqB,sBAAa,EAClC,SAAmB;IAGnB,MAAM,OAAO,GAAG,yBAAyB,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IAE7E;;;OAGG;IACH,IAAI,OAAO,EACX,CAAC;QACA,6BAA6B,CAAC,OAAO,CAAC,CAAC;QAEvC,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC","sourcesContent":["/**\n * Copy single static file entry / 複製單個靜態檔案條目\n *\n * This module provides the function for copying a single static file entry.\n * 此模組提供複製單個靜態檔案條目的函數。\n *\n * @module copyStaticFilesEntry\n */\nimport { IStaticFilesEntryRuntime, IStaticFilesMapArrayEntry } from './types';\nimport { dirname, resolve } from 'path';\nimport { copySync, ensureDirSync, existsSync } from 'fs-extra';\nimport { __STATIC_ROOT } from '../__root';\n\n/**\n * 解析單個靜態檔案條目的複製資訊 / Resolve copy info for a single static file entry\n *\n * 只做路徑解析與存在性檢查,不寫入任何檔案;真正的複製交給 _copyStaticFilesEntryCoreCopy。\n * Only resolves paths and checks existence — nothing is written; the actual copy is done by _copyStaticFilesEntryCoreCopy.\n *\n * @param entry - 靜態檔案條目 / Static file entry\n * @param entry.0 - targetFile:目標檔案路徑 / Target file path\n * @param entry.1 - staticFile:來源靜態檔案路徑 / Source static file path\n * @param entry.2 - detectFile:可選的檢測檔案 / Optional file to check for existence\n *\n * @param cwd - 當前工作目錄 / Current working directory\n * @param staticRoot - 靜態檔案根目錄(預設為套件根目錄)/ Root directory of static files (defaults to package root)\n * @param overwrite - 是否覆蓋已存在的檔案(預設為 false)/ Whether to overwrite existing files (defaults to false)\n *\n * @returns 解析後的複製資訊;被 detectFile 跳過時回傳 undefined / Resolved copy info, or undefined when skipped by detectFile\n * @throws {Error} 當來源靜態檔案不存在時 / When the source static file does not exist\n *\n * @example\n * ```typescript\n * import { _copyStaticFilesEntryCore, _copyStaticFilesEntryCoreCopy } from '@yarn-tool/static-file/lib/copyStaticFilesEntry';\n *\n * // 複製單個檔案 / Copy a single file\n * const runtime = _copyStaticFilesEntryCore(\n * ['.gitignore', 'file/gitignore'],\n * '/path/to/project',\n * '/path/to/static/root',\n * false,\n * );\n *\n * if (runtime)\n * {\n * _copyStaticFilesEntryCoreCopy(runtime);\n * }\n *\n * // 使用檢測檔案:正式設定檔已存在時跳過 / With detect file: skip when the real config already exists\n * _copyStaticFilesEntryCore(\n * ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],\n * '/path/to/project',\n * );\n * // 專案已有 tsconfig.json 時回傳 undefined / Returns undefined when tsconfig.json already exists\n * ```\n */\nexport function _copyStaticFilesEntryCore<K extends string>(entry: IStaticFilesMapArrayEntry<K>,\n\tcwd: string,\n\tstaticRoot: string = __STATIC_ROOT,\n\toverwrite?: boolean,\n): IStaticFilesEntryRuntime<K>\n{\n\tconst [targetFile, staticFile, detectFile] = entry;\n\n\t/**\n\t * 檢查檢測檔案 (detect file) 是否存在,存在即跳過複製\n\t * Check if detect file exists - skip copy if it does\n\t *\n\t * 用於「範本檔」情境:專案已有正式設定檔時不應被樣板覆蓋\n\t * For template scenarios: an existing real config file must not be overwritten by the template\n\t */\n\tif (detectFile?.length)\n\t{\n\t\tconst fc = resolve(cwd, detectFile);\n\n\t\tif (existsSync(fc))\n\t\t{\n\t\t\treturn;\n\t\t}\n\t}\n\n\t/**\n\t * 解析來源檔案路徑\n\t * Resolve source file path\n\t *\n\t * 以靜態根目錄為基準,樣板路徑可為巢狀(如 file/test/…)\n\t * Resolved against the static root; template paths may be nested (e.g. file/test/…)\n\t */\n\tconst fb = resolve(staticRoot, staticFile);\n\n\t/**\n\t * 驗證來源檔案是否存在\n\t * Verify source file exists\n\t *\n\t * 來源缺失代表清單與 file/ 目錄不同步,應立即失敗而非複製出殘缺結果\n\t * A missing source means the map is out of sync with file/; fail instead of producing a partial copy\n\t */\n\tif (!existsSync(fb))\n\t{\n\t\tthrow new Error(`file not exists. ${fb}`)\n\t}\n\n\t/**\n\t * 解析目標檔案路徑\n\t * Resolve target file path\n\t */\n\tconst fa = resolve(cwd, targetFile);\n\n\treturn {\n\t\ttargetFile,\n\t\tstaticFile,\n\t\ttargetFileFull: fa,\n\t\tstaticFileFull: fb,\n\t\toverwrite: overwrite || false,\n\t} as const;\n}\n\n/**\n * 執行單個靜態檔案的實際複製 / Perform the actual copy of a single static file entry\n *\n * @param runtime - _copyStaticFilesEntryCore 解析出的複製資訊 / Copy info resolved by _copyStaticFilesEntryCore\n * @throws {TypeError} 當 runtime 為 undefined 時(detectFile 命中)/ When runtime is undefined (detectFile matched)\n */\nexport function _copyStaticFilesEntryCoreCopy<K extends string>(runtime: IStaticFilesEntryRuntime<K>)\n{\n\t/**\n\t * 確保目標目錄存在\n\t * Ensure target directory exists\n\t *\n\t * 目標可能位於子目錄(如 .github/workflows/),需先建立\n\t * Targets may live in subdirectories (e.g. .github/workflows/), which must be created first\n\t */\n\tensureDirSync(dirname(runtime.targetFileFull))\n\n\t/**\n\t * 複製檔案\n\t * Copy the file\n\t *\n\t * overwrite 預設關閉並搭配 errorOnExist: false,讓已存在的目標維持原狀且不中斷批次\n\t * overwrite defaults off with errorOnExist: false so existing targets stay untouched and the batch continues\n\t */\n\tcopySync(runtime.staticFileFull, runtime.targetFileFull, {\n\t\toverwrite: runtime.overwrite,\n\t\tpreserveTimestamps: true,\n\t\terrorOnExist: false,\n\t});\n}\n\n/**\n * 複製單個靜態檔案到目標目錄 / Copy a single static file into the target directory\n *\n * 先解析再複製;被 detectFile 跳過時不會寫入任何檔案。\n * Resolves first, then copies; nothing is written when detectFile skips the entry.\n *\n * @param entry - 靜態檔案條目 / Static file entry\n * @param entry.0 - targetFile:目標檔案路徑 / Target file path\n * @param entry.1 - staticFile:來源靜態檔案路徑 / Source static file path\n * @param entry.2 - detectFile:可選的檢測檔案 / Optional file to check for existence\n *\n * @param cwd - 當前工作目錄 / Current working directory\n * @param staticRoot - 靜態檔案根目錄(預設為套件根目錄)/ Root directory of static files (defaults to package root)\n * @param overwrite - 是否覆蓋已存在的檔案(預設為 false)/ Whether to overwrite existing files (defaults to false)\n *\n * @returns 已複製時回傳 true;被 detectFile 跳過時回傳 undefined / Returns true when copied, undefined when skipped by detectFile\n * @throws {Error} 當來源靜態檔案不存在時 / When the source static file does not exist\n *\n * @example\n * ```typescript\n * import { copyStaticFilesEntry } from '@yarn-tool/static-file/lib/copyStaticFilesEntry';\n *\n * // 複製單個檔案 / Copy a single file\n * const copied = copyStaticFilesEntry(\n * ['.gitignore', 'file/gitignore'],\n * '/path/to/project',\n * '/path/to/static/root',\n * false,\n * );\n *\n * // 使用檢測檔案:已存在則跳過 / With detect file: skip when it already exists\n * const skipped = copyStaticFilesEntry(\n * ['tsconfig.json', 'file/tsconfig.json.tpl', 'tsconfig.json'],\n * '/path/to/project',\n * );\n * // 專案已有 tsconfig.json 時 skipped 為 undefined / skipped is undefined when tsconfig.json already exists\n * ```\n */\nexport function copyStaticFilesEntry<K extends string>(entry: IStaticFilesMapArrayEntry<K>,\n\tcwd: string,\n\tstaticRoot: string = __STATIC_ROOT,\n\toverwrite?: boolean,\n)\n{\n\tconst runtime = _copyStaticFilesEntryCore(entry, cwd, staticRoot, overwrite);\n\n\t/**\n\t * detectFile 命中時解析結果為 undefined,此時跳過複製並回傳 undefined\n\t * When detectFile matched the resolution yields undefined, so the copy is skipped and undefined is returned\n\t */\n\tif (runtime)\n\t{\n\t\t_copyStaticFilesEntryCoreCopy(runtime);\n\n\t\treturn true;\n\t}\n}\n"]}
@@ -0,0 +1,52 @@
1
+ import { IIgnoreFilesSnapshot, IStaticFilesMapArray } from './types';
2
+ /**
3
+ * 需要參與自動合併的 ignore 檔案名稱 / Ignore file names that participate in auto-merge
4
+ *
5
+ * 只列「忽略規則」類型的檔案;一般設定檔(如 .editorconfig)不適用行合併語意。
6
+ * Only rule-list style files are listed; ordinary config files (e.g. .editorconfig) do not suit line merging.
7
+ *
8
+ * @see _isIgnoreFileForMerge
9
+ */
10
+ export declare const defaultMergeIgnoreFiles: readonly [".gitignore", ".npmignore", ".eslintignore", ".nowignore"];
11
+ /**
12
+ * 判斷目標檔案是否為需要合併的 ignore 檔案 / Decide whether the target file is an ignore file that should be merged
13
+ *
14
+ * 以 basename 比對,讓位於子目錄(如 test/.gitignore)的 ignore 檔同樣被涵蓋。
15
+ * Matched by basename so ignore files inside subdirectories (e.g. test/.gitignore) are covered as well.
16
+ *
17
+ * @param targetFile - 目標檔案路徑(相對於 cwd)/ Target file path (relative to cwd)
18
+ * @returns 是否需要合併 / Whether it should be merged
19
+ */
20
+ export declare function _isIgnoreFileForMerge(targetFile: string): boolean;
21
+ /**
22
+ * 在 reset 之前讀取現有 ignore 檔案並建立快照 / Read existing ignore files before the reset and build a snapshot
23
+ *
24
+ * 快照以記憶體中的 IgnoreFile 保存,後續即使檔案被刪除也不受影響;
25
+ * 檔案不存在時不列入快照,合併階段會因此略過該檔案。
26
+ * The snapshot is held as in-memory IgnoreFile objects, so later deletion does not affect them;
27
+ * a missing file is left out of the snapshot, which makes the merge skip that file.
28
+ *
29
+ * @param cwd - 目標目錄 / Target directory
30
+ * @returns 以相對目標路徑為鍵的快照 / Snapshot keyed by the relative target path
31
+ *
32
+ * @see mergeIgnoreFiles
33
+ */
34
+ export declare function _readIgnoreFilesSnapshot(cwd: string): IIgnoreFilesSnapshot;
35
+ /**
36
+ * 將快照內容合併回複製後的 ignore 檔 / Merge the snapshot back into the copied ignore files
37
+ *
38
+ * 以複製後的目標檔為 B、reset 前取樣的內容為 A,執行 B.addList(A.lines, true) 後寫回目標:
39
+ * - 樣板的新規則來自 B 本身
40
+ * - A 的既有規則(含使用者自訂)不會因 reset 而遺失
41
+ * - addList 會略過重複行,重複執行結果一致
42
+ * With the post-copy target as B and the pre-reset capture as A, it runs B.addList(A.lines, true)
43
+ * and writes B back to the target:
44
+ * - New template rules come from B itself
45
+ * - Existing rules in A (including user-authored ones) survive the reset
46
+ * - addList skips duplicate lines, so re-running yields a stable result
47
+ *
48
+ * @param cwd - 目標目錄 / Target directory
49
+ * @param file_map - 已解析的靜態檔案映射 / Resolved static file map
50
+ * @param snapshot - reset 前建立的快照;未提供時不執行任何合併 / Snapshot taken before the reset; nothing is merged when omitted
51
+ */
52
+ export declare function mergeIgnoreFiles(cwd: string, file_map: IStaticFilesMapArray<string>, snapshot?: IIgnoreFilesSnapshot): void;
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultMergeIgnoreFiles = void 0;
4
+ exports._isIgnoreFileForMerge = _isIgnoreFileForMerge;
5
+ exports._readIgnoreFilesSnapshot = _readIgnoreFilesSnapshot;
6
+ exports.mergeIgnoreFiles = mergeIgnoreFiles;
7
+ /**
8
+ * Merge ignore files with their static templates / 將 ignore 檔案與靜態樣板合併
9
+ *
10
+ * resetStaticFiles 會先刪除正式的 ignore 檔(.gitignore / .npmignore 等)再重新複製樣板,
11
+ * 既有規則會因此遺失;此模組在 reset 之前先取樣,並在複製完成後把取樣內容合併回去。
12
+ * resetStaticFiles deletes the real ignore files (.gitignore / .npmignore, etc.) before copying the
13
+ * templates back, which loses the existing rules; this module captures them before the reset and
14
+ * merges the captured content back once the copy is done.
15
+ *
16
+ * @module mergeIgnoreFiles
17
+ */
18
+ const IgnoreFile_1 = require("@yarn-tool/ignore/lib/IgnoreFile");
19
+ const fs_extra_1 = require("fs-extra");
20
+ const path_1 = require("path");
21
+ /**
22
+ * 需要參與自動合併的 ignore 檔案名稱 / Ignore file names that participate in auto-merge
23
+ *
24
+ * 只列「忽略規則」類型的檔案;一般設定檔(如 .editorconfig)不適用行合併語意。
25
+ * Only rule-list style files are listed; ordinary config files (e.g. .editorconfig) do not suit line merging.
26
+ *
27
+ * @see _isIgnoreFileForMerge
28
+ */
29
+ exports.defaultMergeIgnoreFiles = [
30
+ '.gitignore',
31
+ '.npmignore',
32
+ '.eslintignore',
33
+ '.nowignore',
34
+ ];
35
+ /**
36
+ * 判斷目標檔案是否為需要合併的 ignore 檔案 / Decide whether the target file is an ignore file that should be merged
37
+ *
38
+ * 以 basename 比對,讓位於子目錄(如 test/.gitignore)的 ignore 檔同樣被涵蓋。
39
+ * Matched by basename so ignore files inside subdirectories (e.g. test/.gitignore) are covered as well.
40
+ *
41
+ * @param targetFile - 目標檔案路徑(相對於 cwd)/ Target file path (relative to cwd)
42
+ * @returns 是否需要合併 / Whether it should be merged
43
+ */
44
+ function _isIgnoreFileForMerge(targetFile) {
45
+ return exports.defaultMergeIgnoreFiles.includes((0, path_1.basename)(targetFile));
46
+ }
47
+ /**
48
+ * 在 reset 之前讀取現有 ignore 檔案並建立快照 / Read existing ignore files before the reset and build a snapshot
49
+ *
50
+ * 快照以記憶體中的 IgnoreFile 保存,後續即使檔案被刪除也不受影響;
51
+ * 檔案不存在時不列入快照,合併階段會因此略過該檔案。
52
+ * The snapshot is held as in-memory IgnoreFile objects, so later deletion does not affect them;
53
+ * a missing file is left out of the snapshot, which makes the merge skip that file.
54
+ *
55
+ * @param cwd - 目標目錄 / Target directory
56
+ * @returns 以相對目標路徑為鍵的快照 / Snapshot keyed by the relative target path
57
+ *
58
+ * @see mergeIgnoreFiles
59
+ */
60
+ function _readIgnoreFilesSnapshot(cwd) {
61
+ const snapshot = new Map();
62
+ for (const targetFile of exports.defaultMergeIgnoreFiles) {
63
+ const targetFileFull = (0, path_1.resolve)(cwd, targetFile);
64
+ /**
65
+ * 尚未存在的 ignore 檔沒有既有規則可保留,無需取樣
66
+ * An ignore file that does not exist yet has no rules to preserve, so there is nothing to capture
67
+ */
68
+ if (!(0, fs_extra_1.existsSync)(targetFileFull)) {
69
+ continue;
70
+ }
71
+ snapshot.set(targetFile, IgnoreFile_1.IgnoreFile.from(targetFileFull, {
72
+ endCount: true,
73
+ }));
74
+ }
75
+ return snapshot;
76
+ }
77
+ /**
78
+ * 將快照內容合併回複製後的 ignore 檔 / Merge the snapshot back into the copied ignore files
79
+ *
80
+ * 以複製後的目標檔為 B、reset 前取樣的內容為 A,執行 B.addList(A.lines, true) 後寫回目標:
81
+ * - 樣板的新規則來自 B 本身
82
+ * - A 的既有規則(含使用者自訂)不會因 reset 而遺失
83
+ * - addList 會略過重複行,重複執行結果一致
84
+ * With the post-copy target as B and the pre-reset capture as A, it runs B.addList(A.lines, true)
85
+ * and writes B back to the target:
86
+ * - New template rules come from B itself
87
+ * - Existing rules in A (including user-authored ones) survive the reset
88
+ * - addList skips duplicate lines, so re-running yields a stable result
89
+ *
90
+ * @param cwd - 目標目錄 / Target directory
91
+ * @param file_map - 已解析的靜態檔案映射 / Resolved static file map
92
+ * @param snapshot - reset 前建立的快照;未提供時不執行任何合併 / Snapshot taken before the reset; nothing is merged when omitted
93
+ */
94
+ function mergeIgnoreFiles(cwd, file_map, snapshot) {
95
+ /**
96
+ * 未提供快照代表停用合併,維持單純的複製結果
97
+ * No snapshot means merging is disabled and the plain copy result is kept
98
+ */
99
+ if (!(snapshot === null || snapshot === void 0 ? void 0 : snapshot.size)) {
100
+ return;
101
+ }
102
+ for (const entry of file_map) {
103
+ const [targetFile] = entry;
104
+ /**
105
+ * 非 ignore 檔案維持原本的複製行為,不做行合併
106
+ * Non-ignore files keep the plain copy behaviour and are not merged
107
+ */
108
+ if (!_isIgnoreFileForMerge(targetFile)) {
109
+ continue;
110
+ }
111
+ /**
112
+ * 取樣時該檔案不存在,沒有既有規則需要保留
113
+ * The file did not exist when captured, so there are no existing rules to keep
114
+ */
115
+ const target = snapshot.get((0, path_1.basename)(targetFile));
116
+ if (!target) {
117
+ continue;
118
+ }
119
+ const targetFileFull = (0, path_1.resolve)(cwd, targetFile);
120
+ /**
121
+ * 複製後仍不存在代表對應樣板缺失,維持原狀不寫入
122
+ * Still missing after the copy means the matching template is absent; leave it untouched
123
+ */
124
+ if (!(0, fs_extra_1.existsSync)(targetFileFull)) {
125
+ continue;
126
+ }
127
+ /**
128
+ * B = 複製後的目標檔,內容為最新樣板
129
+ * B = post-copy target, whose content is the fresh template
130
+ */
131
+ const copied = IgnoreFile_1.IgnoreFile.from(targetFileFull, {
132
+ endCount: true,
133
+ });
134
+ /**
135
+ * 將 A(取樣內容)的行併入 B,讓樣板規則與既有規則並存
136
+ * Fold A's lines (the captured content) into B so template rules and existing rules coexist
137
+ */
138
+ copied.addList(target.lines, true);
139
+ /**
140
+ * 寫回目標檔;靜態樣板本身不受影響
141
+ * Write back to the target; the static template itself stays untouched
142
+ */
143
+ copied.outputFile(targetFileFull);
144
+ }
145
+ }
146
+ //# sourceMappingURL=mergeIgnoreFiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeIgnoreFiles.js","sourceRoot":"","sources":["mergeIgnoreFiles.ts"],"names":[],"mappings":";;;AAwCA,sDAGC;AAeD,4DAuBC;AAmBD,4CAqEC;AAzKD;;;;;;;;;;GAUG;AACH,iEAA8D;AAC9D,uCAAsC;AACtC,+BAAyC;AAGzC;;;;;;;GAOG;AACU,QAAA,uBAAuB,GAAG;IACtC,YAAY;IACZ,YAAY;IACZ,eAAe;IACf,YAAY;CACH,CAAC;AAEX;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CAAC,UAAkB;IAEvD,OAAQ,+BAA6C,CAAC,QAAQ,CAAC,IAAA,eAAQ,EAAC,UAAU,CAAC,CAAC,CAAC;AACtF,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,wBAAwB,CAAC,GAAW;IAEnD,MAAM,QAAQ,GAAyB,IAAI,GAAG,EAAE,CAAC;IAEjD,KAAK,MAAM,UAAU,IAAI,+BAAuB,EAChD,CAAC;QACA,MAAM,cAAc,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEhD;;;WAGG;QACH,IAAI,CAAC,IAAA,qBAAU,EAAC,cAAc,CAAC,EAC/B,CAAC;YACA,SAAS;QACV,CAAC;QAED,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,uBAAU,CAAC,IAAI,CAAC,cAAc,EAAE;YACxD,QAAQ,EAAE,IAAI;SACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,gBAAgB,CAAC,GAAW,EAC3C,QAAsC,EACtC,QAA+B;IAG/B;;;OAGG;IACH,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAA,EACnB,CAAC;QACA,OAAO;IACR,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,QAAQ,EAC5B,CAAC;QACA,MAAM,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;QAE3B;;;WAGG;QACH,IAAI,CAAC,qBAAqB,CAAC,UAAU,CAAC,EACtC,CAAC;YACA,SAAS;QACV,CAAC;QAED;;;WAGG;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAA,eAAQ,EAAC,UAAU,CAAC,CAAC,CAAC;QAElD,IAAI,CAAC,MAAM,EACX,CAAC;YACA,SAAS;QACV,CAAC;QAED,MAAM,cAAc,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAEhD;;;WAGG;QACH,IAAI,CAAC,IAAA,qBAAU,EAAC,cAAc,CAAC,EAC/B,CAAC;YACA,SAAS;QACV,CAAC;QAED;;;WAGG;QACH,MAAM,MAAM,GAAG,uBAAU,CAAC,IAAI,CAAC,cAAc,EAAE;YAC9C,QAAQ,EAAE,IAAI;SACd,CAAC,CAAC;QAEH;;;WAGG;QACH,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAEnC;;;WAGG;QACH,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IACnC,CAAC;AACF,CAAC","sourcesContent":["/**\n * Merge ignore files with their static templates / 將 ignore 檔案與靜態樣板合併\n *\n * resetStaticFiles 會先刪除正式的 ignore 檔(.gitignore / .npmignore 等)再重新複製樣板,\n * 既有規則會因此遺失;此模組在 reset 之前先取樣,並在複製完成後把取樣內容合併回去。\n * resetStaticFiles deletes the real ignore files (.gitignore / .npmignore, etc.) before copying the\n * templates back, which loses the existing rules; this module captures them before the reset and\n * merges the captured content back once the copy is done.\n *\n * @module mergeIgnoreFiles\n */\nimport { IgnoreFile } from '@yarn-tool/ignore/lib/IgnoreFile';\nimport { existsSync } from 'fs-extra';\nimport { basename, resolve } from 'path';\nimport { IIgnoreFilesSnapshot, IStaticFilesMapArray } from './types';\n\n/**\n * 需要參與自動合併的 ignore 檔案名稱 / Ignore file names that participate in auto-merge\n *\n * 只列「忽略規則」類型的檔案;一般設定檔(如 .editorconfig)不適用行合併語意。\n * Only rule-list style files are listed; ordinary config files (e.g. .editorconfig) do not suit line merging.\n *\n * @see _isIgnoreFileForMerge\n */\nexport const defaultMergeIgnoreFiles = [\n\t'.gitignore',\n\t'.npmignore',\n\t'.eslintignore',\n\t'.nowignore',\n] as const;\n\n/**\n * 判斷目標檔案是否為需要合併的 ignore 檔案 / Decide whether the target file is an ignore file that should be merged\n *\n * 以 basename 比對,讓位於子目錄(如 test/.gitignore)的 ignore 檔同樣被涵蓋。\n * Matched by basename so ignore files inside subdirectories (e.g. test/.gitignore) are covered as well.\n *\n * @param targetFile - 目標檔案路徑(相對於 cwd)/ Target file path (relative to cwd)\n * @returns 是否需要合併 / Whether it should be merged\n */\nexport function _isIgnoreFileForMerge(targetFile: string)\n{\n\treturn (defaultMergeIgnoreFiles as readonly string[]).includes(basename(targetFile));\n}\n\n/**\n * 在 reset 之前讀取現有 ignore 檔案並建立快照 / Read existing ignore files before the reset and build a snapshot\n *\n * 快照以記憶體中的 IgnoreFile 保存,後續即使檔案被刪除也不受影響;\n * 檔案不存在時不列入快照,合併階段會因此略過該檔案。\n * The snapshot is held as in-memory IgnoreFile objects, so later deletion does not affect them;\n * a missing file is left out of the snapshot, which makes the merge skip that file.\n *\n * @param cwd - 目標目錄 / Target directory\n * @returns 以相對目標路徑為鍵的快照 / Snapshot keyed by the relative target path\n *\n * @see mergeIgnoreFiles\n */\nexport function _readIgnoreFilesSnapshot(cwd: string): IIgnoreFilesSnapshot\n{\n\tconst snapshot: IIgnoreFilesSnapshot = new Map();\n\n\tfor (const targetFile of defaultMergeIgnoreFiles)\n\t{\n\t\tconst targetFileFull = resolve(cwd, targetFile);\n\n\t\t/**\n\t\t * 尚未存在的 ignore 檔沒有既有規則可保留,無需取樣\n\t\t * An ignore file that does not exist yet has no rules to preserve, so there is nothing to capture\n\t\t */\n\t\tif (!existsSync(targetFileFull))\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\tsnapshot.set(targetFile, IgnoreFile.from(targetFileFull, {\n\t\t\tendCount: true,\n\t\t}));\n\t}\n\n\treturn snapshot;\n}\n\n/**\n * 將快照內容合併回複製後的 ignore 檔 / Merge the snapshot back into the copied ignore files\n *\n * 以複製後的目標檔為 B、reset 前取樣的內容為 A,執行 B.addList(A.lines, true) 後寫回目標:\n * - 樣板的新規則來自 B 本身\n * - A 的既有規則(含使用者自訂)不會因 reset 而遺失\n * - addList 會略過重複行,重複執行結果一致\n * With the post-copy target as B and the pre-reset capture as A, it runs B.addList(A.lines, true)\n * and writes B back to the target:\n * - New template rules come from B itself\n * - Existing rules in A (including user-authored ones) survive the reset\n * - addList skips duplicate lines, so re-running yields a stable result\n *\n * @param cwd - 目標目錄 / Target directory\n * @param file_map - 已解析的靜態檔案映射 / Resolved static file map\n * @param snapshot - reset 前建立的快照;未提供時不執行任何合併 / Snapshot taken before the reset; nothing is merged when omitted\n */\nexport function mergeIgnoreFiles(cwd: string,\n\tfile_map: IStaticFilesMapArray<string>,\n\tsnapshot?: IIgnoreFilesSnapshot,\n)\n{\n\t/**\n\t * 未提供快照代表停用合併,維持單純的複製結果\n\t * No snapshot means merging is disabled and the plain copy result is kept\n\t */\n\tif (!snapshot?.size)\n\t{\n\t\treturn;\n\t}\n\n\tfor (const entry of file_map)\n\t{\n\t\tconst [targetFile] = entry;\n\n\t\t/**\n\t\t * 非 ignore 檔案維持原本的複製行為,不做行合併\n\t\t * Non-ignore files keep the plain copy behaviour and are not merged\n\t\t */\n\t\tif (!_isIgnoreFileForMerge(targetFile))\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\t/**\n\t\t * 取樣時該檔案不存在,沒有既有規則需要保留\n\t\t * The file did not exist when captured, so there are no existing rules to keep\n\t\t */\n\t\tconst target = snapshot.get(basename(targetFile));\n\n\t\tif (!target)\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst targetFileFull = resolve(cwd, targetFile);\n\n\t\t/**\n\t\t * 複製後仍不存在代表對應樣板缺失,維持原狀不寫入\n\t\t * Still missing after the copy means the matching template is absent; leave it untouched\n\t\t */\n\t\tif (!existsSync(targetFileFull))\n\t\t{\n\t\t\tcontinue;\n\t\t}\n\n\t\t/**\n\t\t * B = 複製後的目標檔,內容為最新樣板\n\t\t * B = post-copy target, whose content is the fresh template\n\t\t */\n\t\tconst copied = IgnoreFile.from(targetFileFull, {\n\t\t\tendCount: true,\n\t\t});\n\n\t\t/**\n\t\t * 將 A(取樣內容)的行併入 B,讓樣板規則與既有規則並存\n\t\t * Fold A's lines (the captured content) into B so template rules and existing rules coexist\n\t\t */\n\t\tcopied.addList(target.lines, true);\n\n\t\t/**\n\t\t * 寫回目標檔;靜態樣板本身不受影響\n\t\t * Write back to the target; the static template itself stays untouched\n\t\t */\n\t\tcopied.outputFile(targetFileFull);\n\t}\n}\n"]}
@@ -7,16 +7,29 @@ exports.parseStaticMap = parseStaticMap;
7
7
  */
8
8
  function parseStaticMap(file_map) {
9
9
  let ls;
10
- // Handle array format / 處理陣列格式
10
+ /**
11
+ * 陣列格式直接取值即可(索引即為順序)
12
+ * Array format needs no conversion - index order is already the entry order
13
+ */
11
14
  if (Array.isArray(file_map)) {
12
15
  ls = Object.values(file_map);
13
16
  }
14
- // Handle record format / 處理記錄格式
17
+ /**
18
+ * 記錄 (Record) 格式轉成 [key, value] 條目,
19
+ * 與陣列格式共用後續的過濾邏輯
20
+ * Record format becomes [key, value] entries,
21
+ * sharing the same filtering logic as the array format
22
+ */
15
23
  else {
16
24
  // @ts-ignore
17
25
  ls = Object.entries(file_map);
18
26
  }
19
- // Filter out invalid entries / 過濾無效條目
27
+ /**
28
+ * 過濾無效條目:缺值或長度不足的條目無法還原成 [target, source],
29
+ * 若放行會在複製階段造成難以理解的錯誤
30
+ * Filter invalid entries: entries without a value or with too few elements cannot form [target, source];
31
+ * passing them on would cause confusing errors during copy
32
+ */
20
33
  return ls.filter(v => v && Array.isArray(v) && v.length > 1);
21
34
  }
22
35
  //# sourceMappingURL=parseStaticMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parseStaticMap.js","sourceRoot":"","sources":["parseStaticMap.ts"],"names":[],"mappings":";;AAyDA,wCAkBC;AAtBD;;;GAGG;AACH,SAAgB,cAAc,CAAmB,QAAyB;IAEzE,IAAI,EAA2B,CAAC;IAEhC,+BAA+B;IAC/B,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAC3B,CAAC;QACA,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC7B,CAAC;IACD,gCAAgC;SAEhC,CAAC;QACA,aAAa;QACb,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC9B,CAAC;IAED,sCAAsC;IACtC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Parse static file map / 解析靜態檔案映射\n *\n * This module provides functions to parse different static file map formats\n * into a unified array format.\n * 此模組提供將不同靜態檔案映射格式解析為統一陣列格式的函數。\n *\n * @module parseStaticMap\n */\nimport {\n\tIStaticFiles,\n\tIStaticFilesID,\n\tIStaticFilesMapArray,\n\tIStaticFilesMapRecord,\n\tIStaticFilesMapArrayEntry,\n} from './types';\n\n/**\n * Parse static file map from array format / 從陣列格式解析靜態檔案映射\n *\n * Converts an array-based file map to a normalized array format.\n * 將基於陣列的檔案映射轉換為標準化陣列格式。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n * @param file_map - The array-based file map / 基於陣列的檔案映射\n * @returns Normalized array of file map entries / 標準化的檔案映射條目陣列\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFilesMapArray<K>): IStaticFilesMapArray<K | IStaticFilesID>\n\n/**\n * Parse static file map from record format / 從記錄格式解析靜態檔案映射\n *\n * Converts a record-based file map to a normalized array format.\n * 將基於記錄的檔案映射轉換為標準化陣列格式。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n * @param file_map - The record-based file map / 基於記錄的檔案映射\n * @returns Normalized array of file map entries / 標準化的檔案映射條目陣列\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFilesMapRecord<K>): IStaticFilesMapArray<K | IStaticFilesID>\n\n/**\n * Parse static file map from any supported format / 從任何支援的格式解析靜態檔案映射\n *\n * Unified function that handles both array and record formats.\n * 處理陣列和記錄格式的統一函數。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n * @param file_map - The file map in any supported format / 任何支援格式的檔案映射\n * @returns Normalized array of file map entries / 標準化的檔案映射條目陣列\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): IStaticFilesMapArray<K | IStaticFilesID>\n\n/**\n * Implementation of parseStaticMap / parseStaticMap 的實現\n * @internal\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): IStaticFilesMapArray<K | IStaticFilesID>\n{\n\tlet ls: IStaticFilesMapArray<K>;\n\n\t// Handle array format / 處理陣列格式\n\tif (Array.isArray(file_map))\n\t{\n\t\tls = Object.values(file_map)\n\t}\n\t// Handle record format / 處理記錄格式\n\telse\n\t{\n\t\t// @ts-ignore\n\t\tls = Object.entries(file_map)\n\t}\n\n\t// Filter out invalid entries / 過濾無效條目\n\treturn ls.filter(v => v && Array.isArray(v) && v.length > 1);\n}\n"]}
1
+ {"version":3,"file":"parseStaticMap.js","sourceRoot":"","sources":["parseStaticMap.ts"],"names":[],"mappings":";;AAyDA,wCA+BC;AAnCD;;;GAGG;AACH,SAAgB,cAAc,CAAmB,QAAyB;IAEzE,IAAI,EAA2B,CAAC;IAEhC;;;OAGG;IACH,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAC3B,CAAC;QACA,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IAC7B,CAAC;IACD;;;;;OAKG;SAEH,CAAC;QACA,aAAa;QACb,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAC9B,CAAC;IAED;;;;;OAKG;IACH,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Parse static file map / 解析靜態檔案映射\n *\n * This module provides functions to parse different static file map formats\n * into a unified array format.\n * 此模組提供將不同靜態檔案映射格式解析為統一陣列格式的函數。\n *\n * @module parseStaticMap\n */\nimport {\n\tIStaticFiles,\n\tIStaticFilesID,\n\tIStaticFilesMapArray,\n\tIStaticFilesMapRecord,\n\tIStaticFilesMapArrayEntry,\n} from './types';\n\n/**\n * Parse static file map from array format / 從陣列格式解析靜態檔案映射\n *\n * Converts an array-based file map to a normalized array format.\n * 將基於陣列的檔案映射轉換為標準化陣列格式。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n * @param file_map - The array-based file map / 基於陣列的檔案映射\n * @returns Normalized array of file map entries / 標準化的檔案映射條目陣列\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFilesMapArray<K>): IStaticFilesMapArray<K | IStaticFilesID>\n\n/**\n * Parse static file map from record format / 從記錄格式解析靜態檔案映射\n *\n * Converts a record-based file map to a normalized array format.\n * 將基於記錄的檔案映射轉換為標準化陣列格式。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n * @param file_map - The record-based file map / 基於記錄的檔案映射\n * @returns Normalized array of file map entries / 標準化的檔案映射條目陣列\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFilesMapRecord<K>): IStaticFilesMapArray<K | IStaticFilesID>\n\n/**\n * Parse static file map from any supported format / 從任何支援的格式解析靜態檔案映射\n *\n * Unified function that handles both array and record formats.\n * 處理陣列和記錄格式的統一函數。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n * @param file_map - The file map in any supported format / 任何支援格式的檔案映射\n * @returns Normalized array of file map entries / 標準化的檔案映射條目陣列\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): IStaticFilesMapArray<K | IStaticFilesID>\n\n/**\n * Implementation of parseStaticMap / parseStaticMap 的實現\n * @internal\n */\nexport function parseStaticMap<K extends string>(file_map: IStaticFiles<K>): IStaticFilesMapArray<K | IStaticFilesID>\n{\n\tlet ls: IStaticFilesMapArray<K>;\n\n\t/**\n\t * 陣列格式直接取值即可(索引即為順序)\n\t * Array format needs no conversion - index order is already the entry order\n\t */\n\tif (Array.isArray(file_map))\n\t{\n\t\tls = Object.values(file_map)\n\t}\n\t/**\n\t * 記錄 (Record) 格式轉成 [key, value] 條目,\n\t * 與陣列格式共用後續的過濾邏輯\n\t * Record format becomes [key, value] entries,\n\t * sharing the same filtering logic as the array format\n\t */\n\telse\n\t{\n\t\t// @ts-ignore\n\t\tls = Object.entries(file_map)\n\t}\n\n\t/**\n\t * 過濾無效條目:缺值或長度不足的條目無法還原成 [target, source],\n\t * 若放行會在複製階段造成難以理解的錯誤\n\t * Filter invalid entries: entries without a value or with too few elements cannot form [target, source];\n\t * passing them on would cause confusing errors during copy\n\t */\n\treturn ls.filter(v => v && Array.isArray(v) && v.length > 1);\n}\n"]}
@@ -37,20 +37,41 @@ const array_hyper_unique_1 = require("array-hyper-unique");
37
37
  * ```
38
38
  */
39
39
  function reMapStaticFilesMapArray(file_map, replaceMap) {
40
- // Parse the source file map / 解析來源檔案映射
40
+ /**
41
+ * 解析來源檔案映射
42
+ * Parse the source file map
43
+ *
44
+ * 先正規化成陣列,之後才能依 key 查找並重複合成
45
+ * Normalize into an array first, so entries can be looked up by key and merged later
46
+ */
41
47
  const ls = (0, parseStaticMap_1.parseStaticMap)(file_map);
42
- // Process each replacement mapping / 處理每個替換映射
48
+ /**
49
+ * 逐筆處理替換映射:把「新路徑 → 舊路徑」轉成新的條目
50
+ * Process each replacement mapping: turn "new path → old path" into new entries
51
+ */
43
52
  const arr = Object.entries(replaceMap)
44
53
  .reduce((arr, [targetNew, targetOld]) => {
45
- // Find the original entry / 查找原始條目
54
+ /**
55
+ * 查找原始條目
56
+ * Find the original entry
57
+ */
46
58
  let old = (0, getRowOfStaticFilesMapArray_1.getRowOfStaticFilesMapArray)(ls, targetOld);
47
- // If entry exists, create a new entry with the new target path / 如果條目存在,使用新目標路徑創建新條目
59
+ /**
60
+ * 原始條目不存在時略過(例如清單中沒有該檔案),避免產生無來源的條目
61
+ * Skip when the original entry is absent (e.g. the file is not in the list) to avoid source-less entries
62
+ */
48
63
  if (old === null || old === void 0 ? void 0 : old.length) {
49
64
  arr.push((0, replaceTargetOfStaticFilesMapArrayEntry_1.replaceTargetOfStaticFilesMapArrayEntry)(old, targetNew));
50
65
  }
51
66
  return arr;
52
67
  }, []);
53
- // Combine remapped entries with original entries and remove duplicates / 合併重新映射的條目與原始條目並移除重複項
68
+ /**
69
+ * 合併重新映射的條目與原始條目並移除重複項
70
+ * Combine remapped entries with original entries and remove duplicates
71
+ *
72
+ * 重新映射的條目排在原始條目之前,去重結果決定同鍵條目的保留者
73
+ * Remapped entries come before the originals; dedup decides which entry survives for the same key
74
+ */
54
75
  return (0, array_hyper_unique_1.array_unique_overwrite)(arr.concat(ls));
55
76
  }
56
77
  //# sourceMappingURL=reMapStaticFilesMapArray.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"reMapStaticFilesMapArray.js","sourceRoot":"","sources":["reMapStaticFilesMapArray.ts"],"names":[],"mappings":";;AA6CA,4DA2BC;AA/DD,qDAAkD;AAClD,+EAA4E;AAC5E,uGAAoG;AACpG,2DAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,wBAAwB,CAAmD,QAAW,EACrG,UAAyC;IAGzC,uCAAuC;IACvC,MAAM,EAAE,GAAG,IAAA,+BAAc,EAAC,QAAQ,CAAC,CAAC;IAEpC,8CAA8C;IAC9C,MAAM,GAAG,GAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAA+B;SACnE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE;QAGvC,mCAAmC;QACnC,IAAI,GAAG,GAAG,IAAA,yDAA2B,EAAC,EAAE,EAAE,SAAS,CAAC,CAAA;QAEpD,qFAAqF;QACrF,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EACf,CAAC;YACA,GAAG,CAAC,IAAI,CAAC,IAAA,iFAAuC,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;QAClE,CAAC;QAED,OAAO,GAAG,CAAA;IACX,CAAC,EAAE,EAA6B,CAAC,CACjC;IAED,8FAA8F;IAC9F,OAAO,IAAA,2CAAsB,EAAC,GAAG,CAAC,MAAM,CAAC,EAAS,CAAC,CAAiD,CAAA;AACrG,CAAC","sourcesContent":["/**\n * Remap static files map array / 重新映射靜態檔案映射陣列\n *\n * This module provides a function to remap target file paths in a static files map.\n * 此模組提供重新映射靜態檔案映射中目標檔案路徑的函數。\n *\n * @module reMapStaticFilesMapArray\n */\nimport { IStaticFiles, IStaticFilesKey, IStaticFilesMapArray, IStaticFilesMapArrayEntry } from './types';\nimport { parseStaticMap } from './parseStaticMap';\nimport { getRowOfStaticFilesMapArray } from './getRowOfStaticFilesMapArray';\nimport { replaceTargetOfStaticFilesMapArrayEntry } from './replaceTargetOfStaticFilesMapArrayEntry';\nimport { array_unique_overwrite } from 'array-hyper-unique';\n\n/**\n * Remap static files map array with new target paths / 使用新目標路徑重新映射靜態檔案映射陣列\n *\n * Creates a new static files map array by replacing target file paths according to the provided mapping.\n * 根據提供的映射關係,通過替換目標檔案路徑來創建新的靜態檔案映射陣列。\n *\n * This is useful when you want to copy the same static file to different target locations.\n * 當您想將同一個靜態檔案複製到不同的目標位置時,這非常有用。\n *\n * @template T - The source static files map type / 來源靜態檔案映射類型\n * @template N - The new target file path type / 新目標檔案路徑類型\n *\n * @param file_map - The source static files map / 來源靜態檔案映射\n * @param replaceMap - A record mapping new target paths to old target paths / 將新路徑映射到舊路徑的記錄\n *\n * @returns A new static files map array with remapped entries / 重新映射條目的新靜態檔案映射陣列\n *\n * @example\n * ```typescript\n * import { reMapStaticFilesMapArray } from '@yarn-tool/static-file';\n * import { defaultCopyStaticFiles } from '@yarn-tool/static-file/lib/const';\n *\n * // Remap tsconfig.json.tpl to tsconfig.json\n * // 將 tsconfig.json.tpl 重新映射為 tsconfig.json\n * const remapped = reMapStaticFilesMapArray(defaultCopyStaticFiles, {\n * 'tsconfig.json': 'tsconfig.json.tpl'\n * });\n * // The result will have an entry for 'tsconfig.json' instead of 'tsconfig.json.tpl'\n * // 結果將包含 'tsconfig.json' 的條目,而不是 'tsconfig.json.tpl'\n * ```\n */\nexport function reMapStaticFilesMapArray<T extends IStaticFiles<string>, N extends string>(file_map: T,\n\treplaceMap: Record<N, IStaticFilesKey<T>>,\n)\n{\n\t// Parse the source file map / 解析來源檔案映射\n\tconst ls = parseStaticMap(file_map);\n\n\t// Process each replacement mapping / 處理每個替換映射\n\tconst arr = (Object.entries(replaceMap) as [N, IStaticFilesKey<T>][])\n\t\t.reduce((arr, [targetNew, targetOld]) =>\n\t\t{\n\n\t\t\t// Find the original entry / 查找原始條目\n\t\t\tlet old = getRowOfStaticFilesMapArray(ls, targetOld)\n\n\t\t\t// If entry exists, create a new entry with the new target path / 如果條目存在,使用新目標路徑創建新條目\n\t\t\tif (old?.length)\n\t\t\t{\n\t\t\t\tarr.push(replaceTargetOfStaticFilesMapArrayEntry(old, targetNew))\n\t\t\t}\n\n\t\t\treturn arr\n\t\t}, [] as IStaticFilesMapArray<N>)\n\t;\n\n\t// Combine remapped entries with original entries and remove duplicates / 合併重新映射的條目與原始條目並移除重複項\n\treturn array_unique_overwrite(arr.concat(ls as any)) as IStaticFilesMapArray<IStaticFilesKey<T> | N>\n}\n"]}
1
+ {"version":3,"file":"reMapStaticFilesMapArray.js","sourceRoot":"","sources":["reMapStaticFilesMapArray.ts"],"names":[],"mappings":";;AA6CA,4DAgDC;AApFD,qDAAkD;AAClD,+EAA4E;AAC5E,uGAAoG;AACpG,2DAA4D;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,wBAAwB,CAAmD,QAAW,EACrG,UAAyC;IAGzC;;;;;;OAMG;IACH,MAAM,EAAE,GAAG,IAAA,+BAAc,EAAC,QAAQ,CAAC,CAAC;IAEpC;;;OAGG;IACH,MAAM,GAAG,GAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAA+B;SACnE,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,EAAE;QAGvC;;;WAGG;QACH,IAAI,GAAG,GAAG,IAAA,yDAA2B,EAAC,EAAE,EAAE,SAAS,CAAC,CAAA;QAEpD;;;WAGG;QACH,IAAI,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,MAAM,EACf,CAAC;YACA,GAAG,CAAC,IAAI,CAAC,IAAA,iFAAuC,EAAC,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;QAClE,CAAC;QAED,OAAO,GAAG,CAAA;IACX,CAAC,EAAE,EAA6B,CAAC,CACjC;IAED;;;;;;OAMG;IACH,OAAO,IAAA,2CAAsB,EAAC,GAAG,CAAC,MAAM,CAAC,EAAS,CAAC,CAAiD,CAAA;AACrG,CAAC","sourcesContent":["/**\n * Remap static files map array / 重新映射靜態檔案映射陣列\n *\n * This module provides a function to remap target file paths in a static files map.\n * 此模組提供重新映射靜態檔案映射中目標檔案路徑的函數。\n *\n * @module reMapStaticFilesMapArray\n */\nimport { IStaticFiles, IStaticFilesKey, IStaticFilesMapArray, IStaticFilesMapArrayEntry } from './types';\nimport { parseStaticMap } from './parseStaticMap';\nimport { getRowOfStaticFilesMapArray } from './getRowOfStaticFilesMapArray';\nimport { replaceTargetOfStaticFilesMapArrayEntry } from './replaceTargetOfStaticFilesMapArrayEntry';\nimport { array_unique_overwrite } from 'array-hyper-unique';\n\n/**\n * Remap static files map array with new target paths / 使用新目標路徑重新映射靜態檔案映射陣列\n *\n * Creates a new static files map array by replacing target file paths according to the provided mapping.\n * 根據提供的映射關係,通過替換目標檔案路徑來創建新的靜態檔案映射陣列。\n *\n * This is useful when you want to copy the same static file to different target locations.\n * 當您想將同一個靜態檔案複製到不同的目標位置時,這非常有用。\n *\n * @template T - The source static files map type / 來源靜態檔案映射類型\n * @template N - The new target file path type / 新目標檔案路徑類型\n *\n * @param file_map - The source static files map / 來源靜態檔案映射\n * @param replaceMap - A record mapping new target paths to old target paths / 將新路徑映射到舊路徑的記錄\n *\n * @returns A new static files map array with remapped entries / 重新映射條目的新靜態檔案映射陣列\n *\n * @example\n * ```typescript\n * import { reMapStaticFilesMapArray } from '@yarn-tool/static-file';\n * import { defaultCopyStaticFiles } from '@yarn-tool/static-file/lib/const';\n *\n * // Remap tsconfig.json.tpl to tsconfig.json\n * // 將 tsconfig.json.tpl 重新映射為 tsconfig.json\n * const remapped = reMapStaticFilesMapArray(defaultCopyStaticFiles, {\n * 'tsconfig.json': 'tsconfig.json.tpl'\n * });\n * // The result will have an entry for 'tsconfig.json' instead of 'tsconfig.json.tpl'\n * // 結果將包含 'tsconfig.json' 的條目,而不是 'tsconfig.json.tpl'\n * ```\n */\nexport function reMapStaticFilesMapArray<T extends IStaticFiles<string>, N extends string>(file_map: T,\n\treplaceMap: Record<N, IStaticFilesKey<T>>,\n)\n{\n\t/**\n\t * 解析來源檔案映射\n\t * Parse the source file map\n\t *\n\t * 先正規化成陣列,之後才能依 key 查找並重複合成\n\t * Normalize into an array first, so entries can be looked up by key and merged later\n\t */\n\tconst ls = parseStaticMap(file_map);\n\n\t/**\n\t * 逐筆處理替換映射:把「新路徑 → 舊路徑」轉成新的條目\n\t * Process each replacement mapping: turn \"new path → old path\" into new entries\n\t */\n\tconst arr = (Object.entries(replaceMap) as [N, IStaticFilesKey<T>][])\n\t\t.reduce((arr, [targetNew, targetOld]) =>\n\t\t{\n\n\t\t\t/**\n\t\t\t * 查找原始條目\n\t\t\t * Find the original entry\n\t\t\t */\n\t\t\tlet old = getRowOfStaticFilesMapArray(ls, targetOld)\n\n\t\t\t/**\n\t\t\t * 原始條目不存在時略過(例如清單中沒有該檔案),避免產生無來源的條目\n\t\t\t * Skip when the original entry is absent (e.g. the file is not in the list) to avoid source-less entries\n\t\t\t */\n\t\t\tif (old?.length)\n\t\t\t{\n\t\t\t\tarr.push(replaceTargetOfStaticFilesMapArrayEntry(old, targetNew))\n\t\t\t}\n\n\t\t\treturn arr\n\t\t}, [] as IStaticFilesMapArray<N>)\n\t;\n\n\t/**\n\t * 合併重新映射的條目與原始條目並移除重複項\n\t * Combine remapped entries with original entries and remove duplicates\n\t *\n\t * 重新映射的條目排在原始條目之前,去重結果決定同鍵條目的保留者\n\t * Remapped entries come before the originals; dedup decides which entry survives for the same key\n\t */\n\treturn array_unique_overwrite(arr.concat(ls as any)) as IStaticFilesMapArray<IStaticFilesKey<T> | N>\n}\n"]}
@@ -48,12 +48,27 @@ const const_1 = require("../const");
48
48
  * ```
49
49
  */
50
50
  function getRootCopyStaticFilesAuto(rootData) {
51
- // Start with default package-level files / 從預設套件層級檔案開始
51
+ /**
52
+ * 從預設套件層級檔案開始
53
+ * Start with default package-level files
54
+ *
55
+ * 所有情境都需要的基礎檔案(.gitignore、tsconfig 等)
56
+ * Base files needed in every scenario (.gitignore, tsconfig, etc.)
57
+ */
52
58
  let file_map = [
53
59
  ...const_1.defaultCopyStaticFiles,
54
60
  ];
55
- // Add root-only files if this is the root and has no workspaces / 如果這是根目錄且沒有工作區,則添加僅根目錄的檔案
61
+ /**
62
+ * 只有根目錄才可能需要額外檔案
63
+ * Only a root directory can need the extra files
64
+ */
56
65
  if (rootData.isRoot) {
66
+ /**
67
+ * 具有 workspaces 的根目錄代表 monorepo,
68
+ * 根目錄專用檔案(如 pnpm-workspace.yaml)交由工作區流程處理,故不加入
69
+ * A root with workspaces is a monorepo, where root-only files (e.g. pnpm-workspace.yaml)
70
+ * are handled by the workspace flow, so they are not added here
71
+ */
57
72
  if (!rootData.hasWorkspace) {
58
73
  file_map = [
59
74
  ...file_map,