Skip to content

Commit b6805fa

Browse files
authored
fix: make packages optional in pnpm-workspace.yaml (#124)
# fix: make `packages` optional in `pnpm-workspace.yaml` Added the `#[serde(default)]` attribute to the `packages` field in the `PnpmWorkspace` struct to make it optional. This allows PNPM workspaces to function correctly even when the `packages` field is not specified in the `pnpm-workspace.yaml` file. Added a test fixture with a `pnpm-workspace.yaml` that doesn't include a `packages` field to verify the fix works correctly.
1 parent f39c872 commit b6805fa

File tree

6 files changed

+100
-0
lines changed

6 files changed

+100
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "additional-envs",
3+
"private": true,
4+
"scripts": {
5+
"hello": "echo hello"
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# no `packages` field
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[[plan]]
2+
name = "allow `packages` in pnpm-workspace.yaml to be optional"
3+
args = ["run", "hello"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
3+
expression: "&plan_json"
4+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/pnpm-workspace-packages-optional
5+
---
6+
{
7+
"root_node": {
8+
"Expanded": [
9+
{
10+
"key": [
11+
"<workspace>/",
12+
"hello"
13+
],
14+
"node": {
15+
"task_display": {
16+
"package_name": "additional-envs",
17+
"task_name": "hello",
18+
"package_path": "<workspace>/"
19+
},
20+
"items": [
21+
{
22+
"execution_item_display": {
23+
"task_display": {
24+
"package_name": "additional-envs",
25+
"task_name": "hello",
26+
"package_path": "<workspace>/"
27+
},
28+
"command": "echo hello",
29+
"and_item_index": null,
30+
"cwd": "<workspace>/"
31+
},
32+
"kind": {
33+
"Leaf": {
34+
"InProcess": {
35+
"kind": {
36+
"Echo": {
37+
"strings": [
38+
"hello"
39+
],
40+
"trailing_newline": true
41+
}
42+
}
43+
}
44+
}
45+
}
46+
}
47+
]
48+
},
49+
"neighbors": []
50+
}
51+
]
52+
}
53+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
source: crates/vite_task_plan/tests/plan_snapshots/main.rs
3+
expression: task_graph_json
4+
input_file: crates/vite_task_plan/tests/plan_snapshots/fixtures/pnpm-workspace-packages-optional
5+
---
6+
[
7+
{
8+
"key": [
9+
"<workspace>/",
10+
"hello"
11+
],
12+
"node": {
13+
"task_display": {
14+
"package_name": "additional-envs",
15+
"task_name": "hello",
16+
"package_path": "<workspace>/"
17+
},
18+
"resolved_config": {
19+
"command": "echo hello",
20+
"resolved_options": {
21+
"cwd": "<workspace>/",
22+
"cache_config": {
23+
"env_config": {
24+
"fingerprinted_envs": [],
25+
"pass_through_envs": [
26+
"<default pass-through envs>"
27+
]
28+
}
29+
}
30+
}
31+
}
32+
},
33+
"neighbors": []
34+
}
35+
]

crates/vite_workspace/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct PnpmWorkspace {
2727
/// The packages to include in the workspace.
2828
///
2929
/// <https://pnpm.io/pnpm-workspace_yaml>
30+
#[serde(default)]
3031
packages: Vec<Str>,
3132
}
3233

0 commit comments

Comments
 (0)