|
1 | 1 | # Dependencies
|
2 | 2 |
|
3 |
| -Forc has a dependency management system which can pull packages using `git`, `ipfs` or `registry`. This allows users to build and share Forc libraries. |
| 3 | +Forc has a dependency management system which can pull packages using `git`, `ipfs`, `path`, or the community `registry`. This allows users to build and share Forc libraries. |
4 | 4 |
|
5 |
| -## Adding a dependency |
| 5 | +## Adding Dependencies |
6 | 6 |
|
7 |
| -If your `Forc.toml` doesn't already have a `[dependencies]` table, add one. Below, list the package name alongside its source. Currently, `forc` supports `git`, `ipfs`, `path` and `registry` sources. |
| 7 | +You can add dependencies manually in your `Forc.toml`, or by using the `forc add` command. |
8 | 8 |
|
9 |
| -If a `git` source is specified, `forc` will fetch the git repository at the given URL and then search for a `Forc.toml` for a package with the given name anywhere inside the git repository. |
| 9 | +### Using `forc add` |
10 | 10 |
|
11 |
| -The following example adds a library dependency named `custom_lib`. For git dependencies you may optionally specify a `branch`, `tag`, or `rev` (i.e. commit hash) reference. |
| 11 | +The `forc add` CLI supports various sources and optional flags: |
12 | 12 |
|
13 |
| -```toml |
14 |
| -[dependencies] |
15 |
| -custom_lib = { git = "https://github.com/FuelLabs/custom_lib", branch = "master" } |
16 |
| -# custom_lib = { git = "https://github.com/FuelLabs/custom_lib", tag = "v0.0.1" } |
17 |
| -# custom_lib = { git = "https://github.com/FuelLabs/custom_lib", rev = "87f80bdf323e2d64e213895d0a639ad468f4deff" } |
| 13 | +```bash |
| 14 | +forc add <dep> [--path <PATH>] [--git <URL> --tag <TAG>] [--ipfs <CID>] [--contract-dep] |
18 | 15 | ```
|
19 | 16 |
|
20 |
| -Depending on a local library using `path`: |
| 17 | +#### Add Examples |
| 18 | + |
| 19 | +* From a Git branch: |
| 20 | + |
| 21 | + ```bash |
| 22 | + forc add custom_lib --git https://github.com/FuelLabs/custom_lib --branch master |
| 23 | + ``` |
| 24 | + |
| 25 | +* From a local path: |
| 26 | + |
| 27 | + ```bash |
| 28 | + forc add custom_lib --path ../custom_lib |
| 29 | + ``` |
| 30 | + |
| 31 | +* From IPFS: |
| 32 | + |
| 33 | + ```bash |
| 34 | + forc add custom_lib --ipfs QmYwAPJzv5CZsnA... |
| 35 | + ``` |
| 36 | + |
| 37 | +* From registry (forc.pub): |
| 38 | + |
| 39 | + ```bash |
| 40 | + |
| 41 | + ``` |
| 42 | + |
| 43 | +* Add as a contract dependency: |
| 44 | + |
| 45 | + ```bash |
| 46 | + forc add my_contract --git https://github.com/example/contract --contract-dep |
| 47 | + ``` |
| 48 | + |
| 49 | +Optional: |
| 50 | + |
| 51 | +* `--salt <HEX>` for custom contract salt. |
| 52 | +* `--package <NAME>` to target a specific package in a workspace. |
| 53 | +* `--manifest-path <PATH>` to specify a manifest file. |
| 54 | + |
| 55 | +> ⚠️ **Note:** |
| 56 | +> We do not currently support offline mode for projects that use **registry** sources. |
| 57 | +> Also wildcard declarations `(ex: custom_lib = *)` to get the latest version available for that package or caret declarations `(ex: custom_lib = ^0.1)` to get `SemVer` compatible latest available option for a given dependency is not supported yet. |
| 58 | +
|
| 59 | +Once the package is added, running `forc build` will automatically fetch and resolve the dependencies. |
| 60 | + |
| 61 | +### Manually Editing `Forc.toml` |
| 62 | + |
| 63 | +If your `Forc.toml` doesn't already have a `[dependencies]` or `[contract-dependencies]` table, add one. Below, list the package name and its source. |
| 64 | + |
| 65 | +#### Local Path |
21 | 66 |
|
22 | 67 | ```toml
|
23 | 68 | [dependencies]
|
24 | 69 | custom_lib = { path = "../custom_lib" }
|
25 | 70 | ```
|
26 | 71 |
|
27 |
| -For `ipfs` sources, `forc` will fetch the specified `cid` using either a local `ipfs` node or a public gateway. `forc` automatically tries to connect to local `ipfs` node. If it fails, it defaults to using `https://ipfs.io/` as a gateway. |
28 |
| - |
29 |
| -The following example adds a dependency with an `ipfs` source. |
| 72 | +#### IPFS Source |
30 | 73 |
|
31 | 74 | ```toml
|
32 | 75 | [dependencies]
|
33 |
| -custom_lib = { ipfs = "QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG" } |
| 76 | +custom_lib = { ipfs = "QmYwAPJzv5CZsnA..." } |
34 | 77 | ```
|
35 | 78 |
|
36 |
| -For `registry` sources, `forc` will first resolve the source declared by its name and version. This is done using the forc.pub-index repo (located at `https://github.com/FuelLabs/forc.pub-index`). The package name and version is used to convert the declaration to an IPFS CID. The resolved IPFS CID is then used by either a local IPFS node or an IPFS gateway that fuel operates (`https://ipfs.forc.pub/`) to actually fetch the package. |
37 |
| - |
38 |
| -Available packages can be found at `https://forc.pub`. |
39 |
| - |
40 |
| -The following example adds a dependency with a `registry` source. |
| 79 | +#### Registry Source (forc.pub) |
41 | 80 |
|
42 | 81 | ```toml
|
43 | 82 | [dependencies]
|
44 | 83 | custom_lib = "0.0.1"
|
45 | 84 | ```
|
46 | 85 |
|
47 |
| -In the example above the package `custom_lib v0.0.1` will be fetched from `forc.pub` using IPFS. |
| 86 | +## Removing Dependencies |
| 87 | + |
| 88 | +You can remove one or more dependencies using the `forc remove` command: |
| 89 | + |
| 90 | +```bash |
| 91 | +forc remove <dep> [--contract-dep] [--package <NAME>] [--manifest-path <PATH>] |
| 92 | +``` |
| 93 | + |
| 94 | +### Remove Examples |
| 95 | + |
| 96 | +* Remove from `[dependencies]`: |
| 97 | + |
| 98 | + ```bash |
| 99 | + forc remove custom_lib |
| 100 | + ``` |
| 101 | + |
| 102 | +* Remove from `[contract-dependencies]`: |
48 | 103 |
|
49 |
| -We do not currently support `offline` mode of operation for project that uses `registry` sources. Also wildcard declarations (ex: `custom_lib = *`) to get the latest version available for that package or caret declarations (ex: `custom_lib = ^0.1`) to get `SemVer` compatible latest available option for a given dependency is not supported yet. |
| 104 | + ```bash |
| 105 | + forc remove my_contract --contract-dep |
| 106 | + ``` |
50 | 107 |
|
51 |
| -Once the package is added, running `forc build` will automatically download added dependencies. |
| 108 | +* Target a specific package in a workspace: |
52 | 109 |
|
53 |
| -## Updating dependencies |
| 110 | + ```bash |
| 111 | + forc remove custom_lib --package my_project |
| 112 | + ``` |
| 113 | + |
| 114 | +## Updating Dependencies |
| 115 | + |
| 116 | +To update dependencies in your Forc directory you can run: |
| 117 | + |
| 118 | +```bash |
| 119 | +forc update |
| 120 | +``` |
54 | 121 |
|
55 |
| -To update dependencies in your Forc directory you can run `forc update`. For `path` and `ipfs` dependencies this will have no effect. For `git` dependencies with a `branch` reference, this will update the project to use the latest commit for the given branch. |
| 122 | +For path and ipfs dependencies this will have no effect. For git dependencies with a branch reference, this will update the project to use the latest commit for the given branch. |
0 commit comments