Skip to content

Commit 5d478b4

Browse files
committed
Sync open source content 🐝 (from 6598e8aa14dd1fcbb2fa9b7b69c03db48dd3a6a6)
1 parent 1478c0a commit 5d478b4

2 files changed

Lines changed: 61 additions & 11 deletions

File tree

guides/sdks/pnpm-default.mdx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ image: "/assets/examples/generic.png"
55
date: 2024-12-05
66
authors:
77
- name: Logan Gingerich
8-
- image_url: '/assets/author-headshots/logan.jpg'
8+
- image_url: "/assets/author-headshots/logan.jpg"
99
tags:
1010
- SDK Generation
1111
is_featured: false
1212
featured_image: "/assets/examples/generic.png"
1313
---
1414

15+
import { Callout } from "@/mdx/components";
16+
1517
# Switching default package manager to `pnpm`
1618

1719
## Prerequisite
@@ -32,7 +34,7 @@ permissions:
3234
contents: write
3335
pull-requests: write
3436
statuses: write
35-
'on':
37+
"on":
3638
workflow_dispatch:
3739
inputs:
3840
force:
@@ -51,12 +53,13 @@ jobs:
5153
set_version: ${{ github.event.inputs.set_version }}
5254
speakeasy_version: latest
5355
working_directory: packages/sdk
54-
pnpm_version: "9.19.4" # Specify the required pnpm version
56+
pnpm_version: "9.19.4" # Specify the required pnpm version
5557
secrets:
5658
github_access_token: ${{ secrets.GITHUB_TOKEN }}
5759
npm_token: ${{ secrets.NPM_TOKEN_ELEVATED }}
5860
speakeasy_api_key: ${{ secrets.SPEAKEASY_API_KEY }}
5961
```
62+
6063
## (Optional) Verifying `pnpm` Installation
6164

6265
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
7275
## Additional Notes
7376

7477
- 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
109+
- **Better workspace support**: Built-in monorepo tooling
110+
111+
<Callout title="Related Guide">
112+
For comprehensive monorepo setup and troubleshooting tips, see our [TypeScript
113+
Monorepo Tips guide](/guides/sdks/typescript-monorepo-tips).
114+
</Callout>

guides/sdks/typescript-monorepo-tips.mdx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { Callout } from "@/mdx/components";
77

88
# Tips for Integrating a TypeScript SDK into a Monorepo
99

10-
<Callout title="Get Started" >
11-
If you're looking to set up a monorepo from scratch, check out our [Create a monorepo](/guides/sdks/creating-a-monorepo) guide first.
10+
<Callout title="Get Started">
11+
If you're looking to set up a monorepo from scratch, check out our [Create a
12+
monorepo](/guides/sdks/creating-a-monorepo) guide first.
1213
</Callout>
1314

1415
## Dependency Confusion
@@ -23,10 +24,11 @@ Let's say a developer have Zod installed in their monorepo's root, and their Spe
2324
try {
2425
const result = await sdk.products.create({
2526
name: "Cool Product",
26-
price: "not a number" // This should fail validation
27+
price: "not a number", // This should fail validation
2728
});
2829
} catch (err) {
29-
if (err instanceof ZodError) { // 🚨 This check fails!
30+
if (err instanceof ZodError) {
31+
// 🚨 This check fails!
3032
console.log("Validation error:", err.errors);
3133
}
3234
}
@@ -131,7 +133,7 @@ For example, one might see errors about missing dependencies that they know are
131133

132134
### How to fix it
133135

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`:
135137

136138
```yaml
137139
# For pnpm
@@ -141,7 +143,12 @@ typescript:
141143
- install
142144
```
143145

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>
145152

146153
## Putting it all together - a real-world example
147154

@@ -166,12 +173,14 @@ my-monorepo/
166173
```
167174

168175
pnpm-workspace.yaml:
176+
169177
```yaml
170178
packages:
171-
- 'packages/*'
179+
- "packages/*"
172180
```
173181

174182
frontend/package.json:
183+
175184
```json
176185
{
177186
"dependencies": {
@@ -181,6 +190,7 @@ frontend/package.json:
181190
```
182191

183192
gen.yaml:
193+
184194
```yaml
185195
typescript:
186196
moduleFormat: esm
@@ -193,6 +203,7 @@ typescript:
193203
```
194204

195205
This setup gives:
206+
196207
1. A consistent dependency tree with pnpm's strict module resolution
197208
2. ESM modules for maximum compatibility
198209
3. pnpm for package management

0 commit comments

Comments
 (0)