Skip to content

Commit 36bd110

Browse files
authored
docs: Add guide for testing SDK packages with pnpm link (#25512)
docs: Add guide for testing SDK packages with pnpm link
1 parent 2652f0c commit 36bd110

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ upgrading.
5151

5252
To test local versions of SDK packages, for instance in test projects, you have a couple of options:
5353

54-
- Use [`pnpm link`](https://pnpm.io/cli/link) to symlink your package to the test project.
54+
- Use [`pnpm link`](./docs/using-pnpm-link.md) to symlink your package to the test project.
5555
- Use [`yalc` to install SDK packages](./docs/using-yalc.md) as if they were already published.
5656
- Run `build:tarball` in the repo and `pnpm add ./path/to/tarball.tgz` in the project.
5757

‎docs/using-pnpm-link.md‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Using `pnpm link` for Local SDK Testing
2+
3+
[`pnpm link`](https://pnpm.io/cli/link) symlinks a local SDK package into a test project. Changes are available in the
4+
test project after a rebuild, without a publish step. For packages where linking causes problems (e.g. SvelteKit or
5+
Angular), use [`yalc`](./using-yalc.md) instead.
6+
7+
## Building packages
8+
9+
Build the SDK package and the packages it depends on. Run this in the root of the repo:
10+
11+
```sh
12+
pnpm run build:dev:filter @sentry/node # or any other SDK package
13+
```
14+
15+
## Linking packages
16+
17+
In your test project, run `pnpm link` with the path to the SDK package:
18+
19+
```sh
20+
pnpm link /path/to/sentry-javascript/packages/node
21+
```
22+
23+
You only need to link the SDK package that your project imports. Its dependencies (e.g. `@sentry/core`) resolve from
24+
the monorepo, so they are also the local versions. If your project also imports a dependency directly (e.g.
25+
`@sentry/core`), that import still uses the version from the registry. Link that package too.
26+
27+
`pnpm link` adds a `link:` override to the `pnpm-workspace.yaml` of your test project. If the file does not exist,
28+
`pnpm link` creates it. Do not commit this override.
29+
30+
## Updating packages
31+
32+
The link points to the `build/` folder of the package. After a code change, rebuild the package and restart your test
33+
project. You do not need to link again.
34+
35+
```sh
36+
# in the package you changed, e.g. packages/core
37+
pnpm run build:transpile
38+
```
39+
40+
## Unlinking packages
41+
42+
In your test project, run `pnpm unlink` with the package name. This removes the `link:` override and installs the
43+
registry version again.
44+
45+
```sh
46+
pnpm unlink @sentry/node
47+
```
48+
49+
In pnpm 10, `pnpm unlink` shows "Nothing to unlink" and does not remove the override. Remove the override
50+
for the package from `pnpm-workspace.yaml` manually, then run `pnpm install`.
51+
52+
## Troubleshooting
53+
54+
### My test project still uses the registry version
55+
56+
Make sure that `node_modules/@sentry/node` in your test project is a symlink to the monorepo:
57+
58+
```sh
59+
ls -la node_modules/@sentry/node
60+
```
61+
62+
If you run Node.js or your bundler with `--preserve-symlinks`, dependencies resolve from the `node_modules` of your
63+
test project and not from the monorepo. Do not use this flag.
64+
65+
### My test project uses Vite and I still don't see changes
66+
67+
Vite pre-bundles and caches dependencies for dev builds. Run `vite dev --force` to clear the cache.

‎docs/using-yalc.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Using `yalc` for Local SDK Testing
22

33
[Yalc](https://github.com/wclr/yalc) is a simple local dependency repository which we can use to work with local
4-
versions of our SDKs. This is a good alternative to `npm|pnpm link` for packages where linking is problematic (e.g.
4+
versions of our SDKs. This is a good alternative to [`pnpm link`](./using-pnpm-link.md) for packages where linking is problematic (e.g.
55
SvelteKit or Angular).
66

77
Here's how to set up and use yalc:

0 commit comments

Comments
 (0)