Skip to content

Commit d7d5099

Browse files
authored
feat: add support for patching registry dependencies (#7469)
## Overview Implements support for patching registry dependencies (from forc.pub) using the `[patch]` table in `Forc.toml`. Previously, only Git dependencies could be patched, which created a workflow gap when packages like `std` migrated from Git to the registry. ## Motivation When `std` and other core packages moved to forc.pub registry, developers lost the ability to: - Test local changes to standard library code - Use unreleased features from development branches - Debug issues with instrumented versions of dependencies This PR restores that capability by extending the existing patch system to support registry packages. ## Implementation ### Key Features 1. **Registry Patching**: Use `[patch.'forc.pub']` to override registry dependencies 2. **Multiple Source Types**: Patch with local path or Git repository 3. **Namespace Support**: Built-in support for namespaced packages (implementation-ready for future use) 4. **Priority System**: Namespace-specific patches override generic patches ## Usage ### Basic Usage ```toml [dependencies] std = "0.70.1" [patch.'forc.pub'] std = { path = "../sway/sway-lib-std" } ``` ### Patch with Git Branch ```toml [dependencies] std = "0.70.1" [patch.'forc.pub'] std = { git = "https://github.com/fuellabs/sway", branch = "my-feature" } ``` ### Workspace-Level Patches ```toml [workspace] members = ["contract-a", "contract-b"] [patch.'forc.pub'] std = { path = "../custom-std" } ``` ## Documentation Updated user documentation in: - `docs/book/src/forc/manifest_reference.md` - Complete patch section rewrite with examples - `docs/book/src/forc/workspaces.md` - Added registry patching examples - Inline code documentation with TOML syntax notes ## Breaking Changes None. This is a purely additive change. All existing Git patches continue to work exactly as before. ## Notes - **TOML Syntax**: Quotes are required: `[patch.'forc.pub']` not `[patch.forc.pub]` - **Source Matching**: Registry patches only apply to registry dependencies - **Namespace Support**: Implementation includes namespace support <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds support to patch registry dependencies using `[patch.'forc.pub']` (with namespaced overrides and fallback), keeps Git patching intact, and updates docs with examples. > > - **Core (forc-pkg)**: > - Extend `Source::dep_patch` to handle registry sources: checks `[patch.'forc.pub/<namespace>']` first, then `[patch.'forc.pub']`; Git patching unchanged. > - Add `reg::REGISTRY_PATCH_KEY` constant (`"forc.pub"`). > - **Tests**: > - Add unit tests covering flat/domain namespaces, namespace priority vs. generic fallback, Git patch compatibility, and no-op cases. > - **Docs**: > - Update `docs/book/src/forc/manifest_reference.md` with registry patching examples, notes on quoting keys, and clarifications. > - Update `docs/book/src/forc/workspaces.md` with Git and registry patching examples for workspaces. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 089422a. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 8930fe8 commit d7d5099

File tree

4 files changed

+389
-9
lines changed

4 files changed

+389
-9
lines changed

docs/book/src/forc/manifest_reference.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ experimental-private-modules = false
220220

221221
## The `[patch]` Section
222222

223-
The [patch] section of `Forc.toml` can be used to override dependencies with other copies. The example provided below patches `https://github.com/fuellabs/sway` with the `test` branch of the same repo.
223+
The `[patch]` section of `Forc.toml` can be used to override dependencies with other copies. This is useful for testing local changes, using unreleased features, or debugging dependencies.
224+
225+
### Patching Git Dependencies
226+
227+
The example provided below patches `https://github.com/fuellabs/sway` with the `test` branch of the same repo.
224228

225229
```toml
226230
[project]
@@ -260,7 +264,40 @@ foo = { git = "https://github.com/foo/foo", branch = "master" }
260264
foo = { git = "https://github.com/foo/foo", branch = "test" }
261265
```
262266

263-
Note that each key after the `[patch]` is a URL of the source that is being patched.
267+
### Patching Registry Dependencies
268+
269+
You can also patch dependencies from the registry (forc.pub) in the same way. This is particularly useful for testing local changes to `std` or other registry packages.
270+
271+
```toml
272+
[project]
273+
authors = ["user"]
274+
entry = "main.sw"
275+
license = "Apache-2.0"
276+
name = "my_contract"
277+
278+
[dependencies]
279+
std = "0.70.1"
280+
281+
[patch.'forc.pub']
282+
std = { path = "../sway/sway-lib-std" }
283+
```
284+
285+
In the example above, even though `std` version `0.70.1` would normally be fetched from the registry, the local path version is used instead.
286+
287+
You can also patch registry dependencies with a git repository:
288+
289+
```toml
290+
[dependencies]
291+
std = "0.70.1"
292+
293+
[patch.'forc.pub']
294+
std = { git = "https://github.com/fuellabs/sway", branch = "my-feature" }
295+
```
296+
297+
### Important Notes
298+
299+
* **Quotes are required**: Each key after `[patch]` must be in quotes (e.g., `[patch.'forc.pub']`) because they contain special characters. Without quotes, TOML will interpret dots as nested tables.
300+
* **Source matching**: Git patches match Git dependencies, and registry patches match registry dependencies.
264301

265302
## The `[contract-dependencies]` section
266303

docs/book/src/forc/workspaces.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,30 @@ The `[patch]` section can be used to override any dependency in the workspace de
3232

3333
It is not allowed to declare patch table in member of a workspace if the workspace manifest file contains a patch table.
3434

35-
Example:
35+
Example with Git dependency:
3636

3737
```toml
3838
[workspace]
3939
members = ["member1", "path/to/member2"]
4040

41-
4241
[patch.'https://github.com/fuellabs/sway']
4342
std = { git = "https://github.com/fuellabs/sway", branch = "test" }
4443
```
4544

4645
In the above example each occurrence of `std` as a dependency in the workspace will be changed with `std` from `test` branch of sway repo.
4746

47+
Example with registry dependency:
48+
49+
```toml
50+
[workspace]
51+
members = ["contract-a", "contract-b", "script"]
52+
53+
[patch.'forc.pub']
54+
std = { path = "../custom-std" }
55+
```
56+
57+
In this example, all workspace members will use the local custom version of `std` instead of the registry version.
58+
4859
## Some `forc` commands that support workspaces
4960

5061
* `forc build` - Builds an entire workspace.

0 commit comments

Comments
 (0)