@yarn-tool/fix-all 3.0.20 → 3.0.22

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/lib/pkg/index.js CHANGED
@@ -31,12 +31,14 @@ 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
32
  const getRootCopyStaticFiles_1 = require("@yarn-tool/static-file/lib/root/getRootCopyStaticFiles");
33
33
  const static_file_1 = require("@yarn-tool/static-file");
34
+ const mergeIgnoreFiles_1 = require("@yarn-tool/static-file/lib/mergeIgnoreFiles");
34
35
  const pkg_scripts_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/pkg-scripts");
35
36
  const dummy_1 = require("@yarn-tool/pkg-entry-util/lib/util/scripts/dummy");
36
37
  const scripts_1 = require("@yarn-tool/pkg-entry-util/lib/field/scripts");
37
38
  const is_tsdx_1 = require("@yarn-tool/setup-module-env/lib/preset/tsdx/is-tsdx");
38
39
  const fix_1 = require("@yarn-tool/setup-module-env/lib/preset/tsdx/fix");
39
40
  const reset_1 = require("../file/reset");
41
+ const staticFiles_1 = require("../file/staticFiles");
40
42
  const upath2_1 = require("upath2");
41
43
  const fs_extra_1 = require("fs-extra");
42
44
  const writeReadme_1 = require("@yarn-tool/pkg-readme-tpl/lib/writeReadme");
