@yarn-tool/normalize-deps-value 2.0.3 → 2.0.6
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 +46 -0
- package/README.md +61 -3
- package/index.d.ts +157 -0
- package/index.js +214 -3
- package/index.js.map +1 -1
- package/package.json +5 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,52 @@
|
|
|
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.6](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/normalize-deps-value@2.0.5...@yarn-tool/normalize-deps-value@2.0.6) (2026-03-09)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @yarn-tool/normalize-deps-value
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.0.5](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/normalize-deps-value@2.0.4...@yarn-tool/normalize-deps-value@2.0.5) (2026-03-09)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### ♻️ Chores
|
|
19
|
+
|
|
20
|
+
* **deps:** 更新 workspace 依賴版本並新增 CI 安裝腳本 ([fbb5b0b](https://github.com/bluelovers/ws-yarn-workspaces/commit/fbb5b0b32cab8cdd34c1f5b5f9a6f8c54213e738))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## [2.0.4](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/normalize-deps-value@2.0.3...@yarn-tool/normalize-deps-value@2.0.4) (2026-03-02)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### ✨ Features
|
|
29
|
+
|
|
30
|
+
* **npm-package-arg-util:** 新增空值與特殊輸入檢測功能 ([c5e9acc](https://github.com/bluelovers/ws-yarn-workspaces/commit/c5e9acccc49e1c544f8e5aefa1532a35f5e99a9d))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### 🚨 Tests
|
|
34
|
+
|
|
35
|
+
* **fnm-detect:** correct alias props and update dependencies ([21d1c54](https://github.com/bluelovers/ws-yarn-workspaces/commit/21d1c54c60ae64fb2117eae1e2b86bb42c8b6070))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### 🛠 Build System
|
|
39
|
+
|
|
40
|
+
* **semver-parse,npm-package-arg-util:** 支援部分版本並新增輸入檢測功能 ([e824769](https://github.com/bluelovers/ws-yarn-workspaces/commit/e8247696151c6ffcd146eacdb46be0ee721ebefd))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
### ♻️ Chores
|
|
44
|
+
|
|
45
|
+
* Add test config and global types for tsdx ([88a8df6](https://github.com/bluelovers/ws-yarn-workspaces/commit/88a8df6eef5dc59d9e0d9268b21706dceb5ab2a1))
|
|
46
|
+
* 更新 Jest 快照連結並增強類型定義與文件 ([b663b97](https://github.com/bluelovers/ws-yarn-workspaces/commit/b663b97d78d223dc8b3927ea2433938350144de7))
|
|
47
|
+
* remove empty resolutions and redundant packageManager fields ([65b5c5f](https://github.com/bluelovers/ws-yarn-workspaces/commit/65b5c5f929aae82474408b2b46cfc5a471c919f6))
|
|
48
|
+
* add __root.ts test utility to workspace packages ([a771727](https://github.com/bluelovers/ws-yarn-workspaces/commit/a7717278883c86d9ed8ab89f42070d3385c173a7))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
6
52
|
## [2.0.3](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/normalize-deps-value@2.0.2...@yarn-tool/normalize-deps-value@2.0.3) (2025-09-07)
|
|
7
53
|
|
|
8
54
|
**Note:** Version bump only for package @yarn-tool/normalize-deps-value
|
package/README.md
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yarn-tool/normalize-deps-value
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Normalize dependency values to standardized semver format.
|
|
4
|
+
將依賴值正規化為標準化的 semver 格式。
|
|
4
5
|
|
|
5
|
-
##
|
|
6
|
+
## Features / 功能特點
|
|
7
|
+
|
|
8
|
+
- Handles edge cases like empty inputs, spaces, and star wildcards / 處理空輸入、空格和星號萬用字元等邊緣情況
|
|
9
|
+
- Normalizes complex semver ranges / 正規化複雜的 semver 範圍
|
|
10
|
+
- Converts npm-package-arg results to standardized dependency values / 將 npm-package-arg 結果轉換為標準化的依賴值
|
|
11
|
+
|
|
12
|
+
## Install / 安裝
|
|
6
13
|
|
|
7
14
|
```bash
|
|
8
15
|
yarn add @yarn-tool/normalize-deps-value
|
|
@@ -10,3 +17,54 @@ yarn-tool add @yarn-tool/normalize-deps-value
|
|
|
10
17
|
yt add @yarn-tool/normalize-deps-value
|
|
11
18
|
```
|
|
12
19
|
|
|
20
|
+
## Usage / 使用方式
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { normalizeDepsValue, normalizeResultToDepsValue, _getNpaResult } from '@yarn-tool/normalize-deps-value';
|
|
24
|
+
|
|
25
|
+
// Normalize a dependency value string
|
|
26
|
+
// 正規化依賴值字串
|
|
27
|
+
normalizeDepsValue(''); // => "*"
|
|
28
|
+
normalizeDepsValue(' '); // => "*"
|
|
29
|
+
normalizeDepsValue('*'); // => "*"
|
|
30
|
+
normalizeDepsValue('^4.0.0'); // => "^4.0.0"
|
|
31
|
+
normalizeDepsValue('>=1.0.0 <2.0.0'); // => ">=1.0.0 <2.0.0"
|
|
32
|
+
normalizeDepsValue('lodash@^4.0.0'); // => "^4.0.0"
|
|
33
|
+
|
|
34
|
+
// Parse and normalize npm-package-arg result
|
|
35
|
+
// 解析並正規化 npm-package-arg 結果
|
|
36
|
+
const result = _getNpaResult('^4.0.0');
|
|
37
|
+
normalizeResultToDepsValue(result); // => "^4.0.0"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## API / API 文件
|
|
41
|
+
|
|
42
|
+
### `normalizeDepsValue(value: string): string`
|
|
43
|
+
|
|
44
|
+
Normalizes a dependency value string to standard format.
|
|
45
|
+
將依賴值字串正規化為標準格式。
|
|
46
|
+
|
|
47
|
+
**Parameters / 參數:**
|
|
48
|
+
- `value` - The dependency value to normalize / 要正規化的依賴值
|
|
49
|
+
|
|
50
|
+
**Returns / 返回:**
|
|
51
|
+
- Normalized dependency value / 正規化的依賴值
|
|
52
|
+
|
|
53
|
+
### `normalizeResultToDepsValue(result): string`
|
|
54
|
+
|
|
55
|
+
Converts an npm-package-arg result to a dependency value string.
|
|
56
|
+
將 npm-package-arg 結果轉換為依賴值字串。
|
|
57
|
+
|
|
58
|
+
### `_getNpaResult(value: string): IResult`
|
|
59
|
+
|
|
60
|
+
Parses a value string into an npm-package-arg result using multiple strategies.
|
|
61
|
+
使用多種策略將值字串解析為 npm-package-arg 結果。
|
|
62
|
+
|
|
63
|
+
## Related / 相關專案
|
|
64
|
+
|
|
65
|
+
- [@yarn-tool/npm-package-arg-util](../npm-package-arg-util) - npm-package-arg utilities
|
|
66
|
+
- [@yarn-tool/npa-to-deps](../npa-to-deps) - Convert npm-package-arg results to dependency objects
|
|
67
|
+
|
|
68
|
+
## License / 授權
|
|
69
|
+
|
|
70
|
+
ISC
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Normalize dependency values to standardized semver format
|
|
3
|
+
* @description 將依賴值正規化為標準化的 semver 格式
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities to normalize various dependency value formats
|
|
6
|
+
* into a standardized semver string. It handles edge cases like empty inputs,
|
|
7
|
+
* spaces, star wildcards, and complex semver ranges.
|
|
8
|
+
*
|
|
9
|
+
* 本模組提供將各種依賴值格式正規化為標準化 semver 字串的工具。
|
|
10
|
+
* 處理邊緣情況,如空輸入、空格、星號萬用字元和複雜的 semver 範圍。
|
|
11
|
+
*
|
|
12
|
+
* @module @yarn-tool/normalize-deps-value
|
|
13
|
+
*/
|
|
1
14
|
import { IResult } from '@yarn-tool/npm-package-arg-util';
|
|
15
|
+
/**
|
|
16
|
+
* Normalize an npm-package-arg result to a dependency value string
|
|
17
|
+
* 將 npm-package-arg 結果正規化為依賴值字串
|
|
18
|
+
*
|
|
19
|
+
* This function converts an npm-package-arg result into a standardized
|
|
20
|
+
* dependency value string suitable for package.json. It handles:
|
|
21
|
+
* - Empty/space inputs (returns "*")
|
|
22
|
+
* - Range normalization using semver-ampersand
|
|
23
|
+
* - Tag handling with special cases
|
|
24
|
+
* - Direct passthrough for other types
|
|
25
|
+
*
|
|
26
|
+
* 此函數將 npm-package-arg 結果轉換為適合 package.json 的標準化依賴值字串。
|
|
27
|
+
* 處理:
|
|
28
|
+
* - 空/空格輸入(返回 "*")
|
|
29
|
+
* - 使用 semver-ampersand 進行範圍正規化
|
|
30
|
+
* - 標籤的特殊情況處理
|
|
31
|
+
* - 其他類型的直接傳遞
|
|
32
|
+
*
|
|
33
|
+
* @param {ReturnType<typeof _getNpaResult>} result - The npm-package-arg result or string to normalize / 要正規化的 npm-package-arg 結果或字串
|
|
34
|
+
*
|
|
35
|
+
* @returns {string} Normalized dependency value (e.g., "*", "^4.0.0", "1.2.3") / 正規化的依賴值(例如:"*"、"^4.0.0"、"1.2.3")
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Empty input
|
|
39
|
+
* // 空輸入
|
|
40
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: '', ... });
|
|
41
|
+
* // => "*"
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* // Space input
|
|
45
|
+
* // 空格輸入
|
|
46
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: ' ', ... });
|
|
47
|
+
* // => "*"
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Star wildcard
|
|
51
|
+
* // 星號萬用字元
|
|
52
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: '*', ... });
|
|
53
|
+
* // => "*"
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* // Range normalization
|
|
57
|
+
* // 範圍正規化
|
|
58
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: '>=1.0.0 <2.0.0', ... });
|
|
59
|
+
* // => ">=1.0.0 <2.0.0" (normalized via semver-ampersand)
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Tag as package name only
|
|
63
|
+
* // 僅作為套件名稱的標籤
|
|
64
|
+
* normalizeResultToDepsValue({ type: 'tag', name: 'lodash', rawSpec: '*', raw: 'lodash' });
|
|
65
|
+
* // => "lodash"
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* // Direct passthrough
|
|
69
|
+
* // 直接傳遞
|
|
70
|
+
* normalizeResultToDepsValue({ type: 'version', rawSpec: '4.17.21', ... });
|
|
71
|
+
* // => "4.17.21"
|
|
72
|
+
*/
|
|
2
73
|
export declare function normalizeResultToDepsValue(result: ReturnType<typeof _getNpaResult>): string;
|
|
74
|
+
/**
|
|
75
|
+
* Parse a value string into an npm-package-arg result
|
|
76
|
+
* 將值字串解析為 npm-package-arg 結果
|
|
77
|
+
*
|
|
78
|
+
* This function attempts to parse a dependency value string using multiple strategies:
|
|
79
|
+
* 1. Try as semver range with fake package name (for bare version strings like "^4.0.0")
|
|
80
|
+
* 2. Try as full package spec (for "package@version" format)
|
|
81
|
+
* 3. Try with noThrowError flag (for edge cases)
|
|
82
|
+
*
|
|
83
|
+
* 此函數嘗試使用多種策略解析依賴值字串:
|
|
84
|
+
* 1. 嘗試作為帶虛假套件名稱的 semver 範圍(用於純版本字串如 "^4.0.0")
|
|
85
|
+
* 2. 嘗試作為完整套件規格(用於 "package@version" 格式)
|
|
86
|
+
* 3. 嘗試使用 noThrowError 標誌(用於邊緣情況)
|
|
87
|
+
*
|
|
88
|
+
* @param {string} value - The dependency value string to parse
|
|
89
|
+
* @param {string} value - 要解析的依賴值字串
|
|
90
|
+
*
|
|
91
|
+
* @returns {IResult} Parsed npm-package-arg result
|
|
92
|
+
* @returns {IResult} 解析後的 npm-package-arg 結果
|
|
93
|
+
*
|
|
94
|
+
* @throws {Error} Throws if all parsing strategies fail
|
|
95
|
+
* @throws {Error} 如果所有解析策略都失敗則拋出錯誤
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Bare semver range
|
|
99
|
+
* // 純 semver 範圍
|
|
100
|
+
* _getNpaResult('^4.0.0');
|
|
101
|
+
* // => IResult { type: 'range', name: '@fake/fake', rawSpec: '^4.0.0', ... }
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* // Package with version
|
|
105
|
+
* // 帶版本的套件
|
|
106
|
+
* _getNpaResult('lodash@^4.0.0');
|
|
107
|
+
* // => IResult { type: 'range', name: 'lodash', rawSpec: '^4.0.0', ... }
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* // Empty string
|
|
111
|
+
* // 空字串
|
|
112
|
+
* _getNpaResult('');
|
|
113
|
+
* // => IResult { type: 'range', name: '@fake/fake', rawSpec: '', ... }
|
|
114
|
+
*/
|
|
3
115
|
export declare function _getNpaResult(value: string): IResult;
|
|
116
|
+
/**
|
|
117
|
+
* Normalize a dependency value string to standard format
|
|
118
|
+
* 將依賴值字串正規化為標準格式
|
|
119
|
+
*
|
|
120
|
+
* This is the main entry point that combines parsing and normalization
|
|
121
|
+
* into a single operation. It handles all the edge cases tested in
|
|
122
|
+
* space.spec.ts including empty strings, spaces, and star wildcards.
|
|
123
|
+
*
|
|
124
|
+
* 這是主要入口點,將解析和正規化合併為單一操作。
|
|
125
|
+
* 處理 space.spec.ts 中測試的所有邊緣情況,包括空字串、空格和星號萬用字元。
|
|
126
|
+
*
|
|
127
|
+
* @param {string} value - The dependency value to normalize / 要正規化的依賴值
|
|
128
|
+
*
|
|
129
|
+
* @returns {string} Normalized dependency value / 正規化的依賴值
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* // Empty string becomes star
|
|
133
|
+
* // 空字串變為星號
|
|
134
|
+
* normalizeDepsValue('');
|
|
135
|
+
* // => "*"
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* // Space becomes star
|
|
139
|
+
* // 空格變為星號
|
|
140
|
+
* normalizeDepsValue(' ');
|
|
141
|
+
* // => "*"
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Star remains star
|
|
145
|
+
* // 星號保持為星號
|
|
146
|
+
* normalizeDepsValue('*');
|
|
147
|
+
* // => "*"
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // Semver range is normalized
|
|
151
|
+
* // Semver 範圍被正規化
|
|
152
|
+
* normalizeDepsValue('>=1.0.0 <2.0.0');
|
|
153
|
+
* // => ">=1.0.0 <2.0.0"
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* // Package@version returns version
|
|
157
|
+
* // Package@version 返回版本
|
|
158
|
+
* normalizeDepsValue('lodash@^4.0.0');
|
|
159
|
+
* // => "^4.0.0"
|
|
160
|
+
*/
|
|
4
161
|
export declare function normalizeDepsValue(value: string): string;
|
|
5
162
|
export default normalizeDepsValue;
|
package/index.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Normalize dependency values to standardized semver format
|
|
4
|
+
* @description 將依賴值正規化為標準化的 semver 格式
|
|
5
|
+
*
|
|
6
|
+
* This module provides utilities to normalize various dependency value formats
|
|
7
|
+
* into a standardized semver string. It handles edge cases like empty inputs,
|
|
8
|
+
* spaces, star wildcards, and complex semver ranges.
|
|
9
|
+
*
|
|
10
|
+
* 本模組提供將各種依賴值格式正規化為標準化 semver 字串的工具。
|
|
11
|
+
* 處理邊緣情況,如空輸入、空格、星號萬用字元和複雜的 semver 範圍。
|
|
12
|
+
*
|
|
13
|
+
* @module @yarn-tool/normalize-deps-value
|
|
14
|
+
*/
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.normalizeResultToDepsValue = normalizeResultToDepsValue;
|
|
4
17
|
exports._getNpaResult = _getNpaResult;
|
|
@@ -8,42 +21,195 @@ const buildRangeSet_1 = require("@lazy-node/semver-ampersand/lib/range/buildRang
|
|
|
8
21
|
const stringifyRangeSet_1 = require("@lazy-node/semver-ampersand/lib/range/stringifyRangeSet");
|
|
9
22
|
const toRangeString_1 = require("@lazy-node/semver-ampersand/lib/range/toRangeString");
|
|
10
23
|
const Range_1 = require("@lazy-node/semver-ampersand/lib/Range");
|
|
24
|
+
const detect_1 = require("@yarn-tool/npm-package-arg-util/lib/detect");
|
|
25
|
+
/**
|
|
26
|
+
* Fake package name used for parsing bare semver strings
|
|
27
|
+
* 用於解析純 semver 字串的虛假套件名稱
|
|
28
|
+
*
|
|
29
|
+
* When a user provides just a version string (e.g., "^4.0.0") without a package name,
|
|
30
|
+
* we prepend this fake name to make it parseable by npm-package-arg.
|
|
31
|
+
*
|
|
32
|
+
* 當使用者只提供版本字串(例如:"^4.0.0")而沒有套件名稱時,
|
|
33
|
+
* 我們會加上這個虛假名稱使其能被 npm-package-arg 解析。
|
|
34
|
+
*/
|
|
11
35
|
const FAKE_NAME = '@fake/fake';
|
|
36
|
+
/**
|
|
37
|
+
* Normalize an npm-package-arg result to a dependency value string
|
|
38
|
+
* 將 npm-package-arg 結果正規化為依賴值字串
|
|
39
|
+
*
|
|
40
|
+
* This function converts an npm-package-arg result into a standardized
|
|
41
|
+
* dependency value string suitable for package.json. It handles:
|
|
42
|
+
* - Empty/space inputs (returns "*")
|
|
43
|
+
* - Range normalization using semver-ampersand
|
|
44
|
+
* - Tag handling with special cases
|
|
45
|
+
* - Direct passthrough for other types
|
|
46
|
+
*
|
|
47
|
+
* 此函數將 npm-package-arg 結果轉換為適合 package.json 的標準化依賴值字串。
|
|
48
|
+
* 處理:
|
|
49
|
+
* - 空/空格輸入(返回 "*")
|
|
50
|
+
* - 使用 semver-ampersand 進行範圍正規化
|
|
51
|
+
* - 標籤的特殊情況處理
|
|
52
|
+
* - 其他類型的直接傳遞
|
|
53
|
+
*
|
|
54
|
+
* @param {ReturnType<typeof _getNpaResult>} result - The npm-package-arg result or string to normalize / 要正規化的 npm-package-arg 結果或字串
|
|
55
|
+
*
|
|
56
|
+
* @returns {string} Normalized dependency value (e.g., "*", "^4.0.0", "1.2.3") / 正規化的依賴值(例如:"*"、"^4.0.0"、"1.2.3")
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Empty input
|
|
60
|
+
* // 空輸入
|
|
61
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: '', ... });
|
|
62
|
+
* // => "*"
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Space input
|
|
66
|
+
* // 空格輸入
|
|
67
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: ' ', ... });
|
|
68
|
+
* // => "*"
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* // Star wildcard
|
|
72
|
+
* // 星號萬用字元
|
|
73
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: '*', ... });
|
|
74
|
+
* // => "*"
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* // Range normalization
|
|
78
|
+
* // 範圍正規化
|
|
79
|
+
* normalizeResultToDepsValue({ type: 'range', rawSpec: '>=1.0.0 <2.0.0', ... });
|
|
80
|
+
* // => ">=1.0.0 <2.0.0" (normalized via semver-ampersand)
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* // Tag as package name only
|
|
84
|
+
* // 僅作為套件名稱的標籤
|
|
85
|
+
* normalizeResultToDepsValue({ type: 'tag', name: 'lodash', rawSpec: '*', raw: 'lodash' });
|
|
86
|
+
* // => "lodash"
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* // Direct passthrough
|
|
90
|
+
* // 直接傳遞
|
|
91
|
+
* normalizeResultToDepsValue({ type: 'version', rawSpec: '4.17.21', ... });
|
|
92
|
+
* // => "4.17.21"
|
|
93
|
+
*/
|
|
12
94
|
function normalizeResultToDepsValue(result) {
|
|
13
95
|
let value;
|
|
96
|
+
// String input: use directly
|
|
97
|
+
// 字串輸入:直接使用
|
|
14
98
|
if (typeof result === 'string') {
|
|
15
99
|
value = result;
|
|
16
100
|
}
|
|
101
|
+
// Object result: process based on type
|
|
102
|
+
// 物件結果:根據類型處理
|
|
17
103
|
else if (result) {
|
|
104
|
+
/**
|
|
105
|
+
* Range type: requires special normalization
|
|
106
|
+
* Range 類型:需要特殊正規化
|
|
107
|
+
*/
|
|
18
108
|
if (result.type === 'range') {
|
|
19
|
-
|
|
20
|
-
|
|
109
|
+
// Empty/space/star input: return ANY (which becomes STAR)
|
|
110
|
+
// 空/空格/星號輸入:返回 ANY(會變成 STAR)
|
|
111
|
+
if ((0, detect_1.isInputSpecIsEmpty)(result)) {
|
|
112
|
+
value = "" /* EnumSemverVersion.ANY */;
|
|
113
|
+
}
|
|
114
|
+
// Non-empty range: normalize through semver-ampersand
|
|
115
|
+
// 非空範圍:透過 semver-ampersand 正規化
|
|
116
|
+
else {
|
|
117
|
+
const rangeSet = (0, buildRangeSet_1.buildRangeSet)(result.rawSpec);
|
|
118
|
+
value = (0, toRangeString_1.toRangeString)((0, stringifyRangeSet_1.stringifyRangeSet)(rangeSet));
|
|
119
|
+
}
|
|
21
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Tag type with ANY spec (like "*") and not fake@ pattern:
|
|
123
|
+
* return just the package name
|
|
124
|
+
* Tag 類型且規格為 ANY(如 "*")且不是 fake@ 模式:
|
|
125
|
+
* 僅返回套件名稱
|
|
126
|
+
*/
|
|
22
127
|
else if (result.type === 'tag' && result.rawSpec === "" /* EnumSemverVersion.ANY */ && result.raw !== `${FAKE_NAME}@`) {
|
|
23
128
|
value = result.name;
|
|
24
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* All other types: use rawSpec directly
|
|
132
|
+
* 所有其他類型:直接使用 rawSpec
|
|
133
|
+
*/
|
|
25
134
|
else {
|
|
26
135
|
value = result.rawSpec;
|
|
27
136
|
}
|
|
28
137
|
}
|
|
138
|
+
// Convert ANY to undefined (will fallback to STAR)
|
|
139
|
+
// 將 ANY 轉換為 undefined(會回退到 STAR)
|
|
29
140
|
if (value === "" /* EnumSemverVersion.ANY */) {
|
|
30
141
|
value = void 0;
|
|
31
142
|
}
|
|
143
|
+
// Return value or default to STAR wildcard
|
|
144
|
+
// 返回值或預設為 STAR 萬用字元
|
|
32
145
|
return value !== null && value !== void 0 ? value : "*" /* EnumSemverVersion.STAR */;
|
|
33
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Parse a value string into an npm-package-arg result
|
|
149
|
+
* 將值字串解析為 npm-package-arg 結果
|
|
150
|
+
*
|
|
151
|
+
* This function attempts to parse a dependency value string using multiple strategies:
|
|
152
|
+
* 1. Try as semver range with fake package name (for bare version strings like "^4.0.0")
|
|
153
|
+
* 2. Try as full package spec (for "package@version" format)
|
|
154
|
+
* 3. Try with noThrowError flag (for edge cases)
|
|
155
|
+
*
|
|
156
|
+
* 此函數嘗試使用多種策略解析依賴值字串:
|
|
157
|
+
* 1. 嘗試作為帶虛假套件名稱的 semver 範圍(用於純版本字串如 "^4.0.0")
|
|
158
|
+
* 2. 嘗試作為完整套件規格(用於 "package@version" 格式)
|
|
159
|
+
* 3. 嘗試使用 noThrowError 標誌(用於邊緣情況)
|
|
160
|
+
*
|
|
161
|
+
* @param {string} value - The dependency value string to parse
|
|
162
|
+
* @param {string} value - 要解析的依賴值字串
|
|
163
|
+
*
|
|
164
|
+
* @returns {IResult} Parsed npm-package-arg result
|
|
165
|
+
* @returns {IResult} 解析後的 npm-package-arg 結果
|
|
166
|
+
*
|
|
167
|
+
* @throws {Error} Throws if all parsing strategies fail
|
|
168
|
+
* @throws {Error} 如果所有解析策略都失敗則拋出錯誤
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* // Bare semver range
|
|
172
|
+
* // 純 semver 範圍
|
|
173
|
+
* _getNpaResult('^4.0.0');
|
|
174
|
+
* // => IResult { type: 'range', name: '@fake/fake', rawSpec: '^4.0.0', ... }
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* // Package with version
|
|
178
|
+
* // 帶版本的套件
|
|
179
|
+
* _getNpaResult('lodash@^4.0.0');
|
|
180
|
+
* // => IResult { type: 'range', name: 'lodash', rawSpec: '^4.0.0', ... }
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* // Empty string
|
|
184
|
+
* // 空字串
|
|
185
|
+
* _getNpaResult('');
|
|
186
|
+
* // => IResult { type: 'range', name: '@fake/fake', rawSpec: '', ... }
|
|
187
|
+
*/
|
|
34
188
|
function _getNpaResult(value) {
|
|
35
189
|
let result;
|
|
190
|
+
// Strategy 1: Parse as semver range with fake name
|
|
191
|
+
// 策略 1:作為帶虛假名稱的 semver 範圍解析
|
|
36
192
|
try {
|
|
37
193
|
let sr = new Range_1.SemverRange(value);
|
|
38
194
|
result = (0, npm_package_arg_util_1.npa)(`${FAKE_NAME}@${value}`);
|
|
39
195
|
}
|
|
196
|
+
// Strategy 2: Parse as full package spec
|
|
197
|
+
// 策略 2:作為完整套件規格解析
|
|
40
198
|
catch (e) {
|
|
41
199
|
try {
|
|
42
200
|
result = (0, npm_package_arg_util_1.npa)(`${value}`);
|
|
43
201
|
}
|
|
202
|
+
// Strategy 3: Parse with noThrowError flag
|
|
203
|
+
// 策略 3:使用 noThrowError 標誌解析
|
|
44
204
|
catch (e) {
|
|
45
205
|
try {
|
|
46
|
-
result = (0, npm_package_arg_util_1.npa)(`${FAKE_NAME}@${value}
|
|
206
|
+
result = (0, npm_package_arg_util_1.npa)(`${FAKE_NAME}@${value}`, {
|
|
207
|
+
noThrowError: true,
|
|
208
|
+
});
|
|
209
|
+
// Type check for range (appears to be validation placeholder)
|
|
210
|
+
// 範圍類型檢查(似乎是驗證預留位置)
|
|
211
|
+
if (result.type === 'range') {
|
|
212
|
+
}
|
|
47
213
|
}
|
|
48
214
|
catch (e2) {
|
|
49
215
|
throw e;
|
|
@@ -52,6 +218,51 @@ function _getNpaResult(value) {
|
|
|
52
218
|
}
|
|
53
219
|
return result;
|
|
54
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Normalize a dependency value string to standard format
|
|
223
|
+
* 將依賴值字串正規化為標準格式
|
|
224
|
+
*
|
|
225
|
+
* This is the main entry point that combines parsing and normalization
|
|
226
|
+
* into a single operation. It handles all the edge cases tested in
|
|
227
|
+
* space.spec.ts including empty strings, spaces, and star wildcards.
|
|
228
|
+
*
|
|
229
|
+
* 這是主要入口點,將解析和正規化合併為單一操作。
|
|
230
|
+
* 處理 space.spec.ts 中測試的所有邊緣情況,包括空字串、空格和星號萬用字元。
|
|
231
|
+
*
|
|
232
|
+
* @param {string} value - The dependency value to normalize / 要正規化的依賴值
|
|
233
|
+
*
|
|
234
|
+
* @returns {string} Normalized dependency value / 正規化的依賴值
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* // Empty string becomes star
|
|
238
|
+
* // 空字串變為星號
|
|
239
|
+
* normalizeDepsValue('');
|
|
240
|
+
* // => "*"
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* // Space becomes star
|
|
244
|
+
* // 空格變為星號
|
|
245
|
+
* normalizeDepsValue(' ');
|
|
246
|
+
* // => "*"
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* // Star remains star
|
|
250
|
+
* // 星號保持為星號
|
|
251
|
+
* normalizeDepsValue('*');
|
|
252
|
+
* // => "*"
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* // Semver range is normalized
|
|
256
|
+
* // Semver 範圍被正規化
|
|
257
|
+
* normalizeDepsValue('>=1.0.0 <2.0.0');
|
|
258
|
+
* // => ">=1.0.0 <2.0.0"
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* // Package@version returns version
|
|
262
|
+
* // Package@version 返回版本
|
|
263
|
+
* normalizeDepsValue('lodash@^4.0.0');
|
|
264
|
+
* // => "^4.0.0"
|
|
265
|
+
*/
|
|
55
266
|
function normalizeDepsValue(value) {
|
|
56
267
|
const result = _getNpaResult(value);
|
|
57
268
|
return normalizeResultToDepsValue(result);
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AASA,gEA6BC;AAED,sCA6BC;AAED,gDAIC;AA3ED,0EAA+D;AAC/D,uFAAoF;AACpF,+FAA4F;AAC5F,uFAAoF;AAEpF,iEAAoE;AAEpE,MAAM,SAAS,GAAG,YAAqB,CAAA;AAEvC,SAAgB,0BAA0B,CAAC,MAAwC;IAElF,IAAI,KAAa,CAAC;IAClB,IAAI,OAAO,MAAM,KAAK,QAAQ,EAC9B,CAAC;QACA,KAAK,GAAG,MAAM,CAAC;IAChB,CAAC;SACI,IAAI,MAAM,EACf,CAAC;QACA,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAC3B,CAAC;YACA,MAAM,QAAQ,GAAG,IAAA,6BAAa,EAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC/C,KAAK,GAAG,IAAA,6BAAa,EAAC,IAAA,qCAAiB,EAAC,QAAQ,CAAC,CAAC,CAAA;QACnD,CAAC;aACI,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,MAAM,CAAC,OAAO,mCAA0B,IAAI,MAAM,CAAC,GAAG,KAAK,GAAG,SAAS,GAAG,EAC5G,CAAC;YACA,KAAK,GAAG,MAAM,CAAC,IAAI,CAAA;QACpB,CAAC;aAED,CAAC;YACA,KAAK,GAAG,MAAM,CAAC,OAAO,CAAA;QACvB,CAAC;IACF,CAAC;IACD,IAAI,KAAK,mCAA0B,EACnC,CAAC;QACA,KAAK,GAAG,KAAK,CAAC,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,mCAA0B,CAAA;AACvC,CAAC;AAED,SAAgB,aAAa,CAAC,KAAa;IAE1C,IAAI,MAAwB,CAAC;IAE7B,IACA,CAAC;QACA,IAAI,EAAE,GAAG,IAAI,mBAAW,CAAC,KAAK,CAAC,CAAC;QAChC,MAAM,GAAG,IAAA,0BAAG,EAAC,GAAG,SAAS,IAAI,KAAK,EAAE,CAAC,CAAA;IACtC,CAAC;IACD,OAAO,CAAC,EACR,CAAC;QACA,IACA,CAAC;YACA,MAAM,GAAG,IAAA,0BAAG,EAAC,GAAG,KAAK,EAAE,CAAC,CAAA;QACzB,CAAC;QACD,OAAO,CAAC,EACR,CAAC;YACA,IACA,CAAC;gBACA,MAAM,GAAG,IAAA,0BAAG,EAAC,GAAG,SAAS,IAAI,KAAK,EAAE,CAAC,CAAA;YACtC,CAAC;YACD,OAAO,EAAE,EACT,CAAC;gBACA,MAAM,CAAC,CAAA;YACR,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC;AAED,SAAgB,kBAAkB,CAAC,KAAa;IAE/C,MAAM,MAAM,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,0BAA0B,CAAC,MAAM,CAAC,CAAA;AAC1C,CAAC;AAED,kBAAe,kBAAkB,CAAA","sourcesContent":["import { 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';\n\nconst FAKE_NAME = '@fake/fake' as const\n\nexport function normalizeResultToDepsValue(result: ReturnType<typeof _getNpaResult>)\n{\n\tlet value: string;\n\tif (typeof result === 'string')\n\t{\n\t\tvalue = result;\n\t}\n\telse if (result)\n\t{\n\t\tif (result.type === 'range')\n\t\t{\n\t\t\tconst rangeSet = buildRangeSet(result.rawSpec);\n\t\t\tvalue = toRangeString(stringifyRangeSet(rangeSet))\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\telse\n\t\t{\n\t\t\tvalue = result.rawSpec\n\t\t}\n\t}\n\tif (value === EnumSemverVersion.ANY)\n\t{\n\t\tvalue = void 0;\n\t}\n\n\treturn value ?? EnumSemverVersion.STAR\n}\n\nexport function _getNpaResult(value: string)\n{\n\tlet result: IResult | string;\n\n\ttry\n\t{\n\t\tlet sr = new SemverRange(value);\n\t\tresult = npa(`${FAKE_NAME}@${value}`)\n\t}\n\tcatch (e)\n\t{\n\t\ttry\n\t\t{\n\t\t\tresult = npa(`${value}`)\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}\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\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":"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","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"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/normalize-deps-value",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "2.0.6",
|
|
4
|
+
"description": "Normalize dependency values to standardized semver format / 將依賴值正規化為標準化的 semver 格式",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yarn",
|
|
7
7
|
"yarn-tool",
|
|
@@ -72,13 +72,12 @@
|
|
|
72
72
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@lazy-node/semver-ampersand": "^3.0.
|
|
76
|
-
"@yarn-tool/npm-package-arg-util": "^2.0.
|
|
75
|
+
"@lazy-node/semver-ampersand": "^3.0.8",
|
|
76
|
+
"@yarn-tool/npm-package-arg-util": "^2.0.5",
|
|
77
77
|
"tslib": ">=2"
|
|
78
78
|
},
|
|
79
|
-
"packageManager": "yarn@1.22.19",
|
|
80
79
|
"publishConfig": {
|
|
81
80
|
"access": "public"
|
|
82
81
|
},
|
|
83
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "ca3fae2bbdf31ed1ce9bab14793912026200767e"
|
|
84
83
|
}
|