Skip to content

Commit 1ffdce3

Browse files
build: agent-js peer dependencies (#161)
# Motivation Developers may be using both [nns](/packages/nns) and [sns](/packages/sns) in their projects - as we do in [NNS-dapp](https://github.com/dfinity/nns-dapp/). That is s why, to help tree-shaking and avoid duplication of code, the libraries of this project need to reference [agent-js](https://github.com/dfinity/agent-js) as peer dependencies. When we are building here both `nns` and `sns`, as both builds are standalone, `agent-js` libs get bundled within the outcome. Which is fine if the libraries were always use separately but unfortunately, as we noticed in NNS-dapp, when both are consumed app bundlers are not always able to tree-shake correctly the code afterwards. So developers might end-up with `agent-js` libs twice in their code. # Breaking Changes - set `agent-js` libraries as peer dependencies # Tests Libraries were locally bundled, then packed (`npm pack`) and integrated in NNS-dapp to build and run the dapp.
1 parent 401478d commit 1ffdce3

File tree

8 files changed

+123
-60
lines changed

8 files changed

+123
-60
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Breaking changes
1010

11+
- `agent-js` dependencies set as `peerDependencies`
1112
- Sns canisters' classes renamed with prefix `Sns`
1213

1314
### Features

HACKING.md

+9
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,12 @@ The files of the [candid](./candid) folders are shared across packages. Their ar
5252
- `something.certified.idl.d.ts`: the typescript definition of the above factory file
5353

5454
(1) auto-generated with [didc](https://github.com/dfinity/candid)
55+
56+
# Update peer dependencies
57+
58+
Saving peer dependencies in `package-lock.json` needs npm >= v7.
59+
60+
```bash
61+
npm rm @dfinity/principal @dfinity/agent @dfinity/candid
62+
npm i @dfinity/[email protected] @dfinity/[email protected] @dfinity/[email protected] --save-peer
63+
```

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ The libraries are still in active development, and new features will incremental
1111
- cmc: querying the Cmc canister (_coming soon_)
1212
- [utils](/packages/utils): a collection of utilities and constants for NNS/SNS projects.
1313

14+
## Installation
15+
16+
Install [nns](/packages/nns) and/or [sns](/packages/sns) in your project from [npm](https://www.npmjs.com):
17+
18+
```bash
19+
npm i @dfinity/nns
20+
npm i @dfinity/sns
21+
```
22+
23+
You may be using both [nns](/packages/nns) and [sns](/packages/sns) in your project - as we do in [NNS-dapp](https://github.com/dfinity/nns-dapp/).
24+
That is s why, to help tree-shaking and avoid duplication of code, the libraries of this project are referencing [agent-js](https://github.com/dfinity/agent-js) as peer dependencies.
25+
26+
Therefore, be sure that the needed `agent-js` dependencies are available in your project or install these as following:
27+
28+
```bash
29+
npm i @dfinity/agent @dfinity/candid @dfinity/principal
30+
```
31+
1432
## Links
1533

1634
Here are some useful links:

0 commit comments

Comments
 (0)