@yarn-tool/npa-to-deps 3.0.2 → 3.0.3
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 +130 -3
- package/index.d.ts +140 -2
- package/index.js +134 -1
- package/index.js.map +1 -1
- package/package.json +8 -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
|
+
## [3.0.3](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/npa-to-deps@3.0.2...@yarn-tool/npa-to-deps@3.0.3) (2026-03-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **release:** 核心工具鏈套件升級
|
|
12
|
+
- @lazy-node/semver-simple-parse v4.0.0
|
|
13
|
+
- @yarn-tool/require-resolve v4.0.0
|
|
14
|
+
- @yarn-tool/resolve-package v3.0.0
|
|
15
|
+
- @yarn-tool/get-pkg-bin v3.0.0
|
|
16
|
+
- @yarn-tool/check-pkg-bin v4.0.0
|
|
17
|
+
|
|
18
|
+
更新所有工作區套件以使用相容的主要版本,並重構
|
|
19
|
+
npm-package-arg-util 以抽離 _parsePackageNameCore 核心函式。
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### 🐛 Bug Fixes
|
|
24
|
+
|
|
25
|
+
* **npa-to-deps:** 新增名稱與規格相同時的查詢標記邏輯 ([6baa8eb](https://github.com/bluelovers/ws-yarn-workspaces/commit/6baa8eb5b1900ae548e459f5756eb4155f2842f2))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### ✨ Features
|
|
29
|
+
|
|
30
|
+
* **npm-package-arg-util:** 新增空值與特殊輸入檢測功能 ([c5e9acc](https://github.com/bluelovers/ws-yarn-workspaces/commit/c5e9acccc49e1c544f8e5aefa1532a35f5e99a9d))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### 🛠 Build System
|
|
34
|
+
|
|
35
|
+
* **semver-parse,npm-package-arg-util:** 支援部分版本並新增輸入檢測功能 ([e824769](https://github.com/bluelovers/ws-yarn-workspaces/commit/e8247696151c6ffcd146eacdb46be0ee721ebefd))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### ♻️ Chores
|
|
39
|
+
|
|
40
|
+
* Add test config and global types for tsdx ([88a8df6](https://github.com/bluelovers/ws-yarn-workspaces/commit/88a8df6eef5dc59d9e0d9268b21706dceb5ab2a1))
|
|
41
|
+
* 更新 Jest 快照連結並增強類型定義與文件 ([b663b97](https://github.com/bluelovers/ws-yarn-workspaces/commit/b663b97d78d223dc8b3927ea2433938350144de7))
|
|
42
|
+
* remove empty resolutions and redundant packageManager fields ([65b5c5f](https://github.com/bluelovers/ws-yarn-workspaces/commit/65b5c5f929aae82474408b2b46cfc5a471c919f6))
|
|
43
|
+
* add __root.ts test utility to workspace packages ([a771727](https://github.com/bluelovers/ws-yarn-workspaces/commit/a7717278883c86d9ed8ab89f42070d3385c173a7))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### 📌 Dependencies
|
|
47
|
+
|
|
48
|
+
* **release:** 主要版本升級與跨套件相依更新 ([2a24889](https://github.com/bluelovers/ws-yarn-workspaces/commit/2a248893f3667704d1ba0de12544091abf5d341e))
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
6
52
|
## [3.0.2](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/npa-to-deps@3.0.1...@yarn-tool/npa-to-deps@3.0.2) (2025-09-07)
|
|
7
53
|
|
|
8
54
|
**Note:** Version bump only for package @yarn-tool/npa-to-deps
|
package/README.md
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yarn-tool/npa-to-deps
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Convert npm-package-arg (npa) parsing results to standardized dependency value objects.
|
|
4
|
+
將 npm-package-arg (npa) 解析結果轉換為標準化的依賴值物件。
|
|
4
5
|
|
|
5
|
-
##
|
|
6
|
+
## Features / 功能特點
|
|
7
|
+
|
|
8
|
+
- Handles various input types including git URLs, version tags, semver ranges, and local file paths / 處理各種輸入類型,包括 git URL、版本標籤、semver 範圍和本地檔案路徑
|
|
9
|
+
- Converts npm-package-arg results to standardized dependency objects / 將 npm-package-arg 結果轉換為標準化的依賴物件
|
|
10
|
+
- Supports options for preserving tags and ranges / 支援保留標籤和範圍的選項
|
|
11
|
+
|
|
12
|
+
## Install / 安裝
|
|
6
13
|
|
|
7
14
|
```bash
|
|
8
15
|
yarn add @yarn-tool/npa-to-deps
|
|
@@ -10,3 +17,123 @@ yarn-tool add @yarn-tool/npa-to-deps
|
|
|
10
17
|
yt add @yarn-tool/npa-to-deps
|
|
11
18
|
```
|
|
12
19
|
|
|
20
|
+
## Usage / 使用方式
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { npaToDepsValue, npaResultToDepsValue } from '@yarn-tool/npa-to-deps';
|
|
24
|
+
import { npa } from '@yarn-tool/npm-package-arg-util';
|
|
25
|
+
|
|
26
|
+
// Parse and convert in one step
|
|
27
|
+
// 一步完成解析和轉換
|
|
28
|
+
const deps = npaToDepsValue('lodash@^4.17.0');
|
|
29
|
+
// => { name: 'lodash', operator: '^', fetchQuery: true, result: ... }
|
|
30
|
+
|
|
31
|
+
// With preserveTag option
|
|
32
|
+
// 使用 preserveTag 選項
|
|
33
|
+
const tagDeps = npaToDepsValue('lodash@latest', { preserveTag: true });
|
|
34
|
+
// => { name: 'lodash', semver: 'latest', result: ... }
|
|
35
|
+
|
|
36
|
+
// Convert existing npa result
|
|
37
|
+
// 轉換現有的 npa 結果
|
|
38
|
+
const result = npa('github:user/repo#branch');
|
|
39
|
+
const gitDeps = npaResultToDepsValue(result);
|
|
40
|
+
// => { name: 'repo', semver: 'github:user/repo#branch', result: ... }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API / API 文件
|
|
44
|
+
|
|
45
|
+
### `npaToDepsValue<T>(arg: string, options?: IOptions): IDepsResult<T>`
|
|
46
|
+
|
|
47
|
+
Parse a package argument string and convert to dependency value.
|
|
48
|
+
解析套件參數字串並轉換為依賴值。
|
|
49
|
+
|
|
50
|
+
**Parameters / 參數:**
|
|
51
|
+
- `arg` - The package argument string to parse / 要解析的套件參數字串
|
|
52
|
+
- `options` - Parsing and conversion options / 解析和轉換選項
|
|
53
|
+
- `where` - Base directory for resolving relative paths / 解析相對路徑的基礎目錄
|
|
54
|
+
- `preserveTag` - Preserve tag instead of converting to ^ / 保留標籤而不是轉換為 ^
|
|
55
|
+
- `preserveRange` - Preserve original range instead of normalizing / 保留原始範圍而不是正規化
|
|
56
|
+
|
|
57
|
+
**Returns / 返回:**
|
|
58
|
+
- Standardized dependency value object / 標準化的依賴值物件
|
|
59
|
+
|
|
60
|
+
### `npaResultToDepsValue<T>(result: T, options?: IOptions): IDepsResult<T>`
|
|
61
|
+
|
|
62
|
+
Convert an npm-package-arg result to a dependency value object.
|
|
63
|
+
將 npm-package-arg 結果轉換為依賴值物件。
|
|
64
|
+
|
|
65
|
+
**Parameters / 參數:**
|
|
66
|
+
- `result` - The npm-package-arg parsing result / npm-package-arg 解析結果
|
|
67
|
+
- `options` - Conversion options / 轉換選項
|
|
68
|
+
|
|
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
|
+
### `IDepsResult<T>` Interface
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
interface IDepsResult<T> {
|
|
83
|
+
name: string; // Package name / 套件名稱
|
|
84
|
+
semver?: string; // Semantic version string / 語義化版本字串
|
|
85
|
+
operator?: string; // Version operator (^, ~, >=) / 版本運算子
|
|
86
|
+
fetchQuery?: boolean; // Whether to fetch from registry / 是否從 registry 查詢
|
|
87
|
+
result: T; // Original npm-package-arg result / 原始結果
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Examples / 範例
|
|
92
|
+
|
|
93
|
+
### Git Repository / Git 儲存庫
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const result = npa('github:user/repo#branch');
|
|
97
|
+
npaResultToDepsValue(result);
|
|
98
|
+
// => { name: 'repo', semver: 'github:user/repo#branch', result: ... }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Version Tag / 版本標籤
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
// Default behavior - convert to ^
|
|
105
|
+
// 預設行為 - 轉換為 ^
|
|
106
|
+
npaToDepsValue('lodash@latest');
|
|
107
|
+
// => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
108
|
+
|
|
109
|
+
// Preserve tag
|
|
110
|
+
// 保留標籤
|
|
111
|
+
npaToDepsValue('lodash@latest', { preserveTag: true });
|
|
112
|
+
// => { name: 'lodash', semver: 'latest', ... }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Semver Range / Semver 範圍
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
npaToDepsValue('lodash@^4.17.0');
|
|
119
|
+
// => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
120
|
+
|
|
121
|
+
npaToDepsValue('lodash@>=4.0.0 <5.0.0');
|
|
122
|
+
// => { name: 'lodash', semver: '>=4.0.0 <5.0.0', ... }
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Exact Version / 精確版本
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
npaToDepsValue('lodash@4.17.21');
|
|
129
|
+
// => { name: 'lodash', semver: '4.17.21', ... }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Related / 相關專案
|
|
133
|
+
|
|
134
|
+
- [@yarn-tool/npm-package-arg-util](../npm-package-arg-util) - npm-package-arg utilities
|
|
135
|
+
- [@yarn-tool/normalize-deps-value](../normalize-deps-value) - Normalize dependency values
|
|
136
|
+
|
|
137
|
+
## License / 授權
|
|
138
|
+
|
|
139
|
+
ISC
|
package/index.d.ts
CHANGED
|
@@ -1,22 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Convert npm-package-arg results to dependency values
|
|
3
|
+
* @description 將 npm-package-arg 結果轉換為依賴值
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities to convert npm-package-arg (npa) parsing results
|
|
6
|
+
* into standardized dependency value objects. It handles various input types
|
|
7
|
+
* including git URLs, version tags, semver ranges, and local file paths.
|
|
8
|
+
*
|
|
9
|
+
* 本模組提供將 npm-package-arg (npa) 解析結果轉換為標準化依賴值物件的工具。
|
|
10
|
+
* 處理各種輸入類型,包括 git URL、版本標籤、semver 範圍和本地檔案路徑。
|
|
11
|
+
*
|
|
12
|
+
* @module @yarn-tool/npa-to-deps
|
|
13
|
+
*/
|
|
1
14
|
import { IResult } from '@yarn-tool/npm-package-arg-util';
|
|
15
|
+
/**
|
|
16
|
+
* Options for converting npm-package-arg results to dependency values
|
|
17
|
+
* 轉換 npm-package-arg 結果為依賴值的選項
|
|
18
|
+
*
|
|
19
|
+
* @export
|
|
20
|
+
* @interface IOptions
|
|
21
|
+
*/
|
|
2
22
|
export interface IOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Base directory for resolving relative paths
|
|
25
|
+
* 解析相對路徑的基礎目錄
|
|
26
|
+
*/
|
|
3
27
|
where?: string;
|
|
4
28
|
/**
|
|
5
|
-
*
|
|
29
|
+
* When input is a tag (e.g., "latest", "beta"), preserve it instead of converting to ^
|
|
30
|
+
* 當輸入是標籤(例如:"latest"、"beta")時,保留它而不是轉換為 ^
|
|
6
31
|
*/
|
|
7
32
|
preserveTag?: boolean;
|
|
8
33
|
/**
|
|
9
|
-
*
|
|
34
|
+
* When input is a range, preserve the original range instead of normalizing it
|
|
35
|
+
* 當輸入是範圍時,保留原始範圍而不是正規化它
|
|
10
36
|
*/
|
|
11
37
|
preserveRange?: boolean;
|
|
12
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of converting npm-package-arg result to dependency value
|
|
41
|
+
* 將 npm-package-arg 結果轉換為依賴值的結果
|
|
42
|
+
*
|
|
43
|
+
* @export
|
|
44
|
+
* @interface IDepsResult
|
|
45
|
+
* @template T - The specific result type from npm-package-arg
|
|
46
|
+
* @template T - npm-package-arg 的特定結果類型
|
|
47
|
+
*/
|
|
13
48
|
export interface IDepsResult<T extends IResult = IResult> {
|
|
49
|
+
/**
|
|
50
|
+
* Package name
|
|
51
|
+
* 套件名稱
|
|
52
|
+
*/
|
|
14
53
|
name: string;
|
|
54
|
+
/**
|
|
55
|
+
* Semantic version string or specification
|
|
56
|
+
* 語義化版本字串或規格
|
|
57
|
+
*/
|
|
15
58
|
semver?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Version operator (e.g., "^", "~", ">=")
|
|
61
|
+
* 版本運算子(例如:"^"、"~"、">=")
|
|
62
|
+
*/
|
|
16
63
|
operator?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Whether to fetch from registry query
|
|
66
|
+
* 是否要從 registry 查詢獲取
|
|
67
|
+
*/
|
|
17
68
|
fetchQuery?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Original npm-package-arg result
|
|
71
|
+
* 原始的 npm-package-arg 結果
|
|
72
|
+
*/
|
|
18
73
|
result: T;
|
|
19
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Convert an npm-package-arg result to a dependency value object
|
|
77
|
+
* 將 npm-package-arg 結果轉換為依賴值物件
|
|
78
|
+
*
|
|
79
|
+
* This function takes a parsed npm-package-arg result and converts it into
|
|
80
|
+
* a standardized dependency value format suitable for package.json dependencies.
|
|
81
|
+
* It handles various result types including git, tags, ranges, versions, etc.
|
|
82
|
+
*
|
|
83
|
+
* 此函數接受解析後的 npm-package-arg 結果,並將其轉換為適合 package.json
|
|
84
|
+
* 依賴項的標準化依賴值格式。處理各種結果類型,包括 git、標籤、範圍、版本等。
|
|
85
|
+
*
|
|
86
|
+
* @template T - The type of npm-package-arg result / npm-package-arg 結果的類型
|
|
87
|
+
*
|
|
88
|
+
* @param {T} result - The npm-package-arg parsing result / npm-package-arg 解析結果
|
|
89
|
+
*
|
|
90
|
+
* @param {IOptions} [options] - Conversion options / 轉換選項
|
|
91
|
+
*
|
|
92
|
+
* @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Git repository
|
|
96
|
+
* // Git 儲存庫
|
|
97
|
+
* const result = npa('github:user/repo#branch');
|
|
98
|
+
* npaResultToDepsValue(result);
|
|
99
|
+
* // => { name: 'repo', semver: 'github:user/repo#branch', result: ... }
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* // Version tag with preserveTag
|
|
103
|
+
* // 保留標籤的版本標籤
|
|
104
|
+
* const result = npa('lodash@latest');
|
|
105
|
+
* npaResultToDepsValue(result, { preserveTag: true });
|
|
106
|
+
* // => { name: 'lodash', semver: 'latest', operator: undefined, ... }
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* // Version tag without preserveTag (default behavior)
|
|
110
|
+
* // 不保留標籤的版本標籤(預設行為)
|
|
111
|
+
* const result = npa('lodash@latest');
|
|
112
|
+
* npaResultToDepsValue(result);
|
|
113
|
+
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* // Semver range with ^ operator
|
|
117
|
+
* // 帶有 ^ 運算子的 semver 範圍
|
|
118
|
+
* const result = npa('lodash@^4.17.0');
|
|
119
|
+
* npaResultToDepsValue(result);
|
|
120
|
+
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* // Exact version
|
|
124
|
+
* // 精確版本
|
|
125
|
+
* const result = npa('lodash@4.17.21');
|
|
126
|
+
* npaResultToDepsValue(result);
|
|
127
|
+
* // => { name: 'lodash', semver: '4.17.21', ... }
|
|
128
|
+
*/
|
|
20
129
|
export declare function npaResultToDepsValue<T extends IResult>(result: T, options?: IOptions): IDepsResult<T>;
|
|
130
|
+
/**
|
|
131
|
+
* Parse a package argument string and convert to dependency value
|
|
132
|
+
* 解析套件參數字串並轉換為依賴值
|
|
133
|
+
*
|
|
134
|
+
* This is a convenience function that combines npa parsing with
|
|
135
|
+
* npaResultToDepsValue conversion in one step.
|
|
136
|
+
*
|
|
137
|
+
* 這是一個便利函數,將 npa 解析與 npaResultToDepsValue 轉換合併為一步。
|
|
138
|
+
*
|
|
139
|
+
* @template T - The expected result type / 預期的結果類型
|
|
140
|
+
*
|
|
141
|
+
* @param {string} arg - The package argument string to parse / 要解析的套件參數字串
|
|
142
|
+
*
|
|
143
|
+
* @param {IOptions} [options] - Parsing and conversion options / 解析和轉換選項
|
|
144
|
+
*
|
|
145
|
+
* @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Parse and convert in one step
|
|
149
|
+
* // 一步完成解析和轉換
|
|
150
|
+
* npaToDepsValue('lodash@^4.17.0');
|
|
151
|
+
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // With options
|
|
155
|
+
* // 使用選項
|
|
156
|
+
* npaToDepsValue('lodash@latest', { preserveTag: true });
|
|
157
|
+
* // => { name: 'lodash', semver: 'latest', ... }
|
|
158
|
+
*/
|
|
21
159
|
export declare function npaToDepsValue<T extends IResult = IResult>(arg: string, options?: IOptions): IDepsResult<T>;
|
|
22
160
|
export default npaToDepsValue;
|
package/index.js
CHANGED
|
@@ -1,18 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Convert npm-package-arg results to dependency values
|
|
4
|
+
* @description 將 npm-package-arg 結果轉換為依賴值
|
|
5
|
+
*
|
|
6
|
+
* This module provides utilities to convert npm-package-arg (npa) parsing results
|
|
7
|
+
* into standardized dependency value objects. It handles various input types
|
|
8
|
+
* including git URLs, version tags, semver ranges, and local file paths.
|
|
9
|
+
*
|
|
10
|
+
* 本模組提供將 npm-package-arg (npa) 解析結果轉換為標準化依賴值物件的工具。
|
|
11
|
+
* 處理各種輸入類型,包括 git URL、版本標籤、semver 範圍和本地檔案路徑。
|
|
12
|
+
*
|
|
13
|
+
* @module @yarn-tool/npa-to-deps
|
|
14
|
+
*/
|
|
2
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
16
|
exports.npaResultToDepsValue = npaResultToDepsValue;
|
|
4
17
|
exports.npaToDepsValue = npaToDepsValue;
|
|
5
18
|
const npm_package_arg_util_1 = require("@yarn-tool/npm-package-arg-util");
|
|
6
19
|
const parseSimpleSemVerRange_1 = require("@lazy-node/semver-simple-parse/lib/parseSimpleSemVerRange");
|
|
20
|
+
const detect_1 = require("@yarn-tool/npm-package-arg-util/lib/detect");
|
|
21
|
+
/**
|
|
22
|
+
* Convert an npm-package-arg result to a dependency value object
|
|
23
|
+
* 將 npm-package-arg 結果轉換為依賴值物件
|
|
24
|
+
*
|
|
25
|
+
* This function takes a parsed npm-package-arg result and converts it into
|
|
26
|
+
* a standardized dependency value format suitable for package.json dependencies.
|
|
27
|
+
* It handles various result types including git, tags, ranges, versions, etc.
|
|
28
|
+
*
|
|
29
|
+
* 此函數接受解析後的 npm-package-arg 結果,並將其轉換為適合 package.json
|
|
30
|
+
* 依賴項的標準化依賴值格式。處理各種結果類型,包括 git、標籤、範圍、版本等。
|
|
31
|
+
*
|
|
32
|
+
* @template T - The type of npm-package-arg result / npm-package-arg 結果的類型
|
|
33
|
+
*
|
|
34
|
+
* @param {T} result - The npm-package-arg parsing result / npm-package-arg 解析結果
|
|
35
|
+
*
|
|
36
|
+
* @param {IOptions} [options] - Conversion options / 轉換選項
|
|
37
|
+
*
|
|
38
|
+
* @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Git repository
|
|
42
|
+
* // Git 儲存庫
|
|
43
|
+
* const result = npa('github:user/repo#branch');
|
|
44
|
+
* npaResultToDepsValue(result);
|
|
45
|
+
* // => { name: 'repo', semver: 'github:user/repo#branch', result: ... }
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* // Version tag with preserveTag
|
|
49
|
+
* // 保留標籤的版本標籤
|
|
50
|
+
* const result = npa('lodash@latest');
|
|
51
|
+
* npaResultToDepsValue(result, { preserveTag: true });
|
|
52
|
+
* // => { name: 'lodash', semver: 'latest', operator: undefined, ... }
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* // Version tag without preserveTag (default behavior)
|
|
56
|
+
* // 不保留標籤的版本標籤(預設行為)
|
|
57
|
+
* const result = npa('lodash@latest');
|
|
58
|
+
* npaResultToDepsValue(result);
|
|
59
|
+
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* // Semver range with ^ operator
|
|
63
|
+
* // 帶有 ^ 運算子的 semver 範圍
|
|
64
|
+
* const result = npa('lodash@^4.17.0');
|
|
65
|
+
* npaResultToDepsValue(result);
|
|
66
|
+
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* // Exact version
|
|
70
|
+
* // 精確版本
|
|
71
|
+
* const result = npa('lodash@4.17.21');
|
|
72
|
+
* npaResultToDepsValue(result);
|
|
73
|
+
* // => { name: 'lodash', semver: '4.17.21', ... }
|
|
74
|
+
*/
|
|
7
75
|
function npaResultToDepsValue(result, options) {
|
|
8
76
|
var _a, _b, _c;
|
|
9
77
|
let semver;
|
|
10
78
|
let operator;
|
|
11
79
|
let fetchQuery;
|
|
12
80
|
switch (result.type) {
|
|
81
|
+
/**
|
|
82
|
+
* Git type: use saveSpec as the semver value
|
|
83
|
+
* Git 類型:使用 saveSpec 作為 semver 值
|
|
84
|
+
*/
|
|
13
85
|
case 'git':
|
|
14
86
|
semver = result.saveSpec;
|
|
15
87
|
break;
|
|
88
|
+
/**
|
|
89
|
+
* Tag type: handle based on preserveTag option
|
|
90
|
+
* 標籤類型:根據 preserveTag 選項處理
|
|
91
|
+
*/
|
|
16
92
|
case 'tag':
|
|
17
93
|
if (((_a = result.fetchSpec) === null || _a === void 0 ? void 0 : _a.length) && (options === null || options === void 0 ? void 0 : options.preserveTag)) {
|
|
18
94
|
semver = result.fetchSpec;
|
|
@@ -22,29 +98,53 @@ function npaResultToDepsValue(result, options) {
|
|
|
22
98
|
fetchQuery = true;
|
|
23
99
|
}
|
|
24
100
|
break;
|
|
101
|
+
/**
|
|
102
|
+
* Range type: complex handling based on range structure
|
|
103
|
+
* 範圍類型:根據範圍結構進行複雜處理
|
|
104
|
+
*/
|
|
25
105
|
case 'range':
|
|
26
|
-
|
|
106
|
+
// Empty input spec: mark for query
|
|
107
|
+
// 空輸入規格:標記為需要查詢
|
|
108
|
+
if ((0, detect_1.isInputSpecIsEmpty)(result) || (0, detect_1.isNameSameAsRaw)(result)) {
|
|
109
|
+
semver = void 0;
|
|
110
|
+
fetchQuery = true;
|
|
111
|
+
}
|
|
112
|
+
else if ((_b = result.fetchSpec) === null || _b === void 0 ? void 0 : _b.length) {
|
|
27
113
|
let ls = (0, parseSimpleSemVerRange_1.parseSimpleSemVerRange)(result.fetchSpec);
|
|
114
|
+
// Multiple range entries: keep original
|
|
115
|
+
// 多個範圍項目:保留原始值
|
|
28
116
|
if (ls.length > 1) {
|
|
29
117
|
semver = result.fetchSpec;
|
|
30
118
|
}
|
|
119
|
+
// Preserve range option is set: keep original
|
|
120
|
+
// 保留範圍選項已設定:保留原始值
|
|
31
121
|
else if (options === null || options === void 0 ? void 0 : options.preserveRange) {
|
|
32
122
|
semver = result.fetchSpec;
|
|
33
123
|
}
|
|
124
|
+
// Single entry: analyze operator
|
|
125
|
+
// 單一項目:分析運算子
|
|
34
126
|
else if (ls.length === 1) {
|
|
35
127
|
let entry = ls[0];
|
|
128
|
+
// No operator: treat as version to query
|
|
129
|
+
// 無運算子:視為需要查詢的版本
|
|
36
130
|
if (!entry.operator) {
|
|
37
131
|
semver = result.fetchSpec;
|
|
38
132
|
fetchQuery = true;
|
|
39
133
|
}
|
|
134
|
+
// Non-^ operator: keep original spec
|
|
135
|
+
// 非 ^ 運算子:保留原始規格
|
|
40
136
|
else if (entry.operator !== '^') {
|
|
41
137
|
semver = result.fetchSpec;
|
|
42
138
|
}
|
|
139
|
+
// ^ operator: use shorthand form
|
|
140
|
+
// ^ 運算子:使用簡短形式
|
|
43
141
|
else {
|
|
44
142
|
operator = '^';
|
|
45
143
|
fetchQuery = true;
|
|
46
144
|
}
|
|
47
145
|
}
|
|
146
|
+
// No valid entries: use shorthand
|
|
147
|
+
// 無有效項目:使用簡短形式
|
|
48
148
|
else {
|
|
49
149
|
operator = '^';
|
|
50
150
|
fetchQuery = true;
|
|
@@ -55,6 +155,10 @@ function npaResultToDepsValue(result, options) {
|
|
|
55
155
|
fetchQuery = true;
|
|
56
156
|
}
|
|
57
157
|
break;
|
|
158
|
+
/**
|
|
159
|
+
* Default case: use fetchSpec if available
|
|
160
|
+
* 預設情況:如有 fetchSpec 則使用
|
|
161
|
+
*/
|
|
58
162
|
default:
|
|
59
163
|
if ((_c = result.fetchSpec) === null || _c === void 0 ? void 0 : _c.length) {
|
|
60
164
|
semver = result.fetchSpec;
|
|
@@ -69,6 +173,35 @@ function npaResultToDepsValue(result, options) {
|
|
|
69
173
|
result,
|
|
70
174
|
};
|
|
71
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Parse a package argument string and convert to dependency value
|
|
178
|
+
* 解析套件參數字串並轉換為依賴值
|
|
179
|
+
*
|
|
180
|
+
* This is a convenience function that combines npa parsing with
|
|
181
|
+
* npaResultToDepsValue conversion in one step.
|
|
182
|
+
*
|
|
183
|
+
* 這是一個便利函數,將 npa 解析與 npaResultToDepsValue 轉換合併為一步。
|
|
184
|
+
*
|
|
185
|
+
* @template T - The expected result type / 預期的結果類型
|
|
186
|
+
*
|
|
187
|
+
* @param {string} arg - The package argument string to parse / 要解析的套件參數字串
|
|
188
|
+
*
|
|
189
|
+
* @param {IOptions} [options] - Parsing and conversion options / 解析和轉換選項
|
|
190
|
+
*
|
|
191
|
+
* @returns {IDepsResult<T>} Standardized dependency value object / 標準化的依賴值物件
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* // Parse and convert in one step
|
|
195
|
+
* // 一步完成解析和轉換
|
|
196
|
+
* npaToDepsValue('lodash@^4.17.0');
|
|
197
|
+
* // => { name: 'lodash', operator: '^', fetchQuery: true, ... }
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* // With options
|
|
201
|
+
* // 使用選項
|
|
202
|
+
* npaToDepsValue('lodash@latest', { preserveTag: true });
|
|
203
|
+
* // => { name: 'lodash', semver: 'latest', ... }
|
|
204
|
+
*/
|
|
72
205
|
function npaToDepsValue(arg, options) {
|
|
73
206
|
let result = (0, npm_package_arg_util_1.npa)(arg, options === null || options === void 0 ? void 0 : options.where);
|
|
74
207
|
return npaResultToDepsValue(result);
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;AA0BA,oDAsFC;AAED,wCAKC;AAvHD,0EAA+D;AAC/D,sGAAmG;AAyBnG,SAAgB,oBAAoB,CAAoB,MAAS,EAAE,OAAkB;;IAEpF,IAAI,MAAc,CAAC;IACnB,IAAI,QAAgB,CAAC;IACrB,IAAI,UAAmB,CAAC;IAExB,QAAQ,MAAM,CAAC,IAAI,EACnB,CAAC;QACA,KAAK,KAAK;YACT,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAA;YACxB,MAAM;QACP,KAAK,KAAK;YACT,IAAI,CAAA,MAAA,MAAM,CAAC,SAAS,0CAAE,MAAM,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAA,EACpD,CAAC;gBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;YAC1B,CAAC;iBAED,CAAC;gBACA,QAAQ,GAAG,GAAG,CAAC;gBACf,UAAU,GAAG,IAAI,CAAC;YACnB,CAAC;YACD,MAAM;QACP,KAAK,OAAO;YAEX,IAAI,MAAA,MAAM,CAAC,SAAS,0CAAE,MAAM,EAC5B,CAAC;gBACA,IAAI,EAAE,GAAG,IAAA,+CAAsB,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAElD,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EACjB,CAAC;oBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;gBAC1B,CAAC;qBACI,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,EAC/B,CAAC;oBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;gBAC1B,CAAC;qBACI,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EACxB,CAAC;oBACA,IAAI,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;oBAElB,IAAI,CAAC,KAAK,CAAC,QAAQ,EACnB,CAAC;wBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;wBACzB,UAAU,GAAG,IAAI,CAAC;oBACnB,CAAC;yBACI,IAAI,KAAK,CAAC,QAAQ,KAAK,GAAG,EAC/B,CAAC;wBACA,MAAM,GAAG,MAAM,CAAC,SAAS,CAAA;oBAC1B,CAAC;yBAED,CAAC;wBACA,QAAQ,GAAG,GAAG,CAAC;wBACf,UAAU,GAAG,IAAI,CAAC;oBACnB,CAAC;gBAEF,CAAC;qBAED,CAAC;oBACA,QAAQ,GAAG,GAAG,CAAC;oBACf,UAAU,GAAG,IAAI,CAAC;gBACnB,CAAC;YACF,CAAC;iBAED,CAAC;gBACA,QAAQ,GAAG,GAAG,CAAC;gBACf,UAAU,GAAG,IAAI,CAAC;YACnB,CAAC;YAED,MAAM;QACP;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,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,OAAO,oBAAoB,CAAI,MAAa,CAAC,CAAA;AAC9C,CAAC;AAED,kBAAe,cAAc,CAAA","sourcesContent":["import { IResult, npa } from '@yarn-tool/npm-package-arg-util';\nimport { parseSimpleSemVerRange } from '@lazy-node/semver-simple-parse/lib/parseSimpleSemVerRange';\n\nexport interface IOptions\n{\n\twhere?: string,\n\t/**\n\t * when input is tag, preserve it\n\t */\n\tpreserveTag?: boolean,\n\n\t/**\n\t * when input is range, preserve it\n\t */\n\tpreserveRange?: boolean,\n}\n\nexport interface IDepsResult<T extends IResult = IResult>\n{\n name: string;\n semver?: string;\n operator?: string;\n fetchQuery?: boolean;\n result: T;\n}\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)\n\t{\n\t\tcase 'git':\n\t\t\tsemver = result.saveSpec\n\t\t\tbreak;\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\t\tcase 'range':\n\n\t\t\tif (result.fetchSpec?.length)\n\t\t\t{\n\t\t\t\tlet ls = parseSimpleSemVerRange(result.fetchSpec);\n\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\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\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\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\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\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\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\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\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":"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","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"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/npa-to-deps",
|
|
3
|
-
"version": "3.0.
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "3.0.3",
|
|
4
|
+
"description": "Convert npm-package-arg results to dependency values / 將 npm-package-arg 結果轉換為依賴值",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yarn",
|
|
7
7
|
"yarn-tool",
|
|
@@ -52,13 +52,15 @@
|
|
|
52
52
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@lazy-node/semver-simple-parse": "^
|
|
56
|
-
"@yarn-tool/npm-package-arg-util": "^2.0.
|
|
55
|
+
"@lazy-node/semver-simple-parse": "^4.0.1",
|
|
56
|
+
"@yarn-tool/npm-package-arg-util": "^2.0.3",
|
|
57
57
|
"tslib": ">=2"
|
|
58
58
|
},
|
|
59
|
-
"
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"npm-package-arg": "^13.0.2"
|
|
61
|
+
},
|
|
60
62
|
"publishConfig": {
|
|
61
63
|
"access": "public"
|
|
62
64
|
},
|
|
63
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "ae9b0817b25b1019ba68c88e541bbffc7d84047c"
|
|
64
66
|
}
|