@@ -61,7 +63,7 @@ function _handler(cwd, ...argv) {
61
63
  * 此函數負責對單一套件執行完整的修復流程,包括:
62
64
  * This function performs the complete fix process for a single package, including:
63
65
  * 1. 重置靜態檔案(如啟用)/ Reset static files (if enabled)
64
- * 2. 複製靜態檔案到套件目錄 / Copy static files to package directory
66
+ * 2. 複製靜態檔案到套件目錄(依 addStaticFiles / noStaticFiles / resetStaticFiles 判定)/ Copy static files to package directory (resolved via addStaticFiles / noStaticFiles / resetStaticFiles)
65
67
  * 3. 驗證套件匯出 / Verify package exports
66
68
  * 4. 填充託管 git 資訊 / Fill hosted git info
67
69
  * 5. 修復 tsdx 套件(如適用)/ Fix tsdx package (if applicable)
@@ -78,6 +80,14 @@ function _handler(cwd, ...argv) {
78
80
  function _runFixPackagesCore(row, options, cache, err) {
79
81
  var _a, _b, _c;
80
82
  const { rootData, overwriteHostedGitInfo, hostedGitInfo, branch, resetStaticFiles, } = options;
83
+ /**
84
+ * 是否自動偵測並加入靜態檔案
85
+ * Whether to auto-detect and add static files
86
+ *
87
+ * 統一由底層公用邏輯判定 noStaticFiles / addStaticFiles / resetStaticFiles
88
+ * Resolved by the shared low-level logic for noStaticFiles / addStaticFiles / resetStaticFiles
89
+ */
90
+ const _addStaticFiles = (0, staticFiles_1._isAddStaticFilesOrReset)(options);
81
91
  // 為套件建立假的根資料 / Create fake root data for the package
82
92
  const _rootDataFake = (0, find_root_1.newFakeRootData)(rootData, {
83
93
  pkg: row.location,
@@ -85,6 +95,18 @@ function _runFixPackagesCore(row, options, cache, err) {
85
95
  const { isRoot, isWorkspace } = _rootDataFake;
86
96
  // 載入 package.json / Load package.json
87
97
  const pkg = new npm_package_json_loader_1.PackageJsonLoader(row.manifestLocation);
98
+ /**
99
+ * 在 reset 之前讀取現有 ignore 檔案並建立快照
100
+ * Read the existing ignore files and build a snapshot before the reset
101
+ *
102
+ * resetStaticFiles 會刪除 .gitignore / .npmignore 等檔案,
103
+ * 因此必須先取樣,稍後複製完成時才能把既有規則合併回去。
104
+ * resetStaticFiles deletes .gitignore / .npmignore and the like, so they must be captured
105
+ * first in order to merge the existing rules back once the copy is done.
106
+ */
107
+ const ignoreFilesSnapshot = options.noMergeIgnoreFiles
108
+ ? undefined
109
+ : (0, mergeIgnoreFiles_1._readIgnoreFilesSnapshot)(row.location);
88
110
  // 若選項啟用則重置靜態檔案 / Reset static files if option enabled
89
111
  if (resetStaticFiles) {
90
112
  (0, reset_1._resetStaticFiles)(_rootDataFake.pkg, {
@@ -106,11 +128,20 @@ function _runFixPackagesCore(row, options, cache, err) {
106
128
  shouldWriteReadme = true;
107
129
  }
108
130
  }
109
- // 複製靜態檔案到套件目錄 / Copy static files to package directory
110
- (0, static_file_1.copyStaticFiles)({
111
- cwd: row.location,
112
- file_map: (0, getRootCopyStaticFiles_1.getRootCopyStaticFilesAuto)(_rootDataFake),
113
- });
131
+ /**
132
+ * 複製靜態檔案到套件目錄
133
+ * Copy static files to package directory
134
+ *
135
+ * 僅在判定結果為 true 時才自動偵測並加入
136
+ * Only auto-detect and add when the result is true
137
+ */
138
+ if (_addStaticFiles) {
139
+ (0, static_file_1.copyStaticFiles)({
140
+ cwd: row.location,
141
+ file_map: (0, getRootCopyStaticFiles_1.getRootCopyStaticFilesAuto)(_rootDataFake),
142
+ ignoreFilesSnapshot,
143
+ });
144
+ }
114
145
  // 若 README.md 不存在或小於 1KB 則自動生成 / Auto-generate README.md if it doesn't exist or is smaller than 1KB
115
146
  if (shouldWriteReadme) {
116
147
  (0, writeReadme_1.writeReadme)({
@@ -174,7 +205,7 @@ function _runFixPackagesCore(row, options, cache, err) {
174
205
  // 非根套件:修復 preversion 腳本並移除 packageManager
175
206
  // Non-root package: fix preversion script and remove packageManager
176
207
  if (!((_c = pkg.data.scripts['_preversion']) === null || _c === void 0 ? void 0 : _c.length) && (0, dummy_1.isDummyEchoMaybeOrEmpty)(pkg.data.scripts.preversion)) {
177
- pkg.data.scripts.preversion = "yarn run test" /* EnumScriptsEntry.preversion */;
208
+ pkg.data.scripts.preversion = "pnpm run test" /* EnumScriptsEntry.preversion */;
178
209
  }
179
210
  // 從非根套件移除 packageManager 欄位
180
211
  // Remove packageManager field from non-root packages
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAgDA,4BAMC;AA2CD,kDA0JC;AAoBD,sDAoDC;AAYD,gEA0BC;;AAzWD;;;;;;;;GAQG;AACH,6CAAoH;AACpH,oDAA4E;AAC5E,qEAA4D;AAC5D,8DAA6D;AAC7D,+DAA2D;AAC3D,aAAa;AACb,gEAAgC;AAChC,uDAA+D;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AC,CAAC,GAAG,GAAG,GAAG,CAAC;YACZ,aAAa;YACb,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACb,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAA;QAEb,OAAO,aAAa;aAClB,KAAK,CAAC,CAAC,CAAC,EAAE;YACV,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;YACZ,aAAa;YACb,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACb,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,EAAE;YAEV,8BAA8B;YAC9B,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 { 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 { 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 { 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 ITSRequiredPick<IFillPkgHostedInfoOptions & INpmAutoFixAll, 'overwriteHostedGitInfo' | 'branch' | 'rootData' | 'hostedGitInfo' | 'resetStaticFiles'>\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. 複製靜態檔案到套件目錄 / Copy static files to package directory\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// 為套件建立假的根資料 / 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// 若選項啟用則重置靜態檔案 / 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// 複製靜態檔案到套件目錄 / Copy static files to package directory\n\tcopyStaticFiles({\n\t\tcwd: row.location,\n\t\tfile_map: getRootCopyStaticFilesAuto(_rootDataFake),\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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ChD,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,6 +1,31 @@
1
+ /**
2
+ * @yarn-tool/fix-all/lib/root
3
+ *
4
+ * 根目錄 package.json 的修復模組
5
+ * Fix module for root package.json
6
+ *
7
+ * 分別處理「單一套件根目錄」與「workspace 根目錄」兩種情境:
8
+ * 補齊 hosted git 資訊、workspace 專用腳本與必要的開發依賴
9
+ * Handles both "single package root" and "workspace root" cases:
10
+ * fills in hosted git info, workspace-specific scripts, and required dev dependencies
11
+ */
1
12
  import { ITSRequiredPick } from 'ts-type/lib/type/record';
2
13
  import { IFillPkgHostedInfoOptions } from '@yarn-tool/pkg-hosted-info';
3
14
  import { PackageJsonLoader } from 'npm-package-json-loader';
15
+ /**
16
+ * 修復單一套件根目錄的 package.json
17
+ * Fix package.json of a single package root
18
+ *
19
+ * 流程:載入 package.json → 填充 hosted git 資訊 → 排序 → 寫回磁碟。
20
+ * hostedGitInfo 未傳入時會嘗試從當前目錄自動推導,推導失敗則完全略過修復
21
+ * Flow: load package.json → fill hosted git info → sort → write back to disk.
22
+ * When hostedGitInfo is not given it is derived from the current directory; if
23
+ * derivation fails the fix is skipped entirely (nothing is written)
24
+ *
25
+ * @param options - 修復選項,需包含 rootData / hostedGitInfo / branch / overwriteHostedGitInfo / targetDir
26
+ * @param options.targetDir - 要修復的根目錄路徑 / Root directory to fix
27
+ * @returns 回傳執行過程中的各項資料,供呼叫端續用 / Returns runtime data for the caller to reuse
28
+ */
4
29
  export declare function _fixRoot(options: Required<IFillPkgHostedInfoOptions>): {
5
30
  root_file_package_json: string;
6
31
  root_pkg_json: PackageJsonLoader<import("@ts-type/package-dts").IPackageJson<unknown>>;
@@ -10,6 +35,24 @@ export declare function _fixRoot(options: Required<IFillPkgHostedInfoOptions>):
10
35
  branch: string;
11
36
  overwriteHostedGitInfo: boolean;
12
37
  };
38
+ /**
39
+ * 修復 workspace 根目錄(ws)的 package.json
40
+ * Fix package.json of the workspace root (ws)
41
+ *
42
+ * 在 _fixRoot 的基礎上額外:
43
+ * 1. 檢查 ws 目錄有效性(無效時拋錯)
44
+ * 2. 補上 workspace 根目錄專用的預設腳本(僅補缺失項,不覆寫既有腳本)
45
+ * 3. 確保共用開發依賴存在(缺漏時以 * 加入 devDependencies)
46
+ * 4. 同步 workspace 內各套件的版本號
47
+ * On top of _fixRoot it additionally:
48
+ * 1. Validates the ws directory (throws when invalid)
49
+ * 2. Adds default workspace-root scripts (only fills missing ones, never overwrites)
50
+ * 3. Ensures shared dev dependencies exist (adds them with * when missing)
51
+ * 4. Syncs versions across workspace packages
52
+ *
53
+ * @param options - 需包含 rootData / hostedGitInfo / branch / overwriteHostedGitInfo
54
+ * @returns 與 _fixRoot 相同的執行期資料 / Same runtime data as _fixRoot
55
+ */
13
56
  export declare function _fixWsRoot(options: ITSRequiredPick<IFillPkgHostedInfoOptions, 'hostedGitInfo' | 'rootData' | 'overwriteHostedGitInfo' | 'branch'>): {
14
57
  root_file_package_json: string;
15
58
  root_pkg_json: PackageJsonLoader<import("@ts-type/package-dts").IPackageJson<unknown>>;
package/lib/root/index.js CHANGED
@@ -11,10 +11,31 @@ const sort_package_json3_1 = require("sort-package-json3");
11
11
  const ws_root_scripts_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/ws-root-scripts");
12
12
  const dummy_1 = require("@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy");
13
13
  const pkg_deps_add_1 = require("@yarn-tool/pkg-deps-add");
14
+ /**
15
+ * 修復單一套件根目錄的 package.json
16
+ * Fix package.json of a single package root
17
+ *
18
+ * 流程:載入 package.json → 填充 hosted git 資訊 → 排序 → 寫回磁碟。
19
+ * hostedGitInfo 未傳入時會嘗試從當前目錄自動推導,推導失敗則完全略過修復
20
+ * Flow: load package.json → fill hosted git info → sort → write back to disk.
21
+ * When hostedGitInfo is not given it is derived from the current directory; if
22
+ * derivation fails the fix is skipped entirely (nothing is written)
23
+ *
24
+ * @param options - 修復選項,需包含 rootData / hostedGitInfo / branch / overwriteHostedGitInfo / targetDir
25
+ * @param options.targetDir - 要修復的根目錄路徑 / Root directory to fix
26
+ * @returns 回傳執行過程中的各項資料,供呼叫端續用 / Returns runtime data for the caller to reuse
27
+ */
14
28
  function _fixRoot(options) {
15
29
  let { rootData, branch, overwriteHostedGitInfo, hostedGitInfo, targetDir } = options;
16
30
  const root_file_package_json = (0, upath2_1.join)(targetDir, 'package.json');
17
31
  let root_pkg_json = new npm_package_json_loader_1.PackageJsonLoader(root_file_package_json);
32
+ /**
33
+ * 未提供 hostedGitInfo 時,嘗試從 git remote 惰性推導;
34
+ * 推導結果為 falsy 時下方 if 不成立,代表無法取得 git 資訊,此時不寫入任何變更
35
+ * Lazily derive hostedGitInfo from git remote when not provided;
36
+ * a falsy result makes the if below fail, meaning no git info is available
37
+ * and no changes are written
38
+ */
18
39
  hostedGitInfo !== null && hostedGitInfo !== void 0 ? hostedGitInfo : (hostedGitInfo = (0, pkg_git_info_1.npmHostedGitInfoLazy)());
19
40
  if (hostedGitInfo) {
20
41
  (0, pkg_hosted_info_1.fillPkgHostedInfo)(root_pkg_json.data, {
@@ -24,6 +45,10 @@ function _fixRoot(options) {
24
45
  branch,
25
46
  overwriteHostedGitInfo,
26
47
  });
48
+ /**
49
+ * 排序欄位以減少 git diff 的雜訊
50
+ * Sort fields to reduce noise in git diff
51
+ */
27
52
  root_pkg_json.data = (0, sort_package_json3_1.sortPackageJson)(root_pkg_json.data);
28
53
  root_pkg_json.write();
29
54
  }
@@ -37,8 +62,32 @@ function _fixRoot(options) {
37
62
  overwriteHostedGitInfo,
38
63
  };
39
64
  }
65
+ /**
66
+ * 修復 workspace 根目錄(ws)的 package.json
67
+ * Fix package.json of the workspace root (ws)
68
+ *
69
+ * 在 _fixRoot 的基礎上額外:
70
+ * 1. 檢查 ws 目錄有效性(無效時拋錯)
71
+ * 2. 補上 workspace 根目錄專用的預設腳本(僅補缺失項,不覆寫既有腳本)
72
+ * 3. 確保共用開發依賴存在(缺漏時以 * 加入 devDependencies)
73
+ * 4. 同步 workspace 內各套件的版本號
74
+ * On top of _fixRoot it additionally:
75
+ * 1. Validates the ws directory (throws when invalid)
76
+ * 2. Adds default workspace-root scripts (only fills missing ones, never overwrites)
77
+ * 3. Ensures shared dev dependencies exist (adds them with * when missing)
78
+ * 4. Syncs versions across workspace packages
79
+ *
80
+ * @param options - 需包含 rootData / hostedGitInfo / branch / overwriteHostedGitInfo
81
+ * @returns 與 _fixRoot 相同的執行期資料 / Same runtime data as _fixRoot
82
+ */
40
83
  function _fixWsRoot(options) {
41
84
  var _a;
85
+ /**
86
+ * ws 為空代表這不是有效的 workspace 結構,
87
+ * 與其在後續流程產生難以理解的錯誤,不如在此明確中斷
88
+ * An empty ws means this is not a valid workspace; failing fast here
89
+ * is clearer than an obscure error later in the pipeline
90
+ */
42
91
  if (!((_a = options.rootData.ws) === null || _a === void 0 ? void 0 : _a.length)) {
43
92
  throw new Error(`Invalid workspaces`);
44
93
  }
@@ -46,11 +95,26 @@ function _fixWsRoot(options) {
46
95
  ...options,
47
96
  targetDir: options.rootData.ws,
48
97
  });
98
+ /**
99
+ * 只在腳本不存在(??=)時才填入預設值,
100
+ * 避免覆蓋使用者自訂的同名腳本
101
+ * Fill defaults only when the script is absent (??=),
102
+ * so user-defined scripts with the same name are preserved
103
+ */
49
104
  Object.entries((0, dummy_1.fillDummyScripts)((0, ws_root_scripts_1.defaultWorkspaceRootScripts)())).forEach(([key, value]) => {
50
105
  var _a;
51
106
  var _b;
52
107
  (_a = (_b = runtime.root_pkg_json.data.scripts)[key]) !== null && _a !== void 0 ? _a : (_b[key] = value);
53
108
  });
109
+ /**
110
+ * 這些是 workspace 根目錄常見的共用開發依賴,
111
+ * 逐一檢查 devDependencies / dependencies,皆不存在才補上,
112
+ * 使用 '*' 而非固定版本,交由 workspace 內統一控管版本
113
+ * These are commonly shared dev dependencies at the workspace root;
114
+ * each is checked against devDependencies / dependencies and only added
115
+ * when absent. Uses '*' instead of a pinned version so the workspace
116
+ * controls versions centrally
117
+ */
54
118
  [
55
119
  '@yarn-tool/ws-find-up-paths',
56
120
  '@types/node',
@@ -68,8 +132,18 @@ function _fixWsRoot(options) {
68
132
  runtime.root_pkg_json.data.devDependencies[name] = '*';
69
133
  }
70
134
  });
135
+ /**
136
+ * 任何欄位增補後都需要重新排序並寫回
137
+ * Re-sort and write back after any field additions
138
+ */
71
139
  runtime.root_pkg_json.data = (0, sort_package_json3_1.sortPackageJson)(runtime.root_pkg_json.data);
72
140
  runtime.root_pkg_json.write();
141
+ /**
142
+ * 同步 workspace 內各套件的依賴版本號並儲存,
143
+ * 確保內部互相依賴的版本一致
144
+ * Sync dependency version numbers across workspace packages and save,
145
+ * keeping internal cross-dependencies consistent
146
+ */
73
147
  let wss = new ws_scope_1.WorkspacesScope(runtime.rootData.ws);
74
148
  wss.syncValue();
75
149
  wss.save();
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAWA,4BAkCC;AAED,gCA4CC;AA1FD,gEAA0F;AAC1F,mCAA8B;AAC9B,0DAA+D;AAC/D,qEAA4D;AAC5D,kDAAsD;AACtD,2DAAqD;AACrD,kGAA2G;AAC3G,8EAAsF;AACtF,0DAAsE;AAEtE,SAAgB,QAAQ,CAAC,OAA4C;IAEpE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,sBAAsB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAErF,MAAM,sBAAsB,GAAG,IAAA,aAAI,EAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAE/D,IAAI,aAAa,GAAG,IAAI,2CAAiB,CAAC,sBAAsB,CAAC,CAAC;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Aa,CAAC,IAAI,EAAE;YACtE,iBAAiB;YACjB,cAAc;SACd,EAAE,IAAI,CAAC,CAAC;QAET,IAAI,CAAC,MAAM,CAAC,OAAO,EACnB,CAAC;YACA,YAAA,OAAO,CAAC,aAAa,CAAC,IAAI,EAAC,eAAe,uCAAf,eAAe,GAAK,EAAE,EAAC;YAClD,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC;QACxD,CAAC;IACF,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,aAAa,CAAC,IAAI,GAAG,IAAA,oCAAe,EAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IAEzE,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IAE9B,IAAI,GAAG,GAAG,IAAI,0BAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnD,GAAG,CAAC,SAAS,EAAE,CAAC;IAChB,GAAG,CAAC,IAAI,EAAE,CAAC;IAEX,OAAO,OAAO,CAAA;AACf,CAAC","sourcesContent":["import { ITSRequiredPick } from 'ts-type/lib/type/record';\nimport { fillPkgHostedInfo, IFillPkgHostedInfoOptions } from '@yarn-tool/pkg-hosted-info';\nimport { join } from 'upath2';\nimport { npmHostedGitInfoLazy } from '@yarn-tool/pkg-git-info';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\nimport { WorkspacesScope } from '@yarn-tool/ws-scope';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { defaultWorkspaceRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/ws-root-scripts';\nimport { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy';\nimport { _checkDependenciesExistsAll } from '@yarn-tool/pkg-deps-add';\n\nexport function _fixRoot(options: Required<IFillPkgHostedInfoOptions>)\n{\n\tlet { rootData, branch, overwriteHostedGitInfo, hostedGitInfo, targetDir } = options;\n\n\tconst root_file_package_json = join(targetDir, 'package.json');\n\n\tlet root_pkg_json = new PackageJsonLoader(root_file_package_json);\n\n\thostedGitInfo ??= npmHostedGitInfoLazy();\n\n\tif (hostedGitInfo)\n\t{\n\t\tfillPkgHostedInfo(root_pkg_json.data, {\n\t\t\ttargetDir,\n\t\t\trootData,\n\t\t\thostedGitInfo,\n\t\t\tbranch,\n\t\t\toverwriteHostedGitInfo,\n\t\t});\n\n\t\troot_pkg_json.data = sortPackageJson(root_pkg_json.data);\n\n\t\troot_pkg_json.write();\n\t}\n\n\treturn {\n\t\troot_file_package_json,\n\t\troot_pkg_json,\n\t\ttargetDir,\n\t\trootData,\n\t\thostedGitInfo,\n\t\tbranch,\n\t\toverwriteHostedGitInfo,\n\t}\n}\n\nexport function _fixWsRoot(options: ITSRequiredPick<IFillPkgHostedInfoOptions, 'hostedGitInfo' | 'rootData' | 'overwriteHostedGitInfo' | 'branch'>)\n{\n\tif (!options.rootData.ws?.length)\n\t{\n\t\tthrow new Error(`Invalid workspaces`)\n\t}\n\n\tlet runtime = _fixRoot({\n\t\t...options,\n\t\ttargetDir: options.rootData.ws,\n\t});\n\n\tObject.entries(fillDummyScripts(defaultWorkspaceRootScripts())).forEach(([key, value]) =>\n\t{\n\t\truntime.root_pkg_json.data.scripts[key] ??= value;\n\t});\n\n\t[\n\t\t'@yarn-tool/ws-find-up-paths',\n\t\t'@types/node',\n\t\t'@bluelovers/tsconfig',\n\t\t'@yarn-tool/require-resolve',\n\t].forEach(name => {\n\t\tconst _check = _checkDependenciesExistsAll(runtime.root_pkg_json.data, [\n\t\t\t'devDependencies',\n\t\t\t'dependencies',\n\t\t], name);\n\n\t\tif (!_check._exists)\n\t\t{\n\t\t\truntime.root_pkg_json.data.devDependencies ??= {};\n\t\t\truntime.root_pkg_json.data.devDependencies[name] = '*';\n\t\t}\n\t});\n\n\truntime.root_pkg_json.data = sortPackageJson(runtime.root_pkg_json.data);\n\n\truntime.root_pkg_json.write();\n\n\tlet wss = new WorkspacesScope(runtime.rootData.ws);\n\twss.syncValue();\n\twss.save();\n\n\treturn runtime\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AAoCA,4BA6CC;AAoBD,gCA2EC;AApKD,gEAA0F;AAC1F,mCAA8B;AAC9B,0DAA+D;AAC/D,qEAA4D;AAC5D,kDAAsD;AACtD,2DAAqD;AACrD,kGAA2G;AAC3G,8EAAsF;AACtF,0DAAsE;AAEtE;;;;;;;;;;;;;GAaG;AACH,SAAgB,QAAQ,CAAC,OAA4C;IAEpE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,sBAAsB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAErF,MAAM,sBAAsB,GAAG,IAAA,aAAI,EAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAE/D,IAAI,aAAa,GAAG,IAAI,2CAAiB,CAAC,sBAAsB,CAAC,CAAC;IAElE;;;;;;OAMG;IACH,aAAa,aAAb,aAAa,cAAb,aAAa,IAAb,aAAa,GAAK,IAAA,mCAAoB,GAAE,EAAC;IAEzC,IAAI,aAAa,EACjB,CAAC;QACA,IAAA,mCAAiB,EAAC,aAAa,CAAC,IAAI,EAAE;YACrC,SAAS;YACT,QAAQ;YACR,aAAa;YACb,MAAM;YACN,sBAAsB;SACtB,CAAC,CAAC;QAEH;;;WAGG;QACH,aAAa,CAAC,IAAI,GAAG,IAAA,oCAAe,EAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAEzD,aAAa,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,OAAO;QACN,sBAAsB;QACtB,aAAa;QACb,SAAS;QACT,QAAQ;QACR,aAAa;QACb,MAAM;QACN,sBAAsB;KACtB,CAAA;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,UAAU,CAAC,OAAuH;;IAEjJ;;;;;OAKG;IACH,IAAI,CAAC,CAAA,MAAA,OAAO,CAAC,QAAQ,CAAC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I,0BAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACnD,GAAG,CAAC,SAAS,EAAE,CAAC;IAChB,GAAG,CAAC,IAAI,EAAE,CAAC;IAEX,OAAO,OAAO,CAAA;AACf,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/root\n *\n * 根目錄 package.json 的修復模組\n * Fix module for root package.json\n *\n * 分別處理「單一套件根目錄」與「workspace 根目錄」兩種情境:\n * 補齊 hosted git 資訊、workspace 專用腳本與必要的開發依賴\n * Handles both \"single package root\" and \"workspace root\" cases:\n * fills in hosted git info, workspace-specific scripts, and required dev dependencies\n */\nimport { ITSRequiredPick } from 'ts-type/lib/type/record';\nimport { fillPkgHostedInfo, IFillPkgHostedInfoOptions } from '@yarn-tool/pkg-hosted-info';\nimport { join } from 'upath2';\nimport { npmHostedGitInfoLazy } from '@yarn-tool/pkg-git-info';\nimport { PackageJsonLoader } from 'npm-package-json-loader';\nimport { WorkspacesScope } from '@yarn-tool/ws-scope';\nimport { sortPackageJson } from 'sort-package-json3';\nimport { defaultWorkspaceRootScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/ws-root-scripts';\nimport { fillDummyScripts } from '@yarn-tool/pkg-entry-util/lib/preset/scripts/dummy';\nimport { _checkDependenciesExistsAll } from '@yarn-tool/pkg-deps-add';\n\n/**\n * 修復單一套件根目錄的 package.json\n * Fix package.json of a single package root\n *\n * 流程:載入 package.json → 填充 hosted git 資訊 → 排序 → 寫回磁碟。\n * hostedGitInfo 未傳入時會嘗試從當前目錄自動推導,推導失敗則完全略過修復\n * Flow: load package.json → fill hosted git info → sort → write back to disk.\n * When hostedGitInfo is not given it is derived from the current directory; if\n * derivation fails the fix is skipped entirely (nothing is written)\n *\n * @param options - 修復選項,需包含 rootData / hostedGitInfo / branch / overwriteHostedGitInfo / targetDir\n * @param options.targetDir - 要修復的根目錄路徑 / Root directory to fix\n * @returns 回傳執行過程中的各項資料,供呼叫端續用 / Returns runtime data for the caller to reuse\n */\nexport function _fixRoot(options: Required<IFillPkgHostedInfoOptions>)\n{\n\tlet { rootData, branch, overwriteHostedGitInfo, hostedGitInfo, targetDir } = options;\n\n\tconst root_file_package_json = join(targetDir, 'package.json');\n\n\tlet root_pkg_json = new PackageJsonLoader(root_file_package_json);\n\n\t/**\n\t * 未提供 hostedGitInfo 時,嘗試從 git remote 惰性推導;\n\t * 推導結果為 falsy 時下方 if 不成立,代表無法取得 git 資訊,此時不寫入任何變更\n\t * Lazily derive hostedGitInfo from git remote when not provided;\n\t * a falsy result makes the if below fail, meaning no git info is available\n\t * and no changes are written\n\t */\n\thostedGitInfo ??= npmHostedGitInfoLazy();\n\n\tif (hostedGitInfo)\n\t{\n\t\tfillPkgHostedInfo(root_pkg_json.data, {\n\t\t\ttargetDir,\n\t\t\trootData,\n\t\t\thostedGitInfo,\n\t\t\tbranch,\n\t\t\toverwriteHostedGitInfo,\n\t\t});\n\n\t\t/**\n\t\t * 排序欄位以減少 git diff 的雜訊\n\t\t * Sort fields to reduce noise in git diff\n\t\t */\n\t\troot_pkg_json.data = sortPackageJson(root_pkg_json.data);\n\n\t\troot_pkg_json.write();\n\t}\n\n\treturn {\n\t\troot_file_package_json,\n\t\troot_pkg_json,\n\t\ttargetDir,\n\t\trootData,\n\t\thostedGitInfo,\n\t\tbranch,\n\t\toverwriteHostedGitInfo,\n\t}\n}\n\n/**\n * 修復 workspace 根目錄(ws)的 package.json\n * Fix package.json of the workspace root (ws)\n *\n * 在 _fixRoot 的基礎上額外:\n * 1. 檢查 ws 目錄有效性(無效時拋錯)\n * 2. 補上 workspace 根目錄專用的預設腳本(僅補缺失項,不覆寫既有腳本)\n * 3. 確保共用開發依賴存在(缺漏時以 * 加入 devDependencies)\n * 4. 同步 workspace 內各套件的版本號\n * On top of _fixRoot it additionally:\n * 1. Validates the ws directory (throws when invalid)\n * 2. Adds default workspace-root scripts (only fills missing ones, never overwrites)\n * 3. Ensures shared dev dependencies exist (adds them with * when missing)\n * 4. Syncs versions across workspace packages\n *\n * @param options - 需包含 rootData / hostedGitInfo / branch / overwriteHostedGitInfo\n * @returns 與 _fixRoot 相同的執行期資料 / Same runtime data as _fixRoot\n */\nexport function _fixWsRoot(options: ITSRequiredPick<IFillPkgHostedInfoOptions, 'hostedGitInfo' | 'rootData' | 'overwriteHostedGitInfo' | 'branch'>)\n{\n\t/**\n\t * ws 為空代表這不是有效的 workspace 結構,\n\t * 與其在後續流程產生難以理解的錯誤,不如在此明確中斷\n\t * An empty ws means this is not a valid workspace; failing fast here\n\t * is clearer than an obscure error later in the pipeline\n\t */\n\tif (!options.rootData.ws?.length)\n\t{\n\t\tthrow new Error(`Invalid workspaces`)\n\t}\n\n\tlet runtime = _fixRoot({\n\t\t...options,\n\t\ttargetDir: options.rootData.ws,\n\t});\n\n\t/**\n\t * 只在腳本不存在(??=)時才填入預設值,\n\t * 避免覆蓋使用者自訂的同名腳本\n\t * Fill defaults only when the script is absent (??=),\n\t * so user-defined scripts with the same name are preserved\n\t */\n\tObject.entries(fillDummyScripts(defaultWorkspaceRootScripts())).forEach(([key, value]) =>\n\t{\n\t\truntime.root_pkg_json.data.scripts[key] ??= value;\n\t});\n\n\t/**\n\t * 這些是 workspace 根目錄常見的共用開發依賴,\n\t * 逐一檢查 devDependencies / dependencies,皆不存在才補上,\n\t * 使用 '*' 而非固定版本,交由 workspace 內統一控管版本\n\t * These are commonly shared dev dependencies at the workspace root;\n\t * each is checked against devDependencies / dependencies and only added\n\t * when absent. Uses '*' instead of a pinned version so the workspace\n\t * controls versions centrally\n\t */\n\t[\n\t\t'@yarn-tool/ws-find-up-paths',\n\t\t'@types/node',\n\t\t'@bluelovers/tsconfig',\n\t\t'@yarn-tool/require-resolve',\n\t].forEach(name => {\n\t\tconst _check = _checkDependenciesExistsAll(runtime.root_pkg_json.data, [\n\t\t\t'devDependencies',\n\t\t\t'dependencies',\n\t\t], name);\n\n\t\tif (!_check._exists)\n\t\t{\n\t\t\truntime.root_pkg_json.data.devDependencies ??= {};\n\t\t\truntime.root_pkg_json.data.devDependencies[name] = '*';\n\t\t}\n\t});\n\n\t/**\n\t * 任何欄位增補後都需要重新排序並寫回\n\t * Re-sort and write back after any field additions\n\t */\n\truntime.root_pkg_json.data = sortPackageJson(runtime.root_pkg_json.data);\n\n\truntime.root_pkg_json.write();\n\n\t/**\n\t * 同步 workspace 內各套件的依賴版本號並儲存,\n\t * 確保內部互相依賴的版本一致\n\t * Sync dependency version numbers across workspace packages and save,\n\t * keeping internal cross-dependencies consistent\n\t */\n\tlet wss = new WorkspacesScope(runtime.rootData.ws);\n\twss.syncValue();\n\twss.save();\n\n\treturn runtime\n}\n"]}
@@ -1,2 +1,15 @@
1
1
  import progressEstimator from 'progress-estimator';
2
+ /**
3
+ * 建立進度估計器
4
+ * Create a progress estimator
5
+ *
6
+ * 快取路徑 (Cache path) 放在套件自己的 node_modules 快取目錄下,
7
+ * 避免污染專案原始碼;目錄可能不存在,故先 ensureDirSync 建立
8
+ * The cache path lives under the package's own node_modules cache directory
9
+ * to avoid polluting project sources; the directory may not exist, so it is
10
+ * created up front via ensureDirSync
11
+ *
12
+ * @param root - 專案根目錄,用於推導快取路徑 / Project root, used to derive the cache path
13
+ * @returns 已設定儲存位置的 progress-estimator 實例 / A progress-estimator instance with storage configured
14
+ */
2
15
  export declare function createProgressEstimator(root: string): progressEstimator.ProgressEstimator;
@@ -2,11 +2,34 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createProgressEstimator = createProgressEstimator;
4
4
  const tslib_1 = require("tslib");
5
+ /**
6
+ * @yarn-tool/fix-all/lib/util/cli-progress
7
+ *
8
+ * 進度顯示工具模組
9
+ * CLI progress display module
10
+ *
11
+ * 建立 progress-estimator 實例,讓逐套件修復時能在終端顯示進度與預估時間
12
+ * Creates a progress-estimator instance so per-package fixes can show
13
+ * progress and a time estimate in the terminal
14
+ */
5
15
  const fs_extra_1 = require("fs-extra");
6
16
  const path_1 = require("path");
7
17
  // @ts-ignore
8
18
  const progress_estimator_1 = tslib_1.__importDefault(require("progress-estimator"));
9
19
  const findPkgModuleCachePath_1 = require("cache-path/lib/finder/findPkgModuleCachePath");
20
+ /**
21
+ * 建立進度估計器
22
+ * Create a progress estimator
23
+ *
24
+ * 快取路徑 (Cache path) 放在套件自己的 node_modules 快取目錄下,
25
+ * 避免污染專案原始碼;目錄可能不存在,故先 ensureDirSync 建立
26
+ * The cache path lives under the package's own node_modules cache directory
27
+ * to avoid polluting project sources; the directory may not exist, so it is
28
+ * created up front via ensureDirSync
29
+ *
30
+ * @param root - 專案根目錄,用於推導快取路徑 / Project root, used to derive the cache path
31
+ * @returns 已設定儲存位置的 progress-estimator 實例 / A progress-estimator instance with storage configured
32
+ */
10
33
  function createProgressEstimator(root) {
11
34
  const storagePath = (0, path_1.join)((0, findPkgModuleCachePath_1.findPkgModuleCachePathCore)(root), '.progress-estimator');
12
35
  (0, fs_extra_1.ensureDirSync)(storagePath);
@@ -1 +1 @@
1
- {"version":3,"file":"cli-progress.js","sourceRoot":"","sources":["cli-progress.ts"],"names":[],"mappings":";;AAMA,0DAQC;;AAdD,uCAAyC;AACzC,+BAA4B;AAC5B,aAAa;AACb,oFAAmD;AACnD,yFAAiH;AAEjH,SAAgB,uBAAuB,CAAC,IAAY;IAEnD,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,IAAA,mDAA0B,EAAC,IAAI,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAClF,IAAA,wBAAa,EAAC,WAAW,CAAC,CAAC;IAC3B,OAAO,IAAA,4BAAiB,EAAC;QACxB,2FAA2F;QAC3F,WAAW;KACX,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { ensureDirSync } from 'fs-extra';\nimport { join } from 'path';\n// @ts-ignore\nimport progressEstimator from 'progress-estimator';\nimport { findPkgModuleCachePathCore, findPkgModulePathCore } from 'cache-path/lib/finder/findPkgModuleCachePath';\n\nexport function createProgressEstimator(root: string)\n{\n\tconst storagePath = join(findPkgModuleCachePathCore(root), '.progress-estimator');\n\tensureDirSync(storagePath);\n\treturn progressEstimator({\n\t\t// All configuration keys are optional, but it's recommended to specify a storage location.\n\t\tstoragePath,\n\t});\n}\n"]}
1
+ {"version":3,"file":"cli-progress.js","sourceRoot":"","sources":["cli-progress.ts"],"names":[],"mappings":";;AA6BA,0DAQC;;AArCD;;;;;;;;;GASG;AACH,uCAAyC;AACzC,+BAA4B;AAC5B,aAAa;AACb,oFAAmD;AACnD,yFAAiH;AAEjH;;;;;;;;;;;;GAYG;AACH,SAAgB,uBAAuB,CAAC,IAAY;IAEnD,MAAM,WAAW,GAAG,IAAA,WAAI,EAAC,IAAA,mDAA0B,EAAC,IAAI,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAClF,IAAA,wBAAa,EAAC,WAAW,CAAC,CAAC;IAC3B,OAAO,IAAA,4BAAiB,EAAC;QACxB,2FAA2F;QAC3F,WAAW;KACX,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/util/cli-progress\n *\n * 進度顯示工具模組\n * CLI progress display module\n *\n * 建立 progress-estimator 實例,讓逐套件修復時能在終端顯示進度與預估時間\n * Creates a progress-estimator instance so per-package fixes can show\n * progress and a time estimate in the terminal\n */\nimport { ensureDirSync } from 'fs-extra';\nimport { join } from 'path';\n// @ts-ignore\nimport progressEstimator from 'progress-estimator';\nimport { findPkgModuleCachePathCore, findPkgModulePathCore } from 'cache-path/lib/finder/findPkgModuleCachePath';\n\n/**\n * 建立進度估計器\n * Create a progress estimator\n *\n * 快取路徑 (Cache path) 放在套件自己的 node_modules 快取目錄下,\n * 避免污染專案原始碼;目錄可能不存在,故先 ensureDirSync 建立\n * The cache path lives under the package's own node_modules cache directory\n * to avoid polluting project sources; the directory may not exist, so it is\n * created up front via ensureDirSync\n *\n * @param root - 專案根目錄,用於推導快取路徑 / Project root, used to derive the cache path\n * @returns 已設定儲存位置的 progress-estimator 實例 / A progress-estimator instance with storage configured\n */\nexport function createProgressEstimator(root: string)\n{\n\tconst storagePath = join(findPkgModuleCachePathCore(root), '.progress-estimator');\n\tensureDirSync(storagePath);\n\treturn progressEstimator({\n\t\t// All configuration keys are optional, but it's recommended to specify a storage location.\n\t\tstoragePath,\n\t});\n}\n"]}
@@ -1,9 +1,39 @@
1
+ /**
2
+ * @yarn-tool/fix-all/lib/util/yargs-setting
3
+ *
4
+ * yargs 選項設定模組
5
+ * yargs options setup module
6
+ *
7
+ * 將 npmAutoFixAll 的選項註冊到 yargs,
8
+ * 讓 CLI 與程式化 API 共用同一組選項名稱與別名
9
+ * Registers npmAutoFixAll options into yargs so that the CLI and the
10
+ * programmatic API share the same option names and aliases
11
+ */
1
12
  import { Argv } from 'yargs';
2
13
  import { IYargsSync } from '@yarn-tool/types';
14
+ /**
15
+ * 註冊自動修復相關的 yargs 選項
16
+ * Register yargs options related to auto-fix
17
+ *
18
+ * 選項定義與 INpmAutoFixAll 介面一一對應;別名(-O / -S)是為了讓 CLI
19
+ * 操作更簡短,同時保留完整名稱以利閱讀指令歷程
20
+ * Option definitions map one-to-one with the INpmAutoFixAll interface;
21
+ * aliases (-O / -S) keep the CLI short while full names remain for
22
+ * readable command history
23
+ *
24
+ * @param yargs - 要擴充的 yargs 實例 / The yargs instance to extend
25
+ * @returns 帶有選項定義的 yargs 實例(以 IYargsSync 型別回傳)/ The yargs instance with options defined (typed as IYargsSync)
26
+ */
3
27
  export declare function setupToYargs<T>(yargs: Argv<T>): IYargsSync<Argv<T & {
4
28
  overwriteHostedGitInfo: boolean;
5
29
  } & {
6
30
  branch: string;
7
31
  } & {
8
32
  resetStaticFiles: boolean;
33
+ } & {
34
+ addStaticFiles: boolean;
35
+ } & {
36
+ noStaticFiles: boolean;
37
+ } & {
38
+ noMergeIgnoreFiles: boolean;
9
39
  }>>;
@@ -1,19 +1,53 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupToYargs = setupToYargs;
4
+ /**
5
+ * 註冊自動修復相關的 yargs 選項
6
+ * Register yargs options related to auto-fix
7
+ *
8
+ * 選項定義與 INpmAutoFixAll 介面一一對應;別名(-O / -S)是為了讓 CLI
9
+ * 操作更簡短,同時保留完整名稱以利閱讀指令歷程
10
+ * Option definitions map one-to-one with the INpmAutoFixAll interface;
11
+ * aliases (-O / -S) keep the CLI short while full names remain for
12
+ * readable command history
13
+ *
14
+ * @param yargs - 要擴充的 yargs 實例 / The yargs instance to extend
15
+ * @returns 帶有選項定義的 yargs 實例(以 IYargsSync 型別回傳)/ The yargs instance with options defined (typed as IYargsSync)
16
+ */
4
17
  function setupToYargs(yargs) {
5
18
  const _return = yargs
6
19
  .option('overwriteHostedGitInfo', {
7
20
  boolean: true,
8
21
  alias: ['O', 'overwrite'],
22
+ describe: 'Overwrite hosted git info (homepage / repository / bugs)',
9
23
  })
10
24
  .option('branch', {
11
25
  string: true,
26
+ describe: 'Git branch name',
12
27
  })
13
28
  .option('resetStaticFiles', {
14
29
  boolean: true,
15
30
  alias: ['S'],
31
+ describe: 'Delete existing static files, copy them again, and force the static file add',
32
+ })
33
+ .option('addStaticFiles', {
34
+ boolean: true,
35
+ describe: 'Auto-detect and add static files (disabled by default)',
36
+ })
37
+ .option('noStaticFiles', {
38
+ boolean: true,
39
+ describe: 'Skip adding static files, taking precedence over addStaticFiles; resetStaticFiles still forces the add',
40
+ })
41
+ .option('noMergeIgnoreFiles', {
42
+ boolean: true,
43
+ describe: 'Disable auto-merging ignore files; when unset, existing rules are captured before the reset and merged back after the copy',
16
44
  });
45
+ /**
46
+ * 以雙重斷言繞過 yargs 泛型推導的限制,
47
+ * 取得可精確推導選項型別的 IYargsSync 包裝
48
+ * Double assertion bypasses yargs' generic inference limitation to
49
+ * obtain the IYargsSync wrapper with precise option type inference
50
+ */
17
51
  return _return;
18
52
  }
19
53
  //# sourceMappingURL=yargs-setting.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"yargs-setting.js","sourceRoot":"","sources":["yargs-setting.ts"],"names":[],"mappings":";;AAGA,oCAiBC;AAjBD,SAAgB,YAAY,CAAI,KAAc;IAE7C,MAAM,OAAO,GAAG,KAAK;SACnB,MAAM,CAAC,wBAAwB,EAAE;QACjC,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC;KACzB,CAAC;SACD,MAAM,CAAC,QAAQ,EAAE;QACjB,MAAM,EAAE,IAAI;KACZ,CAAC;SACD,MAAM,CAAC,kBAAkB,EAAE;QAC3B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,CAAC,GAAG,CAAC;KACZ,CAAC,CACF;IAED,OAAO,OAA4C,CAAA;AACpD,CAAC","sourcesContent":["import { Argv } from 'yargs';\nimport { IYargsSync, IYargsUnPackArgv } from '@yarn-tool/types';\n\nexport function setupToYargs<T>(yargs: Argv<T>)\n{\n\tconst _return = yargs\n\t\t.option('overwriteHostedGitInfo', {\n\t\t\tboolean: true,\n\t\t\talias: ['O', 'overwrite'],\n\t\t})\n\t\t.option('branch', {\n\t\t\tstring: true,\n\t\t})\n\t\t.option('resetStaticFiles', {\n\t\t\tboolean: true,\n\t\t\talias: ['S'],\n\t\t})\n\t;\n\n\treturn _return as any as IYargsSync<typeof _return>\n}\n"]}
1
+ {"version":3,"file":"yargs-setting.js","sourceRoot":"","sources":["yargs-setting.ts"],"names":[],"mappings":";;AA2BA,oCAsCC;AAnDD;;;;;;;;;;;;GAYG;AACH,SAAgB,YAAY,CAAI,KAAc;IAE7C,MAAM,OAAO,GAAG,KAAK;SACnB,MAAM,CAAC,wBAAwB,EAAE;QACjC,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,CAAC,GAAG,EAAE,WAAW,CAAC;QACzB,QAAQ,EAAE,0DAA0D;KACpE,CAAC;SACD,MAAM,CAAC,QAAQ,EAAE;QACjB,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,iBAAiB;KAC3B,CAAC;SACD,MAAM,CAAC,kBAAkB,EAAE;QAC3B,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,CAAC,GAAG,CAAC;QACZ,QAAQ,EAAE,8EAA8E;KACxF,CAAC;SACD,MAAM,CAAC,gBAAgB,EAAE;QACzB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,wDAAwD;KAClE,CAAC;SACD,MAAM,CAAC,eAAe,EAAE;QACxB,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,wGAAwG;KAClH,CAAC;SACD,MAAM,CAAC,oBAAoB,EAAE;QAC7B,OAAO,EAAE,IAAI;QACb,QAAQ,EAAE,4HAA4H;KACtI,CAAC,CACF;IAED;;;;;OAKG;IACH,OAAO,OAA4C,CAAA;AACpD,CAAC","sourcesContent":["/**\n * @yarn-tool/fix-all/lib/util/yargs-setting\n *\n * yargs 選項設定模組\n * yargs options setup module\n *\n * 將 npmAutoFixAll 的選項註冊到 yargs,\n * 讓 CLI 與程式化 API 共用同一組選項名稱與別名\n * Registers npmAutoFixAll options into yargs so that the CLI and the\n * programmatic API share the same option names and aliases\n */\nimport { Argv } from 'yargs';\nimport { IYargsSync, IYargsUnPackArgv } from '@yarn-tool/types';\n\n/**\n * 註冊自動修復相關的 yargs 選項\n * Register yargs options related to auto-fix\n *\n * 選項定義與 INpmAutoFixAll 介面一一對應;別名(-O / -S)是為了讓 CLI\n * 操作更簡短,同時保留完整名稱以利閱讀指令歷程\n * Option definitions map one-to-one with the INpmAutoFixAll interface;\n * aliases (-O / -S) keep the CLI short while full names remain for\n * readable command history\n *\n * @param yargs - 要擴充的 yargs 實例 / The yargs instance to extend\n * @returns 帶有選項定義的 yargs 實例(以 IYargsSync 型別回傳)/ The yargs instance with options defined (typed as IYargsSync)\n */\nexport function setupToYargs<T>(yargs: Argv<T>)\n{\n\tconst _return = yargs\n\t\t.option('overwriteHostedGitInfo', {\n\t\t\tboolean: true,\n\t\t\talias: ['O', 'overwrite'],\n\t\t\tdescribe: 'Overwrite hosted git info (homepage / repository / bugs)',\n\t\t})\n\t\t.option('branch', {\n\t\t\tstring: true,\n\t\t\tdescribe: 'Git branch name',\n\t\t})\n\t\t.option('resetStaticFiles', {\n\t\t\tboolean: true,\n\t\t\talias: ['S'],\n\t\t\tdescribe: 'Delete existing static files, copy them again, and force the static file add',\n\t\t})\n\t\t.option('addStaticFiles', {\n\t\t\tboolean: true,\n\t\t\tdescribe: 'Auto-detect and add static files (disabled by default)',\n\t\t})\n\t\t.option('noStaticFiles', {\n\t\t\tboolean: true,\n\t\t\tdescribe: 'Skip adding static files, taking precedence over addStaticFiles; resetStaticFiles still forces the add',\n\t\t})\n\t\t.option('noMergeIgnoreFiles', {\n\t\t\tboolean: true,\n\t\t\tdescribe: 'Disable auto-merging ignore files; when unset, existing rules are captured before the reset and merged back after the copy',\n\t\t})\n\t;\n\n\t/**\n\t * 以雙重斷言繞過 yargs 泛型推導的限制,\n\t * 取得可精確推導選項型別的 IYargsSync 包裝\n\t * Double assertion bypasses yargs' generic inference limitation to\n\t * obtain the IYargsSync wrapper with precise option type inference\n\t */\n\treturn _return as any as IYargsSync<typeof _return>\n}\n"]}