@yarn-tool/fix-all 3.0.19 → 3.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +43 -6
- package/index.d.ts +42 -2
- package/index.js +67 -24
- package/index.js.map +1 -1
- package/lib/file/reset.d.ts +26 -0
- package/lib/file/reset.js +19 -0
- package/lib/file/reset.js.map +1 -1
- package/lib/file/staticFiles.d.ts +43 -0
- package/lib/file/staticFiles.js +39 -0
- package/lib/file/staticFiles.js.map +1 -0
- package/lib/pkg/index.d.ts +3 -3
- package/lib/pkg/index.js +38 -7
- package/lib/pkg/index.js.map +1 -1
- package/lib/root/index.d.ts +43 -0
- package/lib/root/index.js +74 -0
- package/lib/root/index.js.map +1 -1
- package/lib/util/cli-progress.d.ts +13 -0
- package/lib/util/cli-progress.js +23 -0
- package/lib/util/cli-progress.js.map +1 -1
- package/lib/util/yargs-setting.d.ts +30 -0
- package/lib/util/yargs-setting.js +34 -0
- package/lib/util/yargs-setting.js.map +1 -1
- package/package.json +27 -24
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,68 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.21](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/fix-all@3.0.20...@yarn-tool/fix-all@3.0.21) (2026-10-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **static-file:** 支援在重置靜態檔案時自動合併既有的 ignore 規則
|
|
12
|
+
* **fix-all:** 重構靜態檔案判定函式名稱以提升語意清晰度
|
|
13
|
+
* **fix-all:** 引入共用靜態檔案控制邏輯並優化多套件支援
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### ✨ Features
|
|
18
|
+
|
|
19
|
+
* **fix-all:** 引入共用靜態檔案控制邏輯並優化多套件支援 ([e447590](https://github.com/bluelovers/ws-yarn-workspaces/commit/e447590f2dfd34a83f028db773a2f4c60e30dec2))
|
|
20
|
+
* **static-file:** 支援在重置靜態檔案時自動合併既有的 ignore 規則 ([11ab7c6](https://github.com/bluelovers/ws-yarn-workspaces/commit/11ab7c6023e142b74694365fe9a0f78e3c000d92))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### 📦 Code Refactoring
|
|
24
|
+
|
|
25
|
+
* **core:** 統一靜態檔案控制邏輯並更新 package.json 腳本規範 ([12f5a56](https://github.com/bluelovers/ws-yarn-workspaces/commit/12f5a5623a6f19e33616a326c86a094c548a0436))
|
|
26
|
+
* **fix-all:** 重構靜態檔案判定函式名稱以提升語意清晰度 ([f6d2bc9](https://github.com/bluelovers/ws-yarn-workspaces/commit/f6d2bc9f2c4698b23ce2eb86f8fbe4a159b7f15d))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### 📚 Documentation
|
|
30
|
+
|
|
31
|
+
* add jsdoc ([9cb9b13](https://github.com/bluelovers/ws-yarn-workspaces/commit/9cb9b13eda8c357221ad1b754458aa9916eada22))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### 🚨 Tests
|
|
35
|
+
|
|
36
|
+
* **test:** 將測試框架從 jest 遷移至 node:test ([3af9774](https://github.com/bluelovers/ws-yarn-workspaces/commit/3af9774964abc48083ec60b2021c1cec08874803))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### 🛠 Build System
|
|
40
|
+
|
|
41
|
+
* update build ([5fb6966](https://github.com/bluelovers/ws-yarn-workspaces/commit/5fb6966a57ec31ba89d8c20aa676c60755b7b286))
|
|
42
|
+
* update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
|
|
43
|
+
* **deps:** 更新測試腳本與依賴以支援 node:test ([f9c71c7](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9c71c795c792c5c7ed9d613ce7e9c3c726c39d5))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### ♻️ Chores
|
|
47
|
+
|
|
48
|
+
* **deps:** 更新依賴版本並清理 npm-init2 腳本 ([82bf1e5](https://github.com/bluelovers/ws-yarn-workspaces/commit/82bf1e5d229759aa285205d81cf0651e4d3d9792))
|
|
49
|
+
* **deps:** 更新各套件依賴版本 ([569f075](https://github.com/bluelovers/ws-yarn-workspaces/commit/569f0756189cdadf69955d8e388ac0a6a8988056))
|
|
50
|
+
* **deps:** 更新依賴並調整 workspace 配置 ([06d46b5](https://github.com/bluelovers/ws-yarn-workspaces/commit/06d46b5a9ee7f1768c3a3bd87450d63e6c6bd2ef))
|
|
51
|
+
* **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### 🔖 Miscellaneous
|
|
55
|
+
|
|
56
|
+
* . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## [3.0.20](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/fix-all@3.0.19...@yarn-tool/fix-all@3.0.20) (2026-09-10)
|
|
61
|
+
|
|
62
|
+
**Note:** Version bump only for package @yarn-tool/fix-all
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
6
68
|
## [3.0.19](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/fix-all@3.0.18...@yarn-tool/fix-all@3.0.19) (2026-09-08)
|
|
7
69
|
|
|
8
70
|
**Note:** Version bump only for package @yarn-tool/fix-all
|
package/README.md
CHANGED
|
@@ -24,10 +24,10 @@ npm install @yarn-tool/fix-all
|
|
|
24
24
|
|
|
25
25
|
- `npmAutoFixAll()` - 自動修復 workspaces/package 的主要函數
|
|
26
26
|
- **Git 資訊更新** - 自動更新 homepage, repository, bugs 等欄位
|
|
27
|
-
- **靜態檔案同步** - 複製 .gitignore, .npmignore, tsconfig.json
|
|
27
|
+
- **靜態檔案同步** - 複製 .gitignore, .npmignore, tsconfig.json 等模板檔案(需指定 `addStaticFiles` / requires `addStaticFiles`)
|
|
28
28
|
- **Lerna 配置修復** - 自動修復 lerna.json 配置
|
|
29
29
|
- **版本依賴修正** - 同步 workspace 內部套件的版本號
|
|
30
|
-
- **支援選項** - 可控制是否覆寫 git
|
|
30
|
+
- **支援選項** - 可控制是否覆寫 git 資訊、加入或重置靜態檔案等
|
|
31
31
|
|
|
32
32
|
## 使用方式 (Usage)
|
|
33
33
|
|
|
@@ -41,22 +41,59 @@ await npmAutoFixAll(process.cwd());
|
|
|
41
41
|
await npmAutoFixAll(process.cwd(), {
|
|
42
42
|
overwriteHostedGitInfo: true, // 覆寫 git 資訊 / Overwrite git info
|
|
43
43
|
branch: 'main', // Git 分支名稱 / Git branch name
|
|
44
|
-
|
|
44
|
+
addStaticFiles: true, // 自動偵測並加入靜態檔案 / Auto-detect and add static files
|
|
45
|
+
resetStaticFiles: true, // 重置靜態檔案(會強制 addStaticFiles)/ Reset static files (forces addStaticFiles)
|
|
45
46
|
});
|
|
46
47
|
```
|
|
47
48
|
|
|
48
|
-
##
|
|
49
|
+
## 設定 (Configuration)
|
|
50
|
+
|
|
51
|
+
下列選項可透過 `npmAutoFixAll(cwd, options)` 的第二個參數傳入:
|
|
49
52
|
|
|
50
53
|
| 選項 / Option | 類型 / Type | 說明 / Description |
|
|
51
54
|
|--------------|-------------|-------------------|
|
|
52
55
|
| `overwriteHostedGitInfo` | `boolean` | 是否覆寫 hosted git 資訊 / Whether to overwrite hosted git info |
|
|
53
56
|
| `branch` | `string` | Git 分支名稱(預設自動偵測)/ Git branch name (auto-detected by default) |
|
|
54
|
-
| `
|
|
57
|
+
| `addStaticFiles` | `boolean` | 是否自動偵測並加入靜態檔案,預設不執行 / Whether to auto-detect and add static files; disabled by default |
|
|
58
|
+
| `noStaticFiles` | `boolean` | 是否略過靜態檔案,為 true 時 `addStaticFiles` 視為 false / Skip static files; when true, `addStaticFiles` is treated as false |
|
|
59
|
+
| `resetStaticFiles` | `boolean` | 是否重置靜態檔案,會強制觸發 `addStaticFiles` / Whether to reset static files; forces `addStaticFiles` |
|
|
60
|
+
|
|
61
|
+
> 判定邏輯集中在 `lib/file/staticFiles.ts` 的 `_isAddStaticFiles()` 與 `_isAddStaticFilesWithReset()`,可由其他套件共用(`addStaticFiles` 可透過第二個參數指定預設值)。
|
|
62
|
+
> The decision logic lives in `_isAddStaticFiles()` / `_isAddStaticFilesWithReset()` in `lib/file/staticFiles.ts`, shared by other packages (the second argument sets the default of `addStaticFiles`).
|
|
63
|
+
|
|
64
|
+
## API 文件 (API Documentation)
|
|
65
|
+
|
|
66
|
+
### `npmAutoFixAll(cwd, options?)`
|
|
67
|
+
|
|
68
|
+
主要匯出函式(同時也是預設匯出 / default export),回傳 `Bluebird<void>`。
|
|
69
|
+
|
|
70
|
+
| 參數 / Param | 型別 / Type | 說明 / Description |
|
|
71
|
+
|--------------|-------------|-------------------|
|
|
72
|
+
| `cwd` | `string` | 當前工作目錄,未傳入時使用 `process.cwd()` / Current working directory; defaults to `process.cwd()` when omitted |
|
|
73
|
+
| `options` | `INpmAutoFixAll` | 修復選項,詳見 [設定 (Configuration)](#設定-configuration) / Fix options; see Configuration above |
|
|
74
|
+
|
|
75
|
+
拋出 `Invalid workspaces / package` 錯誤的情況:`cwd` 無法解析出有效的 workspace 或套件根目錄。
|
|
76
|
+
|
|
77
|
+
Throws an `Invalid workspaces / package` error when `cwd` cannot resolve to a valid workspace or package root.
|
|
78
|
+
|
|
79
|
+
### `INpmAutoFixAll`
|
|
80
|
+
|
|
81
|
+
選項介面 (Options interface),欄位說明同 [設定 (Configuration)](#設定-configuration) 表格。
|
|
82
|
+
|
|
83
|
+
### 內部模組 (Internal modules)
|
|
84
|
+
|
|
85
|
+
以下模組供 repo 內其他套件共用,非本套件的主要公開 API:
|
|
86
|
+
|
|
87
|
+
These modules are shared by other packages in the repo and are not part of the main public API:
|
|
88
|
+
|
|
89
|
+
- `lib/file/staticFiles.ts` - `_isAddStaticFiles()` / `_isAddStaticFilesWithReset()` 靜態檔案判定 (static file decision helpers)
|
|
90
|
+
- `lib/root/index.ts` - `_fixRoot()` / `_fixWsRoot()` 根目錄 package.json 修復 (root package.json fixing)
|
|
91
|
+
- `lib/ws/lerna.ts` - `_fixLernaJson()` lerna.json 修復 (lerna.json fixing)
|
|
55
92
|
|
|
56
93
|
## 執行流程 (Execution Flow)
|
|
57
94
|
|
|
58
95
|
1. **尋找根目錄** - 自動偵測 workspace 或套件根目錄
|
|
59
|
-
2. **複製靜態檔案** -
|
|
96
|
+
2. **複製靜態檔案** - 依 `_isAddStaticFilesWithReset()` 判定(`addStaticFiles` / `noStaticFiles` / `resetStaticFiles`)決定是否複製對應的模板檔案
|
|
60
97
|
3. **取得 Git 資訊** - 從 git remote 提取 repository 相關資訊
|
|
61
98
|
4. **修復根目錄** - 更新 package.json 的 git 相關欄位
|
|
62
99
|
5. **修復 Lerna** - 更新 lerna.json 配置
|
package/index.d.ts
CHANGED
|
@@ -17,8 +17,46 @@ export interface INpmAutoFixAll {
|
|
|
17
17
|
/**
|
|
18
18
|
* 是否重置靜態檔案
|
|
19
19
|
* Whether to reset static files
|
|
20
|
+
*
|
|
21
|
+
* 若為 true 會強制觸發 addStaticFiles(重置後重新加入)
|
|
22
|
+
* If true, forces addStaticFiles (re-add after reset)
|
|
20
23
|
*/
|
|
21
24
|
resetStaticFiles?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* 是否自動偵測並加入靜態檔案
|
|
27
|
+
* Whether to auto-detect and add static files
|
|
28
|
+
*
|
|
29
|
+
* 僅在指定此選項時才會自動偵測並複製靜態檔案,預設不執行
|
|
30
|
+
* Static files are only auto-detected/copied when this option is given; disabled by default
|
|
31
|
+
*
|
|
32
|
+
* 注意:resetStaticFiles 為 true 時會強制視為 true
|
|
33
|
+
* Note: forced to true when resetStaticFiles is true
|
|
34
|
+
*/
|
|
35
|
+
addStaticFiles?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* 是否略過(不加入)靜態檔案
|
|
38
|
+
* Whether to skip (not add) static files
|
|
39
|
+
*
|
|
40
|
+
* 為 true 時 addStaticFiles 視為 false(優先於 addStaticFiles)
|
|
41
|
+
* When true, addStaticFiles is treated as false (takes precedence over addStaticFiles)
|
|
42
|
+
*
|
|
43
|
+
* 注意:resetStaticFiles 為 true 時仍會強制加入
|
|
44
|
+
* Note: static files are still force-added when resetStaticFiles is true
|
|
45
|
+
*/
|
|
46
|
+
noStaticFiles?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* 是否停用自動合併 ignore 檔案
|
|
49
|
+
* Whether to disable auto-merging ignore files
|
|
50
|
+
*
|
|
51
|
+
* 未設定(false)時,會在 reset 之前先讀取現有的 .gitignore / .npmignore 等檔案,
|
|
52
|
+
* 並在複製完成後把這些既有規則合併回複製出的檔案,使其不因 reset 而遺失。
|
|
53
|
+
* When not set (false), the existing .gitignore / .npmignore files are read before the reset and
|
|
54
|
+
* their rules are merged back into the freshly copied files afterwards, so a reset does not lose them.
|
|
55
|
+
*
|
|
56
|
+
* 注意:不論是 resetStaticFiles 或單純的 addStaticFiles 觸發,都會執行此合併。
|
|
57
|
+
* Note: the merge runs for both the resetStaticFiles and the plain addStaticFiles trigger.
|
|
58
|
+
*/
|
|
59
|
+
noMergeIgnoreFiles?: boolean;
|
|
22
60
|
}
|
|
23
61
|
/**
|
|
24
62
|
* 自動修復 workspaces/package 的主要函數
|
|
@@ -26,14 +64,14 @@ export interface INpmAutoFixAll {
|
|
|
26
64
|
*
|
|
27
65
|
* 執行以下操作:
|
|
28
66
|
* 1. 尋找工作區根目錄
|
|
29
|
-
* 2. 複製靜態檔案(.gitignore, .npmignore
|
|
67
|
+
* 2. 複製靜態檔案(.gitignore, .npmignore 等,依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)
|
|
30
68
|
* 3. 更新 git 相關資訊(homepage, repository, bugs)
|
|
31
69
|
* 4. 修復 lerna.json 配置
|
|
32
70
|
* 5. 遍歷所有套件進行修復
|
|
33
71
|
*
|
|
34
72
|
* Performs the following operations:
|
|
35
73
|
* 1. Find workspace root directory
|
|
36
|
-
* 2. Copy static files (.gitignore, .npmignore, etc
|
|
74
|
+
* 2. Copy static files (.gitignore, .npmignore, etc.; resolved via addStaticFiles / noStaticFiles / resetStaticFiles)
|
|
37
75
|
* 3. Update git-related info (homepage, repository, bugs)
|
|
38
76
|
* 4. Fix lerna.json configuration
|
|
39
77
|
* 5. Iterate all packages for fixing
|
|
@@ -51,6 +89,8 @@ export interface INpmAutoFixAll {
|
|
|
51
89
|
* await npmAutoFixAll(process.cwd(), {
|
|
52
90
|
* overwriteHostedGitInfo: true,
|
|
53
91
|
* branch: 'main',
|
|
92
|
+
* addStaticFiles: true,
|
|
93
|
+
* noStaticFiles: false,
|
|
54
94
|
* resetStaticFiles: true,
|
|
55
95
|
* });
|
|
56
96
|
*/
|
package/index.js
CHANGED
|
@@ -18,24 +18,26 @@ const index_2 = require("./lib/pkg/index");
|
|
|
18
18
|
const logger_1 = require("debug-color2/logger");
|
|
19
19
|
const bluebird_1 = tslib_1.__importDefault(require("bluebird"));
|
|
20
20
|
const static_file_1 = require("@yarn-tool/static-file");
|
|
21
|
+
const mergeIgnoreFiles_1 = require("@yarn-tool/static-file/lib/mergeIgnoreFiles");
|
|
21
22
|
const wsCopyStaticFiles_1 = require("@yarn-tool/static-file/lib/ws/wsCopyStaticFiles");
|
|
22
23
|
const getRootCopyStaticFiles_1 = require("@yarn-tool/static-file/lib/root/getRootCopyStaticFiles");
|
|
23
24
|
const lerna_1 = require("./lib/ws/lerna");
|
|
24
25
|
const reset_1 = require("./lib/file/reset");
|
|
26
|
+
const staticFiles_1 = require("./lib/file/staticFiles");
|
|
25
27
|
/**
|
|
26
28
|
* 自動修復 workspaces/package 的主要函數
|
|
27
29
|
* Main function for auto-fixing workspaces/packages
|
|
28
30
|
*
|
|
29
31
|
* 執行以下操作:
|
|
30
32
|
* 1. 尋找工作區根目錄
|
|
31
|
-
* 2. 複製靜態檔案(.gitignore, .npmignore
|
|
33
|
+
* 2. 複製靜態檔案(.gitignore, .npmignore 等,依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)
|
|
32
34
|
* 3. 更新 git 相關資訊(homepage, repository, bugs)
|
|
33
35
|
* 4. 修復 lerna.json 配置
|
|
34
36
|
* 5. 遍歷所有套件進行修復
|
|
35
37
|
*
|
|
36
38
|
* Performs the following operations:
|
|
37
39
|
* 1. Find workspace root directory
|
|
38
|
-
* 2. Copy static files (.gitignore, .npmignore, etc
|
|
40
|
+
* 2. Copy static files (.gitignore, .npmignore, etc.; resolved via addStaticFiles / noStaticFiles / resetStaticFiles)
|
|
39
41
|
* 3. Update git-related info (homepage, repository, bugs)
|
|
40
42
|
* 4. Fix lerna.json configuration
|
|
41
43
|
* 5. Iterate all packages for fixing
|
|
@@ -53,6 +55,8 @@ const reset_1 = require("./lib/file/reset");
|
|
|
53
55
|
* await npmAutoFixAll(process.cwd(), {
|
|
54
56
|
* overwriteHostedGitInfo: true,
|
|
55
57
|
* branch: 'main',
|
|
58
|
+
* addStaticFiles: true,
|
|
59
|
+
* noStaticFiles: false,
|
|
56
60
|
* resetStaticFiles: true,
|
|
57
61
|
* });
|
|
58
62
|
*/
|
|
@@ -90,41 +94,77 @@ function npmAutoFixAll(cwd, options) {
|
|
|
90
94
|
console.log(`root:`, rootData.root);
|
|
91
95
|
console.log(`hasWorkspace:`, rootData.hasWorkspace);
|
|
92
96
|
// 解構選項 / Destructure options
|
|
93
|
-
let { branch, overwriteHostedGitInfo, resetStaticFiles } = options !== null && options !== void 0 ? options : {};
|
|
97
|
+
let { branch, overwriteHostedGitInfo, resetStaticFiles, addStaticFiles, noStaticFiles, noMergeIgnoreFiles, } = options !== null && options !== void 0 ? options : {};
|
|
94
98
|
cwd = rootData.cwd;
|
|
95
|
-
|
|
99
|
+
/**
|
|
100
|
+
* 在 reset 之前讀取現有 ignore 檔案並建立快照
|
|
101
|
+
* Read the existing ignore files and build a snapshot before the reset
|
|
102
|
+
*
|
|
103
|
+
* resetStaticFiles 會刪除 .gitignore / .npmignore 等檔案,
|
|
104
|
+
* 因此必須先取樣,稍後複製完成時才能把既有規則合併回去。
|
|
105
|
+
* resetStaticFiles deletes .gitignore / .npmignore and the like, so they must be captured
|
|
106
|
+
* first in order to merge the existing rules back once the copy is done.
|
|
107
|
+
*
|
|
108
|
+
* 取樣目錄與後續複製的目標一致(workspace 取 ws,單一套件取 root)。
|
|
109
|
+
* The captured directory matches the later copy target (ws for a workspace, root for a single package).
|
|
110
|
+
*/
|
|
111
|
+
const ignoreFilesSnapshot = noMergeIgnoreFiles
|
|
112
|
+
? undefined
|
|
113
|
+
: (0, mergeIgnoreFiles_1._readIgnoreFilesSnapshot)(rootData.hasWorkspace ? rootData.ws : rootData.root);
|
|
114
|
+
/**
|
|
115
|
+
* 重置靜態檔案(若選項啟用)/ Reset static files (if option enabled)
|
|
116
|
+
*/
|
|
96
117
|
if (resetStaticFiles) {
|
|
97
118
|
(0, reset_1._resetStaticFiles)(rootData.root, {
|
|
98
119
|
rootData,
|
|
99
120
|
});
|
|
100
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* 是否要自動偵測並加入靜態檔案
|
|
124
|
+
* Whether to auto-detect and add static files
|
|
125
|
+
*
|
|
126
|
+
* 統一由底層公用邏輯判定 noStaticFiles / addStaticFiles / resetStaticFiles
|
|
127
|
+
* Resolved by the shared low-level logic for noStaticFiles / addStaticFiles / resetStaticFiles
|
|
128
|
+
*/
|
|
129
|
+
const _addStaticFiles = (0, staticFiles_1._isAddStaticFilesOrReset)(options);
|
|
101
130
|
/**
|
|
102
131
|
* 複製靜態檔案到 workspace 或根目錄
|
|
103
132
|
* Copy static files to workspace or root
|
|
104
133
|
*
|
|
134
|
+
* 僅在判定結果為 true 時才自動偵測並加入
|
|
135
|
+
* Only auto-detect and add when the result is true
|
|
136
|
+
*
|
|
105
137
|
* 根據專案類型(workspace 或單一套件)複製對應的模板檔案
|
|
106
138
|
* Copy corresponding template files based on project type
|
|
107
139
|
*/
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
file_map,
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
file_map,
|
|
127
|
-
|
|
140
|
+
if (_addStaticFiles) {
|
|
141
|
+
if (rootData.hasWorkspace) {
|
|
142
|
+
/**
|
|
143
|
+
* Workspace 模式:複製 workspace 靜態檔案(.gitignore, .npmignore 等)
|
|
144
|
+
* Workspace mode: copy workspace static files
|
|
145
|
+
*/
|
|
146
|
+
const file_map = (0, wsCopyStaticFiles_1.getWsCopyStaticFiles)();
|
|
147
|
+
(0, static_file_1.copyStaticFiles)({
|
|
148
|
+
cwd: rootData.ws,
|
|
149
|
+
file_map,
|
|
150
|
+
ignoreFilesSnapshot,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else if (rootData.root) {
|
|
154
|
+
/**
|
|
155
|
+
* 單一套件模式:複製根目錄靜態檔案
|
|
156
|
+
* Single package mode: copy root static files
|
|
157
|
+
*/
|
|
158
|
+
const file_map = (0, getRootCopyStaticFiles_1.getRootCopyStaticFilesAuto)({
|
|
159
|
+
...rootData,
|
|
160
|
+
isRoot: true,
|
|
161
|
+
});
|
|
162
|
+
(0, static_file_1.copyStaticFiles)({
|
|
163
|
+
cwd: rootData.root,
|
|
164
|
+
file_map,
|
|
165
|
+
ignoreFilesSnapshot,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
128
168
|
}
|
|
129
169
|
logger_1.consoleLogger.info(`check git info`);
|
|
130
170
|
// 取得 hosted git 資訊 / Get hosted git info
|
|
@@ -185,6 +225,9 @@ function npmAutoFixAll(cwd, options) {
|
|
|
185
225
|
branch,
|
|
186
226
|
hostedGitInfo,
|
|
187
227
|
resetStaticFiles,
|
|
228
|
+
addStaticFiles,
|
|
229
|
+
noStaticFiles,
|
|
230
|
+
noMergeIgnoreFiles,
|
|
188
231
|
});
|
|
189
232
|
}).then(() => void 0);
|
|
190
233
|
}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * @yarn-tool/fix-all\n *\n * 自動檢查和修復 workspaces/package 的工具\n * Auto check/fix tool for workspaces/packages\n *\n * 支援 git 資訊更新、靜態檔案複製與版本修正\n * Supports git info update, static file copy, and version fix\n */\nimport { findRoot, findRootLazy } from '@yarn-tool/find-root';\nimport { npmHostedGitInfoLazy } from '@yarn-tool/pkg-git-info';\nimport { _fixRoot, _fixWsRoot } from './lib/root/index';\nimport { _initPkgListableByRootData, _runEachPackagesAsync } from './lib/pkg/index';\nimport { consoleLogger } from 'debug-color2/logger';\nimport Bluebird from 'bluebird';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { getWsCopyStaticFiles } from '@yarn-tool/static-file/lib/ws/wsCopyStaticFiles';\nimport { getRootCopyStaticFilesAuto } from '@yarn-tool/static-file/lib/root/getRootCopyStaticFiles';\nimport { _fixLernaJson } from './lib/ws/lerna';\nimport { _resetStaticFiles } from './lib/file/reset';\n\n/**\n * npmAutoFixAll 的選項介面\n * Options interface for npmAutoFixAll\n */\nexport interface INpmAutoFixAll\n{\n\t/**\n\t * 是否覆寫 hosted git 資訊\n\t * Whether to overwrite hosted git info\n\t */\n\toverwriteHostedGitInfo?: boolean;\n\n\t/**\n\t * Git 分支名稱\n\t * Git branch name\n\t */\n\tbranch?: string;\n\n\t/**\n\t * 是否重置靜態檔案\n\t * Whether to reset static files\n\t */\n\tresetStaticFiles?: boolean;\n}\n\n/**\n * 自動修復 workspaces/package 的主要函數\n * Main function for auto-fixing workspaces/packages\n *\n * 執行以下操作:\n * 1. 尋找工作區根目錄\n * 2. 複製靜態檔案(.gitignore, .npmignore 等)\n * 3. 更新 git 相關資訊(homepage, repository, bugs)\n * 4. 修復 lerna.json 配置\n * 5. 遍歷所有套件進行修復\n *\n * Performs the following operations:\n * 1. Find workspace root directory\n * 2. Copy static files (.gitignore, .npmignore, etc.)\n * 3. Update git-related info (homepage, repository, bugs)\n * 4. Fix lerna.json configuration\n * 5. Iterate all packages for fixing\n *\n * @param {string} cwd - 當前工作目錄 / Current working directory\n * @param {INpmAutoFixAll} options - 選項 / Options\n * @returns {Bluebird<void>} Promise 物件 / Promise object\n *\n * @example\n * // 在當前目錄執行\n * await npmAutoFixAll(process.cwd());\n *\n * @example\n * // 帶選項執行\n * await npmAutoFixAll(process.cwd(), {\n * overwriteHostedGitInfo: true,\n * branch: 'main',\n * resetStaticFiles: true,\n * });\n */\nexport function npmAutoFixAll(cwd: string, options?: INpmAutoFixAll)\n{\n\treturn Bluebird.resolve().then(async () =>\n\t{\n\t\t// 設定預設工作目錄 / Set default working directory\n\t\tcwd ??= process.cwd();\n\n\t\tconsoleLogger.info(`cwd: ${cwd}`);\n\n\t\t// 尋找工作區根目錄 / Find workspace root directory\n\t\tlet rootData = findRootLazy({\n\t\t\tcwd,\n\t\t});\n\n\t\t/**\n\t\t * 驗證是否為有效的工作區或套件\n\t\t * Validate if it's a valid workspace or package\n\t\t *\n\t\t * 必須存在 root 屬性才視為有效專案\n\t\t * Must have root property to be considered a valid project\n\t\t */\n\t\tif (!rootData?.root)\n\t\t{\n\t\t\tthrow new Error(`Invalid workspaces / package: ${cwd}`)\n\t\t}\n\n\t\t/**\n\t\t * 若在 workspace 根目錄但不在子套件中,重新尋找根目錄\n\t\t * If at workspace root but not in sub-package, re-find root\n\t\t *\n\t\t * 這確保我們總是從正確的位置開始處理\n\t\t * This ensures we always start processing from the correct location\n\t\t */\n\t\tif (rootData.hasWorkspace && !rootData.isWorkspace)\n\t\t{\n\t\t\trootData = findRoot({\n\t\t\t\tcwd: rootData.root,\n\t\t\t});\n\t\t}\n\n\t\tconsole.log(`root:`, rootData.root);\n\t\tconsole.log(`hasWorkspace:`, rootData.hasWorkspace);\n\n\t\t// 解構選項 / Destructure options\n\t\tlet {\n\t\t\tbranch,\n\t\t\toverwriteHostedGitInfo,\n\t\t\tresetStaticFiles\n\t\t} = options ?? {};\n\n\t\tcwd = rootData.cwd;\n\n\t\t// 重置靜態檔案(若選項啟用)/ Reset static files (if option enabled)\n\t\tif (resetStaticFiles)\n\t\t{\n\t\t\t_resetStaticFiles(rootData.root, {\n\t\t\t\trootData,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * 複製靜態檔案到 workspace 或根目錄\n\t\t * Copy static files to workspace or root\n\t\t *\n\t\t * 根據專案類型(workspace 或單一套件)複製對應的模板檔案\n\t\t * Copy corresponding template files based on project type\n\t\t */\n\t\tif (rootData.hasWorkspace)\n\t\t{\n\t\t\t// Workspace 模式:複製 workspace 靜態檔案(.gitignore, .npmignore 等)\n\t\t\t// Workspace mode: copy workspace static files\n\t\t\tconst file_map = getWsCopyStaticFiles();\n\n\t\t\tcopyStaticFiles({\n\t\t\t\tcwd: rootData.ws,\n\t\t\t\tfile_map,\n\t\t\t});\n\t\t}\n\t\telse if (rootData.root)\n\t\t{\n\t\t\t// 單一套件模式:複製根目錄靜態檔案\n\t\t\t// Single package mode: copy root static files\n\t\t\tconst file_map = getRootCopyStaticFilesAuto({\n\t\t\t\t...rootData,\n\t\t\t\tisRoot: true,\n\t\t\t});\n\n\t\t\tcopyStaticFiles({\n\t\t\t\tcwd: rootData.root,\n\t\t\t\tfile_map,\n\t\t\t});\n\t\t}\n\n\t\tconsoleLogger.info(`check git info`);\n\n\t\t// 取得 hosted git 資訊 / Get hosted git info\n\t\tconst hostedGitInfo = npmHostedGitInfoLazy(cwd);\n\n\t\tconsole.log(`homepage:`, hostedGitInfo.homepage);\n\t\tconsole.log(`repository:`, hostedGitInfo.repository);\n\n\t\tconsoleLogger.info(`auto fix root of workspaces / package`);\n\n\t\tconsole.log(`root:`, rootData.root);\n\n\t\t/**\n\t\t * 修復根目錄 package.json\n\t\t * Fix root package.json\n\t\t *\n\t\t * 根據專案類型選擇對應的修復策略\n\t\t * Select appropriate fix strategy based on project type\n\t\t */\n\t\tif (rootData.hasWorkspace)\n\t\t{\n\t\t\t// Workspace 模式:修復 workspace 根目錄的 package.json\n\t\t\t// Workspace mode: fix workspace root package.json\n\t\t\t_fixWsRoot({\n\t\t\t\trootData,\n\t\t\t\thostedGitInfo,\n\t\t\t\tbranch,\n\t\t\t\toverwriteHostedGitInfo,\n\t\t\t});\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// 單一套件模式:修復套件根目錄的 package.json\n\t\t\t// Single package mode: fix package root package.json\n\t\t\t_fixRoot({\n\t\t\t\trootData,\n\t\t\t\thostedGitInfo,\n\t\t\t\tbranch,\n\t\t\t\toverwriteHostedGitInfo,\n\t\t\t\ttargetDir: rootData.root,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * 修復 lerna.json 配置\n\t\t * Fix lerna.json configuration\n\t\t *\n\t\t * 確保 lerna 配置與 workspace 設定一致\n\t\t * Ensure lerna config is consistent with workspace settings\n\t\t */\n\t\t_fixLernaJson({\n\t\t\trootData,\n\t\t});\n\n\t\t/**\n\t\t * 初始化套件列表並遍歷修復\n\t\t * Initialize package list and iterate for fixing\n\t\t *\n\t\t * 對每個子套件執行自動修復操作\n\t\t * Execute auto-fix operations for each sub-package\n\t\t */\n\t\tconst list = _initPkgListableByRootData(rootData);\n\n\t\treturn _runEachPackagesAsync(list, {\n\t\t\trootData,\n\t\t\toverwriteHostedGitInfo,\n\t\t\tbranch,\n\t\t\thostedGitInfo,\n\t\t\tresetStaticFiles,\n\t\t})\n\t}).then(() => void 0 as void)\n}\n\nexport default npmAutoFixAll\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * @yarn-tool/fix-all\n *\n * 自動檢查和修復 workspaces/package 的工具\n * Auto check/fix tool for workspaces/packages\n *\n * 支援 git 資訊更新、靜態檔案複製與版本修正\n * Supports git info update, static file copy, and version fix\n */\nimport { findRoot, findRootLazy } from '@yarn-tool/find-root';\nimport { npmHostedGitInfoLazy } from '@yarn-tool/pkg-git-info';\nimport { _fixRoot, _fixWsRoot } from './lib/root/index';\nimport { _initPkgListableByRootData, _runEachPackagesAsync } from './lib/pkg/index';\nimport { consoleLogger } from 'debug-color2/logger';\nimport Bluebird from 'bluebird';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { _readIgnoreFilesSnapshot } from '@yarn-tool/static-file/lib/mergeIgnoreFiles';\nimport { getWsCopyStaticFiles } from '@yarn-tool/static-file/lib/ws/wsCopyStaticFiles';\nimport { getRootCopyStaticFilesAuto } from '@yarn-tool/static-file/lib/root/getRootCopyStaticFiles';\nimport { _fixLernaJson } from './lib/ws/lerna';\nimport { _resetStaticFiles } from './lib/file/reset';\nimport { _isAddStaticFilesOrReset } from './lib/file/staticFiles';\n\n/**\n * npmAutoFixAll 的選項介面\n * Options interface for npmAutoFixAll\n */\nexport interface INpmAutoFixAll\n{\n\t/**\n\t * 是否覆寫 hosted git 資訊\n\t * Whether to overwrite hosted git info\n\t */\n\toverwriteHostedGitInfo?: boolean;\n\n\t/**\n\t * Git 分支名稱\n\t * Git branch name\n\t */\n\tbranch?: string;\n\n\t/**\n\t * 是否重置靜態檔案\n\t * Whether to reset static files\n\t *\n\t * 若為 true 會強制觸發 addStaticFiles(重置後重新加入)\n\t * If true, forces addStaticFiles (re-add after reset)\n\t */\n\tresetStaticFiles?: boolean;\n\n\t/**\n\t * 是否自動偵測並加入靜態檔案\n\t * Whether to auto-detect and add static files\n\t *\n\t * 僅在指定此選項時才會自動偵測並複製靜態檔案,預設不執行\n\t * Static files are only auto-detected/copied when this option is given; disabled by default\n\t *\n\t * 注意:resetStaticFiles 為 true 時會強制視為 true\n\t * Note: forced to true when resetStaticFiles is true\n\t */\n\taddStaticFiles?: boolean;\n\n\t/**\n\t * 是否略過(不加入)靜態檔案\n\t * Whether to skip (not add) static files\n\t *\n\t * 為 true 時 addStaticFiles 視為 false(優先於 addStaticFiles)\n\t * When true, addStaticFiles is treated as false (takes precedence over addStaticFiles)\n\t *\n\t * 注意:resetStaticFiles 為 true 時仍會強制加入\n\t * Note: static files are still force-added when resetStaticFiles is true\n\t */\n\tnoStaticFiles?: boolean;\n\n\t/**\n\t * 是否停用自動合併 ignore 檔案\n\t * Whether to disable auto-merging ignore files\n\t *\n\t * 未設定(false)時,會在 reset 之前先讀取現有的 .gitignore / .npmignore 等檔案,\n\t * 並在複製完成後把這些既有規則合併回複製出的檔案,使其不因 reset 而遺失。\n\t * When not set (false), the existing .gitignore / .npmignore files are read before the reset and\n\t * their rules are merged back into the freshly copied files afterwards, so a reset does not lose them.\n\t *\n\t * 注意:不論是 resetStaticFiles 或單純的 addStaticFiles 觸發,都會執行此合併。\n\t * Note: the merge runs for both the resetStaticFiles and the plain addStaticFiles trigger.\n\t */\n\tnoMergeIgnoreFiles?: boolean;\n}\n\n/**\n * 自動修復 workspaces/package 的主要函數\n * Main function for auto-fixing workspaces/packages\n *\n * 執行以下操作:\n * 1. 尋找工作區根目錄\n * 2. 複製靜態檔案(.gitignore, .npmignore 等,依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)\n * 3. 更新 git 相關資訊(homepage, repository, bugs)\n * 4. 修復 lerna.json 配置\n * 5. 遍歷所有套件進行修復\n *\n * Performs the following operations:\n * 1. Find workspace root directory\n * 2. Copy static files (.gitignore, .npmignore, etc.; resolved via addStaticFiles / noStaticFiles / resetStaticFiles)\n * 3. Update git-related info (homepage, repository, bugs)\n * 4. Fix lerna.json configuration\n * 5. Iterate all packages for fixing\n *\n * @param {string} cwd - 當前工作目錄 / Current working directory\n * @param {INpmAutoFixAll} options - 選項 / Options\n * @returns {Bluebird<void>} Promise 物件 / Promise object\n *\n * @example\n * // 在當前目錄執行\n * await npmAutoFixAll(process.cwd());\n *\n * @example\n * // 帶選項執行\n * await npmAutoFixAll(process.cwd(), {\n * overwriteHostedGitInfo: true,\n * branch: 'main',\n * addStaticFiles: true,\n * noStaticFiles: false,\n * resetStaticFiles: true,\n * });\n */\nexport function npmAutoFixAll(cwd: string, options?: INpmAutoFixAll)\n{\n\treturn Bluebird.resolve().then(async () =>\n\t{\n\t\t// 設定預設工作目錄 / Set default working directory\n\t\tcwd ??= process.cwd();\n\n\t\tconsoleLogger.info(`cwd: ${cwd}`);\n\n\t\t// 尋找工作區根目錄 / Find workspace root directory\n\t\tlet rootData = findRootLazy({\n\t\t\tcwd,\n\t\t});\n\n\t\t/**\n\t\t * 驗證是否為有效的工作區或套件\n\t\t * Validate if it's a valid workspace or package\n\t\t *\n\t\t * 必須存在 root 屬性才視為有效專案\n\t\t * Must have root property to be considered a valid project\n\t\t */\n\t\tif (!rootData?.root)\n\t\t{\n\t\t\tthrow new Error(`Invalid workspaces / package: ${cwd}`)\n\t\t}\n\n\t\t/**\n\t\t * 若在 workspace 根目錄但不在子套件中,重新尋找根目錄\n\t\t * If at workspace root but not in sub-package, re-find root\n\t\t *\n\t\t * 這確保我們總是從正確的位置開始處理\n\t\t * This ensures we always start processing from the correct location\n\t\t */\n\t\tif (rootData.hasWorkspace && !rootData.isWorkspace)\n\t\t{\n\t\t\trootData = findRoot({\n\t\t\t\tcwd: rootData.root,\n\t\t\t});\n\t\t}\n\n\t\tconsole.log(`root:`, rootData.root);\n\t\tconsole.log(`hasWorkspace:`, rootData.hasWorkspace);\n\n\t\t// 解構選項 / Destructure options\n\t\tlet {\n\t\t\tbranch,\n\t\t\toverwriteHostedGitInfo,\n\t\t\tresetStaticFiles,\n\t\t\taddStaticFiles,\n\t\t\tnoStaticFiles,\n\t\t\tnoMergeIgnoreFiles,\n\t\t} = options ?? {};\n\n\t\tcwd = rootData.cwd;\n\n\t\t/**\n\t\t * 在 reset 之前讀取現有 ignore 檔案並建立快照\n\t\t * Read the existing ignore files and build a snapshot before the reset\n\t\t *\n\t\t * resetStaticFiles 會刪除 .gitignore / .npmignore 等檔案,\n\t\t * 因此必須先取樣,稍後複製完成時才能把既有規則合併回去。\n\t\t * resetStaticFiles deletes .gitignore / .npmignore and the like, so they must be captured\n\t\t * first in order to merge the existing rules back once the copy is done.\n\t\t *\n\t\t * 取樣目錄與後續複製的目標一致(workspace 取 ws,單一套件取 root)。\n\t\t * The captured directory matches the later copy target (ws for a workspace, root for a single package).\n\t\t */\n\t\tconst ignoreFilesSnapshot = noMergeIgnoreFiles\n\t\t\t? undefined\n\t\t\t: _readIgnoreFilesSnapshot(rootData.hasWorkspace ? rootData.ws : rootData.root);\n\n\t\t/**\n\t\t * 重置靜態檔案(若選項啟用)/ Reset static files (if option enabled)\n\t\t */\n\t\tif (resetStaticFiles)\n\t\t{\n\t\t\t_resetStaticFiles(rootData.root, {\n\t\t\t\trootData,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * 是否要自動偵測並加入靜態檔案\n\t\t * Whether to auto-detect and add static files\n\t\t *\n\t\t * 統一由底層公用邏輯判定 noStaticFiles / addStaticFiles / resetStaticFiles\n\t\t * Resolved by the shared low-level logic for noStaticFiles / addStaticFiles / resetStaticFiles\n\t\t */\n\t\tconst _addStaticFiles = _isAddStaticFilesOrReset(options);\n\n\t\t/**\n\t\t * 複製靜態檔案到 workspace 或根目錄\n\t\t * Copy static files to workspace or root\n\t\t *\n\t\t * 僅在判定結果為 true 時才自動偵測並加入\n\t\t * Only auto-detect and add when the result is true\n\t\t *\n\t\t * 根據專案類型(workspace 或單一套件)複製對應的模板檔案\n\t\t * Copy corresponding template files based on project type\n\t\t */\n\t\tif (_addStaticFiles)\n\t\t{\n\t\t\tif (rootData.hasWorkspace)\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * Workspace 模式:複製 workspace 靜態檔案(.gitignore, .npmignore 等)\n\t\t\t\t * Workspace mode: copy workspace static files\n\t\t\t\t */\n\t\t\t\tconst file_map = getWsCopyStaticFiles();\n\n\t\t\t\tcopyStaticFiles({\n\t\t\t\t\tcwd: rootData.ws,\n\t\t\t\t\tfile_map,\n\t\t\t\t\tignoreFilesSnapshot,\n\t\t\t\t});\n\t\t\t}\n\t\t\telse if (rootData.root)\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * 單一套件模式:複製根目錄靜態檔案\n\t\t\t\t * Single package mode: copy root static files\n\t\t\t\t */\n\t\t\t\tconst file_map = getRootCopyStaticFilesAuto({\n\t\t\t\t\t...rootData,\n\t\t\t\t\tisRoot: true,\n\t\t\t\t});\n\n\t\t\t\tcopyStaticFiles({\n\t\t\t\t\tcwd: rootData.root,\n\t\t\t\t\tfile_map,\n\t\t\t\t\tignoreFilesSnapshot,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconsoleLogger.info(`check git info`);\n\n\t\t// 取得 hosted git 資訊 / Get hosted git info\n\t\tconst hostedGitInfo = npmHostedGitInfoLazy(cwd);\n\n\t\tconsole.log(`homepage:`, hostedGitInfo.homepage);\n\t\tconsole.log(`repository:`, hostedGitInfo.repository);\n\n\t\tconsoleLogger.info(`auto fix root of workspaces / package`);\n\n\t\tconsole.log(`root:`, rootData.root);\n\n\t\t/**\n\t\t * 修復根目錄 package.json\n\t\t * Fix root package.json\n\t\t *\n\t\t * 根據專案類型選擇對應的修復策略\n\t\t * Select appropriate fix strategy based on project type\n\t\t */\n\t\tif (rootData.hasWorkspace)\n\t\t{\n\t\t\t// Workspace 模式:修復 workspace 根目錄的 package.json\n\t\t\t// Workspace mode: fix workspace root package.json\n\t\t\t_fixWsRoot({\n\t\t\t\trootData,\n\t\t\t\thostedGitInfo,\n\t\t\t\tbranch,\n\t\t\t\toverwriteHostedGitInfo,\n\t\t\t});\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// 單一套件模式:修復套件根目錄的 package.json\n\t\t\t// Single package mode: fix package root package.json\n\t\t\t_fixRoot({\n\t\t\t\trootData,\n\t\t\t\thostedGitInfo,\n\t\t\t\tbranch,\n\t\t\t\toverwriteHostedGitInfo,\n\t\t\t\ttargetDir: rootData.root,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * 修復 lerna.json 配置\n\t\t * Fix lerna.json configuration\n\t\t *\n\t\t * 確保 lerna 配置與 workspace 設定一致\n\t\t * Ensure lerna config is consistent with workspace settings\n\t\t */\n\t\t_fixLernaJson({\n\t\t\trootData,\n\t\t});\n\n\t\t/**\n\t\t * 初始化套件列表並遍歷修復\n\t\t * Initialize package list and iterate for fixing\n\t\t *\n\t\t * 對每個子套件執行自動修復操作\n\t\t * Execute auto-fix operations for each sub-package\n\t\t */\n\t\tconst list = _initPkgListableByRootData(rootData);\n\n\t\treturn _runEachPackagesAsync(list, {\n\t\t\trootData,\n\t\t\toverwriteHostedGitInfo,\n\t\t\tbranch,\n\t\t\thostedGitInfo,\n\t\t\tresetStaticFiles,\n\t\t\taddStaticFiles,\n\t\t\tnoStaticFiles,\n\t\t\tnoMergeIgnoreFiles,\n\t\t})\n\t}).then(() => void 0 as void)\n}\n\nexport default npmAutoFixAll\n"]}
|
package/lib/file/reset.d.ts
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yarn-tool/fix-all/lib/file/reset
|
|
3
|
+
*
|
|
4
|
+
* 重置靜態檔案模組
|
|
5
|
+
* Static file reset module
|
|
6
|
+
*
|
|
7
|
+
* 在 resetStaticFiles 啟用時,先刪除既有的靜態檔案(含 .tpl 樣板),
|
|
8
|
+
* 讓後續流程能重新複製最新版本
|
|
9
|
+
* When resetStaticFiles is enabled, deletes existing static files (including
|
|
10
|
+
* .tpl templates) so the following step can copy fresh copies
|
|
11
|
+
*/
|
|
1
12
|
import { IFindRootReturnType } from '@yarn-tool/find-root';
|
|
13
|
+
/**
|
|
14
|
+
* 刪除指定目錄下可被重新複製的靜態檔案
|
|
15
|
+
* Delete static files under the given directory that can be re-copied
|
|
16
|
+
*
|
|
17
|
+
* 清單中刻意包含 .tpl 檔與重複的 .nowignore:
|
|
18
|
+
* - .tpl 樣板若不刪除,複製流程可能因檔案已存在而略過更新
|
|
19
|
+
* - 重複項目在 fsRemoveFileSync 內為冪等操作,無副作用
|
|
20
|
+
* The list intentionally includes .tpl templates and a duplicate .nowignore:
|
|
21
|
+
* - Without removing .tpl templates, the copy step may skip updating them
|
|
22
|
+
* because the files already exist
|
|
23
|
+
* - Duplicate entries are idempotent inside fsRemoveFileSync and harmless
|
|
24
|
+
*
|
|
25
|
+
* @param cwd - 要清理的目錄路徑 / Directory to clean up
|
|
26
|
+
* @param options.rootData - 根目錄資料(預留供未來判斷專案型別使用)/ Root data (reserved for future project-type checks)
|
|
27
|
+
*/
|
|
2
28
|
export declare function _resetStaticFiles(cwd: string, options: {
|
|
3
29
|
rootData: IFindRootReturnType;
|
|
4
30
|
}): void;
|
package/lib/file/reset.js
CHANGED
|
@@ -3,6 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports._resetStaticFiles = _resetStaticFiles;
|
|
4
4
|
const upath2_1 = require("upath2");
|
|
5
5
|
const fs_remove_extra_1 = require("fs-remove-extra");
|
|
6
|
+
/**
|
|
7
|
+
* 刪除指定目錄下可被重新複製的靜態檔案
|
|
8
|
+
* Delete static files under the given directory that can be re-copied
|
|
9
|
+
*
|
|
10
|
+
* 清單中刻意包含 .tpl 檔與重複的 .nowignore:
|
|
11
|
+
* - .tpl 樣板若不刪除,複製流程可能因檔案已存在而略過更新
|
|
12
|
+
* - 重複項目在 fsRemoveFileSync 內為冪等操作,無副作用
|
|
13
|
+
* The list intentionally includes .tpl templates and a duplicate .nowignore:
|
|
14
|
+
* - Without removing .tpl templates, the copy step may skip updating them
|
|
15
|
+
* because the files already exist
|
|
16
|
+
* - Duplicate entries are idempotent inside fsRemoveFileSync and harmless
|
|
17
|
+
*
|
|
18
|
+
* @param cwd - 要清理的目錄路徑 / Directory to clean up
|
|
19
|
+
* @param options.rootData - 根目錄資料(預留供未來判斷專案型別使用)/ Root data (reserved for future project-type checks)
|
|
20
|
+
*/
|
|
6
21
|
function _resetStaticFiles(cwd, options) {
|
|
7
22
|
for (const file of [
|
|
8
23
|
'.gitignore',
|
|
@@ -25,6 +40,10 @@ function _resetStaticFiles(cwd, options) {
|
|
|
25
40
|
'.browserslistrc',
|
|
26
41
|
'.browserslistrc.tpl',
|
|
27
42
|
]) {
|
|
43
|
+
/**
|
|
44
|
+
* 檔案不存在時也不會拋錯,可安全重複執行
|
|
45
|
+
* Safe to re-run; missing files do not throw
|
|
46
|
+
*/
|
|
28
47
|
(0, fs_remove_extra_1.fsRemoveFileSync)((0, upath2_1.resolve)(cwd, file));
|
|
29
48
|
}
|
|
30
49
|
}
|
package/lib/file/reset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reset.js","sourceRoot":"","sources":["reset.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"reset.js","sourceRoot":"","sources":["reset.ts"],"names":[],"mappings":";;AA8BA,8CAgCC;AAlDD,mCAAiC;AACjC,qDAAmD;AAEnD;;;;;;;;;;;;;;GAcG;AACH,SAAgB,iBAAiB,CAAC,GAAW,EAAE,OAE9C;IAEA,KAAK,MAAM,IAAI,IAAI;QAClB,YAAY;QACZ,YAAY;QACZ,gBAAgB;QAChB,gBAAgB;QAChB,YAAY;QACZ,mBAAmB;QACnB,oBAAoB;QACpB,iBAAiB;QACjB,oBAAoB;QACpB,uBAAuB;QACvB,mBAAmB;QACnB,wBAAwB;QACxB,oBAAoB;QACpB,YAAY;QACZ,YAAY;QACZ,kBAAkB;QAClB,YAAY;QACZ,iBAAiB;QACjB,qBAAqB;KACZ,EACV,CAAC;QACA;;;WAGG;QACH,IAAA,kCAAgB,EAAC,IAAA,gBAAO,EAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;IACrC,CAAC;AACF,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/file/reset\n *\n * 重置靜態檔案模組\n * Static file reset module\n *\n * 在 resetStaticFiles 啟用時,先刪除既有的靜態檔案(含 .tpl 樣板),\n * 讓後續流程能重新複製最新版本\n * When resetStaticFiles is enabled, deletes existing static files (including\n * .tpl templates) so the following step can copy fresh copies\n */\nimport { IFindRootReturnType } from '@yarn-tool/find-root';\nimport { resolve } from 'upath2';\nimport { fsRemoveFileSync } from 'fs-remove-extra';\n\n/**\n * 刪除指定目錄下可被重新複製的靜態檔案\n * Delete static files under the given directory that can be re-copied\n *\n * 清單中刻意包含 .tpl 檔與重複的 .nowignore:\n * - .tpl 樣板若不刪除,複製流程可能因檔案已存在而略過更新\n * - 重複項目在 fsRemoveFileSync 內為冪等操作,無副作用\n * The list intentionally includes .tpl templates and a duplicate .nowignore:\n * - Without removing .tpl templates, the copy step may skip updating them\n * because the files already exist\n * - Duplicate entries are idempotent inside fsRemoveFileSync and harmless\n *\n * @param cwd - 要清理的目錄路徑 / Directory to clean up\n * @param options.rootData - 根目錄資料(預留供未來判斷專案型別使用)/ Root data (reserved for future project-type checks)\n */\nexport function _resetStaticFiles(cwd: string, options: {\n\trootData: IFindRootReturnType\n})\n{\n\tfor (const file of [\n\t\t'.gitignore',\n\t\t'.npmignore',\n\t\t'jest.config.js',\n\t\t'jest-preset.js',\n\t\t'.nowignore',\n\t\t'.editorconfig.tpl',\n\t\t'jest.config.js.tpl',\n\t\t'.yarnrc.yml.tpl',\n\t\t'tsc-multi.json.tpl',\n\t\t'tsconfig.esm.json.tpl',\n\t\t'tsconfig.json.tpl',\n\t\t'tsconfig.tsdx.json.tpl',\n\t\t'tsdx.config.js.tpl',\n\t\t'.nycrc.tpl',\n\t\t'.npmrc.tpl',\n\t\t'.mocharc.yml.tpl',\n\t\t'.nowignore',\n\t\t'.browserslistrc',\n\t\t'.browserslistrc.tpl',\n\t] as const)\n\t{\n\t\t/**\n\t\t * 檔案不存在時也不會拋錯,可安全重複執行\n\t\t * Safe to re-run; missing files do not throw\n\t\t */\n\t\tfsRemoveFileSync(resolve(cwd, file))\n\t}\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yarn-tool/fix-all/lib/file/staticFiles
|
|
3
|
+
*
|
|
4
|
+
* 靜態檔案選項的底層公用判定邏輯
|
|
5
|
+
* Shared low-level decision logic for static file options
|
|
6
|
+
*
|
|
7
|
+
* 統一處理 noStaticFiles / addStaticFiles / resetStaticFiles 的優先順序,
|
|
8
|
+
* 供 fix-all 與其他套件(npm-init2、create-yarn-workspaces 等)共用
|
|
9
|
+
* Unified priority handling for noStaticFiles / addStaticFiles / resetStaticFiles,
|
|
10
|
+
* shared by fix-all and other packages (npm-init2, create-yarn-workspaces, etc.)
|
|
11
|
+
*/
|
|
12
|
+
import { INpmAutoFixAll } from '../../index';
|
|
13
|
+
/**
|
|
14
|
+
* 靜態檔案相關選項(可只帶其中部分欄位)
|
|
15
|
+
* Static file related options (any subset of the fields)
|
|
16
|
+
*/
|
|
17
|
+
export type IStaticFilesOptionsLike = Pick<INpmAutoFixAll, 'addStaticFiles' | 'noStaticFiles' | 'resetStaticFiles'>;
|
|
18
|
+
/**
|
|
19
|
+
* 判定 noStaticFiles 與 addStaticFiles 的結果
|
|
20
|
+
* Resolve the result of noStaticFiles and addStaticFiles
|
|
21
|
+
*
|
|
22
|
+
* - noStaticFiles = true 時,addStaticFiles 視為 false
|
|
23
|
+
* When noStaticFiles is true, addStaticFiles is treated as false
|
|
24
|
+
* - 兩者皆未指定時,退回 defaultValue
|
|
25
|
+
* Falls back to defaultValue when neither is specified
|
|
26
|
+
*
|
|
27
|
+
* @param {IStaticFilesOptionsLike} [options] - 選項物件 / Options object
|
|
28
|
+
* @param {boolean} [defaultValue=false] - addStaticFiles 未指定時的預設值 / Default when addStaticFiles is not given
|
|
29
|
+
* @returns {boolean} 是否要加入靜態檔案 / Whether to add static files
|
|
30
|
+
*/
|
|
31
|
+
export declare function _isAddStaticFiles(options?: IStaticFilesOptionsLike, defaultValue?: boolean): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* 判定 resetStaticFiles + 以上組合的結果
|
|
34
|
+
* Resolve resetStaticFiles combined with the result above
|
|
35
|
+
*
|
|
36
|
+
* resetStaticFiles = true 時會強制觸發(優先於 noStaticFiles / addStaticFiles)
|
|
37
|
+
* When resetStaticFiles is true it forces the add (takes precedence over noStaticFiles / addStaticFiles)
|
|
38
|
+
*
|
|
39
|
+
* @param {IStaticFilesOptionsLike} [options] - 選項物件 / Options object
|
|
40
|
+
* @param {boolean} [defaultValue=false] - addStaticFiles 未指定時的預設值 / Default when addStaticFiles is not given
|
|
41
|
+
* @returns {boolean} 是否要加入靜態檔案 / Whether to add static files
|
|
42
|
+
*/
|
|
43
|
+
export declare function _isAddStaticFilesOrReset(options?: IStaticFilesOptionsLike, defaultValue?: boolean): boolean;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._isAddStaticFiles = _isAddStaticFiles;
|
|
4
|
+
exports._isAddStaticFilesOrReset = _isAddStaticFilesOrReset;
|
|
5
|
+
/**
|
|
6
|
+
* 判定 noStaticFiles 與 addStaticFiles 的結果
|
|
7
|
+
* Resolve the result of noStaticFiles and addStaticFiles
|
|
8
|
+
*
|
|
9
|
+
* - noStaticFiles = true 時,addStaticFiles 視為 false
|
|
10
|
+
* When noStaticFiles is true, addStaticFiles is treated as false
|
|
11
|
+
* - 兩者皆未指定時,退回 defaultValue
|
|
12
|
+
* Falls back to defaultValue when neither is specified
|
|
13
|
+
*
|
|
14
|
+
* @param {IStaticFilesOptionsLike} [options] - 選項物件 / Options object
|
|
15
|
+
* @param {boolean} [defaultValue=false] - addStaticFiles 未指定時的預設值 / Default when addStaticFiles is not given
|
|
16
|
+
* @returns {boolean} 是否要加入靜態檔案 / Whether to add static files
|
|
17
|
+
*/
|
|
18
|
+
function _isAddStaticFiles(options, defaultValue) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (options === null || options === void 0 ? void 0 : options.noStaticFiles) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return (_a = options === null || options === void 0 ? void 0 : options.addStaticFiles) !== null && _a !== void 0 ? _a : defaultValue;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 判定 resetStaticFiles + 以上組合的結果
|
|
27
|
+
* Resolve resetStaticFiles combined with the result above
|
|
28
|
+
*
|
|
29
|
+
* resetStaticFiles = true 時會強制觸發(優先於 noStaticFiles / addStaticFiles)
|
|
30
|
+
* When resetStaticFiles is true it forces the add (takes precedence over noStaticFiles / addStaticFiles)
|
|
31
|
+
*
|
|
32
|
+
* @param {IStaticFilesOptionsLike} [options] - 選項物件 / Options object
|
|
33
|
+
* @param {boolean} [defaultValue=false] - addStaticFiles 未指定時的預設值 / Default when addStaticFiles is not given
|
|
34
|
+
* @returns {boolean} 是否要加入靜態檔案 / Whether to add static files
|
|
35
|
+
*/
|
|
36
|
+
function _isAddStaticFilesOrReset(options, defaultValue = false) {
|
|
37
|
+
return !!(options === null || options === void 0 ? void 0 : options.resetStaticFiles) || _isAddStaticFiles(options, defaultValue);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=staticFiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staticFiles.js","sourceRoot":"","sources":["staticFiles.ts"],"names":[],"mappings":";;AAgCA,8CAQC;AAaD,4DAGC;AArCD;;;;;;;;;;;;GAYG;AACH,SAAgB,iBAAiB,CAAC,OAAiC,EAAE,YAAsB;;IAE1F,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,EAC1B,CAAC;QACA,OAAO,KAAK,CAAC;IACd,CAAC;IAED,OAAO,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,cAAc,mCAAI,YAAY,CAAC;AAChD,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,wBAAwB,CAAC,OAAiC,EAAE,eAAwB,KAAK;IAExG,OAAO,CAAC,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,gBAAgB,CAAA,IAAI,iBAAiB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;AAChF,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/file/staticFiles\n *\n * 靜態檔案選項的底層公用判定邏輯\n * Shared low-level decision logic for static file options\n *\n * 統一處理 noStaticFiles / addStaticFiles / resetStaticFiles 的優先順序,\n * 供 fix-all 與其他套件(npm-init2、create-yarn-workspaces 等)共用\n * Unified priority handling for noStaticFiles / addStaticFiles / resetStaticFiles,\n * shared by fix-all and other packages (npm-init2, create-yarn-workspaces, etc.)\n */\nimport { INpmAutoFixAll } from '../../index';\n\n/**\n * 靜態檔案相關選項(可只帶其中部分欄位)\n * Static file related options (any subset of the fields)\n */\nexport type IStaticFilesOptionsLike = Pick<INpmAutoFixAll, 'addStaticFiles' | 'noStaticFiles' | 'resetStaticFiles'>;\n\n/**\n * 判定 noStaticFiles 與 addStaticFiles 的結果\n * Resolve the result of noStaticFiles and addStaticFiles\n *\n * - noStaticFiles = true 時,addStaticFiles 視為 false\n * When noStaticFiles is true, addStaticFiles is treated as false\n * - 兩者皆未指定時,退回 defaultValue\n * Falls back to defaultValue when neither is specified\n *\n * @param {IStaticFilesOptionsLike} [options] - 選項物件 / Options object\n * @param {boolean} [defaultValue=false] - addStaticFiles 未指定時的預設值 / Default when addStaticFiles is not given\n * @returns {boolean} 是否要加入靜態檔案 / Whether to add static files\n */\nexport function _isAddStaticFiles(options?: IStaticFilesOptionsLike, defaultValue?: boolean)\n{\n\tif (options?.noStaticFiles)\n\t{\n\t\treturn false;\n\t}\n\n\treturn options?.addStaticFiles ?? defaultValue;\n}\n\n/**\n * 判定 resetStaticFiles + 以上組合的結果\n * Resolve resetStaticFiles combined with the result above\n *\n * resetStaticFiles = true 時會強制觸發(優先於 noStaticFiles / addStaticFiles)\n * When resetStaticFiles is true it forces the add (takes precedence over noStaticFiles / addStaticFiles)\n *\n * @param {IStaticFilesOptionsLike} [options] - 選項物件 / Options object\n * @param {boolean} [defaultValue=false] - addStaticFiles 未指定時的預設值 / Default when addStaticFiles is not given\n * @returns {boolean} 是否要加入靜態檔案 / Whether to add static files\n */\nexport function _isAddStaticFilesOrReset(options?: IStaticFilesOptionsLike, defaultValue: boolean = false)\n{\n\treturn !!options?.resetStaticFiles || _isAddStaticFiles(options, defaultValue);\n}\n"]}
|
package/lib/pkg/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { IFindRootReturnType } from '@yarn-tool/find-root';
|
|
|
12
12
|
import { AggregateErrorExtra } from 'lazy-aggregate-error';
|
|
13
13
|
import Bluebird from 'bluebird';
|
|
14
14
|
import { IFillPkgHostedInfoOptions } from '@yarn-tool/pkg-hosted-info';
|
|
15
|
-
import {
|
|
15
|
+
import { ITSPickExtra } from 'ts-type/lib/type/record';
|
|
16
16
|
import { ICacheInput } from '@yarn-tool/fix-ws-versions';
|
|
17
17
|
import { INpmAutoFixAll } from '../../index';
|
|
18
18
|
/**
|
|
@@ -46,7 +46,7 @@ export type IEntry = ReturnType<typeof _handler>;
|
|
|
46
46
|
*
|
|
47
47
|
* @extends {ITSRequiredPick<IFillPkgHostedInfoOptions & INpmAutoFixAll, ...>}
|
|
48
48
|
*/
|
|
49
|
-
export interface IOptionsRunEachPackages extends
|
|
49
|
+
export interface IOptionsRunEachPackages extends ITSPickExtra<IFillPkgHostedInfoOptions & INpmAutoFixAll, 'overwriteHostedGitInfo' | 'branch' | 'rootData' | 'hostedGitInfo' | 'resetStaticFiles' | 'addStaticFiles' | 'noStaticFiles' | 'noMergeIgnoreFiles'> {
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
52
|
* 執行單一套件修復的核心函數
|
|
@@ -55,7 +55,7 @@ export interface IOptionsRunEachPackages extends ITSRequiredPick<IFillPkgHostedI
|
|
|
55
55
|
* 此函數負責對單一套件執行完整的修復流程,包括:
|
|
56
56
|
* This function performs the complete fix process for a single package, including:
|
|
57
57
|
* 1. 重置靜態檔案(如啟用)/ Reset static files (if enabled)
|
|
58
|
-
* 2.
|
|
58
|
+
* 2. 複製靜態檔案到套件目錄(依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)/ Copy static files to package directory (resolved via addStaticFiles / noStaticFiles / resetStaticFiles)
|
|
59
59
|
* 3. 驗證套件匯出 / Verify package exports
|
|
60
60
|
* 4. 填充託管 git 資訊 / Fill hosted git info
|
|
61
61
|
* 5. 修復 tsdx 套件(如適用)/ Fix tsdx package (if applicable)
|