@yarn-tool/workspaces-project 3.0.13 → 3.0.15
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 +59 -0
- package/README.md +81 -5
- package/index.d.ts +99 -0
- package/index.js +126 -2
- package/index.js.map +1 -1
- package/lib/types.d.ts +42 -3
- package/lib/types.js +6 -0
- package/lib/types.js.map +1 -1
- package/lib/util.d.ts +16 -0
- package/lib/util.js +26 -0
- package/lib/util.js.map +1 -1
- package/package.json +25 -16
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,65 @@
|
|
|
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.15](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/workspaces-project@3.0.14...@yarn-tool/workspaces-project@3.0.15) (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
|
+
* **@yarn-tool/workspaces-project:** 重構測試架構並改用 node:test 執行 ([05cbdb5](https://github.com/bluelovers/ws-yarn-workspaces/commit/05cbdb5e1bf567f2b95699f278a25cd2690a64ff))
|
|
18
|
+
* **all:** 完善 node:test 遷移與測試案例優化 ([e38f263](https://github.com/bluelovers/ws-yarn-workspaces/commit/e38f26376a03520b39a54fea5794f27aecc4f424))
|
|
19
|
+
* **snap:** update snapshots ([c9945a5](https://github.com/bluelovers/ws-yarn-workspaces/commit/c9945a5b9cd723d38ded2a69b83e2e83ecc3b524))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### 🛠 Build System
|
|
23
|
+
|
|
24
|
+
* update build ([3186340](https://github.com/bluelovers/ws-yarn-workspaces/commit/3186340758172427cb1e9b8955f6fd677abac625))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### ♻️ Chores
|
|
28
|
+
|
|
29
|
+
* **deps:** 更新依賴版本並清理 npm-init2 腳本 ([82bf1e5](https://github.com/bluelovers/ws-yarn-workspaces/commit/82bf1e5d229759aa285205d81cf0651e4d3d9792))
|
|
30
|
+
* **deps:** 更新各套件依賴版本 ([569f075](https://github.com/bluelovers/ws-yarn-workspaces/commit/569f0756189cdadf69955d8e388ac0a6a8988056))
|
|
31
|
+
* **workspace:** 更新測試指令路徑與新增工作區搜尋選項 ([a80039d](https://github.com/bluelovers/ws-yarn-workspaces/commit/a80039dd8c691e047466966ffc8f8a4e2e31c03f))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### 📌 Dependencies
|
|
35
|
+
|
|
36
|
+
* update deps ([a0c22fe](https://github.com/bluelovers/ws-yarn-workspaces/commit/a0c22feeb1703d1cc10d45ecbf6f2269e92f72da))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### 🔖 Miscellaneous
|
|
40
|
+
|
|
41
|
+
* . ([e5788f8](https://github.com/bluelovers/ws-yarn-workspaces/commit/e5788f84551b870490a96d0a5d67d8d542481373))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## [3.0.14](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/workspaces-project@3.0.13...@yarn-tool/workspaces-project@3.0.14) (2026-09-06)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### 🛠 Build System
|
|
50
|
+
|
|
51
|
+
* update Static Files ([b2f5d72](https://github.com/bluelovers/ws-yarn-workspaces/commit/b2f5d7216773c53eb35f267ba34f8788543d46a1))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### ♻️ Chores
|
|
55
|
+
|
|
56
|
+
* **workspace:** 將所有套件的指令從 yarn 改為 pnpm 並更新依賴版本 ([0505892](https://github.com/bluelovers/ws-yarn-workspaces/commit/0505892e5e7c356f8cf59495fefda1aa681499c6))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
### 🔖 Miscellaneous
|
|
60
|
+
|
|
61
|
+
* . ([b545589](https://github.com/bluelovers/ws-yarn-workspaces/commit/b54558925d67304019e2b4f9bb3c4671c429a96e))
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
6
65
|
## [3.0.13](https://github.com/bluelovers/ws-yarn-workspaces/compare/@yarn-tool/workspaces-project@3.0.12...@yarn-tool/workspaces-project@3.0.13) (2026-04-26)
|
|
7
66
|
|
|
8
67
|
|
package/README.md
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yarn-tool/workspaces-project
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> mixin yarn/lerna workspaces
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
以單一 `WorkspacesProject` 類別混合(Mixin)操作 Yarn Workspaces 與 Lerna 專案設定,讓你用同一套介面讀取/修改 `lerna.json`、workspaces 套件清單與版本發佈設定。
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- 以 `WorkspacesProject` 類別包裝 `@lerna/project`,並自動對齊 Yarn Workspaces 根目錄(Workspace Root)
|
|
10
|
+
- 透過 `checkPaths` 嚴格比對 yarn 根目錄與 lerna 根目錄,不一致時拋出錯誤
|
|
11
|
+
- 以 getter/setter 存取 `npmClient`、`workspaces`、`defaultWorkspace`、`version` 等常用設定
|
|
12
|
+
- 提供 `isIndependent()` 判斷 Lerna 是否採用獨立版本(Independent Versioning)模式
|
|
13
|
+
- `releaseConfig` 會合併 `command.version` 與 `command.publish` 並依鍵名排序,方便產生發佈設定
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
6
16
|
|
|
7
17
|
```bash
|
|
8
18
|
yarn add @yarn-tool/workspaces-project
|
|
@@ -10,8 +20,74 @@ yarn-tool add @yarn-tool/workspaces-project
|
|
|
10
20
|
yt add @yarn-tool/workspaces-project
|
|
11
21
|
```
|
|
12
22
|
|
|
13
|
-
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import WorkspacesProject from '@yarn-tool/workspaces-project';
|
|
27
|
+
|
|
28
|
+
const project = new WorkspacesProject(process.cwd());
|
|
29
|
+
|
|
30
|
+
// 讀取工作區根目錄與 lerna 設定位置
|
|
31
|
+
console.log(project.rootPath);
|
|
32
|
+
console.log(project.lernaConfigLocation);
|
|
33
|
+
|
|
34
|
+
// 讀取/修改 workspaces 套件清單
|
|
35
|
+
console.log(project.workspaces);
|
|
36
|
+
project.defaultWorkspace = project.workspaces[0];
|
|
37
|
+
|
|
38
|
+
// 讀取版本設定;'independent' 代表獨立版本模式
|
|
39
|
+
console.log(project.version, project.isIndependent());
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## API Documentation
|
|
43
|
+
|
|
44
|
+
### `new WorkspacesProject(cwd?, options?)`
|
|
45
|
+
|
|
46
|
+
建立專案實例。
|
|
47
|
+
|
|
48
|
+
- `cwd?: string` — 起始目錄,預設為 `process.cwd()`;會用來尋找 Yarn Workspaces 根目錄。
|
|
49
|
+
- `options?: { skipStrictCheck?: boolean }` — 設為 `true` 時,即使 lerna 根目錄與 yarn 根目錄不一致也不拋錯(交由 `checkPaths` 判斷)。
|
|
50
|
+
- 若 lerna 根目錄與 yarn 根目錄不一致且未豁免檢查,建構函式會拋出 `Error`。
|
|
51
|
+
|
|
52
|
+
### 屬性 (Properties)
|
|
53
|
+
|
|
54
|
+
| Property | Type | 說明 |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `rootPath` | `string` | 工作區根目錄(已正規化) |
|
|
57
|
+
| `lernaConfigLocation` | `string` | `lerna.json` 的檔案路徑 |
|
|
58
|
+
| `npmClient` | `string` | 讀寫 `lerna.json` 的 `npmClient`;根目錄存在且未設定時預設為 `yarn` |
|
|
59
|
+
| `workspaces` | `string[]` | workspaces 套件 glob 清單;來源失效時回退為 `packages/*`,並快取 (Cache) 於內部 |
|
|
60
|
+
| `defaultWorkspace` | `string` | 目前採用的 workspace glob,setter 會驗證其存在於 `workspaces`,否則拋出 `RangeError` |
|
|
61
|
+
| `version` | `string \| 'independent'` | Lerna 版本模式,可讀寫 |
|
|
62
|
+
| `manifest` | `IPackedManifest` | 根套件的 `package.json` 封裝結果 |
|
|
63
|
+
| `config` | `ILernaJson` | `lerna.json` 設定物件,讀取時會同步 `workspaces`/`packages`、`version` 與 `defaultWorkspace` 順序 |
|
|
64
|
+
| `bump` | `IReleaseType` | `command.publish.bump` 或 `command.version.bump` 的發版級別 |
|
|
65
|
+
| `changelogPreset` | `IChangelogPreset` | `command.version`/`command.publish` 的 changelog 預設集 |
|
|
66
|
+
| `releaseConfig` | `object` | 合併 version/publish 指令並補上 `changelogPreset`、`bump`、`conventionalGraduate`,結果依鍵名排序 |
|
|
67
|
+
|
|
68
|
+
### 方法 (Methods)
|
|
69
|
+
|
|
70
|
+
- `isIndependent(): boolean` — 版本為 `'independent'` 時回傳 `true`。
|
|
71
|
+
- `existsLernaConfigFile(): boolean` — `lerna.json` 是否存在於磁碟。
|
|
72
|
+
|
|
73
|
+
### `checkPaths({ root, rootPath }, options?)` (`lib/util`)
|
|
74
|
+
|
|
75
|
+
比對 yarn 根目錄與 lerna 根目錄,回傳 `EnumCheckPaths`:
|
|
76
|
+
|
|
77
|
+
- `EnumCheckPaths.root` — lerna 根目錄位於 yarn 根目錄之下,應改用 yarn 根目錄。
|
|
78
|
+
- `EnumCheckPaths.rootPath` — 兩者一致,或其中一方為空。
|
|
79
|
+
- `EnumCheckPaths.failed` — 不一致且未設定 `skipStrictCheck`。
|
|
80
|
+
|
|
81
|
+
路徑比對前會先以 `path-dir-normalize` 正規化(Normalize),避免尾端斜線造成誤判。
|
|
82
|
+
|
|
83
|
+
## Configuration
|
|
84
|
+
|
|
85
|
+
本套件不新增自己的設定檔,一切以專案既有的 Lerna/Yarn 設定為準:
|
|
86
|
+
|
|
87
|
+
- `lerna.json` — 由 `@lerna/project` 載入,涵蓋 `npmClient`、`useWorkspaces`、`version`、`packages`/`workspaces` 與 `command.version`/`command.publish` 等欄位。
|
|
88
|
+
- `package.json` 的 `workspaces` 欄位 — 由 `find-yarn-workspace-root2` 解析,作為 `rootPath` 對齊的基準。
|
|
89
|
+
|
|
90
|
+
相關參考:
|
|
14
91
|
|
|
15
92
|
- https://www.npmjs.com/package/find-yarn-workspace-root2
|
|
16
93
|
- https://www.npmjs.com/package/%40yarn-tool%2Ffind-root
|
|
17
|
-
-
|
package/index.d.ts
CHANGED
|
@@ -2,37 +2,132 @@ import { Project as LernaProject } from '@lerna/project';
|
|
|
2
2
|
import { IWorkspacesProjectInternal, EnumWorkspacesProject, IPackedManifest } from './lib/types';
|
|
3
3
|
import type { ILernaJson, IReleaseType } from '@ts-type/package-dts/lerna-json';
|
|
4
4
|
import type { IChangelogPreset } from '@yarn-tool/changelog';
|
|
5
|
+
/**
|
|
6
|
+
* 以 Lerna Project 為底層、混入(Mixin)Yarn Workspaces 概念的專案操作類別。
|
|
7
|
+
* A project-handling class wrapping Lerna Project and mixing in Yarn Workspaces concepts.
|
|
8
|
+
*/
|
|
5
9
|
export declare class WorkspacesProject {
|
|
6
10
|
#private;
|
|
7
11
|
/**
|
|
12
|
+
* 底層的 Lerna Project 實例;config 已具型別為 ILernaJson。
|
|
13
|
+
* The underlying Lerna Project instance; `config` is typed as `ILernaJson`.
|
|
14
|
+
*
|
|
8
15
|
* @see https://github.com/lerna/lerna/tree/master/core/project
|
|
9
16
|
*/
|
|
10
17
|
protected _project: LernaProject & {
|
|
11
18
|
config: ILernaJson;
|
|
12
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* 建立實例並對齊 yarn/lerna 根目錄。
|
|
22
|
+
* Create an instance and reconcile the yarn/lerna roots.
|
|
23
|
+
*
|
|
24
|
+
* @param cwd 起始目錄,預設為 process.cwd()。Starting directory; defaults to `process.cwd()`.
|
|
25
|
+
* @param options skipStrictCheck 為 true 時放寬根目錄不一致的檢查。`skipStrictCheck: true` relaxes the mismatched-root check.
|
|
26
|
+
* @throws 當 lerna 根目錄與 yarn 根目錄不一致且未豁免時拋出 Error。Throws when the lerna root and yarn root mismatch without an exemption.
|
|
27
|
+
*/
|
|
13
28
|
constructor(cwd?: string, options?: {
|
|
14
29
|
skipStrictCheck?: boolean;
|
|
15
30
|
});
|
|
31
|
+
/**
|
|
32
|
+
* 檢查內部快取是否已存在指定欄位。
|
|
33
|
+
* Check whether the internal cache already holds the given field.
|
|
34
|
+
*
|
|
35
|
+
* @param field 快取欄位名稱。The cached field name.
|
|
36
|
+
*/
|
|
16
37
|
protected _hasInternal<K extends keyof IWorkspacesProjectInternal>(field: K): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* 讀取內部快取欄位。
|
|
40
|
+
* Read a field from the internal cache.
|
|
41
|
+
*
|
|
42
|
+
* @param field 快取欄位名稱。The cached field name.
|
|
43
|
+
*/
|
|
17
44
|
protected _getInternal<K extends keyof IWorkspacesProjectInternal>(field: K): IWorkspacesProjectInternal[K];
|
|
45
|
+
/**
|
|
46
|
+
* 寫入內部快取欄位。
|
|
47
|
+
* Write a field into the internal cache.
|
|
48
|
+
*
|
|
49
|
+
* @param field 快取欄位名稱。The cached field name.
|
|
50
|
+
* @param value 要寫入的值。The value to store.
|
|
51
|
+
*/
|
|
18
52
|
protected _setInternal<K extends keyof IWorkspacesProjectInternal>(field: K, value: IWorkspacesProjectInternal[K]): IWorkspacesProjectInternal[K];
|
|
53
|
+
/**
|
|
54
|
+
* 工作區根目錄(已正規化)。
|
|
55
|
+
* The workspace root directory (already normalized).
|
|
56
|
+
*/
|
|
19
57
|
get rootPath(): string;
|
|
58
|
+
/**
|
|
59
|
+
* lerna.json 設定檔的完整路徑。
|
|
60
|
+
* Full path to the `lerna.json` config file.
|
|
61
|
+
*/
|
|
20
62
|
get lernaConfigLocation(): string;
|
|
63
|
+
/**
|
|
64
|
+
* lerna 的 npmClient 設定。
|
|
65
|
+
* The `npmClient` setting from lerna.
|
|
66
|
+
*/
|
|
21
67
|
get npmClient(): string;
|
|
68
|
+
/**
|
|
69
|
+
* 設定 npmClient,會直接寫回 lerna 設定。
|
|
70
|
+
* Set `npmClient`, written back into the lerna config directly.
|
|
71
|
+
*/
|
|
22
72
|
set npmClient(value: string);
|
|
73
|
+
/**
|
|
74
|
+
* workspaces 套件 glob 清單,解析結果會快取避免重複計算。
|
|
75
|
+
* The workspace glob list; the resolution result is cached to avoid recomputation.
|
|
76
|
+
*/
|
|
23
77
|
get workspaces(): string[];
|
|
78
|
+
/**
|
|
79
|
+
* 目前預設使用的 workspace glob;找不到時回退到第一個。
|
|
80
|
+
* The currently preferred workspace glob; falls back to the first entry when unset.
|
|
81
|
+
*/
|
|
24
82
|
get defaultWorkspace(): string;
|
|
83
|
+
/**
|
|
84
|
+
* 指定預設 workspace;不存在於清單時拋出 RangeError 以免寫入無效設定。
|
|
85
|
+
* Set the preferred workspace; throws `RangeError` when it is absent from the list to avoid persisting an invalid value.
|
|
86
|
+
*
|
|
87
|
+
* @throws 當 value 不在 workspaces 清單內時拋出。Throws when `value` is not in the `workspaces` list.
|
|
88
|
+
*/
|
|
25
89
|
set defaultWorkspace(value: string);
|
|
90
|
+
/**
|
|
91
|
+
* 是否採用 Lerna 獨立版本(Independent Versioning)模式。
|
|
92
|
+
* Whether Lerna uses independent versioning.
|
|
93
|
+
*/
|
|
26
94
|
isIndependent(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* 版本模式;未設定時視為 independent。
|
|
97
|
+
* The versioning mode; treated as `independent` when unset.
|
|
98
|
+
*/
|
|
27
99
|
get version(): string | EnumWorkspacesProject.independent;
|
|
100
|
+
/**
|
|
101
|
+
* 設定版本模式,寫回 lerna 設定。
|
|
102
|
+
* Set the versioning mode, written back into the lerna config.
|
|
103
|
+
*/
|
|
28
104
|
set version(val: string | EnumWorkspacesProject.independent);
|
|
29
105
|
/**
|
|
106
|
+
* 根套件的 package.json 封裝結果。
|
|
107
|
+
* The packed manifest of the root package.
|
|
108
|
+
*
|
|
30
109
|
* @see https://github.com/lerna/lerna/tree/master/core/package
|
|
31
110
|
*/
|
|
32
111
|
get manifest(): IPackedManifest;
|
|
112
|
+
/**
|
|
113
|
+
* 取得同步後的 lerna 設定;每次存取都會對齊 workspaces、version 與 defaultWorkspace。
|
|
114
|
+
* Obtain the synchronized lerna config; each access aligns `workspaces`, `version`, and `defaultWorkspace`.
|
|
115
|
+
*/
|
|
33
116
|
get config(): ILernaJson;
|
|
117
|
+
/**
|
|
118
|
+
* 發版級別(bump);publish 指令優先於 version 指令。
|
|
119
|
+
* The release bump level; the `publish` command takes precedence over `version`.
|
|
120
|
+
*/
|
|
34
121
|
get bump(): IReleaseType;
|
|
122
|
+
/**
|
|
123
|
+
* changelog 預設集(Preset);version 指令優先於 publish 指令。
|
|
124
|
+
* The changelog preset; the `version` command takes precedence over `publish`.
|
|
125
|
+
*/
|
|
35
126
|
get changelogPreset(): IChangelogPreset;
|
|
127
|
+
/**
|
|
128
|
+
* 合併 version/publish 指令與推導欄位,並依鍵名排序後回傳。
|
|
129
|
+
* Merge the `version`/`publish` commands with derived fields, sort by key, and return the result.
|
|
130
|
+
*/
|
|
36
131
|
get releaseConfig(): import("ts-type").ITSOverwrite<import("ts-type").ITSPickBothDiff<{
|
|
37
132
|
[k: string]: unknown;
|
|
38
133
|
allowBranch?: string | string[];
|
|
@@ -116,6 +211,10 @@ export declare class WorkspacesProject {
|
|
|
116
211
|
conventionalGraduate: import("@ts-type/package-dts/lerna-json").ILernaJsonCommand["publish"]["conventionalGraduate"];
|
|
117
212
|
bump: IReleaseType;
|
|
118
213
|
}>;
|
|
214
|
+
/**
|
|
215
|
+
* lerna.json 是否已存在於磁碟。
|
|
216
|
+
* Whether `lerna.json` exists on disk.
|
|
217
|
+
*/
|
|
119
218
|
existsLernaConfigFile(): boolean;
|
|
120
219
|
}
|
|
121
220
|
export default WorkspacesProject;
|
package/index.js
CHANGED
|
@@ -10,13 +10,32 @@ const util_1 = require("./lib/util");
|
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
11
|
const sort_object_keys2_1 = require("sort-object-keys2");
|
|
12
12
|
const fs_extra_1 = require("fs-extra");
|
|
13
|
+
/**
|
|
14
|
+
* 以 Lerna Project 為底層、混入(Mixin)Yarn Workspaces 概念的專案操作類別。
|
|
15
|
+
* A project-handling class wrapping Lerna Project and mixing in Yarn Workspaces concepts.
|
|
16
|
+
*/
|
|
13
17
|
class WorkspacesProject {
|
|
18
|
+
/**
|
|
19
|
+
* 建立實例並對齊 yarn/lerna 根目錄。
|
|
20
|
+
* Create an instance and reconcile the yarn/lerna roots.
|
|
21
|
+
*
|
|
22
|
+
* @param cwd 起始目錄,預設為 process.cwd()。Starting directory; defaults to `process.cwd()`.
|
|
23
|
+
* @param options skipStrictCheck 為 true 時放寬根目錄不一致的檢查。`skipStrictCheck: true` relaxes the mismatched-root check.
|
|
24
|
+
* @throws 當 lerna 根目錄與 yarn 根目錄不一致且未豁免時拋出 Error。Throws when the lerna root and yarn root mismatch without an exemption.
|
|
25
|
+
*/
|
|
14
26
|
constructor(cwd, options) {
|
|
27
|
+
/**
|
|
28
|
+
* 快取(Cache)內部狀態;避免重複解析 workspaces 與 releaseConfig。
|
|
29
|
+
* Internal cached state; avoids re-resolving `workspaces` and `releaseConfig`.
|
|
30
|
+
*/
|
|
15
31
|
_WorkspacesProject_internal.set(this, {});
|
|
16
32
|
cwd = (0, upath2_1.resolve)(cwd || process.cwd());
|
|
17
33
|
let root = (0, core_1.findWorkspaceRoot)(cwd);
|
|
18
34
|
this._project = new project_1.Project(cwd);
|
|
19
35
|
let rootPath = this._project.rootPath;
|
|
36
|
+
/**
|
|
37
|
+
* checkPaths 決定要用哪個根目錄;failed 代表兩根目錄衝突,直接失敗比默默採用錯誤根目錄更安全。
|
|
38
|
+
*/
|
|
20
39
|
switch ((0, util_1.checkPaths)({
|
|
21
40
|
root,
|
|
22
41
|
rootPath,
|
|
@@ -28,47 +47,99 @@ class WorkspacesProject {
|
|
|
28
47
|
throw new Error(`lerna root is not match yarn workspaces root.\ncwd: ${cwd}\nyarn: ${root}\nlerna: ${rootPath}`);
|
|
29
48
|
break;
|
|
30
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* 有 yarn 工作區時,未明確設定 npmClient 就補上 yarn 並啟用 useWorkspaces,讓 lerna 使用 yarn workspaces。
|
|
52
|
+
*/
|
|
31
53
|
if (root === null || root === void 0 ? void 0 : root.length) {
|
|
32
|
-
if (typeof this.config.npmClient === 'undefined' && this.config
|
|
54
|
+
if (typeof this.config.npmClient === 'undefined' && this.config['useWorkspaces'] !== false) {
|
|
33
55
|
this.npmClient = 'yarn';
|
|
34
|
-
this.config
|
|
56
|
+
this.config['useWorkspaces'] = true;
|
|
35
57
|
}
|
|
36
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* 統一路徑分隔符,避免 Windows 與 POSIX 產生不一致的字串比較結果。
|
|
61
|
+
* Normalize path separators so Windows and POSIX do not produce inconsistent string comparisons.
|
|
62
|
+
*/
|
|
37
63
|
this._project.rootPath = (0, upath2_1.normalize)(this._project.rootPath);
|
|
38
64
|
this._project.rootConfigLocation = (0, upath2_1.normalize)(this._project.rootConfigLocation);
|
|
39
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* 檢查內部快取是否已存在指定欄位。
|
|
68
|
+
* Check whether the internal cache already holds the given field.
|
|
69
|
+
*
|
|
70
|
+
* @param field 快取欄位名稱。The cached field name.
|
|
71
|
+
*/
|
|
40
72
|
_hasInternal(field) {
|
|
41
73
|
return field in tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f");
|
|
42
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* 讀取內部快取欄位。
|
|
77
|
+
* Read a field from the internal cache.
|
|
78
|
+
*
|
|
79
|
+
* @param field 快取欄位名稱。The cached field name.
|
|
80
|
+
*/
|
|
43
81
|
_getInternal(field) {
|
|
44
82
|
return tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f")[field];
|
|
45
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 寫入內部快取欄位。
|
|
86
|
+
* Write a field into the internal cache.
|
|
87
|
+
*
|
|
88
|
+
* @param field 快取欄位名稱。The cached field name.
|
|
89
|
+
* @param value 要寫入的值。The value to store.
|
|
90
|
+
*/
|
|
46
91
|
_setInternal(field, value) {
|
|
47
92
|
return tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f")[field] = value;
|
|
48
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* 工作區根目錄(已正規化)。
|
|
96
|
+
* The workspace root directory (already normalized).
|
|
97
|
+
*/
|
|
49
98
|
get rootPath() {
|
|
50
99
|
return this._project.rootPath;
|
|
51
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* lerna.json 設定檔的完整路徑。
|
|
103
|
+
* Full path to the `lerna.json` config file.
|
|
104
|
+
*/
|
|
52
105
|
get lernaConfigLocation() {
|
|
53
106
|
return this._project.rootConfigLocation;
|
|
54
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* lerna 的 npmClient 設定。
|
|
110
|
+
* The `npmClient` setting from lerna.
|
|
111
|
+
*/
|
|
55
112
|
get npmClient() {
|
|
56
113
|
return this._project.config.npmClient;
|
|
57
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* 設定 npmClient,會直接寫回 lerna 設定。
|
|
117
|
+
* Set `npmClient`, written back into the lerna config directly.
|
|
118
|
+
*/
|
|
58
119
|
set npmClient(value) {
|
|
59
120
|
this._project.config.npmClient = value;
|
|
60
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* workspaces 套件 glob 清單,解析結果會快取避免重複計算。
|
|
124
|
+
* The workspace glob list; the resolution result is cached to avoid recomputation.
|
|
125
|
+
*/
|
|
61
126
|
get workspaces() {
|
|
62
127
|
let ws;
|
|
128
|
+
// 優先回傳快取,避免每次都重新解析 packageConfigs。
|
|
129
|
+
// Return the cached value first to avoid re-parsing `packageConfigs` every time.
|
|
63
130
|
if (this._hasInternal('workspaces')) {
|
|
64
131
|
ws = this._getInternal('workspaces');
|
|
65
132
|
}
|
|
66
133
|
else {
|
|
134
|
+
// packageConfigs 在缺少 lerna 配置時可能拋錯,靜默失敗後改用預設值。
|
|
135
|
+
// `packageConfigs` may throw without lerna config; swallow the failure and fall back to a default.
|
|
67
136
|
try {
|
|
68
137
|
ws = this._project.packageConfigs;
|
|
69
138
|
}
|
|
70
139
|
catch (e) {
|
|
71
140
|
}
|
|
141
|
+
// 取不到任何套件設定時退回 packages/*,確保後續索引不會拿到 undefined。
|
|
142
|
+
// Fall back to `packages/*` when nothing resolves, so downstream indexing never sees `undefined`.
|
|
72
143
|
if (!(ws === null || ws === void 0 ? void 0 : ws.length)) {
|
|
73
144
|
ws = ["packages/*" /* EnumWorkspacesProject.workspace */];
|
|
74
145
|
}
|
|
@@ -76,6 +147,10 @@ class WorkspacesProject {
|
|
|
76
147
|
}
|
|
77
148
|
return ws;
|
|
78
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* 目前預設使用的 workspace glob;找不到時回退到第一個。
|
|
152
|
+
* The currently preferred workspace glob; falls back to the first entry when unset.
|
|
153
|
+
*/
|
|
79
154
|
get defaultWorkspace() {
|
|
80
155
|
if (this._hasInternal('defaultWorkspace')) {
|
|
81
156
|
return this._getInternal('defaultWorkspace');
|
|
@@ -85,30 +160,57 @@ class WorkspacesProject {
|
|
|
85
160
|
}
|
|
86
161
|
return this.workspaces[0];
|
|
87
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* 指定預設 workspace;不存在於清單時拋出 RangeError 以免寫入無效設定。
|
|
165
|
+
* Set the preferred workspace; throws `RangeError` when it is absent from the list to avoid persisting an invalid value.
|
|
166
|
+
*
|
|
167
|
+
* @throws 當 value 不在 workspaces 清單內時拋出。Throws when `value` is not in the `workspaces` list.
|
|
168
|
+
*/
|
|
88
169
|
set defaultWorkspace(value) {
|
|
89
170
|
if (!this.workspaces.includes(value)) {
|
|
90
171
|
throw new RangeError(`${value} not exists in ${this.workspaces}`);
|
|
91
172
|
}
|
|
92
173
|
tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f").defaultWorkspace = value;
|
|
93
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* 是否採用 Lerna 獨立版本(Independent Versioning)模式。
|
|
177
|
+
* Whether Lerna uses independent versioning.
|
|
178
|
+
*/
|
|
94
179
|
isIndependent() {
|
|
95
180
|
return this.version === "independent" /* EnumWorkspacesProject.independent */;
|
|
96
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* 版本模式;未設定時視為 independent。
|
|
184
|
+
* The versioning mode; treated as `independent` when unset.
|
|
185
|
+
*/
|
|
97
186
|
get version() {
|
|
98
187
|
var _a;
|
|
99
188
|
return (_a = this._project.config.version) !== null && _a !== void 0 ? _a : "independent" /* EnumWorkspacesProject.independent */;
|
|
100
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* 設定版本模式,寫回 lerna 設定。
|
|
192
|
+
* Set the versioning mode, written back into the lerna config.
|
|
193
|
+
*/
|
|
101
194
|
set version(val) {
|
|
102
195
|
this._project.config.version = val;
|
|
103
196
|
}
|
|
104
197
|
/**
|
|
198
|
+
* 根套件的 package.json 封裝結果。
|
|
199
|
+
* The packed manifest of the root package.
|
|
200
|
+
*
|
|
105
201
|
* @see https://github.com/lerna/lerna/tree/master/core/package
|
|
106
202
|
*/
|
|
107
203
|
get manifest() {
|
|
108
204
|
return this._project.manifest;
|
|
109
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* 取得同步後的 lerna 設定;每次存取都會對齊 workspaces、version 與 defaultWorkspace。
|
|
208
|
+
* Obtain the synchronized lerna config; each access aligns `workspaces`, `version`, and `defaultWorkspace`.
|
|
209
|
+
*/
|
|
110
210
|
get config() {
|
|
111
211
|
let ws = this.workspaces;
|
|
212
|
+
// 依 lerna 版本慣用的欄位(workspaces 或 packages)寫入套件清單,保持相容。
|
|
213
|
+
// Write the package list into whichever field the lerna version uses (`workspaces` or `packages`) for compatibility.
|
|
112
214
|
if ('workspaces' in this._project.config) {
|
|
113
215
|
this._project.config.workspaces = ws;
|
|
114
216
|
}
|
|
@@ -117,6 +219,8 @@ class WorkspacesProject {
|
|
|
117
219
|
}
|
|
118
220
|
this._project.config.version = this.version;
|
|
119
221
|
let w = this.defaultWorkspace;
|
|
222
|
+
// 將預設 workspace 移到清單最前,讓 lerna 優先採用第一個 glob。
|
|
223
|
+
// Move the preferred workspace to the front of the list so lerna picks the first glob first.
|
|
120
224
|
if (ws[0] !== w) {
|
|
121
225
|
let i = ws.indexOf(w);
|
|
122
226
|
if (i !== -1) {
|
|
@@ -126,27 +230,47 @@ class WorkspacesProject {
|
|
|
126
230
|
}
|
|
127
231
|
return this._project.config;
|
|
128
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* 發版級別(bump);publish 指令優先於 version 指令。
|
|
235
|
+
* The release bump level; the `publish` command takes precedence over `version`.
|
|
236
|
+
*/
|
|
129
237
|
get bump() {
|
|
130
238
|
var _a, _b, _c;
|
|
131
239
|
const command = this._project.config.command;
|
|
132
240
|
return (_b = (_a = command === null || command === void 0 ? void 0 : command.publish) === null || _a === void 0 ? void 0 : _a.bump) !== null && _b !== void 0 ? _b : (_c = command === null || command === void 0 ? void 0 : command.version) === null || _c === void 0 ? void 0 : _c.bump;
|
|
133
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* changelog 預設集(Preset);version 指令優先於 publish 指令。
|
|
244
|
+
* The changelog preset; the `version` command takes precedence over `publish`.
|
|
245
|
+
*/
|
|
134
246
|
get changelogPreset() {
|
|
135
247
|
var _a, _b, _c;
|
|
136
248
|
const command = this._project.config.command;
|
|
137
249
|
return (_b = (_a = command === null || command === void 0 ? void 0 : command.version) === null || _a === void 0 ? void 0 : _a.changelogPreset) !== null && _b !== void 0 ? _b : (_c = command === null || command === void 0 ? void 0 : command.publish) === null || _c === void 0 ? void 0 : _c.changelogPreset;
|
|
138
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* 合併 version/publish 指令與推導欄位,並依鍵名排序後回傳。
|
|
253
|
+
* Merge the `version`/`publish` commands with derived fields, sort by key, and return the result.
|
|
254
|
+
*/
|
|
139
255
|
get releaseConfig() {
|
|
140
256
|
var _a, _b, _c;
|
|
141
257
|
const command = this._project.config.command;
|
|
258
|
+
// merge 到快取欄位以保留前次結果;缺漏的 conventionalGraduate 同樣以 publish 優先補齊。
|
|
259
|
+
// Merge into the cached field to preserve previous results; a missing `conventionalGraduate` is also filled with `publish` taking precedence.
|
|
142
260
|
tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f").releaseConfig = (0, lodash_1.merge)(tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f").releaseConfig, command === null || command === void 0 ? void 0 : command.version, command === null || command === void 0 ? void 0 : command.publish, {
|
|
143
261
|
changelogPreset: this.changelogPreset,
|
|
144
262
|
bump: this.bump,
|
|
145
263
|
conventionalGraduate: (_b = (_a = command === null || command === void 0 ? void 0 : command.publish) === null || _a === void 0 ? void 0 : _a.conventionalGraduate) !== null && _b !== void 0 ? _b : (_c = command === null || command === void 0 ? void 0 : command.version) === null || _c === void 0 ? void 0 : _c.conventionalGraduate,
|
|
146
264
|
});
|
|
265
|
+
// 排序鍵名,讓輸出(如 JSON 寫回)保持穩定可讀的順序。
|
|
266
|
+
// Sort keys so serialized output (e.g. JSON writes) stays stable and readable.
|
|
147
267
|
tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f").releaseConfig = (0, sort_object_keys2_1.sortObjectKeys)(tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f").releaseConfig);
|
|
148
268
|
return tslib_1.__classPrivateFieldGet(this, _WorkspacesProject_internal, "f").releaseConfig;
|
|
149
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* lerna.json 是否已存在於磁碟。
|
|
272
|
+
* Whether `lerna.json` exists on disk.
|
|
273
|
+
*/
|
|
150
274
|
existsLernaConfigFile() {
|
|
151
275
|
return (0, fs_extra_1.pathExistsSync)(this.lernaConfigLocation);
|
|
152
276
|
}
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAyD;AACzD,mCAA4C;AAE5C,yDAAmE;AACnE,qCAAwD;AAGxD,mCAA+B;AAC/B,yDAAmD;AACnD,uCAA0C;AAE1C,MAAa,iBAAiB;IAY7B,YAAY,GAAY,EAAE,OAEzB;QAJD,sCAAwC,EAAS,EAAC;QAMjD,GAAG,GAAG,IAAA,gBAAO,EAAC,GAAG,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAEpC,IAAI,IAAI,GAAG,IAAA,wBAAiB,EAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAY,CAAC,GAAG,CAAC,CAAA;QACrC,IAAI,QAAQ,GAAW,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAE9C,QAAQ,IAAA,iBAAU,EAAC;YAClB,IAAI;YACJ,QAAQ;SACR,EAAE,OAAO,CAAC,EACX,CAAC;YACA;gBACC,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAY,CAAC,IAAI,CAAC,CAAC;gBACvC,MAAM;YACP;gBACC,MAAM,IAAI,KAAK,CAAC,uDAAuD,GAAG,WAAW,IAAI,YAAY,QAAQ,EAAE,CAAC,CAAC;gBACjH,MAAM;QACR,CAAC;QAED,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,EAChB,CAAC;YACA,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,KAAK,WAAW,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,KAAK,KAAK,EACvF,CAAC;gBACA,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC;g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O,CAAA;QAE5C,OAAO,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,eAAe,mCAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,eAAe,CAAA;IAC9E,CAAC;IAED,IAAI,aAAa;;QAEhB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAA;QAE5C,+BAAA,IAAI,mCAAU,CAAC,aAAa,GAAG,IAAA,cAAK,EAAC,+BAAA,IAAI,mCAAU,CAAC,aAAa,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,EAAE;YACtG,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,oBAAoB,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,oBAAoB,mCAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,0CAAE,oBAAoB;SACtG,CAAC,CAAC;QAEH,+BAAA,IAAI,mCAAU,CAAC,aAAa,GAAG,IAAA,kCAAc,EAAC,+BAAA,IAAI,mCAAU,CAAC,aAAa,CAAQ,CAAA;QAElF,OAAO,+BAAA,IAAI,mCAAU,CAAC,aAAa,CAAA;IACpC,CAAC;IAED,qBAAqB;QAEpB,OAAO,IAAA,yBAAc,EAAC,IAAI,CAAC,mBAAmB,CAAC,CAAA;IAChD,CAAC;CAED;AArOD,8CAqOC;;AAED,kBAAe,iBAAiB,CAAA","sourcesContent":["import { Project as LernaProject } from '@lerna/project';\nimport { resolve, normalize } from 'upath2';\nimport { IWorkspacesProjectInternal, EnumWorkspacesProject, IPackedManifest } from './lib/types';\nimport { findWorkspaceRoot } from 'find-yarn-workspace-root2/core';\nimport { checkPaths, EnumCheckPaths } from './lib/util';\nimport type { ILernaJson, IReleaseType } from '@ts-type/package-dts/lerna-json';\nimport type { IChangelogPreset } from '@yarn-tool/changelog';\nimport { merge } from 'lodash';\nimport { sortObjectKeys } from 'sort-object-keys2';\nimport { pathExistsSync } from 'fs-extra';\n\nexport class WorkspacesProject\n{\n\n\t/**\n\t * @see https://github.com/lerna/lerna/tree/master/core/project\n\t */\n\tprotected _project: LernaProject & {\n\t\tconfig: ILernaJson,\n\t};\n\n\t#internal: IWorkspacesProjectInternal = {} as any;\n\n\tconstructor(cwd?: string, options?: {\n\t\tskipStrictCheck?: boolean\n\t})\n\t{\n\t\tcwd = resolve(cwd || process.cwd());\n\n\t\tlet root = findWorkspaceRoot(cwd);\n\n\t\tthis._project = new LernaProject(cwd)\n\t\tlet rootPath: string = this._project.rootPath;\n\n\t\tswitch (checkPaths({\n\t\t\troot,\n\t\t\trootPath,\n\t\t}, options))\n\t\t{\n\t\t\tcase EnumCheckPaths.root:\n\t\t\t\tthis._project = new LernaProject(root);\n\t\t\t\tbreak;\n\t\t\tcase EnumCheckPaths.failed:\n\t\t\t\tthrow new Error(`lerna root is not match yarn workspaces root.\\ncwd: ${cwd}\\nyarn: ${root}\\nlerna: ${rootPath}`);\n\t\t\t\tbreak;\n\t\t}\n\n\t\tif (root?.length)\n\t\t{\n\t\t\tif (typeof this.config.npmClient === 'undefined' && this.config.useWorkspaces !== false)\n\t\t\t{\n\t\t\t\tthis.npmClient = 'yarn';\n\t\t\t\tthis.config.useWorkspaces = true;\n\t\t\t}\n\t\t}\n\n\t\tthis._project.rootPath = normalize(this._project.rootPath);\n\n\t\tthis._project.rootConfigLocation = normalize(this._project.rootConfigLocation);\n\t}\n\n\tprotected _hasInternal<K extends keyof IWorkspacesProjectInternal>(field: K)\n\t{\n\t\treturn field in this.#internal\n\t}\n\n\tprotected _getInternal<K extends keyof IWorkspacesProjectInternal>(field: K)\n\t{\n\t\treturn this.#internal[field]\n\t}\n\n\tprotected _setInternal<K extends keyof IWorkspacesProjectInternal>(field: K, value: IWorkspacesProjectInternal[K])\n\t{\n\t\treturn this.#internal[field] = value\n\t}\n\n\tget rootPath(): string\n\t{\n\t\treturn this._project.rootPath\n\t}\n\n\tget lernaConfigLocation(): string\n\t{\n\t\treturn this._project.rootConfigLocation\n\t}\n\n\tget npmClient(): string\n\t{\n\t\treturn this._project.config.npmClient\n\t}\n\n\tset npmClient(value: string)\n\t{\n\t\tthis._project.config.npmClient = value\n\t}\n\n\tget workspaces(): string[]\n\t{\n\t\tlet ws: string[];\n\n\t\tif (this._hasInternal('workspaces'))\n\t\t{\n\t\t\tws = this._getInternal('workspaces')\n\t\t}\n\t\telse\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tws = this._project.packageConfigs;\n\t\t\t}\n\t\t\tcatch (e)\n\t\t\t{\n\n\t\t\t}\n\n\t\t\tif (!ws?.length)\n\t\t\t{\n\t\t\t\tws = [EnumWorkspacesProject.workspace]\n\t\t\t}\n\n\t\t\tthis._setInternal('workspaces', ws)\n\t\t}\n\n\t\treturn ws;\n\t}\n\n\tget defaultWorkspace(): string\n\t{\n\t\tif (this._hasInternal('defaultWorkspace'))\n\t\t{\n\t\t\treturn this._getInternal('defaultWorkspace')\n\t\t}\n\n\t\tif (this.workspaces.includes(EnumWorkspacesProject.workspace))\n\t\t{\n\t\t\treturn EnumWorkspacesProject.workspace\n\t\t}\n\n\t\treturn this.workspaces[0]\n\t}\n\n\tset defaultWorkspace(value: string)\n\t{\n\t\tif (!this.workspaces.includes(value))\n\t\t{\n\t\t\tthrow new RangeError(`${value} not exists in ${this.workspaces}`)\n\t\t}\n\n\t\tthis.#internal.defaultWorkspace = value;\n\t}\n\n\tisIndependent()\n\t{\n\t\treturn this.version === EnumWorkspacesProject.independent;\n\t}\n\n\tget version(): string | EnumWorkspacesProject.independent\n\t{\n\t\treturn this._project.config.version ?? EnumWorkspacesProject.independent;\n\t}\n\n\tset version(val: string | EnumWorkspacesProject.independent)\n\t{\n\t\tthis._project.config.version = val;\n\t}\n\n\t/**\n\t * @see https://github.com/lerna/lerna/tree/master/core/package\n\t */\n\tget manifest(): IPackedManifest\n\t{\n\t\treturn this._project.manifest\n\t}\n\n\tget config(): ILernaJson\n\t{\n\t\tlet ws = this.workspaces;\n\n\t\tif ('workspaces' in this._project.config)\n\t\t{\n\t\t\tthis._project.config.workspaces = ws\n\t\t}\n\t\telse if ('packages' in this._project.config || 1)\n\t\t{\n\t\t\tthis._project.config.packages = ws\n\t\t}\n\n\t\tthis._project.config.version = this.version;\n\n\t\tlet w = this.defaultWorkspace;\n\n\t\tif (ws[0] !== w)\n\t\t{\n\t\t\tlet i = ws.indexOf(w)\n\n\t\t\tif (i !== -1)\n\t\t\t{\n\t\t\t\tws.splice(i, 1);\n\t\t\t\tws.unshift(w)\n\t\t\t}\n\n\t\t}\n\n\t\treturn this._project.config\n\t}\n\n\tget bump(): IReleaseType\n\t{\n\t\tconst command = this._project.config.command\n\n\t\treturn command?.publish?.bump ?? command?.version?.bump\n\t}\n\n\tget changelogPreset(): IChangelogPreset\n\t{\n\t\tconst command = this._project.config.command\n\n\t\treturn command?.version?.changelogPreset ?? command?.publish?.changelogPreset\n\t}\n\n\tget releaseConfig()\n\t{\n\t\tconst command = this._project.config.command\n\n\t\tthis.#internal.releaseConfig = merge(this.#internal.releaseConfig, command?.version, command?.publish, {\n\t\t\tchangelogPreset: this.changelogPreset,\n\t\t\tbump: this.bump,\n\t\t\tconventionalGraduate: command?.publish?.conventionalGraduate ?? command?.version?.conventionalGraduate,\n\t\t});\n\n\t\tthis.#internal.releaseConfig = sortObjectKeys(this.#internal.releaseConfig) as any\n\n\t\treturn this.#internal.releaseConfig\n\t}\n\n\texistsLernaConfigFile()\n\t{\n\t\treturn pathExistsSync(this.lernaConfigLocation)\n\t}\n\n}\n\nexport default WorkspacesProject\n\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;AAAA,4CAAyD;AACzD,mCAA4C;AAE5C,yDAA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AC,mBAAmB,CAAC,CAAA;IAChD,CAAC;CAED;AAhWD,8CAgWC;;AAED,kBAAe,iBAAiB,CAAA","sourcesContent":["import { Project as LernaProject } from '@lerna/project';\nimport { resolve, normalize } from 'upath2';\nimport { IWorkspacesProjectInternal, EnumWorkspacesProject, IPackedManifest } from './lib/types';\nimport { findWorkspaceRoot } from 'find-yarn-workspace-root2/core';\nimport { checkPaths, EnumCheckPaths } from './lib/util';\nimport type { ILernaJson, IReleaseType } from '@ts-type/package-dts/lerna-json';\nimport type { IChangelogPreset } from '@yarn-tool/changelog';\nimport { merge } from 'lodash';\nimport { sortObjectKeys } from 'sort-object-keys2';\nimport { pathExistsSync } from 'fs-extra';\n\n/**\n * 以 Lerna Project 為底層、混入(Mixin)Yarn Workspaces 概念的專案操作類別。\n * A project-handling class wrapping Lerna Project and mixing in Yarn Workspaces concepts.\n */\nexport class WorkspacesProject\n{\n\n\t/**\n\t * 底層的 Lerna Project 實例;config 已具型別為 ILernaJson。\n\t * The underlying Lerna Project instance; `config` is typed as `ILernaJson`.\n\t *\n\t * @see https://github.com/lerna/lerna/tree/master/core/project\n\t */\n\tprotected _project: LernaProject & {\n\t\tconfig: ILernaJson,\n\t};\n\n\t/**\n\t * 快取(Cache)內部狀態;避免重複解析 workspaces 與 releaseConfig。\n\t * Internal cached state; avoids re-resolving `workspaces` and `releaseConfig`.\n\t */\n\t#internal: IWorkspacesProjectInternal = {} as any;\n\n\t/**\n\t * 建立實例並對齊 yarn/lerna 根目錄。\n\t * Create an instance and reconcile the yarn/lerna roots.\n\t *\n\t * @param cwd 起始目錄,預設為 process.cwd()。Starting directory; defaults to `process.cwd()`.\n\t * @param options skipStrictCheck 為 true 時放寬根目錄不一致的檢查。`skipStrictCheck: true` relaxes the mismatched-root check.\n\t * @throws 當 lerna 根目錄與 yarn 根目錄不一致且未豁免時拋出 Error。Throws when the lerna root and yarn root mismatch without an exemption.\n\t */\n\tconstructor(cwd?: string, options?: {\n\t\tskipStrictCheck?: boolean\n\t})\n\t{\n\t\tcwd = resolve(cwd || process.cwd());\n\n\t\tlet root = findWorkspaceRoot(cwd);\n\n\t\tthis._project = new LernaProject(cwd)\n\t\tlet rootPath: string = this._project.rootPath;\n\n\t\t/**\n\t\t * checkPaths 決定要用哪個根目錄;failed 代表兩根目錄衝突,直接失敗比默默採用錯誤根目錄更安全。\n\t\t */\n\t\tswitch (checkPaths({\n\t\t\troot,\n\t\t\trootPath,\n\t\t}, options))\n\t\t{\n\t\t\tcase EnumCheckPaths.root:\n\t\t\t\tthis._project = new LernaProject(root);\n\t\t\t\tbreak;\n\t\t\tcase EnumCheckPaths.failed:\n\t\t\t\tthrow new Error(`lerna root is not match yarn workspaces root.\\ncwd: ${cwd}\\nyarn: ${root}\\nlerna: ${rootPath}`);\n\t\t\t\tbreak;\n\t\t}\n\n\t\t/**\n\t\t * 有 yarn 工作區時,未明確設定 npmClient 就補上 yarn 並啟用 useWorkspaces,讓 lerna 使用 yarn workspaces。\n\t\t */\n\t\tif (root?.length)\n\t\t{\n\t\t\tif (typeof this.config.npmClient === 'undefined' && this.config['useWorkspaces'] !== false)\n\t\t\t{\n\t\t\t\tthis.npmClient = 'yarn';\n\t\t\t\tthis.config['useWorkspaces'] = true;\n\t\t\t}\n\t\t}\n\n\t\t/**\n\t\t * 統一路徑分隔符,避免 Windows 與 POSIX 產生不一致的字串比較結果。\n\t\t * Normalize path separators so Windows and POSIX do not produce inconsistent string comparisons.\n\t\t */\n\t\tthis._project.rootPath = normalize(this._project.rootPath);\n\n\t\tthis._project.rootConfigLocation = normalize(this._project.rootConfigLocation);\n\t}\n\n\t/**\n\t * 檢查內部快取是否已存在指定欄位。\n\t * Check whether the internal cache already holds the given field.\n\t *\n\t * @param field 快取欄位名稱。The cached field name.\n\t */\n\tprotected _hasInternal<K extends keyof IWorkspacesProjectInternal>(field: K)\n\t{\n\t\treturn field in this.#internal\n\t}\n\n\t/**\n\t * 讀取內部快取欄位。\n\t * Read a field from the internal cache.\n\t *\n\t * @param field 快取欄位名稱。The cached field name.\n\t */\n\tprotected _getInternal<K extends keyof IWorkspacesProjectInternal>(field: K)\n\t{\n\t\treturn this.#internal[field]\n\t}\n\n\t/**\n\t * 寫入內部快取欄位。\n\t * Write a field into the internal cache.\n\t *\n\t * @param field 快取欄位名稱。The cached field name.\n\t * @param value 要寫入的值。The value to store.\n\t */\n\tprotected _setInternal<K extends keyof IWorkspacesProjectInternal>(field: K, value: IWorkspacesProjectInternal[K])\n\t{\n\t\treturn this.#internal[field] = value\n\t}\n\n\t/**\n\t * 工作區根目錄(已正規化)。\n\t * The workspace root directory (already normalized).\n\t */\n\tget rootPath(): string\n\t{\n\t\treturn this._project.rootPath\n\t}\n\n\t/**\n\t * lerna.json 設定檔的完整路徑。\n\t * Full path to the `lerna.json` config file.\n\t */\n\tget lernaConfigLocation(): string\n\t{\n\t\treturn this._project.rootConfigLocation\n\t}\n\n\t/**\n\t * lerna 的 npmClient 設定。\n\t * The `npmClient` setting from lerna.\n\t */\n\tget npmClient(): string\n\t{\n\t\treturn this._project.config.npmClient\n\t}\n\n\t/**\n\t * 設定 npmClient,會直接寫回 lerna 設定。\n\t * Set `npmClient`, written back into the lerna config directly.\n\t */\n\tset npmClient(value: string)\n\t{\n\t\tthis._project.config.npmClient = value\n\t}\n\n\t/**\n\t * workspaces 套件 glob 清單,解析結果會快取避免重複計算。\n\t * The workspace glob list; the resolution result is cached to avoid recomputation.\n\t */\n\tget workspaces(): string[]\n\t{\n\t\tlet ws: string[];\n\n\t\t// 優先回傳快取,避免每次都重新解析 packageConfigs。\n\t\t// Return the cached value first to avoid re-parsing `packageConfigs` every time.\n\t\tif (this._hasInternal('workspaces'))\n\t\t{\n\t\t\tws = this._getInternal('workspaces')\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// packageConfigs 在缺少 lerna 配置時可能拋錯,靜默失敗後改用預設值。\n\t\t\t// `packageConfigs` may throw without lerna config; swallow the failure and fall back to a default.\n\t\t\ttry\n\t\t\t{\n\t\t\t\tws = this._project.packageConfigs;\n\t\t\t}\n\t\t\tcatch (e)\n\t\t\t{\n\n\t\t\t}\n\n\t\t\t// 取不到任何套件設定時退回 packages/*,確保後續索引不會拿到 undefined。\n\t\t\t// Fall back to `packages/*` when nothing resolves, so downstream indexing never sees `undefined`.\n\t\t\tif (!ws?.length)\n\t\t\t{\n\t\t\t\tws = [EnumWorkspacesProject.workspace]\n\t\t\t}\n\n\t\t\tthis._setInternal('workspaces', ws)\n\t\t}\n\n\t\treturn ws;\n\t}\n\n\t/**\n\t * 目前預設使用的 workspace glob;找不到時回退到第一個。\n\t * The currently preferred workspace glob; falls back to the first entry when unset.\n\t */\n\tget defaultWorkspace(): string\n\t{\n\t\tif (this._hasInternal('defaultWorkspace'))\n\t\t{\n\t\t\treturn this._getInternal('defaultWorkspace')\n\t\t}\n\n\t\tif (this.workspaces.includes(EnumWorkspacesProject.workspace))\n\t\t{\n\t\t\treturn EnumWorkspacesProject.workspace\n\t\t}\n\n\t\treturn this.workspaces[0]\n\t}\n\n\t/**\n\t * 指定預設 workspace;不存在於清單時拋出 RangeError 以免寫入無效設定。\n\t * Set the preferred workspace; throws `RangeError` when it is absent from the list to avoid persisting an invalid value.\n\t *\n\t * @throws 當 value 不在 workspaces 清單內時拋出。Throws when `value` is not in the `workspaces` list.\n\t */\n\tset defaultWorkspace(value: string)\n\t{\n\t\tif (!this.workspaces.includes(value))\n\t\t{\n\t\t\tthrow new RangeError(`${value} not exists in ${this.workspaces}`)\n\t\t}\n\n\t\tthis.#internal.defaultWorkspace = value;\n\t}\n\n\t/**\n\t * 是否採用 Lerna 獨立版本(Independent Versioning)模式。\n\t * Whether Lerna uses independent versioning.\n\t */\n\tisIndependent()\n\t{\n\t\treturn this.version === EnumWorkspacesProject.independent;\n\t}\n\n\t/**\n\t * 版本模式;未設定時視為 independent。\n\t * The versioning mode; treated as `independent` when unset.\n\t */\n\tget version(): string | EnumWorkspacesProject.independent\n\t{\n\t\treturn this._project.config.version ?? EnumWorkspacesProject.independent;\n\t}\n\n\t/**\n\t * 設定版本模式,寫回 lerna 設定。\n\t * Set the versioning mode, written back into the lerna config.\n\t */\n\tset version(val: string | EnumWorkspacesProject.independent)\n\t{\n\t\tthis._project.config.version = val;\n\t}\n\n\t/**\n\t * 根套件的 package.json 封裝結果。\n\t * The packed manifest of the root package.\n\t *\n\t * @see https://github.com/lerna/lerna/tree/master/core/package\n\t */\n\tget manifest(): IPackedManifest\n\t{\n\t\treturn this._project.manifest\n\t}\n\n\t/**\n\t * 取得同步後的 lerna 設定;每次存取都會對齊 workspaces、version 與 defaultWorkspace。\n\t * Obtain the synchronized lerna config; each access aligns `workspaces`, `version`, and `defaultWorkspace`.\n\t */\n\tget config(): ILernaJson\n\t{\n\t\tlet ws = this.workspaces;\n\n\t\t// 依 lerna 版本慣用的欄位(workspaces 或 packages)寫入套件清單,保持相容。\n\t\t// Write the package list into whichever field the lerna version uses (`workspaces` or `packages`) for compatibility.\n\t\tif ('workspaces' in this._project.config)\n\t\t{\n\t\t\tthis._project.config.workspaces = ws\n\t\t}\n\t\telse if ('packages' in this._project.config || 1)\n\t\t{\n\t\t\tthis._project.config.packages = ws\n\t\t}\n\n\t\tthis._project.config.version = this.version;\n\n\t\tlet w = this.defaultWorkspace;\n\n\t\t// 將預設 workspace 移到清單最前,讓 lerna 優先採用第一個 glob。\n\t\t// Move the preferred workspace to the front of the list so lerna picks the first glob first.\n\t\tif (ws[0] !== w)\n\t\t{\n\t\t\tlet i = ws.indexOf(w)\n\n\t\t\tif (i !== -1)\n\t\t\t{\n\t\t\t\tws.splice(i, 1);\n\t\t\t\tws.unshift(w)\n\t\t\t}\n\n\t\t}\n\n\t\treturn this._project.config\n\t}\n\n\t/**\n\t * 發版級別(bump);publish 指令優先於 version 指令。\n\t * The release bump level; the `publish` command takes precedence over `version`.\n\t */\n\tget bump(): IReleaseType\n\t{\n\t\tconst command = this._project.config.command\n\n\t\treturn command?.publish?.bump ?? command?.version?.bump\n\t}\n\n\t/**\n\t * changelog 預設集(Preset);version 指令優先於 publish 指令。\n\t * The changelog preset; the `version` command takes precedence over `publish`.\n\t */\n\tget changelogPreset(): IChangelogPreset\n\t{\n\t\tconst command = this._project.config.command\n\n\t\treturn command?.version?.changelogPreset ?? command?.publish?.changelogPreset\n\t}\n\n\t/**\n\t * 合併 version/publish 指令與推導欄位,並依鍵名排序後回傳。\n\t * Merge the `version`/`publish` commands with derived fields, sort by key, and return the result.\n\t */\n\tget releaseConfig()\n\t{\n\t\tconst command = this._project.config.command\n\n\t\t// merge 到快取欄位以保留前次結果;缺漏的 conventionalGraduate 同樣以 publish 優先補齊。\n\t\t// Merge into the cached field to preserve previous results; a missing `conventionalGraduate` is also filled with `publish` taking precedence.\n\t\tthis.#internal.releaseConfig = merge(this.#internal.releaseConfig, command?.version, command?.publish, {\n\t\t\tchangelogPreset: this.changelogPreset,\n\t\t\tbump: this.bump,\n\t\t\tconventionalGraduate: command?.publish?.conventionalGraduate ?? command?.version?.conventionalGraduate,\n\t\t});\n\n\t\t// 排序鍵名,讓輸出(如 JSON 寫回)保持穩定可讀的順序。\n\t\t// Sort keys so serialized output (e.g. JSON writes) stays stable and readable.\n\t\tthis.#internal.releaseConfig = sortObjectKeys(this.#internal.releaseConfig) as any\n\n\t\treturn this.#internal.releaseConfig\n\t}\n\n\t/**\n\t * lerna.json 是否已存在於磁碟。\n\t * Whether `lerna.json` exists on disk.\n\t */\n\texistsLernaConfigFile()\n\t{\n\t\treturn pathExistsSync(this.lernaConfigLocation)\n\t}\n\n}\n\nexport default WorkspacesProject\n\n"]}
|
package/lib/types.d.ts
CHANGED
|
@@ -4,47 +4,86 @@ import type { IPackageJsonDependenciesField, IDependency } from '@ts-type/packag
|
|
|
4
4
|
import type { FileResult, HostedGitResult, URLResult, AliasResult, RegistryResult } from 'npm-package-arg';
|
|
5
5
|
import type { ITSOverwrite } from 'ts-type';
|
|
6
6
|
import { IReleaseType } from '@ts-type/package-dts/lerna-json';
|
|
7
|
+
/**
|
|
8
|
+
* WorkspacesProject 常用的預設值常量。
|
|
9
|
+
* Well-known default values used by `WorkspacesProject`.
|
|
10
|
+
*/
|
|
7
11
|
export declare const enum EnumWorkspacesProject {
|
|
12
|
+
/** 預設的 workspace glob。The default workspace glob. */
|
|
8
13
|
workspace = "packages/*",
|
|
14
|
+
/** Lerna 獨立版本模式的版本值。The version value marking Lerna independent versioning. */
|
|
9
15
|
independent = "independent"
|
|
10
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* WorkspacesProject 內部快取欄位的形狀。
|
|
19
|
+
* Shape of the internal cache fields of `WorkspacesProject`.
|
|
20
|
+
*/
|
|
11
21
|
export interface IWorkspacesProjectInternal {
|
|
22
|
+
/** 目前選用的 workspace glob。The currently preferred workspace glob. */
|
|
12
23
|
defaultWorkspace: string;
|
|
24
|
+
/** 已解析的 workspaces glob 清單。The resolved workspace glob list. */
|
|
13
25
|
workspaces: string[];
|
|
26
|
+
/** 合併過的發佈設定,含推導出的 changelogPreset/bump。Merged release config including derived `changelogPreset`/`bump`. */
|
|
14
27
|
releaseConfig: ITSOverwrite<ILernaJsonCommand["version"] & ILernaJsonCommand["publish"], {
|
|
15
28
|
changelogPreset: ILernaJsonCommand["version"]['changelogPreset'];
|
|
16
29
|
conventionalGraduate: ILernaJsonCommand["publish"]['conventionalGraduate'];
|
|
17
30
|
bump: IReleaseType;
|
|
18
31
|
}>;
|
|
19
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 依 npm-package-arg 解析後的套件解析結果聯集型別。
|
|
35
|
+
* Union of the npm-package-arg resolution results for a dependency.
|
|
36
|
+
*/
|
|
20
37
|
export type IResolvedResult = FileResult | HostedGitResult | URLResult | AliasResult | RegistryResult;
|
|
38
|
+
/**
|
|
39
|
+
* IPackedManifest 中屬於本套件自訂、會覆寫 package.json 同名欄位的部分。
|
|
40
|
+
* The custom part of `IPackedManifest` that overrides same-named `package.json` fields.
|
|
41
|
+
*
|
|
42
|
+
* @see WorkspacesProject.manifest
|
|
43
|
+
*/
|
|
21
44
|
export interface IPackedManifestCore extends Record<IPackageJsonDependenciesField, IDependency> {
|
|
22
45
|
name: string;
|
|
23
46
|
location: string;
|
|
24
47
|
private: boolean;
|
|
48
|
+
/** 依賴的解析結果。The parsed resolution result of the dependency. */
|
|
25
49
|
resolved: IResolvedResult;
|
|
50
|
+
/** 工作區根目錄。The workspace root. */
|
|
26
51
|
rootPath: string;
|
|
52
|
+
/** 是否為 Lerna 套件。Whether this is a Lerna package. */
|
|
27
53
|
__isLernaPackage: boolean;
|
|
54
|
+
/** bin 映射。The `bin` mapping. */
|
|
28
55
|
bin: Record<string, string>;
|
|
29
56
|
scripts: IPackageJson["scripts"];
|
|
30
57
|
/**
|
|
31
|
-
* package.json
|
|
58
|
+
* package.json 檔案路徑。
|
|
59
|
+
* Path of the `package.json` file.
|
|
32
60
|
*/
|
|
33
61
|
manifestLocation: string;
|
|
34
62
|
/**
|
|
35
|
-
* node_modules
|
|
63
|
+
* node_modules 資料夾路徑。
|
|
64
|
+
* Path of the `node_modules` folder.
|
|
36
65
|
*/
|
|
37
66
|
nodeModulesLocation: string;
|
|
38
67
|
/**
|
|
39
|
-
* node_modules/.bin
|
|
68
|
+
* node_modules/.bin 資料夾路徑。
|
|
69
|
+
* Path of the `node_modules/.bin` folder.
|
|
40
70
|
*/
|
|
41
71
|
binLocation: string;
|
|
42
72
|
version: string;
|
|
73
|
+
/** 套件內容目錄。The package contents directory. */
|
|
43
74
|
contents: string;
|
|
75
|
+
/** 轉回純 package.json 物件。Convert back to a plain `package.json` object. */
|
|
44
76
|
toJSON(): IPackageJson;
|
|
77
|
+
/** 重新讀取磁碟上的最新狀態。Re-read the latest state from disk. */
|
|
45
78
|
refresh(): Promise<IPackedManifest>;
|
|
79
|
+
/** 序列化目前狀態。Serialize the current state. */
|
|
46
80
|
serialize(): Promise<IPackedManifest>;
|
|
81
|
+
/** 更新本地依賴的版本字串。Update the version string of a local dependency. */
|
|
47
82
|
updateLocalDependency(resolved: IResolvedResult, depVersion: string, savePrefix: string): any;
|
|
48
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* 完整的封裝 manifest:自訂欄位與標準 package.json 欄位的合體。
|
|
86
|
+
* The full packed manifest: custom fields merged with the standard `package.json` fields.
|
|
87
|
+
*/
|
|
49
88
|
export interface IPackedManifest extends IPackedManifestCore, Omit<IPackageJson, keyof IPackedManifestCore> {
|
|
50
89
|
}
|
package/lib/types.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EnumWorkspacesProject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* WorkspacesProject 常用的預設值常量。
|
|
6
|
+
* Well-known default values used by `WorkspacesProject`.
|
|
7
|
+
*/
|
|
4
8
|
var EnumWorkspacesProject;
|
|
5
9
|
(function (EnumWorkspacesProject) {
|
|
10
|
+
/** 預設的 workspace glob。The default workspace glob. */
|
|
6
11
|
EnumWorkspacesProject["workspace"] = "packages/*";
|
|
12
|
+
/** Lerna 獨立版本模式的版本值。The version value marking Lerna independent versioning. */
|
|
7
13
|
EnumWorkspacesProject["independent"] = "independent";
|
|
8
14
|
})(EnumWorkspacesProject || (exports.EnumWorkspacesProject = EnumWorkspacesProject = {}));
|
|
9
15
|
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":";;;AAaA,IAAkB,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["types.ts"],"names":[],"mappings":";;;AAaA;;;GAGG;AACH,IAAkB,qBAMjB;AAND,WAAkB,qBAAqB;IAEtC,qDAAqD;IACrD,iDAAwB,CAAA;IACxB,+EAA+E;IAC/E,oDAA2B,CAAA;AAC5B,CAAC,EANiB,qBAAqB,qCAArB,qBAAqB,QAMtC","sourcesContent":["import type { IPackageJson } from '@ts-type/package-dts';\nimport type { ILernaJsonCommand } from '@ts-type/package-dts/lerna-json';\nimport type { IPackageJsonDependenciesField, IDependency } from '@ts-type/package-dts/lib/package-json/types';\nimport type {\n\tFileResult,\n\tHostedGitResult,\n\tURLResult,\n\tAliasResult,\n\tRegistryResult\n} from 'npm-package-arg';\nimport type { ITSOverwrite } from 'ts-type';\nimport { IReleaseType } from '@ts-type/package-dts/lerna-json';\n\n/**\n * WorkspacesProject 常用的預設值常量。\n * Well-known default values used by `WorkspacesProject`.\n */\nexport const enum EnumWorkspacesProject\n{\n\t/** 預設的 workspace glob。The default workspace glob. */\n\tworkspace = 'packages/*',\n\t/** Lerna 獨立版本模式的版本值。The version value marking Lerna independent versioning. */\n\tindependent = 'independent'\n}\n\n/**\n * WorkspacesProject 內部快取欄位的形狀。\n * Shape of the internal cache fields of `WorkspacesProject`.\n */\nexport interface IWorkspacesProjectInternal\n{\n\t/** 目前選用的 workspace glob。The currently preferred workspace glob. */\n\tdefaultWorkspace: string;\n\t/** 已解析的 workspaces glob 清單。The resolved workspace glob list. */\n\tworkspaces: string[];\n\t/** 合併過的發佈設定,含推導出的 changelogPreset/bump。Merged release config including derived `changelogPreset`/`bump`. */\n\treleaseConfig: ITSOverwrite<ILernaJsonCommand[\"version\"] & ILernaJsonCommand[\"publish\"], {\n\t\tchangelogPreset: ILernaJsonCommand[\"version\"]['changelogPreset'],\n\t\tconventionalGraduate: ILernaJsonCommand[\"publish\"]['conventionalGraduate'],\n\t\tbump: IReleaseType,\n\t}>,\n}\n\n/**\n * 依 npm-package-arg 解析後的套件解析結果聯集型別。\n * Union of the npm-package-arg resolution results for a dependency.\n */\nexport type IResolvedResult = FileResult | HostedGitResult | URLResult | AliasResult | RegistryResult;\n\n/**\n * IPackedManifest 中屬於本套件自訂、會覆寫 package.json 同名欄位的部分。\n * The custom part of `IPackedManifest` that overrides same-named `package.json` fields.\n *\n * @see WorkspacesProject.manifest\n */\nexport interface IPackedManifestCore extends Record<IPackageJsonDependenciesField, IDependency>\n{\n\tname: string\n\tlocation: string\n\tprivate: boolean\n\t/** 依賴的解析結果。The parsed resolution result of the dependency. */\n\tresolved: IResolvedResult;\n\t/** 工作區根目錄。The workspace root. */\n\trootPath: string\n\t/** 是否為 Lerna 套件。Whether this is a Lerna package. */\n\t__isLernaPackage: boolean\n\t/** bin 映射。The `bin` mapping. */\n\tbin: Record<string, string>\n\tscripts: IPackageJson[\"scripts\"]\n\t/**\n\t * package.json 檔案路徑。\n\t * Path of the `package.json` file.\n\t */\n\tmanifestLocation: string\n\t/**\n\t * node_modules 資料夾路徑。\n\t * Path of the `node_modules` folder.\n\t */\n\tnodeModulesLocation: string\n\t/**\n\t * node_modules/.bin 資料夾路徑。\n\t * Path of the `node_modules/.bin` folder.\n\t */\n\tbinLocation: string\n\tversion: string\n\t/** 套件內容目錄。The package contents directory. */\n\tcontents: string\n\n\t/** 轉回純 package.json 物件。Convert back to a plain `package.json` object. */\n\ttoJSON(): IPackageJson\n\t/** 重新讀取磁碟上的最新狀態。Re-read the latest state from disk. */\n\trefresh(): Promise<IPackedManifest>\n\t/** 序列化目前狀態。Serialize the current state. */\n\tserialize(): Promise<IPackedManifest>\n\t/** 更新本地依賴的版本字串。Update the version string of a local dependency. */\n\tupdateLocalDependency(resolved: IResolvedResult, depVersion: string, savePrefix: string)\n\n}\n\n/**\n * 完整的封裝 manifest:自訂欄位與標準 package.json 欄位的合體。\n * The full packed manifest: custom fields merged with the standard `package.json` fields.\n */\nexport interface IPackedManifest extends IPackedManifestCore, Omit<IPackageJson, keyof IPackedManifestCore>\n{\n\n}\n"]}
|
package/lib/util.d.ts
CHANGED
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* checkPaths() 的回傳結果,代表兩種根目錄比對後的處置方式。
|
|
3
|
+
* Result of `checkPaths()`, describing how to treat the two compared roots.
|
|
4
|
+
*/
|
|
1
5
|
export declare const enum EnumCheckPaths {
|
|
6
|
+
/** lerna 根目錄位於 yarn 根目錄之下,應採用 yarn 根目錄。The lerna root sits under the yarn root; adopt the yarn root. */
|
|
2
7
|
root = 1,
|
|
8
|
+
/** 兩根目錄一致(或其中一方為空),沿用 lerna 根目錄即可。Roots match (or one side is empty); keep the lerna root. */
|
|
3
9
|
rootPath = 0,
|
|
10
|
+
/** 根目錄衝突,無法安全建立專案。Roots conflict; the project cannot be safely constructed. */
|
|
4
11
|
failed = -1
|
|
5
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* 比對 Yarn Workspaces 根目錄與 Lerna 根目錄,決定要採用哪一個。
|
|
15
|
+
* Compare the Yarn Workspaces root against the Lerna root and decide which one to adopt.
|
|
16
|
+
*
|
|
17
|
+
* @param input.root 由 find-yarn-workspace-root2 找到的 yarn 根目錄。The yarn root found by `find-yarn-workspace-root2`.
|
|
18
|
+
* @param input.rootPath 由 @lerna/project 解析出的 lerna 根目錄。The lerna root resolved by `@lerna/project`.
|
|
19
|
+
* @param options skipStrictCheck 為 true 時,只要 lerna 根目錄在 yarn 根目錄之下就視為可接受。When `skipStrictCheck` is true, a lerna root nested under the yarn root is accepted.
|
|
20
|
+
* @returns EnumCheckPaths 判定結果。The `EnumCheckPaths` verdict.
|
|
21
|
+
*/
|
|
6
22
|
export declare function checkPaths(input: {
|
|
7
23
|
root: any;
|
|
8
24
|
rootPath: any;
|
package/lib/util.js
CHANGED
|
@@ -4,21 +4,45 @@ exports.EnumCheckPaths = void 0;
|
|
|
4
4
|
exports.checkPaths = checkPaths;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
6
|
const path_dir_normalize_1 = tslib_1.__importDefault(require("path-dir-normalize"));
|
|
7
|
+
/**
|
|
8
|
+
* checkPaths() 的回傳結果,代表兩種根目錄比對後的處置方式。
|
|
9
|
+
* Result of `checkPaths()`, describing how to treat the two compared roots.
|
|
10
|
+
*/
|
|
7
11
|
var EnumCheckPaths;
|
|
8
12
|
(function (EnumCheckPaths) {
|
|
13
|
+
/** lerna 根目錄位於 yarn 根目錄之下,應採用 yarn 根目錄。The lerna root sits under the yarn root; adopt the yarn root. */
|
|
9
14
|
EnumCheckPaths[EnumCheckPaths["root"] = 1] = "root";
|
|
15
|
+
/** 兩根目錄一致(或其中一方為空),沿用 lerna 根目錄即可。Roots match (or one side is empty); keep the lerna root. */
|
|
10
16
|
EnumCheckPaths[EnumCheckPaths["rootPath"] = 0] = "rootPath";
|
|
17
|
+
/** 根目錄衝突,無法安全建立專案。Roots conflict; the project cannot be safely constructed. */
|
|
11
18
|
EnumCheckPaths[EnumCheckPaths["failed"] = -1] = "failed";
|
|
12
19
|
})(EnumCheckPaths || (exports.EnumCheckPaths = EnumCheckPaths = {}));
|
|
20
|
+
/**
|
|
21
|
+
* 比對 Yarn Workspaces 根目錄與 Lerna 根目錄,決定要採用哪一個。
|
|
22
|
+
* Compare the Yarn Workspaces root against the Lerna root and decide which one to adopt.
|
|
23
|
+
*
|
|
24
|
+
* @param input.root 由 find-yarn-workspace-root2 找到的 yarn 根目錄。The yarn root found by `find-yarn-workspace-root2`.
|
|
25
|
+
* @param input.rootPath 由 @lerna/project 解析出的 lerna 根目錄。The lerna root resolved by `@lerna/project`.
|
|
26
|
+
* @param options skipStrictCheck 為 true 時,只要 lerna 根目錄在 yarn 根目錄之下就視為可接受。When `skipStrictCheck` is true, a lerna root nested under the yarn root is accepted.
|
|
27
|
+
* @returns EnumCheckPaths 判定結果。The `EnumCheckPaths` verdict.
|
|
28
|
+
*/
|
|
13
29
|
function checkPaths(input, options) {
|
|
14
30
|
let { root, rootPath } = input;
|
|
31
|
+
// 兩個根目錄都存在時才做嚴格比對;任一方為空則無法判斷,只能沿用已知的那一方。
|
|
32
|
+
// Strict comparison only applies when both roots exist; if either side is empty there is nothing to compare, so keep whichever is known.
|
|
15
33
|
if ((root === null || root === void 0 ? void 0 : root.length) && (rootPath === null || rootPath === void 0 ? void 0 : rootPath.length)) {
|
|
34
|
+
// 先正規化目錄字串,避免尾端斜線或重複分隔符導致誤判為不同路徑。
|
|
35
|
+
// Normalize the directory strings first so trailing slashes or duplicate separators are not misread as different paths.
|
|
16
36
|
root = (0, path_dir_normalize_1.default)(root);
|
|
17
37
|
rootPath = (0, path_dir_normalize_1.default)(rootPath);
|
|
18
38
|
if (root !== rootPath) {
|
|
39
|
+
// lerna 根目錄是 yarn 根目錄的子路徑,代表 lerna 指向子資料夾,應改用外層 yarn 根目錄。
|
|
40
|
+
// The lerna root is a subpath of the yarn root, meaning lerna points at a subfolder; adopt the outer yarn root instead.
|
|
19
41
|
if (rootPath.indexOf(root) === 0) {
|
|
20
42
|
return 1 /* EnumCheckPaths.root */;
|
|
21
43
|
}
|
|
44
|
+
// 兩根目錄互不相干時視為致命衝突;僅在允許寬鬆檢查時放行。
|
|
45
|
+
// Unrelated roots are treated as a fatal conflict; only tolerated when loose checking is allowed.
|
|
22
46
|
else if (!(options === null || options === void 0 ? void 0 : options.skipStrictCheck)) {
|
|
23
47
|
return -1 /* EnumCheckPaths.failed */;
|
|
24
48
|
}
|
|
@@ -28,6 +52,8 @@ function checkPaths(input, options) {
|
|
|
28
52
|
else if (rootPath === null || rootPath === void 0 ? void 0 : rootPath.length) {
|
|
29
53
|
return 0 /* EnumCheckPaths.rootPath */;
|
|
30
54
|
}
|
|
55
|
+
// 兩邊都沒有根目錄,只能判定失敗。
|
|
56
|
+
// Neither root exists, so the only verdict is failure.
|
|
31
57
|
return -1 /* EnumCheckPaths.failed */;
|
|
32
58
|
}
|
|
33
59
|
//# sourceMappingURL=util.js.map
|
package/lib/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["util.ts"],"names":[],"mappings":";;;AAyBA,gCA4CC;;AArED,oFAAkD;AAElD;;;GAGG;AACH,IAAkB,cAQjB;AARD,WAAkB,cAAc;IAE/B,wGAAwG;IACxG,mDAAQ,CAAA;IACR,8FAA8F;IAC9F,2DAAY,CAAA;IACZ,+EAA+E;IAC/E,wDAAW,CAAA;AACZ,CAAC,EARiB,cAAc,8BAAd,cAAc,QAQ/B;AAED;;;;;;;;GAQG;AACH,SAAgB,UAAU,CAAC,KAG1B,EAAE,OAEF;IAEA,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAA;IAE9B,yCAAyC;IACzC,yIAAyI;IACzI,IAAI,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,MAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,CAAA,EACpC,CAAC;QACA,kCAAkC;QAClC,wHAAwH;QACxH,IAAI,GAAG,IAAA,4BAAgB,EAAC,IAAI,CAAC,CAAA;QAC7B,QAAQ,GAAG,IAAA,4BAAgB,EAAC,QAAQ,CAAC,CAAA;QAErC,IAAI,IAAI,KAAK,QAAQ,EACrB,CAAC;YACA,0DAA0D;YAC1D,wHAAwH;YACxH,IAAI,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAChC,CAAC;gBACA,mCAA0B;YAC3B,CAAC;YACD,+BAA+B;YAC/B,kGAAkG;iBAC7F,IAAI,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,eAAe,CAAA,EAClC,CAAC;gBACA,sCAA4B;YAC7B,CAAC;QACF,CAAC;QAED,uCAA8B;IAC/B,CAAC;SACI,IAAI,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,MAAM,EACzB,CAAC;QACA,uCAA8B;IAC/B,CAAC;IAED,mBAAmB;IACnB,uDAAuD;IACvD,sCAA4B;AAC7B,CAAC","sourcesContent":["import pathDirNormalize from 'path-dir-normalize';\n\n/**\n * checkPaths() 的回傳結果,代表兩種根目錄比對後的處置方式。\n * Result of `checkPaths()`, describing how to treat the two compared roots.\n */\nexport const enum EnumCheckPaths\n{\n\t/** lerna 根目錄位於 yarn 根目錄之下,應採用 yarn 根目錄。The lerna root sits under the yarn root; adopt the yarn root. */\n\troot = 1,\n\t/** 兩根目錄一致(或其中一方為空),沿用 lerna 根目錄即可。Roots match (or one side is empty); keep the lerna root. */\n\trootPath = 0,\n\t/** 根目錄衝突,無法安全建立專案。Roots conflict; the project cannot be safely constructed. */\n\tfailed = -1\n}\n\n/**\n * 比對 Yarn Workspaces 根目錄與 Lerna 根目錄,決定要採用哪一個。\n * Compare the Yarn Workspaces root against the Lerna root and decide which one to adopt.\n *\n * @param input.root 由 find-yarn-workspace-root2 找到的 yarn 根目錄。The yarn root found by `find-yarn-workspace-root2`.\n * @param input.rootPath 由 @lerna/project 解析出的 lerna 根目錄。The lerna root resolved by `@lerna/project`.\n * @param options skipStrictCheck 為 true 時,只要 lerna 根目錄在 yarn 根目錄之下就視為可接受。When `skipStrictCheck` is true, a lerna root nested under the yarn root is accepted.\n * @returns EnumCheckPaths 判定結果。The `EnumCheckPaths` verdict.\n */\nexport function checkPaths(input: {\n\troot,\n\trootPath,\n}, options?: {\n\tskipStrictCheck?: boolean\n}): EnumCheckPaths\n{\n\tlet { root, rootPath } = input\n\n\t// 兩個根目錄都存在時才做嚴格比對;任一方為空則無法判斷,只能沿用已知的那一方。\n\t// Strict comparison only applies when both roots exist; if either side is empty there is nothing to compare, so keep whichever is known.\n\tif (root?.length && rootPath?.length)\n\t{\n\t\t// 先正規化目錄字串,避免尾端斜線或重複分隔符導致誤判為不同路徑。\n\t\t// Normalize the directory strings first so trailing slashes or duplicate separators are not misread as different paths.\n\t\troot = pathDirNormalize(root)\n\t\trootPath = pathDirNormalize(rootPath)\n\n\t\tif (root !== rootPath)\n\t\t{\n\t\t\t// lerna 根目錄是 yarn 根目錄的子路徑,代表 lerna 指向子資料夾,應改用外層 yarn 根目錄。\n\t\t\t// The lerna root is a subpath of the yarn root, meaning lerna points at a subfolder; adopt the outer yarn root instead.\n\t\t\tif (rootPath.indexOf(root) === 0)\n\t\t\t{\n\t\t\t\treturn EnumCheckPaths.root\n\t\t\t}\n\t\t\t// 兩根目錄互不相干時視為致命衝突;僅在允許寬鬆檢查時放行。\n\t\t\t// Unrelated roots are treated as a fatal conflict; only tolerated when loose checking is allowed.\n\t\t\telse if (!options?.skipStrictCheck)\n\t\t\t{\n\t\t\t\treturn EnumCheckPaths.failed\n\t\t\t}\n\t\t}\n\n\t\treturn EnumCheckPaths.rootPath\n\t}\n\telse if (rootPath?.length)\n\t{\n\t\treturn EnumCheckPaths.rootPath\n\t}\n\n\t// 兩邊都沒有根目錄,只能判定失敗。\n\t// Neither root exists, so the only verdict is failure.\n\treturn EnumCheckPaths.failed\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yarn-tool/workspaces-project",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.15",
|
|
4
4
|
"description": "mixin yarn/lerna workspaces",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"yarn",
|
|
7
|
+
"lerna",
|
|
8
|
+
"workspaces",
|
|
9
|
+
"yarn-workspaces",
|
|
10
|
+
"lerna-project"
|
|
11
|
+
],
|
|
5
12
|
"homepage": "https://github.com/bluelovers/ws-yarn-workspaces/tree/master/packages/@yarn-tool/workspaces-project#readme",
|
|
6
13
|
"bugs": {
|
|
7
14
|
"url": "https://github.com/bluelovers/ws-yarn-workspaces/issues"
|
|
@@ -15,39 +22,41 @@
|
|
|
15
22
|
"author": "bluelovers",
|
|
16
23
|
"main": "index.js",
|
|
17
24
|
"scripts": {
|
|
18
|
-
"coverage": "
|
|
25
|
+
"coverage": "pnpm run test -- --coverage",
|
|
19
26
|
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
20
|
-
"test": "
|
|
27
|
+
"test": "node --run test:node",
|
|
21
28
|
"test:jest": "ynpx --quiet jest -- --coverage",
|
|
22
|
-
"test:jest:coverage": "
|
|
23
|
-
"test:jest:snapshot": "
|
|
29
|
+
"test:jest:coverage": "pnpm run test:jest -- --coverage",
|
|
30
|
+
"test:jest:snapshot": "pnpm run test:jest -- -u",
|
|
24
31
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
25
|
-
"test:
|
|
32
|
+
"test:node": "tsx --test --test-update-snapshots **/*.node-spec.ts **/*.node-test.ts **/*.spec.ts **/*.test.ts",
|
|
33
|
+
"test:snapshot": "pnpm run test -u",
|
|
34
|
+
"test:tsc": "tsc --noEmit & echo typescript check done",
|
|
26
35
|
"test:tsd": "ynpx tsd",
|
|
27
|
-
"preversion": "
|
|
36
|
+
"preversion": "pnpm run test",
|
|
28
37
|
"prepublishOnly": "echo prepublishOnly",
|
|
29
38
|
"prepublishOnly:check-bin": "ynpx --quiet @yarn-tool/check-pkg-bin",
|
|
30
|
-
"prepublishOnly:update": "
|
|
39
|
+
"prepublishOnly:update": "pnpm run ncu && pnpm run sort-package-json",
|
|
31
40
|
"ncu": "ynpx --quiet yarn-tool -- ncu -u",
|
|
32
41
|
"sort-package-json": "ynpx --quiet yarn-tool -- sort",
|
|
33
42
|
"tsc:showConfig": "ynpx get-current-tsconfig -p"
|
|
34
43
|
},
|
|
35
44
|
"dependencies": {
|
|
36
45
|
"@lerna/project": "^6.4.1",
|
|
37
|
-
"@ts-type/package-dts": "^3.0.
|
|
46
|
+
"@ts-type/package-dts": "^3.0.14",
|
|
38
47
|
"@types/npm-package-arg": "*",
|
|
39
|
-
"@yarn-tool/changelog": "^3.0.
|
|
40
|
-
"find-yarn-workspace-root2": "^1.2.
|
|
41
|
-
"fs-extra": "^11.
|
|
48
|
+
"@yarn-tool/changelog": "^3.0.15",
|
|
49
|
+
"find-yarn-workspace-root2": "^1.2.56",
|
|
50
|
+
"fs-extra": "^11.4.1",
|
|
42
51
|
"lodash": "^4.18.1",
|
|
43
52
|
"path-dir-normalize": "^1.0.33",
|
|
44
|
-
"sort-object-keys2": "^3.0.
|
|
45
|
-
"ts-type": "^3.0.
|
|
53
|
+
"sort-object-keys2": "^3.0.10",
|
|
54
|
+
"ts-type": "^3.0.18",
|
|
46
55
|
"tslib": ">=2.8.1",
|
|
47
|
-
"upath2": "^3.1.
|
|
56
|
+
"upath2": "^3.1.25"
|
|
48
57
|
},
|
|
49
58
|
"publishConfig": {
|
|
50
59
|
"access": "public"
|
|
51
60
|
},
|
|
52
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "471c63ee11851f0ac3487f23d1c472936f99b460"
|
|
53
62
|
}
|