@yarn-tool/npa-to-deps 3.0.7 → 3.0.9
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 +52 -0
- package/README.md +35 -20
- package/index.d.ts +12 -5
- package/index.js +71 -21
- package/index.js.map +1 -1
- package/package.json +14 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,58 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.0.9](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/npa-to-deps@3.0.8...@yarn-tool/npa-to-deps@3.0.9) (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
|
+
|
|
38
|
+
## [3.0.8](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/npa-to-deps@3.0.7...@yarn-tool/npa-to-deps@3.0.8) (2026-09-06)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### 🛠 Build System
|
|
43
|
+
|
|
44
|
+
* update Static Files ([b2f5d72](https://github.com/bluelovers/ws-yarn-workspaces/commit/b2f5d7216773c53eb35f267ba34f8788543d46a1))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
### ♻️ Chores
|
|
48
|
+
|
|
49
|
+
* **workspace:** 將所有套件的指令從 yarn 改為 pnpm 並更新依賴版本 ([0505892](https://github.com/bluelovers/ws-yarn-workspaces/commit/0505892e5e7c356f8cf59495fefda1aa681499c6))
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### 🔖 Miscellaneous
|
|
53
|
+
|
|
54
|
+
* . ([b545589](https://github.com/bluelovers/ws-yarn-workspaces/commit/b54558925d67304019e2b4f9bb3c4671c429a96e))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
6
58
|
## [3.0.7](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/npa-to-deps@3.0.6...@yarn-tool/npa-to-deps@3.0.7) (2026-04-26)
|
|
7
59
|
|
|
8
60
|
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Convert npm-package-arg (npa) parsing results to standardized dependency value o
|
|
|
9
9
|
- Converts npm-package-arg results to standardized dependency objects / 將 npm-package-arg 結果轉換為標準化的依賴物件
|
|
10
10
|
- Supports options for preserving tags and ranges / 支援保留標籤和範圍的選項
|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Installation / 安裝
|
|
13
13
|
|
|
14
14
|
```bash
|
|
15
15
|
yarn add @yarn-tool/npa-to-deps
|
|
@@ -28,9 +28,10 @@ import { npa } from '@yarn-tool/npm-package-arg-util';
|
|
|
28
28
|
const deps = npaToDepsValue('lodash@^4.17.0');
|
|
29
29
|
// => { name: 'lodash', operator: '^', fetchQuery: true, result: ... }
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
const
|
|
31
|
+
// Keep the tag by passing options to npaResultToDepsValue
|
|
32
|
+
// 保留標籤:選項需傳給 npaResultToDepsValue
|
|
33
|
+
const tagResult = npa('lodash@latest');
|
|
34
|
+
const tagDeps = npaResultToDepsValue(tagResult, { preserveTag: true });
|
|
34
35
|
// => { name: 'lodash', semver: 'latest', result: ... }
|
|
35
36
|
|
|
36
37
|
// Convert existing npa result
|
|
@@ -40,7 +41,7 @@ const gitDeps = npaResultToDepsValue(result);
|
|
|
40
41
|
// => { name: 'repo', semver: 'github:user/repo#branch', result: ... }
|
|
41
42
|
```
|
|
42
43
|
|
|
43
|
-
## API / API 文件
|
|
44
|
+
## API Documentation / API 文件
|
|
44
45
|
|
|
45
46
|
### `npaToDepsValue<T>(arg: string, options?: IOptions): IDepsResult<T>`
|
|
46
47
|
|
|
@@ -51,8 +52,9 @@ Parse a package argument string and convert to dependency value.
|
|
|
51
52
|
- `arg` - The package argument string to parse / 要解析的套件參數字串
|
|
52
53
|
- `options` - Parsing and conversion options / 解析和轉換選項
|
|
53
54
|
- `where` - Base directory for resolving relative paths / 解析相對路徑的基礎目錄
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
> **注意 / Note:** 此函式目前僅會使用 `where`;`preserveTag` 與 `preserveRange` 請改用下方的 `npaResultToDepsValue`(詳見 Configuration 章節)。
|
|
57
|
+
> This function currently only uses `where`; use `npaResultToDepsValue` below for `preserveTag` / `preserveRange` (see the Configuration section).
|
|
56
58
|
|
|
57
59
|
**Returns / 返回:**
|
|
58
60
|
- Standardized dependency value object / 標準化的依賴值物件
|
|
@@ -66,16 +68,6 @@ Convert an npm-package-arg result to a dependency value object.
|
|
|
66
68
|
- `result` - The npm-package-arg parsing result / npm-package-arg 解析結果
|
|
67
69
|
- `options` - Conversion options / 轉換選項
|
|
68
70
|
|
|
69
|
-
### `IOptions` Interface
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
interface IOptions {
|
|
73
|
-
where?: string; // Base directory for resolving relative paths
|
|
74
|
-
preserveTag?: boolean; // Preserve tag instead of converting to ^
|
|
75
|
-
preserveRange?: boolean; // Preserve original range
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
71
|
### `IDepsResult<T>` Interface
|
|
80
72
|
|
|
81
73
|
```typescript
|
|
@@ -88,6 +80,28 @@ interface IDepsResult<T> {
|
|
|
88
80
|
}
|
|
89
81
|
```
|
|
90
82
|
|
|
83
|
+
## Configuration / 設定
|
|
84
|
+
|
|
85
|
+
`npaToDepsValue` 與 `npaResultToDepsValue` 皆接受同一組選項物件 (Options),用來控制解析與轉換的行為。
|
|
86
|
+
Both `npaToDepsValue` and `npaResultToDepsValue` accept the same options object to control parsing and conversion behavior.
|
|
87
|
+
|
|
88
|
+
> **注意 / Note:** `npaToDepsValue` 目前只會使用 `where`(傳給 npa 解析),`preserveTag` 與 `preserveRange` 需直接呼叫 `npaResultToDepsValue` 才會生效。
|
|
89
|
+
> `npaToDepsValue` currently only uses `where` (passed to npa parsing); call `npaResultToDepsValue` directly to apply `preserveTag` / `preserveRange`.
|
|
90
|
+
|
|
91
|
+
### `IOptions` Interface
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
interface IOptions {
|
|
95
|
+
where?: string; // Base directory for resolving relative paths / 解析相對路徑的基礎目錄
|
|
96
|
+
preserveTag?: boolean; // Preserve tag instead of converting to ^ / 保留標籤而不是轉換為 ^
|
|
97
|
+
preserveRange?: boolean; // Preserve original range / 保留原始範圍
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- `where` - Base directory for resolving relative paths / 解析相對路徑的基礎目錄
|
|
102
|
+
- `preserveTag` - Preserve tag instead of converting to ^ / 保留標籤而不是轉換為 ^
|
|
103
|
+
- `preserveRange` - Preserve original range instead of normalizing / 保留原始範圍而不是正規化
|
|
104
|
+
|
|
91
105
|
## Examples / 範例
|
|
92
106
|
|
|
93
107
|
### Git Repository / Git 儲存庫
|
|
@@ -106,9 +120,9 @@ npaResultToDepsValue(result);
|
|
|
106
120
|
npaToDepsValue('lodash@latest');
|
|
107
121
|
// => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
108
122
|
|
|
109
|
-
// Preserve tag
|
|
110
|
-
// 保留標籤
|
|
111
|
-
|
|
123
|
+
// Preserve tag - pass options to npaResultToDepsValue
|
|
124
|
+
// 保留標籤 - 選項傳給 npaResultToDepsValue
|
|
125
|
+
npaResultToDepsValue(npa('lodash@latest'), { preserveTag: true });
|
|
112
126
|
// => { name: 'lodash', semver: 'latest', ... }
|
|
113
127
|
```
|
|
114
128
|
|
|
@@ -133,6 +147,7 @@ npaToDepsValue('lodash@4.17.21');
|
|
|
133
147
|
|
|
134
148
|
- [@yarn-tool/npm-package-arg-util](../npm-package-arg-util) - npm-package-arg utilities
|
|
135
149
|
- [@yarn-tool/normalize-deps-value](../normalize-deps-value) - Normalize dependency values
|
|
150
|
+
- [npm-package-arg 特殊輸入狀況說明](../../../docs/npm-package-arg-special-cases.md) - Special input cases (empty string, space, `*`) and how they are detected / npm-package-arg 特殊輸入(空字串、空格、`*`)的行為與偵測方式
|
|
136
151
|
|
|
137
152
|
## License / 授權
|
|
138
153
|
|
package/index.d.ts
CHANGED
|
@@ -28,11 +28,17 @@ export interface IOptions {
|
|
|
28
28
|
/**
|
|
29
29
|
* When input is a tag (e.g., "latest", "beta"), preserve it instead of converting to ^
|
|
30
30
|
* 當輸入是標籤(例如:"latest"、"beta")時,保留它而不是轉換為 ^
|
|
31
|
+
*
|
|
32
|
+
* Only effective when called through npaResultToDepsValue
|
|
33
|
+
* 僅在透過 npaResultToDepsValue 呼叫時生效
|
|
31
34
|
*/
|
|
32
35
|
preserveTag?: boolean;
|
|
33
36
|
/**
|
|
34
37
|
* When input is a range, preserve the original range instead of normalizing it
|
|
35
38
|
* 當輸入是範圍時,保留原始範圍而不是正規化它
|
|
39
|
+
*
|
|
40
|
+
* Only effective when called through npaResultToDepsValue
|
|
41
|
+
* 僅在透過 npaResultToDepsValue 呼叫時生效
|
|
36
42
|
*/
|
|
37
43
|
preserveRange?: boolean;
|
|
38
44
|
}
|
|
@@ -140,7 +146,7 @@ export declare function npaResultToDepsValue<T extends IResult>(result: T, optio
|
|
|
140
146
|
*
|
|
141
147
|
* @param {string} arg - The package argument string to parse / 要解析的套件參數字串
|
|
142
148
|
*
|
|
143
|
-
* @param {IOptions} [options] - Parsing and conversion options /
|
|
149
|
+
* @param {IOptions} [options] - Parsing and conversion options; only `where` is forwarded / 解析與轉換選項;僅 `where` 會被傳遞
|
|
144
150
|
*
|
|
145
151
|
* @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件
|
|
146
152
|
*
|
|
@@ -151,10 +157,11 @@ export declare function npaResultToDepsValue<T extends IResult>(result: T, optio
|
|
|
151
157
|
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
152
158
|
*
|
|
153
159
|
* @example
|
|
154
|
-
* //
|
|
155
|
-
* //
|
|
156
|
-
*
|
|
157
|
-
* //
|
|
160
|
+
* // `where` as base directory for relative paths;
|
|
161
|
+
* // `preserveTag` / `preserveRange` must be passed to npaResultToDepsValue instead
|
|
162
|
+
* // `where` 作為相對路徑的基礎目錄;
|
|
163
|
+
* // `preserveTag` / `preserveRange` 需改傳給 npaResultToDepsValue
|
|
164
|
+
* npaToDepsValue('./local-pkg', { where: '/path/to/base' });
|
|
158
165
|
*/
|
|
159
166
|
export declare function npaToDepsValue<T extends IResult = IResult>(arg: string, options?: IOptions): IDepsResult<T>;
|
|
160
167
|
export default npaToDepsValue;
|
package/index.js
CHANGED
|
@@ -74,6 +74,13 @@ const detect_1 = require("@yarn-tool/npm-package-arg-util/lib/detect");
|
|
|
74
74
|
*/
|
|
75
75
|
function npaResultToDepsValue(result, options) {
|
|
76
76
|
var _a, _b, _c;
|
|
77
|
+
/**
|
|
78
|
+
* 依 result.type 分別填入的依賴值欄位;未被賦值者維持 undefined,
|
|
79
|
+
* 用來區分「以 operator 簡寫表達」與「以完整 semver 字串表達」兩種依賴寫法
|
|
80
|
+
*
|
|
81
|
+
* Dependency fields assigned per `result.type`; fields never assigned stay `undefined`
|
|
82
|
+
* to distinguish the operator shorthand form from the full semver string form
|
|
83
|
+
*/
|
|
77
84
|
let semver;
|
|
78
85
|
let operator;
|
|
79
86
|
let fetchQuery;
|
|
@@ -90,6 +97,13 @@ function npaResultToDepsValue(result, options) {
|
|
|
90
97
|
* 標籤類型:根據 preserveTag 選項處理
|
|
91
98
|
*/
|
|
92
99
|
case 'tag':
|
|
100
|
+
/**
|
|
101
|
+
* 必須同時滿足 fetchSpec 非空才保留標籤,避免空標籤被寫入依賴值;
|
|
102
|
+
* 未保留時則退回 ^ 並標記需向 registry 查詢
|
|
103
|
+
*
|
|
104
|
+
* Keep the tag only when `fetchSpec` is non-empty, so an empty tag never leaks
|
|
105
|
+
* into the dependency value; otherwise fall back to `^` and flag a registry lookup
|
|
106
|
+
*/
|
|
93
107
|
if (((_a = result.fetchSpec) === null || _a === void 0 ? void 0 : _a.length) && (options === null || options === void 0 ? void 0 : options.preserveTag)) {
|
|
94
108
|
semver = result.fetchSpec;
|
|
95
109
|
}
|
|
@@ -103,53 +117,81 @@ function npaResultToDepsValue(result, options) {
|
|
|
103
117
|
* 範圍類型:根據範圍結構進行複雜處理
|
|
104
118
|
*/
|
|
105
119
|
case 'range':
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
/**
|
|
121
|
+
* 空輸入規格、或輸入只有套件名稱而未指定版本(例如 "lodash"、"lodash@"):
|
|
122
|
+
* 此時不寫入 semver,改標記為需要向 registry 查詢
|
|
123
|
+
*
|
|
124
|
+
* Empty input spec, or input that only names the package without a version
|
|
125
|
+
* (e.g. "lodash", "lodash@"): skip `semver` and flag a registry query instead
|
|
126
|
+
*/
|
|
108
127
|
if ((0, detect_1.isInputSpecIsEmpty)(result) || (0, detect_1.isNameSameAsRaw)(result)) {
|
|
109
128
|
semver = void 0;
|
|
110
129
|
fetchQuery = true;
|
|
111
130
|
}
|
|
112
131
|
else if ((_b = result.fetchSpec) === null || _b === void 0 ? void 0 : _b.length) {
|
|
132
|
+
/**
|
|
133
|
+
* 先把範圍拆解成多個單一條件項目,才能判斷能否簡化成 operator 簡寫
|
|
134
|
+
* Split the range into individual clauses first, to decide whether it can be
|
|
135
|
+
* reduced to an operator shorthand
|
|
136
|
+
*/
|
|
113
137
|
let ls = (0, parseSimpleSemVerRange_1.parseSimpleSemVerRange)(result.fetchSpec);
|
|
114
|
-
|
|
115
|
-
|
|
138
|
+
/**
|
|
139
|
+
* 多個範圍項目:保留原始值
|
|
140
|
+
* Multiple range entries: keep original
|
|
141
|
+
*/
|
|
116
142
|
if (ls.length > 1) {
|
|
117
143
|
semver = result.fetchSpec;
|
|
118
144
|
}
|
|
119
|
-
|
|
120
|
-
|
|
145
|
+
/**
|
|
146
|
+
* 保留範圍選項已設定:保留原始值
|
|
147
|
+
* Preserve range option is set: keep original
|
|
148
|
+
*/
|
|
121
149
|
else if (options === null || options === void 0 ? void 0 : options.preserveRange) {
|
|
122
150
|
semver = result.fetchSpec;
|
|
123
151
|
}
|
|
124
|
-
|
|
125
|
-
|
|
152
|
+
/**
|
|
153
|
+
* 單一項目:分析運算子
|
|
154
|
+
* Single entry: analyze operator
|
|
155
|
+
*/
|
|
126
156
|
else if (ls.length === 1) {
|
|
127
157
|
let entry = ls[0];
|
|
128
|
-
|
|
129
|
-
|
|
158
|
+
/**
|
|
159
|
+
* 無運算子:視為需要查詢的版本
|
|
160
|
+
* No operator: treat as version to query
|
|
161
|
+
*/
|
|
130
162
|
if (!entry.operator) {
|
|
131
163
|
semver = result.fetchSpec;
|
|
132
164
|
fetchQuery = true;
|
|
133
165
|
}
|
|
134
|
-
|
|
135
|
-
|
|
166
|
+
/**
|
|
167
|
+
* 非 ^ 運算子:保留原始規格
|
|
168
|
+
* Non-^ operator: keep original spec
|
|
169
|
+
*/
|
|
136
170
|
else if (entry.operator !== '^') {
|
|
137
171
|
semver = result.fetchSpec;
|
|
138
172
|
}
|
|
139
|
-
|
|
140
|
-
|
|
173
|
+
/**
|
|
174
|
+
* ^ 運算子:使用簡短形式
|
|
175
|
+
* ^ operator: use shorthand form
|
|
176
|
+
*/
|
|
141
177
|
else {
|
|
142
178
|
operator = '^';
|
|
143
179
|
fetchQuery = true;
|
|
144
180
|
}
|
|
145
181
|
}
|
|
146
|
-
|
|
147
|
-
|
|
182
|
+
/**
|
|
183
|
+
* 無有效項目:使用簡短形式
|
|
184
|
+
* No valid entries: use shorthand
|
|
185
|
+
*/
|
|
148
186
|
else {
|
|
149
187
|
operator = '^';
|
|
150
188
|
fetchQuery = true;
|
|
151
189
|
}
|
|
152
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* fetchSpec 為空:沒有具體範圍可保留,退回 ^ 並標記需查詢
|
|
193
|
+
* Empty fetchSpec: no concrete range to keep, fall back to `^` and flag a query
|
|
194
|
+
*/
|
|
153
195
|
else {
|
|
154
196
|
operator = '^';
|
|
155
197
|
fetchQuery = true;
|
|
@@ -186,7 +228,7 @@ function npaResultToDepsValue(result, options) {
|
|
|
186
228
|
*
|
|
187
229
|
* @param {string} arg - The package argument string to parse / 要解析的套件參數字串
|
|
188
230
|
*
|
|
189
|
-
* @param {IOptions} [options] - Parsing and conversion options /
|
|
231
|
+
* @param {IOptions} [options] - Parsing and conversion options; only `where` is forwarded / 解析與轉換選項;僅 `where` 會被傳遞
|
|
190
232
|
*
|
|
191
233
|
* @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件
|
|
192
234
|
*
|
|
@@ -197,13 +239,21 @@ function npaResultToDepsValue(result, options) {
|
|
|
197
239
|
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
198
240
|
*
|
|
199
241
|
* @example
|
|
200
|
-
* //
|
|
201
|
-
* //
|
|
202
|
-
*
|
|
203
|
-
* //
|
|
242
|
+
* // `where` as base directory for relative paths;
|
|
243
|
+
* // `preserveTag` / `preserveRange` must be passed to npaResultToDepsValue instead
|
|
244
|
+
* // `where` 作為相對路徑的基礎目錄;
|
|
245
|
+
* // `preserveTag` / `preserveRange` 需改傳給 npaResultToDepsValue
|
|
246
|
+
* npaToDepsValue('./local-pkg', { where: '/path/to/base' });
|
|
204
247
|
*/
|
|
205
248
|
function npaToDepsValue(arg, options) {
|
|
206
249
|
let result = (0, npm_package_arg_util_1.npa)(arg, options === null || options === void 0 ? void 0 : options.where);
|
|
250
|
+
/**
|
|
251
|
+
* 以 `as any` 略過 npa 回傳的寬鬆 union 型別;
|
|
252
|
+
* 實際分支由 npaResultToDepsValue 內的 result.type 決定,並涵蓋 default 情況
|
|
253
|
+
*
|
|
254
|
+
* Cast with `as any` to bypass npa's loose union return type;
|
|
255
|
+
* branching is decided by `result.type` inside npaResultToDepsValue, including the default case
|
|
256
|
+
*/
|
|
207
257
|
return npaResultToDepsValue(result);
|
|
208
258
|
}
|
|
209
259
|
exports.default = npaToDepsValue;
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAkIH,oDA8HC;AA+BD,wCAKC;AAlSD,0EAA4E;AAC5E,sGAAmG;AACnG,uEAAiG;AAwEjG;;;;;;;;;;;;;;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AAA,0BAAG,EAAC,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,CAAC;IAEtC,OAAO,oBAAoB,CAAI,MAAa,CAAC,CAAA;AAC9C,CAAC;AAED,kBAAe,cAAc,CAAA","sourcesContent":["/**\n * @fileoverview Convert npm-package-arg results to dependency values\n * @description 將 npm-package-arg 結果轉換為依賴值\n *\n * This module provides utilities to convert npm-package-arg (npa) parsing results\n * into standardized dependency value objects. It handles various input types\n * including git URLs, version tags, semver ranges, and local file paths.\n *\n * 本模組提供將 npm-package-arg (npa) 解析結果轉換為標準化依賴值物件的工具。\n * 處理各種輸入類型,包括 git URL、版本標籤、semver 範圍和本地檔案路徑。\n *\n * @module @yarn-tool/npa-to-deps\n */\n\nimport { IResult, IResultType, npa } from '@yarn-tool/npm-package-arg-util';\nimport { parseSimpleSemVerRange } from '@lazy-node/semver-simple-parse/lib/parseSimpleSemVerRange';\nimport { isInputSpecIsEmpty, isNameSameAsRaw } from '@yarn-tool/npm-package-arg-util/lib/detect';\n\n/**\n * Options for converting npm-package-arg results to dependency values\n * 轉換 npm-package-arg 結果為依賴值的選項\n *\n * @export\n * @interface IOptions\n */\nexport interface IOptions\n{\n\t/**\n\t * Base directory for resolving relative paths\n\t * 解析相對路徑的基礎目錄\n\t */\n\twhere?: string,\n\n\t/**\n\t * When input is a tag (e.g., \"latest\", \"beta\"), preserve it instead of converting to ^\n\t * 當輸入是標籤(例如:\"latest\"、\"beta\")時,保留它而不是轉換為 ^\n\t */\n\tpreserveTag?: boolean,\n\n\t/**\n\t * When input is a range, preserve the original range instead of normalizing it\n\t * 當輸入是範圍時,保留原始範圍而不是正規化它\n\t */\n\tpreserveRange?: boolean,\n}\n\n/**\n * Result of converting npm-package-arg result to dependency value\n * 將 npm-package-arg 結果轉換為依賴值的結果\n *\n * @export\n * @interface IDepsResult\n * @template T - The specific result type from npm-package-arg\n * @template T - npm-package-arg 的特定結果類型\n */\nexport interface IDepsResult<T extends IResult = IResult>\n{\n\t/**\n\t * Package name\n\t * 套件名稱\n\t */\n name: string;\n\n\t/**\n\t * Semantic version string or specification\n\t * 語義化版本字串或規格\n\t */\n semver?: string;\n\n\t/**\n\t * Version operator (e.g., \"^\", \"~\", \">=\")\n\t * 版本運算子(例如:\"^\"、\"~\"、\">=\")\n\t */\n operator?: string;\n\n\t/**\n\t * Whether to fetch from registry query\n\t * 是否要從 registry 查詢獲取\n\t */\n fetchQuery?: boolean;\n\n\t/**\n\t * Original npm-package-arg result\n\t * 原始的 npm-package-arg 結果\n\t */\n result: T;\n}\n\n/**\n * Convert an npm-package-arg result to a dependency value object\n * 將 npm-package-arg 結果轉換為依賴值物件\n *\n * This function takes a parsed npm-package-arg result and converts it into\n * a standardized dependency value format suitable for package.json dependencies.\n * It handles various result types including git, tags, ranges, versions, etc.\n *\n * 此函數接受解析後的 npm-package-arg 結果,並將其轉換為適合 package.json\n * 依賴項的標準化依賴值格式。處理各種結果類型,包括 git、標籤、範圍、版本等。\n *\n * @template T - The type of npm-package-arg result / npm-package-arg 結果的類型\n *\n * @param {T} result - The npm-package-arg parsing result / npm-package-arg 解析結果\n *\n * @param {IOptions} [options] - Conversion options / 轉換選項\n *\n * @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件\n *\n * @example\n * // Git repository\n * // Git 儲存庫\n * const result = npa('github:user/repo#branch');\n * npaResultToDepsValue(result);\n * // => { name: 'repo', semver: 'github:user/repo#branch', result: ... }\n *\n * @example\n * // Version tag with preserveTag\n * // 保留標籤的版本標籤\n * const result = npa('lodash@latest');\n * npaResultToDepsValue(result, { preserveTag: true });\n * // => { name: 'lodash', semver: 'latest', operator: undefined, ... }\n *\n * @example\n * // Version tag without preserveTag (default behavior)\n * // 不保留標籤的版本標籤(預設行為)\n * const result = npa('lodash@latest');\n * npaResultToDepsValue(result);\n * // => { name: 'lodash', operator: '^', fetchQuery: true, ... }\n *\n * @example\n * // Semver range with ^ operator\n * // 帶有 ^ 運算子的 semver 範圍\n * const result = npa('lodash@^4.17.0');\n * npaResultToDepsValue(result);\n * // => { name: 'lodash', operator: '^', fetchQuery: true, ... }\n *\n * @example\n * // Exact version\n * // 精確版本\n * const result = npa('lodash@4.17.21');\n * npaResultToDepsValue(result);\n * // => { name: 'lodash', semver: '4.17.21', ... }\n */\nexport function npaResultToDepsValue<T extends IResult>(result: T, options?: IOptions): IDepsResult<T>\n{\n\tlet semver: string;\n\tlet operator: string;\n\tlet fetchQuery: boolean;\n\n\tswitch (result.type as IResultType)\n\t{\n\t\t/**\n\t\t * Git type: use saveSpec as the semver value\n\t\t * Git 類型:使用 saveSpec 作為 semver 值\n\t\t */\n\t\tcase 'git':\n\t\t\tsemver = result.saveSpec\n\t\t\tbreak;\n\n\t\t/**\n\t\t * Tag type: handle based on preserveTag option\n\t\t * 標籤類型:根據 preserveTag 選項處理\n\t\t */\n\t\tcase 'tag':\n\t\t\tif (result.fetchSpec?.length && options?.preserveTag)\n\t\t\t{\n\t\t\t\tsemver = result.fetchSpec\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\toperator = '^';\n\t\t\t\tfetchQuery = true;\n\t\t\t}\n\t\t\tbreak;\n\n\t\t/**\n\t\t * Range type: complex handling based on range structure\n\t\t * 範圍類型:根據範圍結構進行複雜處理\n\t\t */\n\t\tcase 'range':\n\n\t\t\t// Empty input spec: mark for query\n\t\t\t// 空輸入規格:標記為需要查詢\n\t\t\tif (isInputSpecIsEmpty(result) || isNameSameAsRaw(result))\n\t\t\t{\n\t\t\t\tsemver = void 0;\n\t\t\t\tfetchQuery = true;\n\t\t\t}\n\t\t\telse if (result.fetchSpec?.length)\n\t\t\t{\n\t\t\t\tlet ls = parseSimpleSemVerRange(result.fetchSpec);\n\n\t\t\t\t// Multiple range entries: keep original\n\t\t\t\t// 多個範圍項目:保留原始值\n\t\t\t\tif (ls.length > 1)\n\t\t\t\t{\n\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t}\n\t\t\t\t// Preserve range option is set: keep original\n\t\t\t\t// 保留範圍選項已設定:保留原始值\n\t\t\t\telse if (options?.preserveRange)\n\t\t\t\t{\n\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t}\n\t\t\t\t// Single entry: analyze operator\n\t\t\t\t// 單一項目:分析運算子\n\t\t\t\telse if (ls.length === 1)\n\t\t\t\t{\n\t\t\t\t\tlet entry = ls[0];\n\n\t\t\t\t\t// No operator: treat as version to query\n\t\t\t\t\t// 無運算子:視為需要查詢的版本\n\t\t\t\t\tif (!entry.operator)\n\t\t\t\t\t{\n\t\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t\t\tfetchQuery = true;\n\t\t\t\t\t}\n\t\t\t\t\t// Non-^ operator: keep original spec\n\t\t\t\t\t// 非 ^ 運算子:保留原始規格\n\t\t\t\t\telse if (entry.operator !== '^')\n\t\t\t\t\t{\n\t\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t\t}\n\t\t\t\t\t// ^ operator: use shorthand form\n\t\t\t\t\t// ^ 運算子:使用簡短形式\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\toperator = '^';\n\t\t\t\t\t\tfetchQuery = true;\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\t// No valid entries: use shorthand\n\t\t\t\t// 無有效項目:使用簡短形式\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\toperator = '^';\n\t\t\t\t\tfetchQuery = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\toperator = '^';\n\t\t\t\tfetchQuery = true;\n\t\t\t}\n\n\t\t\tbreak;\n\n\t\t/**\n\t\t * Default case: use fetchSpec if available\n\t\t * 預設情況:如有 fetchSpec 則使用\n\t\t */\n\t\tdefault:\n\n\t\t\tif (result.fetchSpec?.length)\n\t\t\t{\n\t\t\t\tsemver = result.fetchSpec\n\t\t\t}\n\n\t\t\tbreak;\n\t}\n\n\treturn {\n\t\tname: result.name,\n\t\tsemver,\n\t\toperator,\n\t\tfetchQuery,\n\t\tresult,\n\t}\n}\n\n/**\n * Parse a package argument string and convert to dependency value\n * 解析套件參數字串並轉換為依賴值\n *\n * This is a convenience function that combines npa parsing with\n * npaResultToDepsValue conversion in one step.\n *\n * 這是一個便利函數,將 npa 解析與 npaResultToDepsValue 轉換合併為一步。\n *\n * @template T - The expected result type / 預期的結果類型\n *\n * @param {string} arg - The package argument string to parse / 要解析的套件參數字串\n *\n * @param {IOptions} [options] - Parsing and conversion options / 解析和轉換選項\n *\n * @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件\n *\n * @example\n * // Parse and convert in one step\n * // 一步完成解析和轉換\n * npaToDepsValue('lodash@^4.17.0');\n * // => { name: 'lodash', operator: '^', fetchQuery: true, ... }\n *\n * @example\n * // With options\n * // 使用選項\n * npaToDepsValue('lodash@latest', { preserveTag: true });\n * // => { name: 'lodash', semver: 'latest', ... }\n */\nexport function npaToDepsValue<T extends IResult = IResult>(arg: string, options?: IOptions)\n{\n\tlet result = npa(arg, options?.where);\n\n\treturn npaResultToDepsValue<T>(result as any)\n}\n\nexport default npaToDepsValue\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;AAwIH,oDAwKC;AAgCD,wCAYC;AA1VD,0EAA4E;AAC5E,sGAAmG;AACnG,uEAAiG;AA8EjG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,SAAgB,oBAAoB,CAAoB,MAAS,EAAE,OAAkB;;IAEpF;;;;;;OAMG;IACH,IAAI,MAAc,CAAC;IACnB,IAAI,QAAgB,CAAC;IACrB,IAAI,UAAmB,CAAC;IAExB,QAAQ,MAAM,CAAC,IAAmB,EAClC,CAAC;QACA;;;WAGG;QACH,KAAK,KAAK;YACT,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAA;YACxB,MAAM;QAEP;;;WAGG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;;;uBAGG;yBACE,IAAI,KAAK,CAAC,QAAQ,KAAK,GAAG,EAC/B,CAAC;wBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;oBAC1B,CAAC;oBACD;;;uBAGG;yBAEH,CAAC;wBACA,QAAQ,GAAG,GAAG,CAAC;wBACf,UAAU,GAAG,IAAI,CAAC;oBACnB,CAAC;gBAEF,CAAC;gBACD;;;mBAGG;qBAEH,CAAC;oBACA,QAAQ,GAAG,GAAG,CAAC;oBACf,UAAU,GAAG,IAAI,CAAC;gBACnB,CAAC;YACF,CAAC;YACD;;;eAGG;iBAEH,CAAC;gBACA,QAAQ,GAAG,GAAG,CAAC;gBACf,UAAU,GAAG,IAAI,CAAC;YACnB,CAAC;YAED,MAAM;QAEP;;;WAGG;QACH;YAEC,IAAI,MAAA,MAAM,CAAC,SAAS,0CAAE,MAAM,EAC5B,CAAC;gBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;YAC1B,CAAC;YAED,MAAM;IACR,CAAC;IAED,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM;QACN,QAAQ;QACR,UAAU;QACV,MAAM;KACN,CAAA;AACF,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,SAAgB,cAAc,CAA8B,GAAW,EAAE,OAAkB;IAE1F,IAAI,MAAM,GAAG,IAAA,0BAAG,EAAC,GAAG,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,CAAC,CAAC;IAEtC;;;;;;OAMG;IACH,OAAO,oBAAoB,CAAI,MAAa,CAAC,CAAA;AAC9C,CAAC;AAED,kBAAe,cAAc,CAAA","sourcesContent":["/**\n * @fileoverview Convert npm-package-arg results to dependency values\n * @description 將 npm-package-arg 結果轉換為依賴值\n *\n * This module provides utilities to convert npm-package-arg (npa) parsing results\n * into standardized dependency value objects. It handles various input types\n * including git URLs, version tags, semver ranges, and local file paths.\n *\n * 本模組提供將 npm-package-arg (npa) 解析結果轉換為標準化依賴值物件的工具。\n * 處理各種輸入類型,包括 git URL、版本標籤、semver 範圍和本地檔案路徑。\n *\n * @module @yarn-tool/npa-to-deps\n */\n\nimport { IResult, IResultType, npa } from '@yarn-tool/npm-package-arg-util';\nimport { parseSimpleSemVerRange } from '@lazy-node/semver-simple-parse/lib/parseSimpleSemVerRange';\nimport { isInputSpecIsEmpty, isNameSameAsRaw } from '@yarn-tool/npm-package-arg-util/lib/detect';\n\n/**\n * Options for converting npm-package-arg results to dependency values\n * 轉換 npm-package-arg 結果為依賴值的選項\n *\n * @export\n * @interface IOptions\n */\nexport interface IOptions\n{\n\t/**\n\t * Base directory for resolving relative paths\n\t * 解析相對路徑的基礎目錄\n\t */\n\twhere?: string,\n\n\t/**\n\t * When input is a tag (e.g., \"latest\", \"beta\"), preserve it instead of converting to ^\n\t * 當輸入是標籤(例如:\"latest\"、\"beta\")時,保留它而不是轉換為 ^\n\t *\n\t * Only effective when called through npaResultToDepsValue\n\t * 僅在透過 npaResultToDepsValue 呼叫時生效\n\t */\n\tpreserveTag?: boolean,\n\n\t/**\n\t * When input is a range, preserve the original range instead of normalizing it\n\t * 當輸入是範圍時,保留原始範圍而不是正規化它\n\t *\n\t * Only effective when called through npaResultToDepsValue\n\t * 僅在透過 npaResultToDepsValue 呼叫時生效\n\t */\n\tpreserveRange?: boolean,\n}\n\n/**\n * Result of converting npm-package-arg result to dependency value\n * 將 npm-package-arg 結果轉換為依賴值的結果\n *\n * @export\n * @interface IDepsResult\n * @template T - The specific result type from npm-package-arg\n * @template T - npm-package-arg 的特定結果類型\n */\nexport interface IDepsResult<T extends IResult = IResult>\n{\n\t/**\n\t * Package name\n\t * 套件名稱\n\t */\n name: string;\n\n\t/**\n\t * Semantic version string or specification\n\t * 語義化版本字串或規格\n\t */\n semver?: string;\n\n\t/**\n\t * Version operator (e.g., \"^\", \"~\", \">=\")\n\t * 版本運算子(例如:\"^\"、\"~\"、\">=\")\n\t */\n operator?: string;\n\n\t/**\n\t * Whether to fetch from registry query\n\t * 是否要從 registry 查詢獲取\n\t */\n fetchQuery?: boolean;\n\n\t/**\n\t * Original npm-package-arg result\n\t * 原始的 npm-package-arg 結果\n\t */\n result: T;\n}\n\n/**\n * Convert an npm-package-arg result to a dependency value object\n * 將 npm-package-arg 結果轉換為依賴值物件\n *\n * This function takes a parsed npm-package-arg result and converts it into\n * a standardized dependency value format suitable for package.json dependencies.\n * It handles various result types including git, tags, ranges, versions, etc.\n *\n * 此函數接受解析後的 npm-package-arg 結果,並將其轉換為適合 package.json\n * 依賴項的標準化依賴值格式。處理各種結果類型,包括 git、標籤、範圍、版本等。\n *\n * @template T - The type of npm-package-arg result / npm-package-arg 結果的類型\n *\n * @param {T} result - The npm-package-arg parsing result / npm-package-arg 解析結果\n *\n * @param {IOptions} [options] - Conversion options / 轉換選項\n *\n * @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件\n *\n * @example\n * // Git repository\n * // Git 儲存庫\n * const result = npa('github:user/repo#branch');\n * npaResultToDepsValue(result);\n * // => { name: 'repo', semver: 'github:user/repo#branch', result: ... }\n *\n * @example\n * // Version tag with preserveTag\n * // 保留標籤的版本標籤\n * const result = npa('lodash@latest');\n * npaResultToDepsValue(result, { preserveTag: true });\n * // => { name: 'lodash', semver: 'latest', operator: undefined, ... }\n *\n * @example\n * // Version tag without preserveTag (default behavior)\n * // 不保留標籤的版本標籤(預設行為)\n * const result = npa('lodash@latest');\n * npaResultToDepsValue(result);\n * // => { name: 'lodash', operator: '^', fetchQuery: true, ... }\n *\n * @example\n * // Semver range with ^ operator\n * // 帶有 ^ 運算子的 semver 範圍\n * const result = npa('lodash@^4.17.0');\n * npaResultToDepsValue(result);\n * // => { name: 'lodash', operator: '^', fetchQuery: true, ... }\n *\n * @example\n * // Exact version\n * // 精確版本\n * const result = npa('lodash@4.17.21');\n * npaResultToDepsValue(result);\n * // => { name: 'lodash', semver: '4.17.21', ... }\n */\nexport function npaResultToDepsValue<T extends IResult>(result: T, options?: IOptions): IDepsResult<T>\n{\n\t/**\n\t * 依 result.type 分別填入的依賴值欄位;未被賦值者維持 undefined,\n\t * 用來區分「以 operator 簡寫表達」與「以完整 semver 字串表達」兩種依賴寫法\n\t *\n\t * Dependency fields assigned per `result.type`; fields never assigned stay `undefined`\n\t * to distinguish the operator shorthand form from the full semver string form\n\t */\n\tlet semver: string;\n\tlet operator: string;\n\tlet fetchQuery: boolean;\n\n\tswitch (result.type as IResultType)\n\t{\n\t\t/**\n\t\t * Git type: use saveSpec as the semver value\n\t\t * Git 類型:使用 saveSpec 作為 semver 值\n\t\t */\n\t\tcase 'git':\n\t\t\tsemver = result.saveSpec\n\t\t\tbreak;\n\n\t\t/**\n\t\t * Tag type: handle based on preserveTag option\n\t\t * 標籤類型:根據 preserveTag 選項處理\n\t\t */\n\t\tcase 'tag':\n\t\t\t/**\n\t\t\t * 必須同時滿足 fetchSpec 非空才保留標籤,避免空標籤被寫入依賴值;\n\t\t\t * 未保留時則退回 ^ 並標記需向 registry 查詢\n\t\t\t *\n\t\t\t * Keep the tag only when `fetchSpec` is non-empty, so an empty tag never leaks\n\t\t\t * into the dependency value; otherwise fall back to `^` and flag a registry lookup\n\t\t\t */\n\t\t\tif (result.fetchSpec?.length && options?.preserveTag)\n\t\t\t{\n\t\t\t\tsemver = result.fetchSpec\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\toperator = '^';\n\t\t\t\tfetchQuery = true;\n\t\t\t}\n\t\t\tbreak;\n\n\t\t/**\n\t\t * Range type: complex handling based on range structure\n\t\t * 範圍類型:根據範圍結構進行複雜處理\n\t\t */\n\t\tcase 'range':\n\n\t\t\t/**\n\t\t\t * 空輸入規格、或輸入只有套件名稱而未指定版本(例如 \"lodash\"、\"lodash@\"):\n\t\t\t * 此時不寫入 semver,改標記為需要向 registry 查詢\n\t\t\t *\n\t\t\t * Empty input spec, or input that only names the package without a version\n\t\t\t * (e.g. \"lodash\", \"lodash@\"): skip `semver` and flag a registry query instead\n\t\t\t */\n\t\t\tif (isInputSpecIsEmpty(result) || isNameSameAsRaw(result))\n\t\t\t{\n\t\t\t\tsemver = void 0;\n\t\t\t\tfetchQuery = true;\n\t\t\t}\n\t\t\telse if (result.fetchSpec?.length)\n\t\t\t{\n\t\t\t\t/**\n\t\t\t\t * 先把範圍拆解成多個單一條件項目,才能判斷能否簡化成 operator 簡寫\n\t\t\t\t * Split the range into individual clauses first, to decide whether it can be\n\t\t\t\t * reduced to an operator shorthand\n\t\t\t\t */\n\t\t\t\tlet ls = parseSimpleSemVerRange(result.fetchSpec);\n\n\t\t\t\t/**\n\t\t\t\t * 多個範圍項目:保留原始值\n\t\t\t\t * Multiple range entries: keep original\n\t\t\t\t */\n\t\t\t\tif (ls.length > 1)\n\t\t\t\t{\n\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t}\n\t\t\t\t/**\n\t\t\t\t * 保留範圍選項已設定:保留原始值\n\t\t\t\t * Preserve range option is set: keep original\n\t\t\t\t */\n\t\t\t\telse if (options?.preserveRange)\n\t\t\t\t{\n\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t}\n\t\t\t\t/**\n\t\t\t\t * 單一項目:分析運算子\n\t\t\t\t * Single entry: analyze operator\n\t\t\t\t */\n\t\t\t\telse if (ls.length === 1)\n\t\t\t\t{\n\t\t\t\t\tlet entry = ls[0];\n\n\t\t\t\t\t/**\n\t\t\t\t\t * 無運算子:視為需要查詢的版本\n\t\t\t\t\t * No operator: treat as version to query\n\t\t\t\t\t */\n\t\t\t\t\tif (!entry.operator)\n\t\t\t\t\t{\n\t\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t\t\tfetchQuery = true;\n\t\t\t\t\t}\n\t\t\t\t\t/**\n\t\t\t\t\t * 非 ^ 運算子:保留原始規格\n\t\t\t\t\t * Non-^ operator: keep original spec\n\t\t\t\t\t */\n\t\t\t\t\telse if (entry.operator !== '^')\n\t\t\t\t\t{\n\t\t\t\t\t\tsemver = result.fetchSpec\n\t\t\t\t\t}\n\t\t\t\t\t/**\n\t\t\t\t\t * ^ 運算子:使用簡短形式\n\t\t\t\t\t * ^ operator: use shorthand form\n\t\t\t\t\t */\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\toperator = '^';\n\t\t\t\t\t\tfetchQuery = true;\n\t\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 * No valid entries: use shorthand\n\t\t\t\t */\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\toperator = '^';\n\t\t\t\t\tfetchQuery = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t/**\n\t\t\t * fetchSpec 為空:沒有具體範圍可保留,退回 ^ 並標記需查詢\n\t\t\t * Empty fetchSpec: no concrete range to keep, fall back to `^` and flag a query\n\t\t\t */\n\t\t\telse\n\t\t\t{\n\t\t\t\toperator = '^';\n\t\t\t\tfetchQuery = true;\n\t\t\t}\n\n\t\t\tbreak;\n\n\t\t/**\n\t\t * Default case: use fetchSpec if available\n\t\t * 預設情況:如有 fetchSpec 則使用\n\t\t */\n\t\tdefault:\n\n\t\t\tif (result.fetchSpec?.length)\n\t\t\t{\n\t\t\t\tsemver = result.fetchSpec\n\t\t\t}\n\n\t\t\tbreak;\n\t}\n\n\treturn {\n\t\tname: result.name,\n\t\tsemver,\n\t\toperator,\n\t\tfetchQuery,\n\t\tresult,\n\t}\n}\n\n/**\n * Parse a package argument string and convert to dependency value\n * 解析套件參數字串並轉換為依賴值\n *\n * This is a convenience function that combines npa parsing with\n * npaResultToDepsValue conversion in one step.\n *\n * 這是一個便利函數,將 npa 解析與 npaResultToDepsValue 轉換合併為一步。\n *\n * @template T - The expected result type / 預期的結果類型\n *\n * @param {string} arg - The package argument string to parse / 要解析的套件參數字串\n *\n * @param {IOptions} [options] - Parsing and conversion options; only `where` is forwarded / 解析與轉換選項;僅 `where` 會被傳遞\n *\n * @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件\n *\n * @example\n * // Parse and convert in one step\n * // 一步完成解析和轉換\n * npaToDepsValue('lodash@^4.17.0');\n * // => { name: 'lodash', operator: '^', fetchQuery: true, ... }\n *\n * @example\n * // `where` as base directory for relative paths;\n * // `preserveTag` / `preserveRange` must be passed to npaResultToDepsValue instead\n * // `where` 作為相對路徑的基礎目錄;\n * // `preserveTag` / `preserveRange` 需改傳給 npaResultToDepsValue\n * npaToDepsValue('./local-pkg', { where: '/path/to/base' });\n */\nexport function npaToDepsValue<T extends IResult = IResult>(arg: string, options?: IOptions)\n{\n\tlet result = npa(arg, options?.where);\n\n\t/**\n\t * 以 `as any` 略過 npa 回傳的寬鬆 union 型別;\n\t * 實際分支由 npaResultToDepsValue 內的 result.type 決定,並涵蓋 default 情況\n\t *\n\t * Cast with `as any` to bypass npa's loose union return type;\n\t * branching is decided by `result.type` inside npaResultToDepsValue, including the default case\n\t */\n\treturn npaResultToDepsValue<T>(result as any)\n}\n\nexport default npaToDepsValue\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/npa-to-deps",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"description": "Convert npm-package-arg results to dependency values / 將 npm-package-arg 結果轉換為依賴值",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yarn",
|
|
@@ -29,21 +29,23 @@
|
|
|
29
29
|
"author": "bluelovers",
|
|
30
30
|
"main": "index.js",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"coverage": "
|
|
32
|
+
"coverage": "pnpm run test -- --coverage",
|
|
33
33
|
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
34
|
-
"test": "
|
|
34
|
+
"test": "node --run test:node",
|
|
35
35
|
"test:jest": "jest --passWithNoTests",
|
|
36
|
-
"test:jest:coverage": "
|
|
37
|
-
"test:jest:snapshot": "
|
|
36
|
+
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
37
|
+
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
38
38
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
39
|
-
"test:
|
|
39
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
40
|
+
"test:snapshot": "pnpm run test -u",
|
|
41
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
40
42
|
"test:tsd": "ynpx tsd",
|
|
41
|
-
"preversion": "echo preversion &&
|
|
43
|
+
"preversion": "echo preversion && pnpm run test",
|
|
42
44
|
"version": "echo version",
|
|
43
45
|
"postversion": "echo postversion",
|
|
44
46
|
"prepublish": "echo prepublish",
|
|
45
47
|
"prepublishOnly": "echo prepublishOnly",
|
|
46
|
-
"prepublishOnly:update": "
|
|
48
|
+
"prepublishOnly:update": "pnpm run ncu && pnpm run sort-package-json",
|
|
47
49
|
"publish": "echo publish",
|
|
48
50
|
"postpublish": "echo postpublish",
|
|
49
51
|
"postpublishOnly": "echo postpublishOnly",
|
|
@@ -52,15 +54,15 @@
|
|
|
52
54
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
53
55
|
},
|
|
54
56
|
"dependencies": {
|
|
55
|
-
"@lazy-node/semver-simple-parse": "^4.0.
|
|
56
|
-
"@yarn-tool/npm-package-arg-util": "^2.0.
|
|
57
|
+
"@lazy-node/semver-simple-parse": "^4.0.9",
|
|
58
|
+
"@yarn-tool/npm-package-arg-util": "^2.0.9",
|
|
57
59
|
"tslib": ">=2.8.1"
|
|
58
60
|
},
|
|
59
61
|
"devDependencies": {
|
|
60
|
-
"npm-package-arg": "^
|
|
62
|
+
"npm-package-arg": "^14.0.0"
|
|
61
63
|
},
|
|
62
64
|
"publishConfig": {
|
|
63
65
|
"access": "public"
|
|
64
66
|
},
|
|
65
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
|
|
66
68
|
}
|