@yarn-tool/normalize-deps-value 2.0.9 → 2.0.10
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 +32 -0
- package/README.md +12 -0
- package/index.d.ts +5 -0
- package/index.js +55 -20
- package/index.js.map +1 -1
- package/package.json +9 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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
|
+
## [2.0.10](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/normalize-deps-value@2.0.9...@yarn-tool/normalize-deps-value@2.0.10) (2026-10-12)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### 📚 Documentation
|
|
11
|
+
|
|
12
|
+
* add jsdoc ([9cb9b13](https://github.com/bluelovers/ws-yarn-workspaces/commit/9cb9b13eda8c357221ad1b754458aa9916eada22))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 🚨 Tests
|
|
16
|
+
|
|
17
|
+
* **snap:** update snapshots ([c9945a5](https://github.com/bluelovers/ws-yarn-workspaces/commit/c9945a5b9cd723d38ded2a69b83e2e83ecc3b524))
|
|
18
|
+
* **test:** 將測試框架從 jest 遷移至 node:test ([3af9774](https://github.com/bluelovers/ws-yarn-workspaces/commit/3af9774964abc48083ec60b2021c1cec08874803))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 🛠 Build System
|
|
22
|
+
|
|
23
|
+
* update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
|
|
24
|
+
* **deps:** 更新測試腳本與依賴以支援 node:test ([f9c71c7](https://github.com/bluelovers/ws-yarn-workspaces/commit/f9c71c795c792c5c7ed9d613ce7e9c3c726c39d5))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### ♻️ Chores
|
|
28
|
+
|
|
29
|
+
* **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### 🔖 Miscellaneous
|
|
33
|
+
|
|
34
|
+
* . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [2.0.9](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/normalize-deps-value@2.0.8...@yarn-tool/normalize-deps-value@2.0.9) (2026-09-06)
|
|
7
39
|
|
|
8
40
|
|
package/README.md
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Normalize dependency values to standardized semver format.
|
|
4
4
|
將依賴值正規化為標準化的 semver 格式。
|
|
5
5
|
|
|
6
|
+
目前版本:`2.0.9`
|
|
7
|
+
|
|
6
8
|
## Features / 功能特點
|
|
7
9
|
|
|
8
10
|
- Handles edge cases like empty inputs, spaces, and star wildcards / 處理空輸入、空格和星號萬用字元等邊緣情況
|
|
@@ -60,6 +62,16 @@ Converts an npm-package-arg result to a dependency value string.
|
|
|
60
62
|
Parses a value string into an npm-package-arg result using multiple strategies.
|
|
61
63
|
使用多種策略將值字串解析為 npm-package-arg 結果。
|
|
62
64
|
|
|
65
|
+
## Configuration / 設定
|
|
66
|
+
|
|
67
|
+
本套件不需任何設定 (No configuration),匯入後即可直接使用:
|
|
68
|
+
|
|
69
|
+
- 所有函式皆為純函式 (Pure function),不讀取檔案系統、環境變數或設定檔。
|
|
70
|
+
- 內部使用的虛假套件名稱 (Fake Package Name) `@fake/fake` 為固定常數,
|
|
71
|
+
僅用於解析純 semver 字串(例如 `^4.0.0`),不影響回傳值。
|
|
72
|
+
- 回傳值只會是 `*`(任意版本)或標準的 semver range 字串,
|
|
73
|
+
因此不需要設定預設版本或替代策略。
|
|
74
|
+
|
|
63
75
|
## Related / 相關專案
|
|
64
76
|
|
|
65
77
|
- [@yarn-tool/npm-package-arg-util](../npm-package-arg-util) - npm-package-arg utilities
|
package/index.d.ts
CHANGED
|
@@ -159,4 +159,9 @@ export declare function _getNpaResult(value: string): IResult;
|
|
|
159
159
|
* // => "^4.0.0"
|
|
160
160
|
*/
|
|
161
161
|
export declare function normalizeDepsValue(value: string): string;
|
|
162
|
+
/**
|
|
163
|
+
* 預設匯出 `normalizeDepsValue` (Default export)
|
|
164
|
+
*
|
|
165
|
+
* The default export is `normalizeDepsValue`.
|
|
166
|
+
*/
|
|
162
167
|
export default normalizeDepsValue;
|
package/index.js
CHANGED
|
@@ -93,26 +93,38 @@ const FAKE_NAME = '@fake/fake';
|
|
|
93
93
|
*/
|
|
94
94
|
function normalizeResultToDepsValue(result) {
|
|
95
95
|
let value;
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
/**
|
|
97
|
+
* 字串輸入:直接使用
|
|
98
|
+
*
|
|
99
|
+
* String input: use directly
|
|
100
|
+
*/
|
|
98
101
|
if (typeof result === 'string') {
|
|
99
102
|
value = result;
|
|
100
103
|
}
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
/**
|
|
105
|
+
* 物件結果:根據類型處理
|
|
106
|
+
*
|
|
107
|
+
* Object result: process based on type
|
|
108
|
+
*/
|
|
103
109
|
else if (result) {
|
|
104
110
|
/**
|
|
105
111
|
* Range type: requires special normalization
|
|
106
112
|
* Range 類型:需要特殊正規化
|
|
107
113
|
*/
|
|
108
114
|
if (result.type === 'range') {
|
|
109
|
-
|
|
110
|
-
|
|
115
|
+
/**
|
|
116
|
+
* 空/空格/星號輸入:返回 ANY(會變成 STAR)
|
|
117
|
+
*
|
|
118
|
+
* Empty/space/star input: return ANY (which becomes STAR)
|
|
119
|
+
*/
|
|
111
120
|
if ((0, detect_1.isInputSpecIsEmpty)(result)) {
|
|
112
121
|
value = "" /* EnumSemverVersion.ANY */;
|
|
113
122
|
}
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
/**
|
|
124
|
+
* 非空範圍:透過 semver-ampersand 正規化
|
|
125
|
+
*
|
|
126
|
+
* Non-empty range: normalize through semver-ampersand
|
|
127
|
+
*/
|
|
116
128
|
else {
|
|
117
129
|
const rangeSet = (0, buildRangeSet_1.buildRangeSet)(result.rawSpec);
|
|
118
130
|
value = (0, toRangeString_1.toRangeString)((0, stringifyRangeSet_1.stringifyRangeSet)(rangeSet));
|
|
@@ -135,13 +147,19 @@ function normalizeResultToDepsValue(result) {
|
|
|
135
147
|
value = result.rawSpec;
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
|
-
|
|
139
|
-
|
|
150
|
+
/**
|
|
151
|
+
* 將 ANY 轉換為 undefined(會回退到 STAR)
|
|
152
|
+
*
|
|
153
|
+
* Convert ANY to undefined (will fallback to STAR)
|
|
154
|
+
*/
|
|
140
155
|
if (value === "" /* EnumSemverVersion.ANY */) {
|
|
141
156
|
value = void 0;
|
|
142
157
|
}
|
|
143
|
-
|
|
144
|
-
|
|
158
|
+
/**
|
|
159
|
+
* 返回值或預設為 STAR 萬用字元
|
|
160
|
+
*
|
|
161
|
+
* Return value or default to STAR wildcard
|
|
162
|
+
*/
|
|
145
163
|
return value !== null && value !== void 0 ? value : "*" /* EnumSemverVersion.STAR */;
|
|
146
164
|
}
|
|
147
165
|
/**
|
|
@@ -187,27 +205,39 @@ function normalizeResultToDepsValue(result) {
|
|
|
187
205
|
*/
|
|
188
206
|
function _getNpaResult(value) {
|
|
189
207
|
let result;
|
|
190
|
-
|
|
191
|
-
|
|
208
|
+
/**
|
|
209
|
+
* 策略 1:作為帶虛假名稱的 semver 範圍解析
|
|
210
|
+
*
|
|
211
|
+
* Strategy 1: Parse as semver range with fake name
|
|
212
|
+
*/
|
|
192
213
|
try {
|
|
193
214
|
let sr = new Range_1.SemverRange(value);
|
|
194
215
|
result = (0, npm_package_arg_util_1.npa)(`${FAKE_NAME}@${value}`);
|
|
195
216
|
}
|
|
196
|
-
|
|
197
|
-
|
|
217
|
+
/**
|
|
218
|
+
* 策略 2:作為完整套件規格解析
|
|
219
|
+
*
|
|
220
|
+
* Strategy 2: Parse as full package spec
|
|
221
|
+
*/
|
|
198
222
|
catch (e) {
|
|
199
223
|
try {
|
|
200
224
|
result = (0, npm_package_arg_util_1.npa)(`${value}`);
|
|
201
225
|
}
|
|
202
|
-
|
|
203
|
-
|
|
226
|
+
/**
|
|
227
|
+
* 策略 3:使用 noThrowError 標誌解析
|
|
228
|
+
*
|
|
229
|
+
* Strategy 3: Parse with noThrowError flag
|
|
230
|
+
*/
|
|
204
231
|
catch (e) {
|
|
205
232
|
try {
|
|
206
233
|
result = (0, npm_package_arg_util_1.npa)(`${FAKE_NAME}@${value}`, {
|
|
207
234
|
noThrowError: true,
|
|
208
235
|
});
|
|
209
|
-
|
|
210
|
-
|
|
236
|
+
/**
|
|
237
|
+
* 範圍類型檢查(似乎是驗證預留位置)
|
|
238
|
+
*
|
|
239
|
+
* Type check for range (appears to be validation placeholder)
|
|
240
|
+
*/
|
|
211
241
|
if (result.type === 'range') {
|
|
212
242
|
}
|
|
213
243
|
}
|
|
@@ -267,5 +297,10 @@ function normalizeDepsValue(value) {
|
|
|
267
297
|
const result = _getNpaResult(value);
|
|
268
298
|
return normalizeResultToDepsValue(result);
|
|
269
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* 預設匯出 `normalizeDepsValue` (Default export)
|
|
302
|
+
*
|
|
303
|
+
* The default export is `normalizeDepsValue`.
|
|
304
|
+
*/
|
|
270
305
|
exports.default = normalizeDepsValue;
|
|
271
306
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAgFH,gEAgEC;AA2CD,sCA4CC;AA+CD,gDAIC;AAxRD,0EAA+D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;AAED,kBAAe,kBAAkB,CAAA","sourcesContent":["/**\n * @fileoverview Normalize dependency values to standardized semver format\n * @description 將依賴值正規化為標準化的 semver 格式\n *\n * This module provides utilities to normalize various dependency value formats\n * into a standardized semver string. It handles edge cases like empty inputs,\n * spaces, star wildcards, and complex semver ranges.\n *\n * 本模組提供將各種依賴值格式正規化為標準化 semver 字串的工具。\n * 處理邊緣情況,如空輸入、空格、星號萬用字元和複雜的 semver 範圍。\n *\n * @module @yarn-tool/normalize-deps-value\n */\n\nimport { IResult, npa } from '@yarn-tool/npm-package-arg-util';\nimport { buildRangeSet } from '@lazy-node/semver-ampersand/lib/range/buildRangeSet';\nimport { stringifyRangeSet } from '@lazy-node/semver-ampersand/lib/range/stringifyRangeSet';\nimport { toRangeString } from '@lazy-node/semver-ampersand/lib/range/toRangeString';\nimport { EnumSemverVersion } from '@lazy-node/semver-ampersand/lib/const';\nimport { SemverRange } from '@lazy-node/semver-ampersand/lib/Range';\nimport { isInputSpecIsEmpty } from '@yarn-tool/npm-package-arg-util/lib/detect';\n\n/**\n * Fake package name used for parsing bare semver strings\n * 用於解析純 semver 字串的虛假套件名稱\n *\n * When a user provides just a version string (e.g., \"^4.0.0\") without a package name,\n * we prepend this fake name to make it parseable by npm-package-arg.\n *\n * 當使用者只提供版本字串(例如:\"^4.0.0\")而沒有套件名稱時,\n * 我們會加上這個虛假名稱使其能被 npm-package-arg 解析。\n */\nconst FAKE_NAME = '@fake/fake' as const\n\n/**\n * Normalize an npm-package-arg result to a dependency value string\n * 將 npm-package-arg 結果正規化為依賴值字串\n *\n * This function converts an npm-package-arg result into a standardized\n * dependency value string suitable for package.json. It handles:\n * - Empty/space inputs (returns \"*\")\n * - Range normalization using semver-ampersand\n * - Tag handling with special cases\n * - Direct passthrough for other types\n *\n * 此函數將 npm-package-arg 結果轉換為適合 package.json 的標準化依賴值字串。\n * 處理:\n * - 空/空格輸入(返回 \"*\")\n * - 使用 semver-ampersand 進行範圍正規化\n * - 標籤的特殊情況處理\n * - 其他類型的直接傳遞\n *\n * @param {ReturnType<typeof _getNpaResult>} result - The npm-package-arg result or string to normalize / 要正規化的 npm-package-arg 結果或字串\n *\n * @returns {string} Normalized dependency value (e.g., \"*\", \"^4.0.0\", \"1.2.3\") / 正規化的依賴值(例如:\"*\"、\"^4.0.0\"、\"1.2.3\")\n *\n * @example\n * // Empty input\n * // 空輸入\n * normalizeResultToDepsValue({ type: 'range', rawSpec: '', ... });\n * // => \"*\"\n *\n * @example\n * // Space input\n * // 空格輸入\n * normalizeResultToDepsValue({ type: 'range', rawSpec: ' ', ... });\n * // => \"*\"\n *\n * @example\n * // Star wildcard\n * // 星號萬用字元\n * normalizeResultToDepsValue({ type: 'range', rawSpec: '*', ... });\n * // => \"*\"\n *\n * @example\n * // Range normalization\n * // 範圍正規化\n * normalizeResultToDepsValue({ type: 'range', rawSpec: '>=1.0.0 <2.0.0', ... });\n * // => \">=1.0.0 <2.0.0\" (normalized via semver-ampersand)\n *\n * @example\n * // Tag as package name only\n * // 僅作為套件名稱的標籤\n * normalizeResultToDepsValue({ type: 'tag', name: 'lodash', rawSpec: '*', raw: 'lodash' });\n * // => \"lodash\"\n *\n * @example\n * // Direct passthrough\n * // 直接傳遞\n * normalizeResultToDepsValue({ type: 'version', rawSpec: '4.17.21', ... });\n * // => \"4.17.21\"\n */\nexport function normalizeResultToDepsValue(result: ReturnType<typeof _getNpaResult>)\n{\n\tlet value: string;\n\n\t// String input: use directly\n\t// 字串輸入:直接使用\n\tif (typeof result === 'string')\n\t{\n\t\tvalue = result;\n\t}\n\t// Object result: process based on type\n\t// 物件結果:根據類型處理\n\telse if (result)\n\t{\n\t\t/**\n\t\t * Range type: requires special normalization\n\t\t * Range 類型:需要特殊正規化\n\t\t */\n\t\tif (result.type === 'range')\n\t\t{\n\t\t\t// Empty/space/star input: return ANY (which becomes STAR)\n\t\t\t// 空/空格/星號輸入:返回 ANY(會變成 STAR)\n\t\t\tif (isInputSpecIsEmpty(result))\n\t\t\t{\n\t\t\t\tvalue = EnumSemverVersion.ANY;\n\t\t\t}\n\t\t\t// Non-empty range: normalize through semver-ampersand\n\t\t\t// 非空範圍:透過 semver-ampersand 正規化\n\t\t\telse\n\t\t\t{\n\t\t\t\tconst rangeSet = buildRangeSet(result.rawSpec);\n\t\t\t\tvalue = toRangeString(stringifyRangeSet(rangeSet));\n\t\t\t}\n\t\t}\n\t\t/**\n\t\t * Tag type with ANY spec (like \"*\") and not fake@ pattern:\n\t\t * return just the package name\n\t\t *\tTag 類型且規格為 ANY(如 \"*\")且不是 fake@ 模式:\n\t\t * 僅返回套件名稱\n\t\t */\n\t\telse if (result.type === 'tag' && result.rawSpec === EnumSemverVersion.ANY && result.raw !== `${FAKE_NAME}@`)\n\t\t{\n\t\t\tvalue = result.name\n\t\t}\n\t\t/**\n\t\t * All other types: use rawSpec directly\n\t\t * 所有其他類型:直接使用 rawSpec\n\t\t */\n\t\telse\n\t\t{\n\t\t\tvalue = result.rawSpec\n\t\t}\n\t}\n\n\t// Convert ANY to undefined (will fallback to STAR)\n\t// 將 ANY 轉換為 undefined(會回退到 STAR)\n\tif (value === EnumSemverVersion.ANY)\n\t{\n\t\tvalue = void 0;\n\t}\n\n\t// Return value or default to STAR wildcard\n\t// 返回值或預設為 STAR 萬用字元\n\treturn value ?? EnumSemverVersion.STAR\n}\n\n/**\n * Parse a value string into an npm-package-arg result\n * 將值字串解析為 npm-package-arg 結果\n *\n * This function attempts to parse a dependency value string using multiple strategies:\n * 1. Try as semver range with fake package name (for bare version strings like \"^4.0.0\")\n * 2. Try as full package spec (for \"package@version\" format)\n * 3. Try with noThrowError flag (for edge cases)\n *\n * 此函數嘗試使用多種策略解析依賴值字串:\n * 1. 嘗試作為帶虛假套件名稱的 semver 範圍(用於純版本字串如 \"^4.0.0\")\n * 2. 嘗試作為完整套件規格(用於 \"package@version\" 格式)\n * 3. 嘗試使用 noThrowError 標誌(用於邊緣情況)\n *\n * @param {string} value - The dependency value string to parse\n * @param {string} value - 要解析的依賴值字串\n *\n * @returns {IResult} Parsed npm-package-arg result\n * @returns {IResult} 解析後的 npm-package-arg 結果\n *\n * @throws {Error} Throws if all parsing strategies fail\n * @throws {Error} 如果所有解析策略都失敗則拋出錯誤\n *\n * @example\n * // Bare semver range\n * // 純 semver 範圍\n * _getNpaResult('^4.0.0');\n * // => IResult { type: 'range', name: '@fake/fake', rawSpec: '^4.0.0', ... }\n *\n * @example\n * // Package with version\n * // 帶版本的套件\n * _getNpaResult('lodash@^4.0.0');\n * // => IResult { type: 'range', name: 'lodash', rawSpec: '^4.0.0', ... }\n *\n * @example\n * // Empty string\n * // 空字串\n * _getNpaResult('');\n * // => IResult { type: 'range', name: '@fake/fake', rawSpec: '', ... }\n */\nexport function _getNpaResult(value: string)\n{\n\tlet result: IResult;\n\n\t// Strategy 1: Parse as semver range with fake name\n\t// 策略 1:作為帶虛假名稱的 semver 範圍解析\n\ttry\n\t{\n\t\tlet sr = new SemverRange(value);\n\t\tresult = npa(`${FAKE_NAME}@${value}`)\n\t}\n\t// Strategy 2: Parse as full package spec\n\t// 策略 2:作為完整套件規格解析\n\tcatch (e)\n\t{\n\t\ttry\n\t\t{\n\t\t\tresult = npa(`${value}`)\n\t\t}\n\t\t// Strategy 3: Parse with noThrowError flag\n\t\t// 策略 3:使用 noThrowError 標誌解析\n\t\tcatch (e)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tresult = npa(`${FAKE_NAME}@${value}`, {\n\t\t\t\t\tnoThrowError: true,\n\t\t\t\t});\n\n\t\t\t\t// Type check for range (appears to be validation placeholder)\n\t\t\t\t// 範圍類型檢查(似乎是驗證預留位置)\n\t\t\t\tif (result.type === 'range')\n\t\t\t\t{\n\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e2)\n\t\t\t{\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result\n}\n\n/**\n * Normalize a dependency value string to standard format\n * 將依賴值字串正規化為標準格式\n *\n * This is the main entry point that combines parsing and normalization\n * into a single operation. It handles all the edge cases tested in\n * space.spec.ts including empty strings, spaces, and star wildcards.\n *\n * 這是主要入口點,將解析和正規化合併為單一操作。\n * 處理 space.spec.ts 中測試的所有邊緣情況,包括空字串、空格和星號萬用字元。\n *\n * @param {string} value - The dependency value to normalize / 要正規化的依賴值\n *\n * @returns {string} Normalized dependency value / 正規化的依賴值\n *\n * @example\n * // Empty string becomes star\n * // 空字串變為星號\n * normalizeDepsValue('');\n * // => \"*\"\n *\n * @example\n * // Space becomes star\n * // 空格變為星號\n * normalizeDepsValue(' ');\n * // => \"*\"\n *\n * @example\n * // Star remains star\n * // 星號保持為星號\n * normalizeDepsValue('*');\n * // => \"*\"\n *\n * @example\n * // Semver range is normalized\n * // Semver 範圍被正規化\n * normalizeDepsValue('>=1.0.0 <2.0.0');\n * // => \">=1.0.0 <2.0.0\"\n *\n * @example\n * // Package@version returns version\n * // Package@version 返回版本\n * normalizeDepsValue('lodash@^4.0.0');\n * // => \"^4.0.0\"\n */\nexport function normalizeDepsValue(value: string)\n{\n\tconst result = _getNpaResult(value);\n\treturn normalizeResultToDepsValue(result)\n}\n\nexport default normalizeDepsValue\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAgFH,gEAkFC;AA2CD,sCAwDC;AA+CD,gDAIC;AAtTD,0EAA+D;AAC/D,uFAAoF;AACpF,+FAA4F;AAC5F,uFAAoF;AAEpF,iEAAoE;AACpE,uEAAgF;AAEhF;;;;;;;;;GASG;AACH,MAAM,SAAS,GAAG,YAAqB,CAAA;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,SAAgB,0BAA0B,CAAC,MAAwC;IAElF,IAAI,KAAa,CAAC;IAElB;;;;OAIG;IACH,IAAI,OAAO,MAAM,KAAK,QAAQ,EAC9B,CAAC;QACA,KAAK,GAAG,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;;OAIG;IACH,OAAO,CAAC,EACR,CAAC;QACA,IACA,CAAC;YACA,MAAM,GAAG,IAAA,0BAAG,EAAC,GAAG,KAAK,EAAE,CAAC,CAAA;QACzB,CAAC;QACD;;;;WAIG;QACH,OAAO,CAAC,EACR,CAAC;YACA,IACA,CAAC;gBACA,MAAM,GAAG,IAAA,0BAAG,EAAC,GAAG,SAAS,IAAI,KAAK,EAAE,EAAE;oBACrC,YAAY,EAAE,IAAI;iBAClB,CAAC,CAAC;gBAEH;;;;mBAIG;gBACH,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAC3B,CAAC;gBAED,CAAC;YACF,CAAC;YACD,OAAO,EAAE,EACT,CAAC;gBACA,MAAM,CAAC,CAAA;YACR,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,SAAgB,kBAAkB,CAAC,KAAa;IAE/C,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAA;AAC1C,CAAC;AAED;;;;GAIG;AACH,kBAAe,kBAAkB,CAAA","sourcesContent":["/**\n * @fileoverview Normalize dependency values to standardized semver format\n * @description 將依賴值正規化為標準化的 semver 格式\n *\n * This module provides utilities to normalize various dependency value formats\n * into a standardized semver string. It handles edge cases like empty inputs,\n * spaces, star wildcards, and complex semver ranges.\n *\n * 本模組提供將各種依賴值格式正規化為標準化 semver 字串的工具。\n * 處理邊緣情況,如空輸入、空格、星號萬用字元和複雜的 semver 範圍。\n *\n * @module @yarn-tool/normalize-deps-value\n */\n\nimport { IResult, npa } from '@yarn-tool/npm-package-arg-util';\nimport { buildRangeSet } from '@lazy-node/semver-ampersand/lib/range/buildRangeSet';\nimport { stringifyRangeSet } from '@lazy-node/semver-ampersand/lib/range/stringifyRangeSet';\nimport { toRangeString } from '@lazy-node/semver-ampersand/lib/range/toRangeString';\nimport { EnumSemverVersion } from '@lazy-node/semver-ampersand/lib/const';\nimport { SemverRange } from '@lazy-node/semver-ampersand/lib/Range';\nimport { isInputSpecIsEmpty } from '@yarn-tool/npm-package-arg-util/lib/detect';\n\n/**\n * Fake package name used for parsing bare semver strings\n * 用於解析純 semver 字串的虛假套件名稱\n *\n * When a user provides just a version string (e.g., \"^4.0.0\") without a package name,\n * we prepend this fake name to make it parseable by npm-package-arg.\n *\n * 當使用者只提供版本字串(例如:\"^4.0.0\")而沒有套件名稱時,\n * 我們會加上這個虛假名稱使其能被 npm-package-arg 解析。\n */\nconst FAKE_NAME = '@fake/fake' as const\n\n/**\n * Normalize an npm-package-arg result to a dependency value string\n * 將 npm-package-arg 結果正規化為依賴值字串\n *\n * This function converts an npm-package-arg result into a standardized\n * dependency value string suitable for package.json. It handles:\n * - Empty/space inputs (returns \"*\")\n * - Range normalization using semver-ampersand\n * - Tag handling with special cases\n * - Direct passthrough for other types\n *\n * 此函數將 npm-package-arg 結果轉換為適合 package.json 的標準化依賴值字串。\n * 處理:\n * - 空/空格輸入(返回 \"*\")\n * - 使用 semver-ampersand 進行範圍正規化\n * - 標籤的特殊情況處理\n * - 其他類型的直接傳遞\n *\n * @param {ReturnType<typeof _getNpaResult>} result - The npm-package-arg result or string to normalize / 要正規化的 npm-package-arg 結果或字串\n *\n * @returns {string} Normalized dependency value (e.g., \"*\", \"^4.0.0\", \"1.2.3\") / 正規化的依賴值(例如:\"*\"、\"^4.0.0\"、\"1.2.3\")\n *\n * @example\n * // Empty input\n * // 空輸入\n * normalizeResultToDepsValue({ type: 'range', rawSpec: '', ... });\n * // => \"*\"\n *\n * @example\n * // Space input\n * // 空格輸入\n * normalizeResultToDepsValue({ type: 'range', rawSpec: ' ', ... });\n * // => \"*\"\n *\n * @example\n * // Star wildcard\n * // 星號萬用字元\n * normalizeResultToDepsValue({ type: 'range', rawSpec: '*', ... });\n * // => \"*\"\n *\n * @example\n * // Range normalization\n * // 範圍正規化\n * normalizeResultToDepsValue({ type: 'range', rawSpec: '>=1.0.0 <2.0.0', ... });\n * // => \">=1.0.0 <2.0.0\" (normalized via semver-ampersand)\n *\n * @example\n * // Tag as package name only\n * // 僅作為套件名稱的標籤\n * normalizeResultToDepsValue({ type: 'tag', name: 'lodash', rawSpec: '*', raw: 'lodash' });\n * // => \"lodash\"\n *\n * @example\n * // Direct passthrough\n * // 直接傳遞\n * normalizeResultToDepsValue({ type: 'version', rawSpec: '4.17.21', ... });\n * // => \"4.17.21\"\n */\nexport function normalizeResultToDepsValue(result: ReturnType<typeof _getNpaResult>)\n{\n\tlet value: string;\n\n\t/**\n\t * 字串輸入:直接使用\n\t *\n\t * String input: use directly\n\t */\n\tif (typeof result === 'string')\n\t{\n\t\tvalue = result;\n\t}\n\t/**\n\t * 物件結果:根據類型處理\n\t *\n\t * Object result: process based on type\n\t */\n\telse if (result)\n\t{\n\t\t/**\n\t\t * Range type: requires special normalization\n\t\t * Range 類型:需要特殊正規化\n\t\t */\n\t\tif (result.type === 'range')\n\t\t{\n\t\t\t/**\n\t\t\t * 空/空格/星號輸入:返回 ANY(會變成 STAR)\n\t\t\t *\n\t\t\t * Empty/space/star input: return ANY (which becomes STAR)\n\t\t\t */\n\t\t\tif (isInputSpecIsEmpty(result))\n\t\t\t{\n\t\t\t\tvalue = EnumSemverVersion.ANY;\n\t\t\t}\n\t\t\t/**\n\t\t\t * 非空範圍:透過 semver-ampersand 正規化\n\t\t\t *\n\t\t\t * Non-empty range: normalize through semver-ampersand\n\t\t\t */\n\t\t\telse\n\t\t\t{\n\t\t\t\tconst rangeSet = buildRangeSet(result.rawSpec);\n\t\t\t\tvalue = toRangeString(stringifyRangeSet(rangeSet));\n\t\t\t}\n\t\t}\n\t\t/**\n\t\t * Tag type with ANY spec (like \"*\") and not fake@ pattern:\n\t\t * return just the package name\n\t\t *\tTag 類型且規格為 ANY(如 \"*\")且不是 fake@ 模式:\n\t\t * 僅返回套件名稱\n\t\t */\n\t\telse if (result.type === 'tag' && result.rawSpec === EnumSemverVersion.ANY && result.raw !== `${FAKE_NAME}@`)\n\t\t{\n\t\t\tvalue = result.name\n\t\t}\n\t\t/**\n\t\t * All other types: use rawSpec directly\n\t\t * 所有其他類型:直接使用 rawSpec\n\t\t */\n\t\telse\n\t\t{\n\t\t\tvalue = result.rawSpec\n\t\t}\n\t}\n\n\t/**\n\t * 將 ANY 轉換為 undefined(會回退到 STAR)\n\t *\n\t * Convert ANY to undefined (will fallback to STAR)\n\t */\n\tif (value === EnumSemverVersion.ANY)\n\t{\n\t\tvalue = void 0;\n\t}\n\n\t/**\n\t * 返回值或預設為 STAR 萬用字元\n\t *\n\t * Return value or default to STAR wildcard\n\t */\n\treturn value ?? EnumSemverVersion.STAR\n}\n\n/**\n * Parse a value string into an npm-package-arg result\n * 將值字串解析為 npm-package-arg 結果\n *\n * This function attempts to parse a dependency value string using multiple strategies:\n * 1. Try as semver range with fake package name (for bare version strings like \"^4.0.0\")\n * 2. Try as full package spec (for \"package@version\" format)\n * 3. Try with noThrowError flag (for edge cases)\n *\n * 此函數嘗試使用多種策略解析依賴值字串:\n * 1. 嘗試作為帶虛假套件名稱的 semver 範圍(用於純版本字串如 \"^4.0.0\")\n * 2. 嘗試作為完整套件規格(用於 \"package@version\" 格式)\n * 3. 嘗試使用 noThrowError 標誌(用於邊緣情況)\n *\n * @param {string} value - The dependency value string to parse\n * @param {string} value - 要解析的依賴值字串\n *\n * @returns {IResult} Parsed npm-package-arg result\n * @returns {IResult} 解析後的 npm-package-arg 結果\n *\n * @throws {Error} Throws if all parsing strategies fail\n * @throws {Error} 如果所有解析策略都失敗則拋出錯誤\n *\n * @example\n * // Bare semver range\n * // 純 semver 範圍\n * _getNpaResult('^4.0.0');\n * // => IResult { type: 'range', name: '@fake/fake', rawSpec: '^4.0.0', ... }\n *\n * @example\n * // Package with version\n * // 帶版本的套件\n * _getNpaResult('lodash@^4.0.0');\n * // => IResult { type: 'range', name: 'lodash', rawSpec: '^4.0.0', ... }\n *\n * @example\n * // Empty string\n * // 空字串\n * _getNpaResult('');\n * // => IResult { type: 'range', name: '@fake/fake', rawSpec: '', ... }\n */\nexport function _getNpaResult(value: string)\n{\n\tlet result: IResult;\n\n\t/**\n\t * 策略 1:作為帶虛假名稱的 semver 範圍解析\n\t *\n\t * Strategy 1: Parse as semver range with fake name\n\t */\n\ttry\n\t{\n\t\tlet sr = new SemverRange(value);\n\t\tresult = npa(`${FAKE_NAME}@${value}`)\n\t}\n\t/**\n\t * 策略 2:作為完整套件規格解析\n\t *\n\t * Strategy 2: Parse as full package spec\n\t */\n\tcatch (e)\n\t{\n\t\ttry\n\t\t{\n\t\t\tresult = npa(`${value}`)\n\t\t}\n\t\t/**\n\t\t * 策略 3:使用 noThrowError 標誌解析\n\t\t *\n\t\t * Strategy 3: Parse with noThrowError flag\n\t\t */\n\t\tcatch (e)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tresult = npa(`${FAKE_NAME}@${value}`, {\n\t\t\t\t\tnoThrowError: true,\n\t\t\t\t});\n\n\t\t\t\t/**\n\t\t\t\t * 範圍類型檢查(似乎是驗證預留位置)\n\t\t\t\t *\n\t\t\t\t * Type check for range (appears to be validation placeholder)\n\t\t\t\t */\n\t\t\t\tif (result.type === 'range')\n\t\t\t\t{\n\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (e2)\n\t\t\t{\n\t\t\t\tthrow e\n\t\t\t}\n\t\t}\n\t}\n\n\treturn result\n}\n\n/**\n * Normalize a dependency value string to standard format\n * 將依賴值字串正規化為標準格式\n *\n * This is the main entry point that combines parsing and normalization\n * into a single operation. It handles all the edge cases tested in\n * space.spec.ts including empty strings, spaces, and star wildcards.\n *\n * 這是主要入口點,將解析和正規化合併為單一操作。\n * 處理 space.spec.ts 中測試的所有邊緣情況,包括空字串、空格和星號萬用字元。\n *\n * @param {string} value - The dependency value to normalize / 要正規化的依賴值\n *\n * @returns {string} Normalized dependency value / 正規化的依賴值\n *\n * @example\n * // Empty string becomes star\n * // 空字串變為星號\n * normalizeDepsValue('');\n * // => \"*\"\n *\n * @example\n * // Space becomes star\n * // 空格變為星號\n * normalizeDepsValue(' ');\n * // => \"*\"\n *\n * @example\n * // Star remains star\n * // 星號保持為星號\n * normalizeDepsValue('*');\n * // => \"*\"\n *\n * @example\n * // Semver range is normalized\n * // Semver 範圍被正規化\n * normalizeDepsValue('>=1.0.0 <2.0.0');\n * // => \">=1.0.0 <2.0.0\"\n *\n * @example\n * // Package@version returns version\n * // Package@version 返回版本\n * normalizeDepsValue('lodash@^4.0.0');\n * // => \"^4.0.0\"\n */\nexport function normalizeDepsValue(value: string)\n{\n\tconst result = _getNpaResult(value);\n\treturn normalizeResultToDepsValue(result)\n}\n\n/**\n * 預設匯出 `normalizeDepsValue` (Default export)\n *\n * The default export is `normalizeDepsValue`.\n */\nexport default normalizeDepsValue\n"]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/normalize-deps-value",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.10",
|
|
4
4
|
"description": "Normalize dependency values to standardized semver format / 將依賴值正規化為標準化的 semver 格式",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"normalize",
|
|
7
|
+
"semver",
|
|
6
8
|
"yarn",
|
|
7
9
|
"yarn-tool",
|
|
8
10
|
"npm",
|
|
@@ -38,12 +40,14 @@
|
|
|
38
40
|
"lint": "pnpm run lint:eslint",
|
|
39
41
|
"lint:eslint": "ynpx eslint --ext .ts,.tsx,.mts,.cts ./",
|
|
40
42
|
"pretest": "echo pretest",
|
|
41
|
-
"test": "
|
|
43
|
+
"test": "node --run test:node",
|
|
42
44
|
"test:jest": "jest --passWithNoTests",
|
|
43
45
|
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
44
46
|
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
45
47
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
48
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
46
49
|
"test:snapshot": "pnpm run test -u",
|
|
50
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
47
51
|
"test:tsd": "ynpx tsd",
|
|
48
52
|
"test:tsdx": "ynpx @bluelovers/tsdx test --passWithNoTests",
|
|
49
53
|
"build:dts:bundle": "ynpx @bluelovers/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts --no-banner --inline-declare-global & echo build:dts:bundle",
|
|
@@ -58,7 +62,6 @@
|
|
|
58
62
|
"version": "echo version",
|
|
59
63
|
"postversion": "echo postversion",
|
|
60
64
|
"prepublish": "echo prepublish",
|
|
61
|
-
"prepare": "echo prepare",
|
|
62
65
|
"prepublishOnly": "echo prepublishOnly",
|
|
63
66
|
"prepublishOnly:update": "pnpm run ncu && pnpm run sort-package-json",
|
|
64
67
|
"prepack": "echo prepack",
|
|
@@ -72,12 +75,12 @@
|
|
|
72
75
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
73
76
|
},
|
|
74
77
|
"dependencies": {
|
|
75
|
-
"@lazy-node/semver-ampersand": "^3.0.
|
|
76
|
-
"@yarn-tool/npm-package-arg-util": "^2.0.
|
|
78
|
+
"@lazy-node/semver-ampersand": "^3.0.12",
|
|
79
|
+
"@yarn-tool/npm-package-arg-util": "^2.0.9",
|
|
77
80
|
"tslib": ">=2.8.1"
|
|
78
81
|
},
|
|
79
82
|
"publishConfig": {
|
|
80
83
|
"access": "public"
|
|
81
84
|
},
|
|
82
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
|
|
83
86
|
}
|