@yarn-tool/static-file 3.0.18 → 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.
- package/CHANGELOG.md +66 -0
- package/README.md +110 -3
- package/file/gitignore +3 -0
- package/file/npmignore +31 -0
- package/file/test/__root-core.cjs +1 -1
- package/file/test/__root-core.mjs +1 -1
- package/file/test/__root.js.map +1 -0
- package/file/test/__root.ts +9 -2
- package/file/test/temp.js.map +1 -0
- package/file/test/tsconfig.json.tpl +7 -0
- package/file/tsconfig.esm.json.tpl +9 -1
- package/file/tsconfig.json.tpl +9 -1
- package/file/tsconfig.tsdx.json.tpl +4 -0
- package/file/tsdx/index.cjs.map +1 -0
- package/file/ws-root/__root_ws.js.map +1 -0
- package/lib/const.js +120 -27
- package/lib/const.js.map +1 -1
- package/lib/copyStaticFiles.d.ts +62 -2
- package/lib/copyStaticFiles.js +156 -9
- package/lib/copyStaticFiles.js.map +1 -1
- package/lib/copyStaticFilesEntry.d.ts +72 -25
- package/lib/copyStaticFilesEntry.js +133 -34
- package/lib/copyStaticFilesEntry.js.map +1 -1
- package/lib/mergeIgnoreFiles.d.ts +52 -0
- package/lib/mergeIgnoreFiles.js +146 -0
- package/lib/mergeIgnoreFiles.js.map +1 -0
- package/lib/parseStaticMap.js +16 -3
- package/lib/parseStaticMap.js.map +1 -1
- package/lib/reMapStaticFilesMapArray.js +26 -5
- package/lib/reMapStaticFilesMapArray.js.map +1 -1
- package/lib/root/getRootCopyStaticFiles.js +17 -2
- package/lib/root/getRootCopyStaticFiles.js.map +1 -1
- package/lib/types.d.ts +71 -0
- package/lib/types.js.map +1 -1
- package/package.json +24 -6
- package/test/__root-core.cjs +1 -0
- package/test/__root-core.d.cts +1 -0
- package/test/__root-core.d.mts +1 -0
- package/test/__root-core.d.ts +1 -0
- package/test/__root-core.mjs +8 -0
- package/test/__root.d.ts +32 -0
- package/test/__root.js +54 -0
- package/test/__root.js.map +1 -0
- package/test/copyStaticFiles.test.js.map +1 -0
- package/test/copyStaticFiles.test.ts.snapshot +439 -0
- package/test/fixtures/out/gitignore +242 -0
- package/test/fixtures/out/npmignore +216 -0
- package/test/fixtures/split/git/00-header.txt +2 -0
- package/test/fixtures/split/git/10-project.txt +24 -0
- package/test/fixtures/split/git/20-test.txt +9 -0
- package/test/fixtures/split/git/40-env.txt +10 -0
- package/test/fixtures/split/git/90-misc.txt +6 -0
- package/test/fixtures/split/git/99-whitelist.txt +40 -0
- package/test/fixtures/split/npm/01-hidden.txt +2 -0
- package/test/fixtures/split/npm/05-source.txt +7 -0
- package/test/fixtures/split/npm/10-project.txt +31 -0
- package/test/fixtures/split/npm/20-test.txt +20 -0
- package/test/fixtures/split/npm/30-ide.txt +2 -0
- package/test/fixtures/split/npm/40-env.txt +2 -0
- package/test/fixtures/split/npm/90-misc.txt +4 -0
- package/test/fixtures/split/other/90-duplicates.txt +33 -0
- package/test/fixtures/split/shared/10-project.txt +38 -0
- package/test/fixtures/split/shared/20-test.txt +7 -0
- package/test/fixtures/split/shared/30-ide.txt +8 -0
- package/test/fixtures/split/shared/40-env.txt +6 -0
- package/test/fixtures/split/shared/90-misc.txt +10 -0
- package/test/scripts/compose-split-ignore-files.d.ts +1 -0
- package/test/scripts/compose-split-ignore-files.js +80 -0
- package/test/scripts/compose-split-ignore-files.js.map +1 -0
- package/test/scripts/lib/ignore-split.d.ts +205 -0
- package/test/scripts/lib/ignore-split.js +286 -0
- package/test/scripts/lib/ignore-split.js.map +1 -0
- package/test/scripts/split-ignore-files.d.ts +1 -0
- package/test/scripts/split-ignore-files.js +454 -0
- package/test/scripts/split-ignore-files.js.map +1 -0
- package/test/scripts/update-npmignore-static-files.d.ts +1 -0
- package/test/scripts/update-npmignore-static-files.js +121 -0
- package/test/scripts/update-npmignore-static-files.js.map +1 -0
- package/test/temp.d.ts +3 -0
- package/test/temp.js +5 -0
- package/test/temp.js.map +1 -0
- package/test/tsconfig.json.tpl +13 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRootCopyStaticFiles.js","sourceRoot":"","sources":["getRootCopyStaticFiles.ts"],"names":[],"mappings":";;AA0DA,
|
|
1
|
+
{"version":3,"file":"getRootCopyStaticFiles.js","sourceRoot":"","sources":["getRootCopyStaticFiles.ts"],"names":[],"mappings":";;AA0DA,gEAmCC;AAlFD,oCAAkF;AAElF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,SAAgB,0BAA0B,CAAC,QAA6D;IAEvG;;;;;;OAMG;IACH,IAAI,QAAQ,GAAiC;QAC5C,GAAG,8BAAsB;KACzB,CAAC;IAEF;;;OAGG;IACH,IAAI,QAAQ,CAAC,MAAM,EACnB,CAAC;QACA;;;;;WAKG;QACH,IAAI,CAAC,QAAQ,CAAC,YAAY,EAC1B,CAAC;YACA,QAAQ,GAAG;gBACV,GAAG,QAAQ;gBACX,GAAG,sCAA8B;aACjC,CAAC;QACH,CAAC;IACF,CAAC;IAED,OAAO,QAAQ,CAAA;AAChB,CAAC","sourcesContent":["/**\n * Get root copy static files configuration / 獲取根目錄複製靜態檔案配置\n *\n * This module provides a function to determine the appropriate static files\n * to copy based on the project root structure.\n * 此模組提供根據專案根目錄結構確定要複製的適當靜態檔案的函數。\n *\n * @module getRootCopyStaticFiles\n */\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { IStaticFilesMapArray } from '../types';\nimport { defaultCopyStaticFiles, defaultCopyStaticFilesRootOnly } from '../const';\n\n/**\n * Get the appropriate static files map based on root data / 根據根目錄數據獲取適當的靜態檔案映射\n *\n * Determines which static files should be copied based on whether the current\n * directory is the workspace root and whether it has workspaces.\n * 根據當前目錄是否為工作區根目錄以及是否具有工作區,確定應複製哪些靜態檔案。\n *\n * @param rootData - Information about the project root / 關於專案根目錄的資訊\n * @param rootData.isRoot - Whether the current directory is the workspace root / 當前目錄是否為工作區根目錄\n * @param rootData.hasWorkspace - Whether the project has workspaces / 專案是否具有工作區\n *\n * @returns An array of static file entries to copy / 要複製的靜態檔案條目陣列\n *\n * @example\n * ```typescript\n * import { getRootCopyStaticFilesAuto } from '@yarn-tool/static-file';\n *\n * // For a workspace root with workspaces\n * // 對於具有工作區的工作區根目錄\n * const files1 = getRootCopyStaticFilesAuto({\n * isRoot: true,\n * hasWorkspace: true\n * });\n * // Returns only defaultCopyStaticFiles (not root-only files)\n * // 僅返回 defaultCopyStaticFiles(不包含僅根目錄的檔案)\n *\n * // For a standalone project root\n * // 對於獨立專案根目錄\n * const files2 = getRootCopyStaticFilesAuto({\n * isRoot: true,\n * hasWorkspace: false\n * });\n * // Returns defaultCopyStaticFiles + defaultCopyStaticFilesRootOnly\n * // 返回 defaultCopyStaticFiles + defaultCopyStaticFilesRootOnly\n *\n * // For a package within a workspace\n * // 對於工作區內的套件\n * const files3 = getRootCopyStaticFilesAuto({\n * isRoot: false,\n * hasWorkspace: true\n * });\n * // Returns only defaultCopyStaticFiles\n * // 僅返回 defaultCopyStaticFiles\n * ```\n */\nexport function getRootCopyStaticFilesAuto(rootData: Pick<IFindRootReturnType, 'isRoot'| 'hasWorkspace'>)\n{\n\t/**\n\t * 從預設套件層級檔案開始\n\t * Start with default package-level files\n\t *\n\t * 所有情境都需要的基礎檔案(.gitignore、tsconfig 等)\n\t * Base files needed in every scenario (.gitignore, tsconfig, etc.)\n\t */\n\tlet file_map: IStaticFilesMapArray<string> = [\n\t\t...defaultCopyStaticFiles,\n\t];\n\n\t/**\n\t * 只有根目錄才可能需要額外檔案\n\t * Only a root directory can need the extra files\n\t */\n\tif (rootData.isRoot)\n\t{\n\t\t/**\n\t\t * 具有 workspaces 的根目錄代表 monorepo,\n\t\t * 根目錄專用檔案(如 pnpm-workspace.yaml)交由工作區流程處理,故不加入\n\t\t * A root with workspaces is a monorepo, where root-only files (e.g. pnpm-workspace.yaml)\n\t\t * are handled by the workspace flow, so they are not added here\n\t\t */\n\t\tif (!rootData.hasWorkspace)\n\t\t{\n\t\t\tfile_map = [\n\t\t\t\t...file_map,\n\t\t\t\t...defaultCopyStaticFilesRootOnly,\n\t\t\t];\n\t\t}\n\t}\n\n\treturn file_map\n}\n"]}
|
package/lib/types.d.ts
CHANGED
|
@@ -5,6 +5,17 @@
|
|
|
5
5
|
* 從靜態檔案映射陣列中提取所有可能的檔案 ID 聯合類型。
|
|
6
6
|
*/
|
|
7
7
|
import { defaultCopyStaticFiles, defaultCopyStaticFilesRootOnly } from './const';
|
|
8
|
+
import type { IgnoreFile } from '@yarn-tool/ignore/lib/IgnoreFile';
|
|
9
|
+
/**
|
|
10
|
+
* 既有 ignore 檔案的快照 / Snapshot of existing ignore files
|
|
11
|
+
*
|
|
12
|
+
* 以相對目標路徑(如 `.gitignore`)為鍵,保存 reset 前讀取到的內容。
|
|
13
|
+
* Keyed by the relative target path (e.g. `.gitignore`), holding the content read before the reset.
|
|
14
|
+
*
|
|
15
|
+
* @see _readIgnoreFilesSnapshot
|
|
16
|
+
* @see mergeIgnoreFiles
|
|
17
|
+
*/
|
|
18
|
+
export type IIgnoreFilesSnapshot = Map<string, IgnoreFile>;
|
|
8
19
|
export type IStaticFilesID<T = typeof defaultCopyStaticFiles & typeof defaultCopyStaticFilesRootOnly> = T extends ({
|
|
9
20
|
[n: number]: IStaticFilesMapArrayEntry<infer U>;
|
|
10
21
|
} | {
|
|
@@ -82,6 +93,66 @@ export interface ICopyStaticFilesOptionsBase<K extends string = string> {
|
|
|
82
93
|
*/
|
|
83
94
|
export interface ICopyStaticFilesOptions<K extends string = string> extends ICopyStaticFilesOptionsBase<K> {
|
|
84
95
|
file_map?: IStaticFiles<K>;
|
|
96
|
+
/**
|
|
97
|
+
* reset 前建立的既有 ignore 檔快照
|
|
98
|
+
* Snapshot of existing ignore files taken before the reset
|
|
99
|
+
*
|
|
100
|
+
* 提供時會在複製完成後自動合併 ignore 檔案;未提供則不做任何合併。
|
|
101
|
+
* When provided, ignore files are auto-merged after the copy; when omitted nothing is merged.
|
|
102
|
+
*
|
|
103
|
+
* @see mergeIgnoreFiles
|
|
104
|
+
*/
|
|
105
|
+
ignoreFilesSnapshot?: IIgnoreFilesSnapshot;
|
|
106
|
+
}
|
|
107
|
+
export interface ICopyStaticFilesOptionsRuntime<K extends string = string> extends Omit<Required<ICopyStaticFilesOptions<K>>, 'file_map' | 'ignoreFilesSnapshot'> {
|
|
108
|
+
file_map: IStaticFilesMapArray<K>;
|
|
109
|
+
/**
|
|
110
|
+
* reset 前建立的既有 ignore 檔快照;未提供時不執行任何合併
|
|
111
|
+
* Snapshot of existing ignore files taken before the reset; nothing is merged when omitted
|
|
112
|
+
*
|
|
113
|
+
* @see mergeIgnoreFiles
|
|
114
|
+
*/
|
|
115
|
+
ignoreFilesSnapshot?: IIgnoreFilesSnapshot;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 單個靜態檔案條目的執行期複製資訊 / Runtime copy info for a single static file entry
|
|
119
|
+
*
|
|
120
|
+
* 由 _copyStaticFilesEntryCore 解析產生;條目被 detectFile 跳過時該函式回傳 undefined,不會產生此物件。
|
|
121
|
+
* Produced by _copyStaticFilesEntryCore; when an entry is skipped by detectFile the function returns undefined and no such object is produced.
|
|
122
|
+
*
|
|
123
|
+
* @template K - 目標檔案路徑類型 / Target file path type
|
|
124
|
+
*
|
|
125
|
+
* @see _copyStaticFilesEntryCore
|
|
126
|
+
*/
|
|
127
|
+
export interface IStaticFilesEntryRuntime<K extends string = string> {
|
|
128
|
+
/** 目標檔案路徑(相對於 cwd)/ Target file path (relative to cwd) */
|
|
129
|
+
readonly targetFile: K;
|
|
130
|
+
/** 來源靜態檔案路徑(相對於 staticRoot)/ Source static file path (relative to staticRoot) */
|
|
131
|
+
readonly staticFile: string;
|
|
132
|
+
/** 以 cwd 為基準解析出的目標檔案完整路徑 / Fully resolved target file path against cwd */
|
|
133
|
+
readonly targetFileFull: string;
|
|
134
|
+
/** 以 staticRoot 為基準解析出的來源檔案完整路徑 / Fully resolved source file path against staticRoot */
|
|
135
|
+
readonly staticFileFull: string;
|
|
136
|
+
/** 是否覆蓋已存在的檔案,未指定選項時為 false / Whether to overwrite an existing file; false when the option is omitted */
|
|
137
|
+
readonly overwrite: boolean;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* 靜態檔案清單產生器的產出項目 / Item yielded by the static file list generator
|
|
141
|
+
*
|
|
142
|
+
* 包含條目、其執行期複製資訊,以及由呼叫端決定是否執行的複製動作。
|
|
143
|
+
* Holds the entry, its runtime copy info, and the copy action whose execution is decided by the caller.
|
|
144
|
+
*
|
|
145
|
+
* @template K - 目標檔案路徑類型 / Target file path type
|
|
146
|
+
*
|
|
147
|
+
* @see _copyStaticFilesCoreListGenerator
|
|
148
|
+
*/
|
|
149
|
+
export interface IStaticFilesEntryGeneratorItem<K extends string = string> {
|
|
150
|
+
/** 靜態檔案條目 / Static file entry */
|
|
151
|
+
entry: IStaticFilesMapArrayEntry<K>;
|
|
152
|
+
/** 執行期複製資訊 / Runtime copy info */
|
|
153
|
+
runtime: IStaticFilesEntryRuntime<K>;
|
|
154
|
+
/** 執行實際複製;不呼叫即不寫入任何檔案 / Perform the actual copy; nothing is written unless it is called */
|
|
155
|
+
copy(): void;
|
|
85
156
|
}
|
|
86
157
|
/**
|
|
87
158
|
* Extracts the key type from static files map / 從靜態檔案映射中提取鍵類型
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Static file ID type / 靜態檔案 ID 類型\n *\n * Extracts the union type of all possible file IDs from the static files map array.\n * 從靜態檔案映射陣列中提取所有可能的檔案 ID 聯合類型。\n */\nimport { defaultCopyStaticFiles, defaultCopyStaticFilesRootOnly } from './const';\n\nexport type IStaticFilesID<T = typeof defaultCopyStaticFiles & typeof defaultCopyStaticFilesRootOnly> =\n\tT extends ({\n\t\t\t[n: number]: IStaticFilesMapArrayEntry<infer U>\n\t\t} | {\n\t\t\treadonly [n: number]: IStaticFilesMapArrayEntry<infer U>;\n\t\t})\n\t\t? U\n\t\t: never\n\t;\n\n/**\n * Static files map array entry type / 靜態檔案映射陣列條目類型\n *\n * Represents a single entry in the static files map array.\n * 表示靜態檔案映射陣列中的單個條目。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @param targetFile - Target file path to copy to / 要複製到的目標檔案路徑\n * @param staticFile - Source static file path / 來源靜態檔案路徑\n * @param detectFile - Optional file path to detect if target already exists / 可選的檢測檔案路徑,用於判斷目標是否已存在\n */\nexport type IStaticFilesMapArrayEntry<K extends string> =\n\t[targetFile: K, staticFile: string, detectFile?: string]\n\n/**\n * Static files map object type (internal) / 靜態檔案映射物件類型(內部使用)\n * @internal\n */\ntype IStaticFilesMap01<K extends string> = {\n\t[P in K]: IStaticFilesMapArrayEntry<P>\n}\n\n/**\n * Static files map record type / 靜態檔案映射記錄類型\n *\n * A record mapping target file paths to source file paths.\n * 將目標檔案路徑映射到來源檔案路徑的記錄類型。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n */\nexport type IStaticFilesMapRecord<K extends string> = {\n\t[P in K]: string\n}\n\n/**\n * Static files map array type / 靜態檔案映射陣列類型\n *\n * An array of static file mapping entries.\n * 靜態檔案映射條目的陣列。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n */\nexport type IStaticFilesMapArray<K extends string> =\n\tIStaticFilesMapArrayEntry<K>[]\n\n/**\n * Static files map type / 靜態檔案映射類型\n *\n * Can be either an array of entries or a record mapping.\n * 可以是條目陣列或記錄映射。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n */\nexport type IStaticFiles<K extends string> = IStaticFilesMapArray<K> | IStaticFilesMapRecord<K>\n\n/**\n * Base options for copying static files / 複製靜態檔案的基本選項\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @property cwd - Current working directory / 當前工作目錄\n * @property staticRoot - Root directory of static files / 靜態檔案的根目錄\n * @property overwrite - Whether to overwrite existing files / 是否覆蓋已存在的檔案\n */\nexport interface ICopyStaticFilesOptionsBase<K extends string = string>\n{\n\tcwd: string,\n\tstaticRoot?: string,\n\toverwrite?: boolean,\n}\n\n/**\n * Options for copying static files / 複製靜態檔案的選項\n *\n * Extends the base options with file map configuration.\n * 擴展基本選項,加入檔案映射配置。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @property file_map - Custom file mapping configuration / 自訂檔案映射配置\n */\nexport interface ICopyStaticFilesOptions<K extends string = string> extends ICopyStaticFilesOptionsBase<K>\n{\n\tfile_map?: IStaticFiles<K
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Static file ID type / 靜態檔案 ID 類型\n *\n * Extracts the union type of all possible file IDs from the static files map array.\n * 從靜態檔案映射陣列中提取所有可能的檔案 ID 聯合類型。\n */\nimport { defaultCopyStaticFiles, defaultCopyStaticFilesRootOnly } from './const';\nimport type { IgnoreFile } from '@yarn-tool/ignore/lib/IgnoreFile';\n\n/**\n * 既有 ignore 檔案的快照 / Snapshot of existing ignore files\n *\n * 以相對目標路徑(如 `.gitignore`)為鍵,保存 reset 前讀取到的內容。\n * Keyed by the relative target path (e.g. `.gitignore`), holding the content read before the reset.\n *\n * @see _readIgnoreFilesSnapshot\n * @see mergeIgnoreFiles\n */\nexport type IIgnoreFilesSnapshot = Map<string, IgnoreFile>;\n\nexport type IStaticFilesID<T = typeof defaultCopyStaticFiles & typeof defaultCopyStaticFilesRootOnly> =\n\tT extends ({\n\t\t\t[n: number]: IStaticFilesMapArrayEntry<infer U>\n\t\t} | {\n\t\t\treadonly [n: number]: IStaticFilesMapArrayEntry<infer U>;\n\t\t})\n\t\t? U\n\t\t: never\n\t;\n\n/**\n * Static files map array entry type / 靜態檔案映射陣列條目類型\n *\n * Represents a single entry in the static files map array.\n * 表示靜態檔案映射陣列中的單個條目。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @param targetFile - Target file path to copy to / 要複製到的目標檔案路徑\n * @param staticFile - Source static file path / 來源靜態檔案路徑\n * @param detectFile - Optional file path to detect if target already exists / 可選的檢測檔案路徑,用於判斷目標是否已存在\n */\nexport type IStaticFilesMapArrayEntry<K extends string> =\n\t[targetFile: K, staticFile: string, detectFile?: string]\n\n/**\n * Static files map object type (internal) / 靜態檔案映射物件類型(內部使用)\n * @internal\n */\ntype IStaticFilesMap01<K extends string> = {\n\t[P in K]: IStaticFilesMapArrayEntry<P>\n}\n\n/**\n * Static files map record type / 靜態檔案映射記錄類型\n *\n * A record mapping target file paths to source file paths.\n * 將目標檔案路徑映射到來源檔案路徑的記錄類型。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n */\nexport type IStaticFilesMapRecord<K extends string> = {\n\t[P in K]: string\n}\n\n/**\n * Static files map array type / 靜態檔案映射陣列類型\n *\n * An array of static file mapping entries.\n * 靜態檔案映射條目的陣列。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n */\nexport type IStaticFilesMapArray<K extends string> =\n\tIStaticFilesMapArrayEntry<K>[]\n\n/**\n * Static files map type / 靜態檔案映射類型\n *\n * Can be either an array of entries or a record mapping.\n * 可以是條目陣列或記錄映射。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n */\nexport type IStaticFiles<K extends string> = IStaticFilesMapArray<K> | IStaticFilesMapRecord<K>\n\n/**\n * Base options for copying static files / 複製靜態檔案的基本選項\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @property cwd - Current working directory / 當前工作目錄\n * @property staticRoot - Root directory of static files / 靜態檔案的根目錄\n * @property overwrite - Whether to overwrite existing files / 是否覆蓋已存在的檔案\n */\nexport interface ICopyStaticFilesOptionsBase<K extends string = string>\n{\n\tcwd: string,\n\tstaticRoot?: string,\n\toverwrite?: boolean,\n}\n\n/**\n * Options for copying static files / 複製靜態檔案的選項\n *\n * Extends the base options with file map configuration.\n * 擴展基本選項,加入檔案映射配置。\n *\n * @template K - The target file path type / 目標檔案路徑類型\n *\n * @property file_map - Custom file mapping configuration / 自訂檔案映射配置\n */\nexport interface ICopyStaticFilesOptions<K extends string = string> extends ICopyStaticFilesOptionsBase<K>\n{\n\tfile_map?: IStaticFiles<K>;\n\n\t/**\n\t * reset 前建立的既有 ignore 檔快照\n\t * Snapshot of existing ignore files taken before the reset\n\t *\n\t * 提供時會在複製完成後自動合併 ignore 檔案;未提供則不做任何合併。\n\t * When provided, ignore files are auto-merged after the copy; when omitted nothing is merged.\n\t *\n\t * @see mergeIgnoreFiles\n\t */\n\tignoreFilesSnapshot?: IIgnoreFilesSnapshot;\n}\n\nexport interface ICopyStaticFilesOptionsRuntime<K extends string = string> extends Omit<Required<ICopyStaticFilesOptions<K>>, 'file_map' | 'ignoreFilesSnapshot'>\n{\n\tfile_map: IStaticFilesMapArray<K>;\n\n\t/**\n\t * reset 前建立的既有 ignore 檔快照;未提供時不執行任何合併\n\t * Snapshot of existing ignore files taken before the reset; nothing is merged when omitted\n\t *\n\t * @see mergeIgnoreFiles\n\t */\n\tignoreFilesSnapshot?: IIgnoreFilesSnapshot;\n}\n\n/**\n * 單個靜態檔案條目的執行期複製資訊 / Runtime copy info for a single static file entry\n *\n * 由 _copyStaticFilesEntryCore 解析產生;條目被 detectFile 跳過時該函式回傳 undefined,不會產生此物件。\n * Produced by _copyStaticFilesEntryCore; when an entry is skipped by detectFile the function returns undefined and no such object is produced.\n *\n * @template K - 目標檔案路徑類型 / Target file path type\n *\n * @see _copyStaticFilesEntryCore\n */\nexport interface IStaticFilesEntryRuntime<K extends string = string>\n{\n\t/** 目標檔案路徑(相對於 cwd)/ Target file path (relative to cwd) */\n\treadonly targetFile: K;\n\n\t/** 來源靜態檔案路徑(相對於 staticRoot)/ Source static file path (relative to staticRoot) */\n\treadonly staticFile: string;\n\n\t/** 以 cwd 為基準解析出的目標檔案完整路徑 / Fully resolved target file path against cwd */\n\treadonly targetFileFull: string;\n\n\t/** 以 staticRoot 為基準解析出的來源檔案完整路徑 / Fully resolved source file path against staticRoot */\n\treadonly staticFileFull: string;\n\n\t/** 是否覆蓋已存在的檔案,未指定選項時為 false / Whether to overwrite an existing file; false when the option is omitted */\n\treadonly overwrite: boolean;\n}\n\n/**\n * 靜態檔案清單產生器的產出項目 / Item yielded by the static file list generator\n *\n * 包含條目、其執行期複製資訊,以及由呼叫端決定是否執行的複製動作。\n * Holds the entry, its runtime copy info, and the copy action whose execution is decided by the caller.\n *\n * @template K - 目標檔案路徑類型 / Target file path type\n *\n * @see _copyStaticFilesCoreListGenerator\n */\nexport interface IStaticFilesEntryGeneratorItem<K extends string = string>\n{\n\t/** 靜態檔案條目 / Static file entry */\n\tentry: IStaticFilesMapArrayEntry<K>;\n\n\t/** 執行期複製資訊 / Runtime copy info */\n\truntime: IStaticFilesEntryRuntime<K>;\n\n\t/** 執行實際複製;不呼叫即不寫入任何檔案 / Perform the actual copy; nothing is written unless it is called */\n\tcopy(): void;\n}\n\n/**\n * Extracts the key type from static files map / 從靜態檔案映射中提取鍵類型\n *\n * Utility type to extract the union type of target file paths from various static file map formats.\n * 工具類型,用於從各種靜態檔案映射格式中提取目標檔案路徑的聯合類型。\n *\n * @template T - The static files map type / 靜態檔案映射類型\n */\nexport type IStaticFilesKey<T extends IStaticFiles<string> | readonly any[]> = T extends IStaticFilesMapArray<infer K>\n\t? K\n\t: T extends readonly IStaticFilesMapArrayEntry<infer K>[]\n\t\t? K\n\t\t: T extends IStaticFilesMapRecord<infer K> ? K\n\t\t\t: _Key<T>\n\t;\n\n/**\n * Internal key extraction type / 內部鍵提取類型\n * @internal\n */\nexport type _Key<T> = T extends readonly (infer U)[] | (infer U)[]\n\t? (U extends [infer K, string, string] | readonly [infer K, string, string] ? K : never)\n\t: never\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/static-file",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "3.0.20",
|
|
4
|
+
"description": "用於將靜態設定檔案 (static configuration files) 複製到 yarn 工作區專案的工具 / A utility for copying static configuration files to yarn workspace projects",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"static-file",
|
|
7
|
+
"static-files",
|
|
8
|
+
"static-templates",
|
|
9
|
+
"copy-static-files",
|
|
10
|
+
"config-files",
|
|
11
|
+
"template",
|
|
12
|
+
"templates",
|
|
13
|
+
"yarn-workspace",
|
|
14
|
+
"workspace",
|
|
15
|
+
"gitignore",
|
|
16
|
+
"npmignore",
|
|
17
|
+
"tsconfig"
|
|
18
|
+
],
|
|
5
19
|
"homepage": "https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/static-file#readme",
|
|
6
20
|
"bugs": {
|
|
7
21
|
"url": "https://github.com/bluelovers/ws-yarn-workspaces/issues"
|
|
@@ -15,26 +29,30 @@
|
|
|
15
29
|
"author": "",
|
|
16
30
|
"main": "index.js",
|
|
17
31
|
"scripts": {
|
|
18
|
-
"
|
|
32
|
+
"coverage": "pnpm run test --coverage",
|
|
33
|
+
"test": "node --run test:node",
|
|
19
34
|
"test:jest": "jest --passWithNoTests",
|
|
20
35
|
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
21
36
|
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
37
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
22
38
|
"test:snapshot": "pnpm run test -u",
|
|
39
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
23
40
|
"test:tsd": "ynpx tsd",
|
|
24
41
|
"npm:publish": "npm publish",
|
|
25
42
|
"preversion": "pnpm run test",
|
|
26
43
|
"prepublishOnly": "node --run fix:ignore",
|
|
44
|
+
"fix:ignore": "tsx test/scripts/update-npmignore-static-files.ts",
|
|
27
45
|
"ncu": "yarn-tool ncu -u",
|
|
28
46
|
"sort-package-json": "yarn-tool sort",
|
|
29
|
-
"fix:ignore": "tsx test/scripts/update-npmignore-static-files.ts",
|
|
30
47
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
31
48
|
},
|
|
32
49
|
"dependencies": {
|
|
33
|
-
"
|
|
50
|
+
"@yarn-tool/ignore": "^1.0.1",
|
|
51
|
+
"fs-extra": "^11.4.1",
|
|
34
52
|
"tslib": ">=2.8.1"
|
|
35
53
|
},
|
|
36
54
|
"publishConfig": {
|
|
37
55
|
"access": "public"
|
|
38
56
|
},
|
|
39
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
|
|
40
58
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports.__ROOT_CORE = require('upath2').resolve(__dirname, '..');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __ROOT_CORE: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __ROOT_CORE: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const __ROOT_CORE: string;
|
package/test/__root.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 專案根目錄
|
|
3
|
+
*/
|
|
4
|
+
export declare const __ROOT: string;
|
|
5
|
+
export declare const isWin: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* 測試資料夾
|
|
8
|
+
* 基於 {@link __ROOT}
|
|
9
|
+
*
|
|
10
|
+
* @default test
|
|
11
|
+
*/
|
|
12
|
+
export declare const __TEST_ROOT: string;
|
|
13
|
+
/**
|
|
14
|
+
* 測試資料夾(唯讀)
|
|
15
|
+
* 基於 {@link __TEST_ROOT}
|
|
16
|
+
*
|
|
17
|
+
* @default test/fixtures
|
|
18
|
+
*/
|
|
19
|
+
export declare const __TEST_FIXTURES: string;
|
|
20
|
+
/**
|
|
21
|
+
* 臨時檔案(可寫,永遠建立子資料夾)
|
|
22
|
+
* 基於 {@link __TEST_ROOT}
|
|
23
|
+
*
|
|
24
|
+
* test/
|
|
25
|
+
* ├── fixtures/ ← 測試資料夾(唯讀)
|
|
26
|
+
* └── temp/ ← 臨時檔案(可寫,永遠建立子資料夾)
|
|
27
|
+
* ├── fake-lib/
|
|
28
|
+
* └── temp-pkg/
|
|
29
|
+
*
|
|
30
|
+
* @default test/temp
|
|
31
|
+
*/
|
|
32
|
+
export declare const __TEST_TEMP: string;
|
package/test/__root.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.__TEST_TEMP = exports.__TEST_FIXTURES = exports.__TEST_ROOT = exports.isWin = exports.__ROOT = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* 測試路徑架構 / Test Path Structure
|
|
7
|
+
*
|
|
8
|
+
* test/
|
|
9
|
+
* ├── fixtures/ ← 測試資料夾(唯讀)
|
|
10
|
+
* └── temp/ ← 臨時檔案(可寫,永遠建立子資料夾)
|
|
11
|
+
* ├── fake-lib/
|
|
12
|
+
* └── temp-pkg/
|
|
13
|
+
*/
|
|
14
|
+
/// <reference types="node" />
|
|
15
|
+
/**
|
|
16
|
+
* 如果不需要 upath2 可改用 path
|
|
17
|
+
*/
|
|
18
|
+
// import path from 'path';
|
|
19
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
const __root_core_cjs_1 = require("./__root-core.cjs");
|
|
22
|
+
/**
|
|
23
|
+
* 專案根目錄
|
|
24
|
+
*/
|
|
25
|
+
exports.__ROOT = path_1.default.normalize(__root_core_cjs_1.__ROOT_CORE);
|
|
26
|
+
exports.isWin = process.platform === "win32";
|
|
27
|
+
/**
|
|
28
|
+
* 測試資料夾
|
|
29
|
+
* 基於 {@link __ROOT}
|
|
30
|
+
*
|
|
31
|
+
* @default test
|
|
32
|
+
*/
|
|
33
|
+
exports.__TEST_ROOT = path_1.default.join(exports.__ROOT, 'test');
|
|
34
|
+
/**
|
|
35
|
+
* 測試資料夾(唯讀)
|
|
36
|
+
* 基於 {@link __TEST_ROOT}
|
|
37
|
+
*
|
|
38
|
+
* @default test/fixtures
|
|
39
|
+
*/
|
|
40
|
+
exports.__TEST_FIXTURES = path_1.default.join(exports.__TEST_ROOT, 'fixtures');
|
|
41
|
+
/**
|
|
42
|
+
* 臨時檔案(可寫,永遠建立子資料夾)
|
|
43
|
+
* 基於 {@link __TEST_ROOT}
|
|
44
|
+
*
|
|
45
|
+
* test/
|
|
46
|
+
* ├── fixtures/ ← 測試資料夾(唯讀)
|
|
47
|
+
* └── temp/ ← 臨時檔案(可寫,永遠建立子資料夾)
|
|
48
|
+
* ├── fake-lib/
|
|
49
|
+
* └── temp-pkg/
|
|
50
|
+
*
|
|
51
|
+
* @default test/temp
|
|
52
|
+
*/
|
|
53
|
+
exports.__TEST_TEMP = path_1.default.join(exports.__TEST_ROOT, 'temp');
|
|
54
|
+
//# sourceMappingURL=__root.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__root.js","sourceRoot":"","sources":["__root.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;GAQG;AACH,8BAA8B;AAC9B;;GAEG;AACH,2BAA2B;AAC3B,wDAAwB;AACxB,aAAa;AACb,uDAAgD;AAEhD;;GAEG;AACU,QAAA,MAAM,GAAG,cAAI,CAAC,SAAS,CAAC,6BAAW,CAAC,CAAC;AAErC,QAAA,KAAK,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC;AAElD;;;;;GAKG;AACU,QAAA,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,cAAM,EAAE,MAAM,CAAC,CAAC;AAErD;;;;;GAKG;AACU,QAAA,eAAe,GAAG,cAAI,CAAC,IAAI,CAAC,mBAAW,EAAE,UAAU,CAAC,CAAC;AAElE;;;;;;;;;;;GAWG;AACU,QAAA,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,mBAAW,EAAE,MAAM,CAAC,CAAC","sourcesContent":["/**\n * 測試路徑架構 / Test Path Structure\n *\n * test/\n * ├── fixtures/ ← 測試資料夾(唯讀)\n * └── temp/ ← 臨時檔案(可寫,永遠建立子資料夾)\n * ├── fake-lib/\n * └── temp-pkg/\n */\n/// <reference types=\"node\" />\n/**\n * 如果不需要 upath2 可改用 path\n */\n// import path from 'path';\nimport path from 'path';\n// @ts-ignore\nimport { __ROOT_CORE } from './__root-core.cjs';\n\n/**\n * 專案根目錄\n */\nexport const __ROOT = path.normalize(__ROOT_CORE);\n\nexport const isWin = process.platform === \"win32\";\n\n/**\n * 測試資料夾\n * 基於 {@link __ROOT}\n *\n * @default test\n */\nexport const __TEST_ROOT = path.join(__ROOT, 'test');\n\n/**\n * 測試資料夾(唯讀)\n * 基於 {@link __TEST_ROOT}\n *\n * @default test/fixtures\n */\nexport const __TEST_FIXTURES = path.join(__TEST_ROOT, 'fixtures');\n\n/**\n * 臨時檔案(可寫,永遠建立子資料夾)\n * 基於 {@link __TEST_ROOT}\n *\n * test/\n * ├── fixtures/ ← 測試資料夾(唯讀)\n * └── temp/ ← 臨時檔案(可寫,永遠建立子資料夾)\n * ├── fake-lib/\n * └── temp-pkg/\n *\n * @default test/temp\n */\nexport const __TEST_TEMP = path.join(__TEST_ROOT, 'temp');\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copyStaticFiles.test.js","sourceRoot":"","sources":["copyStaticFiles.test.ts"],"names":[],"mappings":";;AAAA;;;;;;;;GAQG;AACH,yCAA2C;AAE3C,4DAA0G;AAC1G,4EAA2G;AAE3G;;;;;;;;GAQG;AACH,MAAM,GAAG,GAAG,SAAS,CAAC;AAEtB;;;;;GAKG;AACH,SAAS,eAAe,CAAC,IAAY;IAEpC,OAAO,IAAA,gCAAkB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,uCAAyB,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACrF,CAAC;AAED,IAAA,oBAAQ,EAAC,+BAA+B,EAAE,GAAG,EAAE;IAE9C,IAAA,gBAAI,EAAC,oDAAoD,EAAE,CAAC,CAAC,EAAE,EAAE;QAEhE,MAAM,MAAM,GAAG,IAAA,+CAA6B,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC;QAEtD,MAAM,QAAQ,GAAG;YAChB,GAAG,MAAM;YACT,GAAG,EAAE,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC;YAChC,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC;SAC9C,CAAC;QAEF,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAA,oBAAQ,EAAC,mCAAmC,EAAE,GAAG,EAAE;IAElD,IAAA,gBAAI,EAAC,oDAAoD,EAAE,CAAC,CAAC,EAAE,EAAE;QAEhE;;;;;;;WAOG;QACH,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAA,mDAAiC,EAAC,EAAE,GAAG,EAAE,CAAC,CAAC;aAC9D,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACf,GAAG,IAAI;YACP,OAAO,EAAE;gBACR,GAAG,IAAI,CAAC,OAAO;gBACf,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;gBAC5D,cAAc,EAAE,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC;aAC5D;YACD,IAAI,EAAE,OAAO,IAAI,CAAC,IAAI;SACtB,CAAC,CAAC,CAAC;QAEL,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/**\n * @yarn-tool/static-file 快照測試\n * Snapshot tests for @yarn-tool/static-file\n *\n * 只涵蓋不會寫入檔案的內部函式:選項補齊與清單產出皆為唯讀操作,\n * 因此測試過程不建立、也不覆蓋任何靜態檔案。\n * Only covers internals that never write files: option resolution and list generation are read-only,\n * so the run creates and overwrites nothing.\n */\nimport { describe, test } from 'node:test';\n\nimport { _copyStaticFilesCoreListGenerator, _handleCopyStaticFilesOptions } from '../lib/copyStaticFiles';\nimport { _isPathForSnapshot, _normalizePathForSnapshot } from '../../require-resolve/test/lib/test-helper';\n\n/**\n * 以測試檔所在目錄作為唯一必填的 cwd\n * Use the test file's own directory as the sole required cwd\n *\n * 該目錄必然存在,且不含預設清單中任何 detectFile 指向的檔案,\n * 使快照內容不因執行環境而變動。\n * The directory always exists and holds none of the detectFile targets from the default list,\n * keeping the snapshot independent of the execution environment.\n */\nconst cwd = __dirname;\n\n/**\n * 快照前標準化路徑 / Normalize paths before snapshotting\n *\n * 僅改寫含 workspace 特徵的絕對路徑;entry 內的相對路徑保持原樣\n * Only absolute paths carrying a workspace marker are rewritten; relative paths inside entry stay untouched\n */\nfunction _toSnapshotPath(path: string)\n{\n\treturn _isPathForSnapshot(path) ? _normalizePathForSnapshot(path, undefined) : path;\n}\n\ndescribe('_handleCopyStaticFilesOptions', () =>\n{\n\ttest('預設值 + 必填參數 / defaults with only the required param', (t) =>\n\t{\n\t\tconst actual = _handleCopyStaticFilesOptions({ cwd });\n\n\t\tconst snapshot = {\n\t\t\t...actual,\n\t\t\tcwd: _toSnapshotPath(actual.cwd),\n\t\t\tstaticRoot: _toSnapshotPath(actual.staticRoot),\n\t\t};\n\n\t\tt.assert.snapshot(snapshot);\n\t});\n});\n\ndescribe('_copyStaticFilesCoreListGenerator', () =>\n{\n\ttest('預設值 + 必填參數 / defaults with only the required param', (t) =>\n\t{\n\t\t/**\n\t\t * 保留實際產出的結構(entry / runtime / copy),只標準化 runtime 內的絕對路徑;\n\t\t * copy 是函式、序列化時會被略過,故以 typeof 取代其值讓鍵的存在仍可見;\n\t\t * 刻意不呼叫 copy(),因此測試不會寫入任何檔案。\n\t\t * Keep the yielded shape (entry / runtime / copy) as-is and only normalize the absolute paths inside runtime;\n\t\t * copy is a function and would be dropped by the serializer, so its value is replaced by typeof to keep the key visible;\n\t\t * copy() is deliberately never called, so nothing is written.\n\t\t */\n\t\tconst snapshot = [..._copyStaticFilesCoreListGenerator({ cwd })]\n\t\t\t.map((item) => ({\n\t\t\t\t...item,\n\t\t\t\truntime: {\n\t\t\t\t\t...item.runtime,\n\t\t\t\t\ttargetFileFull: _toSnapshotPath(item.runtime.targetFileFull),\n\t\t\t\t\tstaticFileFull: _toSnapshotPath(item.runtime.staticFileFull),\n\t\t\t\t},\n\t\t\t\tcopy: typeof item.copy,\n\t\t\t}));\n\n\t\tt.assert.snapshot(snapshot);\n\t});\n});\n"]}
|