You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure pnpm is used in the workflow by adding a step to verify its presence:
@@ -72,4 +75,40 @@ This outputs the installed `pnpm` version for confirmation during workflow execu
72
75
## Additional Notes
73
76
74
77
- Use the same `pnpm_version` as used in local development for consistency.
75
-
- Ensure any `package.json` files are compatible with pnpm. Run `pnpm install` locally to verify.
78
+
- Ensure any `package.json` files are compatible with pnpm. Run `pnpm install` locally to verify.
79
+
80
+
## Using PNPM in Monorepos
81
+
82
+
When working with monorepos, pnpm offers several advantages including strict module resolution and efficient workspace management. To configure Speakeasy to use pnpm in your monorepo:
83
+
84
+
### Local Development Configuration
85
+
86
+
Add the `compileCommand` configuration to your `gen.yaml` file:
87
+
88
+
```yaml
89
+
typescript:
90
+
compileCommand:
91
+
- pnpm
92
+
- install
93
+
```
94
+
95
+
### Workspace Configuration
96
+
97
+
Ensure your `pnpm-workspace.yaml` includes the SDK directory:
98
+
99
+
```yaml
100
+
packages:
101
+
- "packages/*"
102
+
- "sdk/*" # Include your SDK location
103
+
```
104
+
105
+
### Benefits for Monorepos
106
+
107
+
- **Strict module resolution**: Prevents dependency confusion between packages
108
+
- **Efficient storage**: Shared dependencies across workspace packages
@@ -23,10 +24,11 @@ Let's say a developer have Zod installed in their monorepo's root, and their Spe
23
24
try {
24
25
const result =awaitsdk.products.create({
25
26
name: "Cool Product",
26
-
price: "not a number"// This should fail validation
27
+
price: "not a number",// This should fail validation
27
28
});
28
29
} catch (err) {
29
-
if (errinstanceofZodError) { // 🚨 This check fails!
30
+
if (errinstanceofZodError) {
31
+
// 🚨 This check fails!
30
32
console.log("Validation error:", err.errors);
31
33
}
32
34
}
@@ -131,7 +133,7 @@ For example, one might see errors about missing dependencies that they know are
131
133
132
134
### How to fix it
133
135
134
-
Fortunately, this one's easy to solve. Just customize the compile command in your `gen.yaml`:
136
+
Configure Speakeasy to use your preferred package manager when building the SDK. For pnpm (recommended for monorepos), customize the compile command in your `gen.yaml`:
135
137
136
138
```yaml
137
139
# For pnpm
@@ -141,7 +143,12 @@ typescript:
141
143
- install
142
144
```
143
145
144
-
This tells Speakeasy to use the preferred package manager when building the SDK.
146
+
This tells Speakeasy to use pnpm instead of npm when building the SDK, which is especially important in monorepos where pnpm's strict module resolution helps prevent dependency confusion issues.
147
+
148
+
<Callout title="Related Guide">
149
+
For more detailed information about configuring pnpm as your default package
150
+
manager, see our [Using PNPM guide](/guides/sdks/pnpm-default).
151
+
</Callout>
145
152
146
153
## Putting it all together - a real-world example
147
154
@@ -166,12 +173,14 @@ my-monorepo/
166
173
```
167
174
168
175
pnpm-workspace.yaml:
176
+
169
177
```yaml
170
178
packages:
171
-
- 'packages/*'
179
+
- "packages/*"
172
180
```
173
181
174
182
frontend/package.json:
183
+
175
184
```json
176
185
{
177
186
"dependencies": {
@@ -181,6 +190,7 @@ frontend/package.json:
181
190
```
182
191
183
192
gen.yaml:
193
+
184
194
```yaml
185
195
typescript:
186
196
moduleFormat: esm
@@ -193,6 +203,7 @@ typescript:
193
203
```
194
204
195
205
This setup gives:
206
+
196
207
1. A consistent dependency tree with pnpm's strict module resolution
0 commit comments