Skip to content

Commit cfd23b9

Browse files
authored
docs: add peer dep explainer (#876)
Adds a blurb out peer deps and lib development, installation. @beeme1mr I also added a bit about `--legacy-peer-deps` after the closure of #834 --------- Signed-off-by: Todd Baert <[email protected]>
1 parent 8ef8c2c commit cfd23b9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

packages/client/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</p>
3737
<!-- x-hide-in-docs-start -->
3838

39-
[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.
39+
[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.
4040

4141
<!-- x-hide-in-docs-end -->
4242

@@ -61,6 +61,11 @@ npm install --save @openfeature/web-sdk
6161
yarn add @openfeature/web-sdk @openfeature/core
6262
```
6363

64+
> [!NOTE]
65+
> `@openfeature/core` contains common components used by all OpenFeature JavaScript implementations.
66+
> Every SDK version has a requirement on a single, specific version of this dependency.
67+
> For more information, and similar implications on libraries developed with OpenFeature see [considerations when extending](#considerations).
68+
6469
### Usage
6570

6671
```ts
@@ -336,3 +341,11 @@ export class MyHook implements Hook {
336341
```
337342

338343
> Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=&labels=hook&projects=&template=document-hook.yaml&title=%5BHook%5D%3A+) so we can add it to the docs!
344+
345+
### Considerations
346+
347+
When developing a library based on OpenFeature components, it's important to list the `@openfeature/web-sdk` as a `peerDependency` of your package.
348+
This is a general best-practice when developing JavaScript libraries that have dependencies in common with their consuming application.
349+
Failing to do this can result in multiple copies of the OpenFeature SDK in the consumer, which can lead to type errors, and broken singleton behavior.
350+
The `@openfeature/core` package itself follows this pattern: the `@openfeature/web-sdk` has a peer dependency on `@openfeature/core`, and uses whatever copy of that module the consumer has installed (note that NPM installs peers automatically unless `--legacy-peer-deps` is set, while yarn does not, and PNPM does so based on its configuration).
351+
When developing such libraries, it's NOT necessary to add a `peerDependency` on `@openfeature/core`, since the `@openfeature/web-sdk` establishes that dependency itself transitively.

packages/server/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</p>
3737
<!-- x-hide-in-docs-start -->
3838

39-
[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool.
39+
[OpenFeature](https://openfeature.dev) is an open specification that provides a vendor-agnostic, community-driven API for feature flagging that works with your favorite feature flag management tool or in-house solution.
4040

4141
<!-- x-hide-in-docs-end -->
4242

@@ -61,6 +61,11 @@ npm install --save @openfeature/server-sdk
6161
yarn add @openfeature/server-sdk @openfeature/core
6262
```
6363

64+
> [!NOTE]
65+
> `@openfeature/core` contains common components used by all OpenFeature JavaScript implementations.
66+
> Every SDK version has a requirement on a single, specific version of this dependency.
67+
> For more information, and similar implications on libraries developed with OpenFeature see [considerations when extending](#considerations).
68+
6469
### Usage
6570

6671
```ts
@@ -362,3 +367,11 @@ export class MyHook implements Hook {
362367
```
363368

364369
> Built a new hook? [Let us know](https://github.com/open-feature/openfeature.dev/issues/new?assignees=&labels=hook&projects=&template=document-hook.yaml&title=%5BHook%5D%3A+) so we can add it to the docs!
370+
371+
### Considerations
372+
373+
When developing a library based on OpenFeature components, it's important to list the `@openfeature/server-sdk` as a `peerDependency` of your package.
374+
This is a general best-practice when developing JavaScript libraries that have dependencies in common with their consuming application.
375+
Failing to do this can result in multiple copies of the OpenFeature SDK in the consumer, which can lead to type errors, and broken singleton behavior.
376+
The `@openfeature/core` package itself follows this pattern: the `@openfeature/server-sdk` has a peer dependency on `@openfeature/core`, and uses whatever copy of that module the consumer has installed (note that NPM installs peers automatically unless `--legacy-peer-deps` is set, while yarn does not, and PNPM does so based on its configuration).
377+
When developing such libraries, it's NOT necessary to add a `peerDependency` on `@openfeature/core`, since the `@openfeature/server-sdk` establishes that dependency itself transitively.

0 commit comments

Comments
 (0)