@yarn-tool/fix-all 3.0.32 → 3.0.34
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 +23 -0
- package/bin/fix-all.js +39 -0
- package/bin/fix-all.js.map +1 -0
- package/index.js +8 -29
- package/index.js.map +1 -1
- package/lib/pkg/index.js +6 -4
- package/lib/pkg/index.js.map +1 -1
- package/package.json +17 -13
- package/playwright.config.js.map +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
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.34](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/fix-all@3.0.33...@yarn-tool/fix-all@3.0.34) (2026-11-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### ✨ Features
|
|
11
|
+
|
|
12
|
+
* **@yarn-tool/fix-all:** 新增 CLI 入口點並重構執行腳本 ([09b56fe](https://github.com/bluelovers/ws-yarn-workspaces/commit/09b56fe92e8de174a892f20ad3483df0cbe90e54))
|
|
13
|
+
* **static-file:** 實作基於 rootData 的靜態檔案複製參數產生器 ([ed756de](https://github.com/bluelovers/ws-yarn-workspaces/commit/ed756de7fd12e978330e1ccc9492da408c93dd24))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### 📦 Code Refactoring
|
|
17
|
+
|
|
18
|
+
* **static-file:** 整合靜態檔案複製邏輯至 rootData 驅動的工具函數 ([de7a526](https://github.com/bluelovers/ws-yarn-workspaces/commit/de7a526bea2ffa7eded6d67f0f84a124a997cc3d))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## [3.0.33](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/fix-all@3.0.32...@yarn-tool/fix-all@3.0.33) (2026-11-16)
|
|
22
|
+
|
|
23
|
+
**Note:** Version bump only for package @yarn-tool/fix-all
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
6
29
|
## [3.0.32](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/fix-all@3.0.31...@yarn-tool/fix-all@3.0.32) (2026-11-16)
|
|
7
30
|
|
|
8
31
|
|
package/bin/fix-all.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* fix-all CLI 入口點
|
|
7
|
+
*/
|
|
8
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
9
|
+
const yargs_setting_1 = require("../lib/util/yargs-setting");
|
|
10
|
+
const __1 = require("..");
|
|
11
|
+
/**
|
|
12
|
+
* setupToYargs 已註冊修復相關選項;此處補上 cwd 讓 --cwd
|
|
13
|
+
* 在 --help 顯示於一般分頁並帶預設值
|
|
14
|
+
*/
|
|
15
|
+
let argv = (0, yargs_setting_1.setupToYargs)(yargs_1.default)
|
|
16
|
+
.option('cwd', {
|
|
17
|
+
default: process.cwd(),
|
|
18
|
+
normalize: true,
|
|
19
|
+
})
|
|
20
|
+
/** 失敗時顯示說明,避免使用者只看到裸錯誤訊息 */
|
|
21
|
+
.showHelpOnFail(true)
|
|
22
|
+
.version()
|
|
23
|
+
.help()
|
|
24
|
+
.parseSync();
|
|
25
|
+
/**
|
|
26
|
+
* yargs 產出的選項名稱與 INpmAutoFixAll 欄位一一對應,直接轉交
|
|
27
|
+
* Yargs option names map one-to-one with INpmAutoFixAll fields, so they are
|
|
28
|
+
* forwarded as-is
|
|
29
|
+
*/
|
|
30
|
+
let options = {
|
|
31
|
+
overwriteHostedGitInfo: argv.overwriteHostedGitInfo,
|
|
32
|
+
branch: argv.branch,
|
|
33
|
+
resetStaticFiles: argv.resetStaticFiles,
|
|
34
|
+
addStaticFiles: argv.addStaticFiles,
|
|
35
|
+
noStaticFiles: argv.noStaticFiles,
|
|
36
|
+
noMergeIgnoreFiles: argv.noMergeIgnoreFiles,
|
|
37
|
+
};
|
|
38
|
+
(0, __1.npmAutoFixAll)(argv.cwd, options);
|
|
39
|
+
//# sourceMappingURL=fix-all.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fix-all.js","sourceRoot":"","sources":["fix-all.ts"],"names":[],"mappings":";;;;AAEA;;GAEG;AACH,0DAA0B;AAC1B,6DAAyD;AACzD,0BAAmD;AAEnD;;;GAGG;AACH,IAAI,IAAI,GAAG,IAAA,4BAAY,EAAC,eAAK,CAAC;KAC5B,MAAM,CAAC,KAAK,EAAE;IACd,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE;IACtB,SAAS,EAAE,IAAI;CACf,CAAC;IACF,4BAA4B;KAC3B,cAAc,CAAC,IAAI,CAAC;KACpB,OAAO,EAAE;KACT,IAAI,EAAE;KACN,SAAS,EAAE,CACZ;AAED;;;;GAIG;AACH,IAAI,OAAO,GAAmB;IAC7B,sBAAsB,EAAE,IAAI,CAAC,sBAAsB;IACnD,MAAM,EAAE,IAAI,CAAC,MAAM;IACnB,gBAAgB,EAAE,IAAI,CAAC,gBAAgB;IACvC,cAAc,EAAE,IAAI,CAAC,cAAc;IACnC,aAAa,EAAE,IAAI,CAAC,aAAa;IACjC,kBAAkB,EAAE,IAAI,CAAC,kBAAkB;CAC3C,CAAC;AAEF,IAAA,iBAAa,EAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n\n/**\n * fix-all CLI 入口點\n */\nimport yargs from 'yargs';\nimport { setupToYargs } from '../lib/util/yargs-setting';\nimport { npmAutoFixAll, INpmAutoFixAll } from '..';\n\n/**\n * setupToYargs 已註冊修復相關選項;此處補上 cwd 讓 --cwd\n * 在 --help 顯示於一般分頁並帶預設值\n */\nlet argv = setupToYargs(yargs)\n\t.option('cwd', {\n\t\tdefault: process.cwd(),\n\t\tnormalize: true,\n\t})\n\t/** 失敗時顯示說明,避免使用者只看到裸錯誤訊息 */\n\t.showHelpOnFail(true)\n\t.version()\n\t.help()\n\t.parseSync()\n;\n\n/**\n * yargs 產出的選項名稱與 INpmAutoFixAll 欄位一一對應,直接轉交\n * Yargs option names map one-to-one with INpmAutoFixAll fields, so they are\n * forwarded as-is\n */\nlet options: INpmAutoFixAll = {\n\toverwriteHostedGitInfo: argv.overwriteHostedGitInfo,\n\tbranch: argv.branch,\n\tresetStaticFiles: argv.resetStaticFiles,\n\taddStaticFiles: argv.addStaticFiles,\n\tnoStaticFiles: argv.noStaticFiles,\n\tnoMergeIgnoreFiles: argv.noMergeIgnoreFiles,\n};\n\nnpmAutoFixAll(argv.cwd, options);\n"]}
|
package/index.js
CHANGED
|
@@ -19,8 +19,7 @@ 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
21
|
const mergeIgnoreFiles_1 = require("@yarn-tool/static-file/lib/mergeIgnoreFiles");
|
|
22
|
-
const
|
|
23
|
-
const getRootCopyStaticFiles_1 = require("@yarn-tool/static-file/lib/root/getRootCopyStaticFiles");
|
|
22
|
+
const copyStaticFilesByRootData_1 = require("@yarn-tool/static-file/lib/copyStaticFilesByRootData");
|
|
24
23
|
const lerna_1 = require("./lib/ws/lerna");
|
|
25
24
|
const reset_1 = require("./lib/file/reset");
|
|
26
25
|
const staticFiles_1 = require("./lib/file/staticFiles");
|
|
@@ -138,33 +137,13 @@ function npmAutoFixAll(cwd, options) {
|
|
|
138
137
|
* Copy corresponding template files based on project type
|
|
139
138
|
*/
|
|
140
139
|
if (_addStaticFiles) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
}
|
|
140
|
+
/**
|
|
141
|
+
* 依 rootData 決定目標與清單:workspace 取 ws 與 workspace 清單,單一套件取 root 與套件清單
|
|
142
|
+
*/
|
|
143
|
+
(0, static_file_1.copyStaticFiles)((0, copyStaticFilesByRootData_1.getCopyStaticFilesOptionsByRootData)(rootData, {
|
|
144
|
+
ignoreFilesSnapshot,
|
|
145
|
+
isRoot: true,
|
|
146
|
+
}));
|
|
168
147
|
}
|
|
169
148
|
logger_1.consoleLogger.info(`check git info`);
|
|
170
149
|
// 取得 hosted git 資訊 / Get hosted git info
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AA6HA,sCAiNC;;AA9UD;;;;;;;;GAQG;AACH,oDAA8D;AAC9D,0DAA+D;AAC/D,4CAAwD;AACxD,2CAAoF;AACpF,gDAAoD;AACpD,gEAAgC;AAChC,wDAAyD;AACzD,kFAAuF;AACvF,uFAAuF;AACvF,mGAAoG;AACpG,0CAA+C;AAC/C,4CAAqD;AACrD,wDAAkE;AAoElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,aAAa,CA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G,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEpC;;;;;;WAMG;QACH,IAAI,QAAQ,CAAC,YAAY,EACzB,CAAC;YACA,8CAA8C;YAC9C,kDAAkD;YAClD,IAAA,kBAAU,EAAC;gBACV,QAAQ;gBACR,aAAa;gBACb,MAAM;gBACN,sBAAsB;aACtB,CAAC,CAAC;QACJ,CAAC;aAED,CAAC;YACA,+BAA+B;YAC/B,qDAAqD;YACrD,IAAA,gBAAQ,EAAC;gBACR,QAAQ;gBACR,aAAa;gBACb,MAAM;gBACN,sBAAsB;gBACtB,SAAS,EAAE,QAAQ,CAAC,IAAI;aACxB,CAAC,CAAC;QACJ,CAAC;QAED;;;;;;WAMG;QACH,IAAA,qBAAa,EAAC;YACb,QAAQ;SACR,CAAC,CAAC;QAEH;;;;;;WAMG;QACH,MAAM,IAAI,GAAG,IAAA,kCAA0B,EAAC,QAAQ,CAAC,CAAC;QAElD,OAAO,IAAA,6BAAqB,EAAC,IAAI,EAAE;YAClC,QAAQ;YACR,sBAAsB;YACtB,MAAM;YACN,aAAa;YACb,gBAAgB;YAChB,cAAc;YACd,aAAa;YACb,kBAAkB;SAClB,CAAC,CAAA;IACH,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,CAAS,CAAC,CAAA;AAC9B,CAAC;AAED,kBAAe,aAAa,CAAA","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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AA4HA,sCAyLC;;AArTD;;;;;;;;GAQG;AACH,oDAA8D;AAC9D,0DAA+D;AAC/D,4CAAwD;AACxD,2CAAoF;AACpF,gDAAoD;AACpD,gEAAgC;AAChC,wDAAyD;AACzD,kFAAuF;AACvF,oGAA2G;AAC3G,0CAA+C;AAC/C,4CAAqD;AACrD,wDAAkE;AAoElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,aAAa,CAAC,GAAW,EAAE,OAAwB;IAElE,OAAO,kBAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE;QAEzC,2CAA2C;QAC3C,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAK,OAAO,CAAC,GAAG,EAAE,EAAC;QAEtB,sBAAa,CAAC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC,CAAC;QAElC,2CAA2C;QAC3C,IAAI,QAAQ,GAAG,IAAA,wBAAY,EAAC;YAC3B,GAAG;SACH,CAAC,CAAC;QAEH;;;;;;WAMG;QACH,IAAI,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,IAAI,CAAA,EACnB,CAAC;YACA,MAAM,IAAI,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAA;QACxD,CAAC;QAED;;;;;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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 { getCopyStaticFilesOptionsByRootData } from '@yarn-tool/static-file/lib/copyStaticFilesByRootData';\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\t/**\n\t\t\t * 依 rootData 決定目標與清單:workspace 取 ws 與 workspace 清單,單一套件取 root 與套件清單\n\t\t\t */\n\t\t\tcopyStaticFiles(getCopyStaticFilesOptionsByRootData(rootData, {\n\t\t\t\tignoreFilesSnapshot,\n\t\t\t\tisRoot: true,\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/pkg/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const sort_package_json3_1 = require("sort-package-json3");
|
|
|
29
29
|
const fix_ws_versions_1 = require("@yarn-tool/fix-ws-versions");
|
|
30
30
|
const types_1 = require("@ts-type/package-dts/lib/package-json/types");
|
|
31
31
|
const normalize_deps_value_1 = require("@yarn-tool/normalize-deps-value");
|
|
32
|
-
const
|
|
32
|
+
const copyStaticFilesByRootData_1 = require("@yarn-tool/static-file/lib/copyStaticFilesByRootData");
|
|
33
33
|
const static_file_1 = require("@yarn-tool/static-file");
|
|
34
34
|
const mergeIgnoreFiles_1 = require("@yarn-tool/static-file/lib/mergeIgnoreFiles");
|
|
35
35
|
const pkg_scripts_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-scripts");
|
|
@@ -136,11 +136,13 @@ function _runFixPackagesCore(row, options, cache, err) {
|
|
|
136
136
|
* Only auto-detect and add when the result is true
|
|
137
137
|
*/
|
|
138
138
|
if (_addStaticFiles) {
|
|
139
|
-
|
|
139
|
+
/**
|
|
140
|
+
* 覆寫 cwd 為套件目錄,file_map 依 _rootDataFake 的旗標以套件模式判定
|
|
141
|
+
*/
|
|
142
|
+
(0, static_file_1.copyStaticFiles)((0, copyStaticFilesByRootData_1.getCopyStaticFilesOptionsByRootData)(_rootDataFake, {
|
|
140
143
|
cwd: row.location,
|
|
141
|
-
file_map: (0, getRootCopyStaticFiles_1.getRootCopyStaticFilesAuto)(_rootDataFake),
|
|
142
144
|
ignoreFilesSnapshot,
|
|
143
|
-
});
|
|
145
|
+
}));
|
|
144
146
|
}
|
|
145
147
|
// 若 README.md 不存在或小於 1KB 則自動生成 / Auto-generate README.md if it doesn't exist or is smaller than 1KB
|
|
146
148
|
if (shouldWriteReadme) {
|
package/lib/pkg/index.js.map
CHANG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AC,IAAI,CAAC;IAExB,mCAAmC;IACnC,gDAAgD;IAChD,IAAI,QAAQ,CAAC,YAAY,EACzB,CAAC;QACA,OAAO,IAAA,2BAAa,EAAC,GAAG,EAAE;YACzB,OAAO,CAAC,GAAG,IAAI;gBAEd,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;YAC9B,CAAC;SACD,CAAC,CAAA;IACH,CAAC;IAED,gBAAgB;IAChB,oDAAoD;IACpD,OAAO,IAAA,oCAAsB,EAAC;QAC7B,GAAG;KACH,EAAE,GAAG,EAAE;QACP,OAAO,CAAC,GAAG,IAAI;YAEd,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC9B,CAAC;KACD,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/pkg\n *\n * package.json 自動修復處理模組\n * package.json auto-fix processing module\n *\n * 處理 workspace 中每個套件的迭代與修復\n * Handles the iteration and fixing of each package in the workspace\n */\nimport { IOptionsPkgListable, normalizeListableRowExtra, wsPkgListable, wsPkgListableFromPaths } from 'ws-pkg-list';\nimport { IFindRootReturnType, newFakeRootData } from '@yarn-tool/find-root';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\nimport { pkgExportsVerify } from '@yarn-tool/pkg-entry-util';\nimport { AggregateErrorExtra } from 'lazy-aggregate-error';\n// @ts-ignore\nimport Bluebird from 'bluebird';\nimport { createProgressEstimator } from '../util/cli-progress';\nimport { consoleLogger } from 'debug-color2/logger';\nimport { console } from 'debug-color2';\nimport { ProgressEstimator } from 'progress-estimator';\nimport { fillPkgHostedInfo, IFillPkgHostedInfoOptions } from '@yarn-tool/pkg-hosted-info';\nimport { ITSPickExtra, ITSRequiredPick } from 'ts-type/lib/type/record';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { fixPkgDepsVersionsCore, ICache, ICacheInput } from '@yarn-tool/fix-ws-versions';\nimport { packageJsonDependenciesFields } from '@ts-type/package-dts/lib/package-json/types';\nimport { normalizeDepsValue } from '@yarn-tool/normalize-deps-value';\nimport { getRootCopyStaticFilesAuto } from '@yarn-tool/static-file/lib/root/getRootCopyStaticFiles';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { _readIgnoreFilesSnapshot } from '@yarn-tool/static-file/lib/mergeIgnoreFiles';\nimport { defaultPkgScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-scripts';\nimport { pathIsSame } from 'path-is-same';\nimport { isDummyEchoMaybeOrEmpty } from '@yarn-tool/pkg-entry-util/lib/util/scripts/dummy';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { isTsdxPackage } from '@yarn-tool/setup-module-env/lib/preset/tsdx/is-tsdx';\nimport { fixTsdxPackage } from '@yarn-tool/setup-module-env/lib/preset/tsdx/fix';\nimport { _resetStaticFiles } from '../file/reset';\nimport { _isAddStaticFilesOrReset } from '../file/staticFiles';\nimport { INpmAutoFixAll } from '../../index';\nimport { join } from 'upath2';\nimport { existsSync, statSync } from 'fs-extra';\nimport { writeReadme } from '@yarn-tool/pkg-readme-tpl/lib/writeReadme';\n\n/**\n * 處理套件列表項目的 handler 函數\n * Handler function for processing package list entries\n *\n * @param {string} cwd - 當前工作目錄 / Current working directory\n * @param {Parameters<IOptionsPkgListable[\"handler\"]>} argv - Handler 參數 / Handler arguments\n * @returns {object} 處理後的項目物件 / Processed entry object\n */\nexport function _handler(cwd: string, ...argv: Parameters<IOptionsPkgListable[\"handler\"]>)\n{\n\treturn {\n\t\t...normalizeListableRowExtra(argv[0], cwd),\n\t\tpkg: argv[1],\n\t}\n}\n\n/**\n * _handler 返回的項目類型\n * Entry type returned by _handler\n */\nexport type IEntry = ReturnType<typeof _handler>\n\n/**\n * 執行每個套件修復的選項\n * Options for running each package fix\n *\n * 繼承自 IFillPkgHostedInfoOptions 和 INpmAutoFixAll 的必要屬性\n * Inherits required properties from IFillPkgHostedInfoOptions and INpmAutoFixAll\n *\n * @extends {ITSRequiredPick<IFillPkgHostedInfoOptions & INpmAutoFixAll, ...>}\n */\nexport interface IOptionsRunEachPackages extends ITSPickExtra<IFillPkgHostedInfoOptions & INpmAutoFixAll, 'overwriteHostedGitInfo' | 'branch' | 'rootData' | 'hostedGitInfo' | 'resetStaticFiles' | 'addStaticFiles' | 'noStaticFiles' | 'noMergeIgnoreFiles'>\n{\n\n}\n\n/**\n * 執行單一套件修復的核心函數\n * Core function for fixing a single package\n *\n * 此函數負責對單一套件執行完整的修復流程,包括:\n * This function performs the complete fix process for a single package, including:\n * 1. 重置靜態檔案(如啟用)/ Reset static files (if enabled)\n * 2. 複製靜態檔案到套件目錄(依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)/ Copy static files to package directory (resolved via addStaticFiles / noStaticFiles / resetStaticFiles)\n * 3. 驗證套件匯出 / Verify package exports\n * 4. 填充託管 git 資訊 / Fill hosted git info\n * 5. 修復 tsdx 套件(如適用)/ Fix tsdx package (if applicable)\n * 6. 修復依賴版本 / Fix dependency versions\n * 7. 標準化依賴值 / Normalize dependency values\n * 8. 設定預設腳本 / Set default scripts\n * 9. 排序並寫入 package.json / Sort and write package.json\n *\n * @param {IEntry} row - 套件項目資料 / Package entry data\n * @param {IOptionsRunEachPackages} options - 修復操作的選項 / Options for the fix operation\n * @param {ICacheInput<IEntry>} cache - 依賴版本修復的快取 / Cache for dependency version fixing\n * @param {AggregateErrorExtra} err - 錯誤聚合器 / Error aggregator\n */\nexport function _runFixPackagesCore(row: IEntry, options: IOptionsRunEachPackages, cache: ICacheInput<IEntry>, err: AggregateErrorExtra)\n{\n\tconst {\n\t\trootData,\n\t\toverwriteHostedGitInfo,\n\t\thostedGitInfo,\n\t\tbranch,\n\t\tresetStaticFiles,\n\t} = options;\n\n\t/**\n\t * 是否自動偵測並加入靜態檔案\n\t * Whether to auto-detect and add static files\n\t *\n\t * 統一由底層公用邏輯判定 noStaticFiles / addStaticFiles / resetStaticFiles\n\t * Resolved by the shared low-level logic for noStaticFiles / addStaticFiles / resetStaticFiles\n\t */\n\tconst _addStaticFiles = _isAddStaticFilesOrReset(options);\n\n\t// 為套件建立假的根資料 / Create fake root data for the package\n\tconst _rootDataFake = newFakeRootData(rootData, {\n\t\tpkg: row.location,\n\t});\n\n\tconst { isRoot, isWorkspace } = _rootDataFake;\n\n\t// 載入 package.json / Load package.json\n\tconst pkg = new PackageJsonLoader(row.manifestLocation);\n\n\t/**\n\t * 在 reset 之前讀取現有 ignore 檔案並建立快照\n\t * Read the existing ignore files and build a snapshot before the reset\n\t *\n\t * resetStaticFiles 會刪除 .gitignore / .npmignore 等檔案,\n\t * 因此必須先取樣,稍後複製完成時才能把既有規則合併回去。\n\t * resetStaticFiles deletes .gitignore / .npmignore and the like, so they must be captured\n\t * first in order to merge the existing rules back once the copy is done.\n\t */\n\tconst ignoreFilesSnapshot = options.noMergeIgnoreFiles\n\t\t? undefined\n\t\t: _readIgnoreFilesSnapshot(row.location);\n\n\t// 若選項啟用則重置靜態檔案 / Reset static files if option enabled\n\tif (resetStaticFiles)\n\t{\n\t\t_resetStaticFiles(_rootDataFake.pkg, {\n\t\t\trootData: _rootDataFake,\n\t\t});\n\t}\n\n\t// 檢查 README.md 是否存在或檔案過小,若符合條件則標記需要生成\n\t// Check if README.md exists or file is too small, mark for generation if condition met\n\tconst mdFile = join(row.location, 'README.md');\n\tlet shouldWriteReadme = false;\n\n\tif (!existsSync(mdFile))\n\t{\n\t\t// README.md 不存在,需要生成 / README.md doesn't exist, needs generation\n\t\tshouldWriteReadme = true;\n\t}\n\telse\n\t{\n\t\t// 檢查檔案大小,若小於 1KB 則重新生成 / Check file size, regenerate if smaller than 1KB\n\t\tconst stats = statSync(mdFile);\n\t\tif (stats.size < 1024)\n\t\t{\n\t\t\tshouldWriteReadme = true;\n\t\t}\n\t}\n\n\t/**\n\t * 複製靜態檔案到套件目錄\n\t * Copy static files to package directory\n\t *\n\t * 僅在判定結果為 true 時才自動偵測並加入\n\t * Only auto-detect and add when the result is true\n\t */\n\tif (_addStaticFiles)\n\t{\n\t\tcopyStaticFiles({\n\t\t\tcwd: row.location,\n\t\t\tfile_map: getRootCopyStaticFilesAuto(_rootDataFake),\n\t\t\tignoreFilesSnapshot,\n\t\t});\n\t}\n\n\t// 若 README.md 不存在或小於 1KB 則自動生成 / Auto-generate README.md if it doesn't exist or is smaller than 1KB\n\tif (shouldWriteReadme)\n\t{\n\t\twriteReadme({\n\t\t\tfile: mdFile,\n\t\t\tvariable: pkg.data,\n\t\t})\n\t}\n\n\t// 驗證套件匯出 / Verify package exports\n\ttry\n\t{\n\t\tpkgExportsVerify(pkg.data, {\n\t\t\tcwd: row.location,\n\t\t});\n\t}\n\tcatch (e)\n\t{\n\t\t// @ts-ignore\n\t\terr.push(e);\n\t}\n\n\t// 填充託管 git 資訊(homepage, repository, bugs)/ Fill hosted git info\n\tfillPkgHostedInfo(pkg.data, {\n\t\ttargetDir: row.location,\n\t\toverwriteHostedGitInfo,\n\t\thostedGitInfo,\n\t\tbranch,\n\t});\n\n\tif (scriptsEntryIsNoTestSpecified(pkg.data.scripts?.test))\n\t{\n\t\tdelete pkg.data.scripts!.test\n\t}\n\n\t// 若適用則修復 tsdx 套件 / Fix tsdx package if applicable\n\tif (isTsdxPackage(pkg.data))\n\t{\n\t\tfixTsdxPackage(pkg.data, {\n\t\t\trootData: _rootDataFake,\n\t\t});\n\t}\n\n\t// 修復依賴版本 / Fix dependency versions\n\tfixPkgDepsVersionsCore(pkg.data, cache);\n\n\t// 標準化依賴值 / Normalize dependency values\n\tpackageJsonDependenciesFields\n\t\t.forEach(field => {\n\n\t\t\tObject.keys(pkg.data[field] ?? {})\n\t\t\t\t.forEach(name => {\n\t\t\t\t\tconst _value = normalizeDepsValue(pkg.data[field][name]);\n\t\t\t\t\tpkg.data[field][name] = _value;\n\t\t\t\t})\n\t\t\t;\n\n\t\t})\n\t;\n\n\t// 設定預設腳本 / Set default scripts\n\tpkg.data.scripts = {\n\t\t...defaultPkgScripts(),\n\t\t...(pkg.data.scripts ?? {}),\n\t};\n\n\t// 處理根套件與非根套件 / Handle root vs non-root packages\n\tif (isRoot)\n\t{\n\t\tif (isWorkspace)\n\t\t{\n\t\t\t// Workspace 根套件 - 無特殊處理 / Workspace root - no special handling\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// 單一套件根 - 無特殊處理 / Single package root - no special handling\n\t\t}\n\t}\n\telse\n\t{\n\t\t// 非根套件:修復 preversion 腳本並移除 packageManager\n\t\t// Non-root package: fix preversion script and remove packageManager\n\t\tif (!pkg.data.scripts['_preversion']?.length && isDummyEchoMaybeOrEmpty(pkg.data.scripts.preversion))\n\t\t{\n\t\t\tpkg.data.scripts.preversion = EnumScriptsEntry.preversion;\n\t\t}\n\n\t\t// 從非根套件移除 packageManager 欄位\n\t\t// Remove packageManager field from non-root packages\n\t\tif (pkg.data['packageManager'])\n\t\t{\n\t\t\tdelete pkg.data['packageManager'];\n\t\t}\n\t}\n\n\t// 排序並寫入 package.json / Sort and write package.json\n\tpkg.data = sortPackageJson(pkg.data);\n\n\tpkg.autofix();\n\tpkg.write();\n}\n\n/**\n * 非同步執行每個套件的修復操作\n * Run fix operations on each package asynchronously\n *\n * 對每個套件執行以下操作:\n * Performs the following operations on each package:\n * 1. 驗證套件匯出 / Verify package exports\n * 2. 填充託管 git 資訊 / Fill hosted git info\n * 3. 修復 tsdx 套件(如適用)/ Fix tsdx package (if applicable)\n * 4. 修復依賴版本 / Fix dependency versions\n * 5. 標準化依賴值 / Normalize dependency values\n * 6. 設定預設腳本 / Set default scripts\n * 7. 排序並寫入 package.json / Sort and write package.json\n *\n * @param {IEntry[]} list - 套件項目列表 / List of package entries\n * @param {IOptionsRunEachPackages} options - 修復操作的選項 / Options for the fix operation\n * @returns {Bluebird<void>} Promise 物件 / Promise object\n */\nexport function _runEachPackagesAsync(list: IEntry[],\n\toptions: IOptionsRunEachPackages,\n)\n{\n\tlet logger: ProgressEstimator;\n\t// 依賴版本修復的快取 / Cache for dependency version fixing\n\tlet cache: ICacheInput<IEntry> = {} as any;\n\n\treturn Bluebird.resolve(list)\n\t\t.tap((listable) =>\n\t\t{\n\t\t\t// 建立進度估計器 / Create progress estimator\n\t\t\tlogger = createProgressEstimator(options.rootData.root);\n\n\t\t\tconsoleLogger.info(`auto check/fix packages`);\n\n\t\t\tcache.listable = listable;\n\n\t\t})\n\t\t.mapSeries(async (row) =>\n\t\t{\n\t\t\t// 錯誤收集器 / Error aggregator for collecting errors\n\t\t\tconst err = new AggregateErrorExtra();\n\n\t\t\tconst promiseLogger = logger((async () =>\n\t\t\t{\n\n\t\t\t\t_runFixPackagesCore(row, options, cache, err);\n\n\t\t\t})().catch(e => {\n\t\t\t\te.row = row;\n\t\t\t\t// @ts-ignore\n\t\t\t\terr.push(e);\n\t\t\t}), row.name)\n\n\t\t\treturn promiseLogger\n\t\t\t\t.catch(e => {\n\t\t\t\t\te.row = row;\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\terr.push(e);\n\t\t\t\t})\n\t\t\t\t.then(() =>\n\t\t\t\t{\n\t\t\t\t\t// 若有錯誤則記錄 / Log errors if any\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tif (err.length)\n\t\t\t\t\t{\n\t\t\t\t\t\tconsole.error(err);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t})\n\t\t;\n}\n\n/**\n * 從根資料初始化套件列表\n * Initialize package list from root data\n *\n * 根據 workspace 或單一套件模式返回要處理的套件列表\n * Returns list of packages to process based on workspace or single package mode\n *\n * @param {Pick<IFindRootReturnType, 'root' | 'hasWorkspace'>} rootData - 根資料物件 / Root data object\n * @returns {IEntry[]} 套件項目列表 / List of package entries\n */\nexport function _initPkgListableByRootData(rootData: Pick<IFindRootReturnType, 'root' | 'hasWorkspace'>)\n{\n\tlet cwd = rootData.root;\n\n\t// Workspace 模式:取得 workspace 中的所有套件\n\t// Workspace mode: get all packages in workspace\n\tif (rootData.hasWorkspace)\n\t{\n\t\treturn wsPkgListable(cwd, {\n\t\t\thandler(...argv)\n\t\t\t{\n\t\t\t\treturn _handler(cwd, ...argv)\n\t\t\t},\n\t\t})\n\t}\n\n\t// 單一套件模式:僅返回根套件\n\t// Single package mode: return only the root package\n\treturn wsPkgListableFromPaths([\n\t\tcwd,\n\t], cwd, {\n\t\thandler(...argv)\n\t\t{\n\t\t\treturn _handler(cwd, ...argv)\n\t\t},\n\t})\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAkDA,4BAMC;AA2CD,kDA4LC;AAoBD,sDAoDC;AAYD,gEA0BC;;AA7YD;;;;;;;;GAQG;AACH,6CAAoH;AACpH,oDAA4E;AAC5E,qEAA4D;AAC5D,8DAA6D;AAC7D,+DAA2D;AAC3D,aAAa;AACb,gEAAgC;AAChC,uDAA+D;AAC/D,gDAAoD;AACpD,+CAAuC;AAEvC,gEAA0F;AAE1F,2DAAqD;AACrD,gEAAyF;AACzF,uEAA4F;AAC5F,0EAAqE;AACrE,oGAA2G;AAC3G,wDAAyD;AACzD,kFAAuF;AACvF,0FAA6F;AAE7F,4EAA2F;AAC3F,yEAA8G;AAC9G,iFAAoF;AACpF,yEAAiF;AACjF,yCAAkD;AAClD,qDAA+D;AAE/D,mCAA8B;AAC9B,uCAAgD;AAChD,2EAAwE;AAExE;;;;;;;GAOG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,GAAG,IAAgD;IAExF,OAAO;QACN,GAAG,IAAA,uCAAyB,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC;QAC1C,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC;KACZ,CAAA;AACF,CAAC;AAsBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,mBAAmB,CAAC,GAAW,EAAE,OAAgC,EAAE,KAA0B,EAAE,GAAwB;;IAEtI,MAAM,EACL,QAAQ,EACR,sBAAsB,EACtB,aAAa,EACb,MA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9B,aAAa;YACb,IAAI,GAAG,CAAC,MAAM,EACd,CAAC;gBACA,sBAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;QACF,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CACD;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,0BAA0B,CAAC,QAA4D;IAEtG,IAAI,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC;IAExB,mCAAmC;IACnC,gDAAgD;IAChD,IAAI,QAAQ,CAAC,YAAY,EACzB,CAAC;QACA,OAAO,IAAA,2BAAa,EAAC,GAAG,EAAE;YACzB,OAAO,CAAC,GAAG,IAAI;gBAEd,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;YAC9B,CAAC;SACD,CAAC,CAAA;IACH,CAAC;IAED,gBAAgB;IAChB,oDAAoD;IACpD,OAAO,IAAA,oCAAsB,EAAC;QAC7B,GAAG;KACH,EAAE,GAAG,EAAE;QACP,OAAO,CAAC,GAAG,IAAI;YAEd,OAAO,QAAQ,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;QAC9B,CAAC;KACD,CAAC,CAAA;AACH,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/pkg\n *\n * package.json 自動修復處理模組\n * package.json auto-fix processing module\n *\n * 處理 workspace 中每個套件的迭代與修復\n * Handles the iteration and fixing of each package in the workspace\n */\nimport { IOptionsPkgListable, normalizeListableRowExtra, wsPkgListable, wsPkgListableFromPaths } from 'ws-pkg-list';\nimport { IFindRootReturnType, newFakeRootData } from '@yarn-tool/find-root';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\nimport { pkgExportsVerify } from '@yarn-tool/pkg-entry-util';\nimport { AggregateErrorExtra } from 'lazy-aggregate-error';\n// @ts-ignore\nimport Bluebird from 'bluebird';\nimport { createProgressEstimator } from '../util/cli-progress';\nimport { consoleLogger } from 'debug-color2/logger';\nimport { console } from 'debug-color2';\nimport { ProgressEstimator } from 'progress-estimator';\nimport { fillPkgHostedInfo, IFillPkgHostedInfoOptions } from '@yarn-tool/pkg-hosted-info';\nimport { ITSPickExtra, ITSRequiredPick } from 'ts-type/lib/type/record';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { fixPkgDepsVersionsCore, ICache, ICacheInput } from '@yarn-tool/fix-ws-versions';\nimport { packageJsonDependenciesFields } from '@ts-type/package-dts/lib/package-json/types';\nimport { normalizeDepsValue } from '@yarn-tool/normalize-deps-value';\nimport { getCopyStaticFilesOptionsByRootData } from '@yarn-tool/static-file/lib/copyStaticFilesByRootData';\nimport { copyStaticFiles } from '@yarn-tool/static-file';\nimport { _readIgnoreFilesSnapshot } from '@yarn-tool/static-file/lib/mergeIgnoreFiles';\nimport { defaultPkgScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-scripts';\nimport { pathIsSame } from 'path-is-same';\nimport { isDummyEchoMaybeOrEmpty } from '@yarn-tool/pkg-entry-util/lib/util/scripts/dummy';\nimport { EnumScriptsEntry, scriptsEntryIsNoTestSpecified } from '@yarn-tool/pkg-entry-util/lib/field/scripts';\nimport { isTsdxPackage } from '@yarn-tool/setup-module-env/lib/preset/tsdx/is-tsdx';\nimport { fixTsdxPackage } from '@yarn-tool/setup-module-env/lib/preset/tsdx/fix';\nimport { _resetStaticFiles } from '../file/reset';\nimport { _isAddStaticFilesOrReset } from '../file/staticFiles';\nimport { INpmAutoFixAll } from '../../index';\nimport { join } from 'upath2';\nimport { existsSync, statSync } from 'fs-extra';\nimport { writeReadme } from '@yarn-tool/pkg-readme-tpl/lib/writeReadme';\n\n/**\n * 處理套件列表項目的 handler 函數\n * Handler function for processing package list entries\n *\n * @param {string} cwd - 當前工作目錄 / Current working directory\n * @param {Parameters<IOptionsPkgListable[\"handler\"]>} argv - Handler 參數 / Handler arguments\n * @returns {object} 處理後的項目物件 / Processed entry object\n */\nexport function _handler(cwd: string, ...argv: Parameters<IOptionsPkgListable[\"handler\"]>)\n{\n\treturn {\n\t\t...normalizeListableRowExtra(argv[0], cwd),\n\t\tpkg: argv[1],\n\t}\n}\n\n/**\n * _handler 返回的項目類型\n * Entry type returned by _handler\n */\nexport type IEntry = ReturnType<typeof _handler>\n\n/**\n * 執行每個套件修復的選項\n * Options for running each package fix\n *\n * 繼承自 IFillPkgHostedInfoOptions 和 INpmAutoFixAll 的必要屬性\n * Inherits required properties from IFillPkgHostedInfoOptions and INpmAutoFixAll\n *\n * @extends {ITSRequiredPick<IFillPkgHostedInfoOptions & INpmAutoFixAll, ...>}\n */\nexport interface IOptionsRunEachPackages extends ITSPickExtra<IFillPkgHostedInfoOptions & INpmAutoFixAll, 'overwriteHostedGitInfo' | 'branch' | 'rootData' | 'hostedGitInfo' | 'resetStaticFiles' | 'addStaticFiles' | 'noStaticFiles' | 'noMergeIgnoreFiles'>\n{\n\n}\n\n/**\n * 執行單一套件修復的核心函數\n * Core function for fixing a single package\n *\n * 此函數負責對單一套件執行完整的修復流程,包括:\n * This function performs the complete fix process for a single package, including:\n * 1. 重置靜態檔案(如啟用)/ Reset static files (if enabled)\n * 2. 複製靜態檔案到套件目錄(依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)/ Copy static files to package directory (resolved via addStaticFiles / noStaticFiles / resetStaticFiles)\n * 3. 驗證套件匯出 / Verify package exports\n * 4. 填充託管 git 資訊 / Fill hosted git info\n * 5. 修復 tsdx 套件(如適用)/ Fix tsdx package (if applicable)\n * 6. 修復依賴版本 / Fix dependency versions\n * 7. 標準化依賴值 / Normalize dependency values\n * 8. 設定預設腳本 / Set default scripts\n * 9. 排序並寫入 package.json / Sort and write package.json\n *\n * @param {IEntry} row - 套件項目資料 / Package entry data\n * @param {IOptionsRunEachPackages} options - 修復操作的選項 / Options for the fix operation\n * @param {ICacheInput<IEntry>} cache - 依賴版本修復的快取 / Cache for dependency version fixing\n * @param {AggregateErrorExtra} err - 錯誤聚合器 / Error aggregator\n */\nexport function _runFixPackagesCore(row: IEntry, options: IOptionsRunEachPackages, cache: ICacheInput<IEntry>, err: AggregateErrorExtra)\n{\n\tconst {\n\t\trootData,\n\t\toverwriteHostedGitInfo,\n\t\thostedGitInfo,\n\t\tbranch,\n\t\tresetStaticFiles,\n\t} = options;\n\n\t/**\n\t * 是否自動偵測並加入靜態檔案\n\t * Whether to auto-detect and add static files\n\t *\n\t * 統一由底層公用邏輯判定 noStaticFiles / addStaticFiles / resetStaticFiles\n\t * Resolved by the shared low-level logic for noStaticFiles / addStaticFiles / resetStaticFiles\n\t */\n\tconst _addStaticFiles = _isAddStaticFilesOrReset(options);\n\n\t// 為套件建立假的根資料 / Create fake root data for the package\n\tconst _rootDataFake = newFakeRootData(rootData, {\n\t\tpkg: row.location,\n\t});\n\n\tconst { isRoot, isWorkspace } = _rootDataFake;\n\n\t// 載入 package.json / Load package.json\n\tconst pkg = new PackageJsonLoader(row.manifestLocation);\n\n\t/**\n\t * 在 reset 之前讀取現有 ignore 檔案並建立快照\n\t * Read the existing ignore files and build a snapshot before the reset\n\t *\n\t * resetStaticFiles 會刪除 .gitignore / .npmignore 等檔案,\n\t * 因此必須先取樣,稍後複製完成時才能把既有規則合併回去。\n\t * resetStaticFiles deletes .gitignore / .npmignore and the like, so they must be captured\n\t * first in order to merge the existing rules back once the copy is done.\n\t */\n\tconst ignoreFilesSnapshot = options.noMergeIgnoreFiles\n\t\t? undefined\n\t\t: _readIgnoreFilesSnapshot(row.location);\n\n\t// 若選項啟用則重置靜態檔案 / Reset static files if option enabled\n\tif (resetStaticFiles)\n\t{\n\t\t_resetStaticFiles(_rootDataFake.pkg, {\n\t\t\trootData: _rootDataFake,\n\t\t});\n\t}\n\n\t// 檢查 README.md 是否存在或檔案過小,若符合條件則標記需要生成\n\t// Check if README.md exists or file is too small, mark for generation if condition met\n\tconst mdFile = join(row.location, 'README.md');\n\tlet shouldWriteReadme = false;\n\n\tif (!existsSync(mdFile))\n\t{\n\t\t// README.md 不存在,需要生成 / README.md doesn't exist, needs generation\n\t\tshouldWriteReadme = true;\n\t}\n\telse\n\t{\n\t\t// 檢查檔案大小,若小於 1KB 則重新生成 / Check file size, regenerate if smaller than 1KB\n\t\tconst stats = statSync(mdFile);\n\t\tif (stats.size < 1024)\n\t\t{\n\t\t\tshouldWriteReadme = true;\n\t\t}\n\t}\n\n\t/**\n\t * 複製靜態檔案到套件目錄\n\t * Copy static files to package directory\n\t *\n\t * 僅在判定結果為 true 時才自動偵測並加入\n\t * Only auto-detect and add when the result is true\n\t */\n\tif (_addStaticFiles)\n\t{\n\t\t/**\n\t\t * 覆寫 cwd 為套件目錄,file_map 依 _rootDataFake 的旗標以套件模式判定\n\t\t */\n\t\tcopyStaticFiles(getCopyStaticFilesOptionsByRootData(_rootDataFake, {\n\t\t\tcwd: row.location,\n\t\t\tignoreFilesSnapshot,\n\t\t}));\n\t}\n\n\t// 若 README.md 不存在或小於 1KB 則自動生成 / Auto-generate README.md if it doesn't exist or is smaller than 1KB\n\tif (shouldWriteReadme)\n\t{\n\t\twriteReadme({\n\t\t\tfile: mdFile,\n\t\t\tvariable: pkg.data,\n\t\t})\n\t}\n\n\t// 驗證套件匯出 / Verify package exports\n\ttry\n\t{\n\t\tpkgExportsVerify(pkg.data, {\n\t\t\tcwd: row.location,\n\t\t});\n\t}\n\tcatch (e)\n\t{\n\t\t// @ts-ignore\n\t\terr.push(e);\n\t}\n\n\t// 填充託管 git 資訊(homepage, repository, bugs)/ Fill hosted git info\n\tfillPkgHostedInfo(pkg.data, {\n\t\ttargetDir: row.location,\n\t\toverwriteHostedGitInfo,\n\t\thostedGitInfo,\n\t\tbranch,\n\t});\n\n\tif (scriptsEntryIsNoTestSpecified(pkg.data.scripts?.test))\n\t{\n\t\tdelete pkg.data.scripts!.test\n\t}\n\n\t// 若適用則修復 tsdx 套件 / Fix tsdx package if applicable\n\tif (isTsdxPackage(pkg.data))\n\t{\n\t\tfixTsdxPackage(pkg.data, {\n\t\t\trootData: _rootDataFake,\n\t\t});\n\t}\n\n\t// 修復依賴版本 / Fix dependency versions\n\tfixPkgDepsVersionsCore(pkg.data, cache);\n\n\t// 標準化依賴值 / Normalize dependency values\n\tpackageJsonDependenciesFields\n\t\t.forEach(field => {\n\n\t\t\tObject.keys(pkg.data[field] ?? {})\n\t\t\t\t.forEach(name => {\n\t\t\t\t\tconst _value = normalizeDepsValue(pkg.data[field][name]);\n\t\t\t\t\tpkg.data[field][name] = _value;\n\t\t\t\t})\n\t\t\t;\n\n\t\t})\n\t;\n\n\t// 設定預設腳本 / Set default scripts\n\tpkg.data.scripts = {\n\t\t...defaultPkgScripts(),\n\t\t...(pkg.data.scripts ?? {}),\n\t};\n\n\t// 處理根套件與非根套件 / Handle root vs non-root packages\n\tif (isRoot)\n\t{\n\t\tif (isWorkspace)\n\t\t{\n\t\t\t// Workspace 根套件 - 無特殊處理 / Workspace root - no special handling\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// 單一套件根 - 無特殊處理 / Single package root - no special handling\n\t\t}\n\t}\n\telse\n\t{\n\t\t// 非根套件:修復 preversion 腳本並移除 packageManager\n\t\t// Non-root package: fix preversion script and remove packageManager\n\t\tif (!pkg.data.scripts['_preversion']?.length && isDummyEchoMaybeOrEmpty(pkg.data.scripts.preversion))\n\t\t{\n\t\t\tpkg.data.scripts.preversion = EnumScriptsEntry.preversion;\n\t\t}\n\n\t\t// 從非根套件移除 packageManager 欄位\n\t\t// Remove packageManager field from non-root packages\n\t\tif (pkg.data['packageManager'])\n\t\t{\n\t\t\tdelete pkg.data['packageManager'];\n\t\t}\n\t}\n\n\t// 排序並寫入 package.json / Sort and write package.json\n\tpkg.data = sortPackageJson(pkg.data);\n\n\tpkg.autofix();\n\tpkg.write();\n}\n\n/**\n * 非同步執行每個套件的修復操作\n * Run fix operations on each package asynchronously\n *\n * 對每個套件執行以下操作:\n * Performs the following operations on each package:\n * 1. 驗證套件匯出 / Verify package exports\n * 2. 填充託管 git 資訊 / Fill hosted git info\n * 3. 修復 tsdx 套件(如適用)/ Fix tsdx package (if applicable)\n * 4. 修復依賴版本 / Fix dependency versions\n * 5. 標準化依賴值 / Normalize dependency values\n * 6. 設定預設腳本 / Set default scripts\n * 7. 排序並寫入 package.json / Sort and write package.json\n *\n * @param {IEntry[]} list - 套件項目列表 / List of package entries\n * @param {IOptionsRunEachPackages} options - 修復操作的選項 / Options for the fix operation\n * @returns {Bluebird<void>} Promise 物件 / Promise object\n */\nexport function _runEachPackagesAsync(list: IEntry[],\n\toptions: IOptionsRunEachPackages,\n)\n{\n\tlet logger: ProgressEstimator;\n\t// 依賴版本修復的快取 / Cache for dependency version fixing\n\tlet cache: ICacheInput<IEntry> = {} as any;\n\n\treturn Bluebird.resolve(list)\n\t\t.tap((listable) =>\n\t\t{\n\t\t\t// 建立進度估計器 / Create progress estimator\n\t\t\tlogger = createProgressEstimator(options.rootData.root);\n\n\t\t\tconsoleLogger.info(`auto check/fix packages`);\n\n\t\t\tcache.listable = listable;\n\n\t\t})\n\t\t.mapSeries(async (row) =>\n\t\t{\n\t\t\t// 錯誤收集器 / Error aggregator for collecting errors\n\t\t\tconst err = new AggregateErrorExtra();\n\n\t\t\tconst promiseLogger = logger((async () =>\n\t\t\t{\n\n\t\t\t\t_runFixPackagesCore(row, options, cache, err);\n\n\t\t\t})().catch(e => {\n\t\t\t\te.row = row;\n\t\t\t\t// @ts-ignore\n\t\t\t\terr.push(e);\n\t\t\t}), row.name)\n\n\t\t\treturn promiseLogger\n\t\t\t\t.catch(e => {\n\t\t\t\t\te.row = row;\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\terr.push(e);\n\t\t\t\t})\n\t\t\t\t.then(() =>\n\t\t\t\t{\n\t\t\t\t\t// 若有錯誤則記錄 / Log errors if any\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\tif (err.length)\n\t\t\t\t\t{\n\t\t\t\t\t\tconsole.error(err);\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t})\n\t\t;\n}\n\n/**\n * 從根資料初始化套件列表\n * Initialize package list from root data\n *\n * 根據 workspace 或單一套件模式返回要處理的套件列表\n * Returns list of packages to process based on workspace or single package mode\n *\n * @param {Pick<IFindRootReturnType, 'root' | 'hasWorkspace'>} rootData - 根資料物件 / Root data object\n * @returns {IEntry[]} 套件項目列表 / List of package entries\n */\nexport function _initPkgListableByRootData(rootData: Pick<IFindRootReturnType, 'root' | 'hasWorkspace'>)\n{\n\tlet cwd = rootData.root;\n\n\t// Workspace 模式:取得 workspace 中的所有套件\n\t// Workspace mode: get all packages in workspace\n\tif (rootData.hasWorkspace)\n\t{\n\t\treturn wsPkgListable(cwd, {\n\t\t\thandler(...argv)\n\t\t\t{\n\t\t\t\treturn _handler(cwd, ...argv)\n\t\t\t},\n\t\t})\n\t}\n\n\t// 單一套件模式:僅返回根套件\n\t// Single package mode: return only the root package\n\treturn wsPkgListableFromPaths([\n\t\tcwd,\n\t], cwd, {\n\t\thandler(...argv)\n\t\t{\n\t\t\treturn _handler(cwd, ...argv)\n\t\t},\n\t})\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/fix-all",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.34",
|
|
4
4
|
"description": "一站式自動修復工具,支援 git 資訊更新、靜態檔案同步、版本修正與 workspace 管理 (All-in-one auto-fix tool for git info update, static file sync, version fix, and workspace management)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fix-all",
|
|
@@ -33,6 +33,9 @@
|
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"author": "bluelovers",
|
|
35
35
|
"main": "index.js",
|
|
36
|
+
"bin": {
|
|
37
|
+
"fix-all": "./bin/fix-all.js"
|
|
38
|
+
},
|
|
36
39
|
"scripts": {
|
|
37
40
|
"coverage": "pnpm run test -- --coverage",
|
|
38
41
|
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
@@ -64,35 +67,36 @@
|
|
|
64
67
|
"publish": "echo publish",
|
|
65
68
|
"postpublish": "echo postpublish",
|
|
66
69
|
"postpublishOnly": "echo postpublishOnly",
|
|
70
|
+
"bin:self": "pnpm run --filter @yarn-tool/static-file bin:self && tsx ./bin/fix-all.ts",
|
|
67
71
|
"ncu": "yarn-tool ncu -u",
|
|
68
72
|
"sort-package-json": "yarn-tool sort",
|
|
69
73
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
70
74
|
},
|
|
71
75
|
"dependencies": {
|
|
72
76
|
"@ts-type/package-dts": "^3.0.15",
|
|
73
|
-
"@yarn-tool/find-root": "^2.0.
|
|
74
|
-
"@yarn-tool/fix-ws-versions": "^3.0.
|
|
77
|
+
"@yarn-tool/find-root": "^2.0.31",
|
|
78
|
+
"@yarn-tool/fix-ws-versions": "^3.0.19",
|
|
75
79
|
"@yarn-tool/normalize-deps-value": "^2.0.16",
|
|
76
|
-
"@yarn-tool/pkg-deps-add": "^3.0.
|
|
77
|
-
"@yarn-tool/pkg-entry-util": "^3.0.
|
|
80
|
+
"@yarn-tool/pkg-deps-add": "^3.0.16",
|
|
81
|
+
"@yarn-tool/pkg-entry-util": "^3.0.29",
|
|
78
82
|
"@yarn-tool/pkg-git-info": "^2.0.12",
|
|
79
|
-
"@yarn-tool/pkg-hosted-info": "^3.0.
|
|
83
|
+
"@yarn-tool/pkg-hosted-info": "^3.0.17",
|
|
80
84
|
"@yarn-tool/pkg-readme-tpl": "^1.0.14",
|
|
81
85
|
"@yarn-tool/require-resolve": "^4.0.17",
|
|
82
|
-
"@yarn-tool/setup-module-env": "^3.0.
|
|
83
|
-
"@yarn-tool/static-file": "^3.0.
|
|
86
|
+
"@yarn-tool/setup-module-env": "^3.0.32",
|
|
87
|
+
"@yarn-tool/static-file": "^3.0.34",
|
|
84
88
|
"@yarn-tool/types": "^1.0.25",
|
|
85
89
|
"@yarn-tool/write-package-json": "^1.0.22",
|
|
86
|
-
"@yarn-tool/ws-scope": "^3.0.
|
|
90
|
+
"@yarn-tool/ws-scope": "^3.0.18",
|
|
87
91
|
"array-hyper-unique": "^2.1.10",
|
|
88
92
|
"bluebird": "^3.7.2",
|
|
89
|
-
"cache-path": "^4.0.
|
|
93
|
+
"cache-path": "^4.0.19",
|
|
90
94
|
"debug-color2": "^1.3.2",
|
|
91
95
|
"fs-extra": "^11.4.1",
|
|
92
96
|
"fs-remove-extra": "^1.0.8",
|
|
93
97
|
"lazy-aggregate-error": "^1.0.21",
|
|
94
98
|
"lodash": "^4.18.1",
|
|
95
|
-
"npm-package-json-loader": "^3.0.
|
|
99
|
+
"npm-package-json-loader": "^3.0.28",
|
|
96
100
|
"path-is-same": "^1.0.29",
|
|
97
101
|
"progress-estimator": "^0.3.1",
|
|
98
102
|
"semver": "^7.8.6",
|
|
@@ -100,11 +104,11 @@
|
|
|
100
104
|
"ts-type": "^3.0.19",
|
|
101
105
|
"tslib": ">=2.8.1",
|
|
102
106
|
"upath2": "^3.1.25",
|
|
103
|
-
"ws-pkg-list": "^3.0.
|
|
107
|
+
"ws-pkg-list": "^3.0.17",
|
|
104
108
|
"yargs": "<18 >=17.7.2"
|
|
105
109
|
},
|
|
106
110
|
"publishConfig": {
|
|
107
111
|
"access": "public"
|
|
108
112
|
},
|
|
109
|
-
"gitHead": "
|
|
113
|
+
"gitHead": "314b389c12023220506f368dadea7b7624cbb740"
|
|
110
114
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playwright.config.js","sourceRoot":"","sources":["playwright.config.ts"],"names":[],"mappings":";;AAAA,aAAa;AACb,2CAAgD;AAEhD,kBAAe,IAAA,mBAAY,EAAC;IAC3B,SAAS,EAAE,6CAA6C;CACxD,CAAC,CAAC","sourcesContent":["// @ts-ignore\nimport { defineConfig } from '@playwright/test';\n\nexport default defineConfig({\n\ttestMatch: /.*\\.playwright(?:-|\\.)(?:spec|test)\\.(?:ts)/,\n});\n"]}
|