Skip to content

Commit 8dca647

Browse files
authored
Reworks the diff finder (#195)
This PR attempts to rework how the diff finder works to cover those two improvements: - The diff_finder now accepts an array of roots. This makes it possible to restrict the crawling to the few folders we know may contain workspaces, based on the prefixes passed to the `workspaces` key. For example if we have a `"workspaces": ["packages/**"]` field, then we know workspaces can only be in the `workspaces` folder. - The diff_finder now stores an additional cache entry type called Error, which indicates that a file returned an error when calling `get_file_data`. The errors aren't immediately returned anymore during crawling - instead, the consumer is expected to report them as it reads the results from the diff_finder. This allows us to filter the results useful to us before reporting errors, fixing the issue where Yarn was reporting errors on malformed `package.json` files that weren't actually part of the project's workspaces. Another notable change is the attempt to switch to rkyv whenever possible due to bincode [not being maintained anymore](https://docs.rs/crate/bincode/latest). It makes the code more complicated due to rkyv requiring [boilerplate](https://github.com/rkyv/rkyv/blob/3b76edd96adf89b18ae06cdb2dd340886f724226/rkyv/examples/json_like_schema.rs#L6) to support recursive types. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Modernizes filesystem diffing and persistence, and propagates changes across crates. > > - **Diff finder redesign**: accepts `roots` to constrain scans, adds `Error` cache entries, and renames `SaveState/SaveEntry` → `CacheState/CacheEntry`; updates `ManifestFinder` and workspace discovery to use rooted scanning and handle deferred errors > - **Serialization migration**: replaces `bincode` with `rkyv` for install state, lockfile, tree resolution, utils, primitives, semver, git models, and switch manifest; adds required `Archive` derives and bounds > - **Workspace detection**: computes roots from `workspaces` globs via new `zpm_utils::Glob::prefix()` to limit crawl scope > - **Macro enum enhancements**: supports `#[variant_struct_attr(...)]`, per-variant `#[struct_attr(...)]`, and preserves field attributes in generated structs > - Minor config/dep updates: remove bincode deps/derives; add `rkyv` deps; small API tweaks (e.g., `build::DiffFinder::new(root, roots, state)`) and error variants cleanup > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5f0ff2d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent ba5dbbc commit 8dca647

48 files changed

Lines changed: 563 additions & 337 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.claude/settings.local.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"Bash(git add:*)",
1414
"Bash(gh pr edit:*)",
1515
"Bash(git push)",
16-
"Bash(yarn test:integration:*)"
16+
"Bash(yarn test:integration:*)",
17+
"Bash(cargo check:*)",
18+
"Bash(git stash:*)"
1719
],
1820
"deny": [],
1921
"ask": []

Cargo.lock

Lines changed: 33 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/zpm-config/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ zpm-macro-enum = { path = "../zpm-macro-enum" }
1313
zpm-primitives = { path = "../zpm-primitives" }
1414
zpm-semver = { path = "../zpm-semver" }
1515
zpm-utils = { path = "../zpm-utils" }
16-
bincode = "2.0.1"
1716

1817
[build-dependencies]
1918
convert_case = "0.8.0"

packages/zpm-config/src/types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use bincode::{Decode, Encode};
21
use zpm_macro_enum::zpm_enum;
32

43
use crate::ConfigurationError;
54

65
#[zpm_enum(error = ConfigurationError, or_else = |s| Err(ConfigurationError::EnumError(s.to_string())))]
7-
#[derive(Debug, Clone, Copy, Encode, Decode, PartialEq, Eq)]
6+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
87
pub enum NodeLinker {
98
#[literal("pnp")]
109
Pnp,
@@ -17,7 +16,7 @@ pub enum NodeLinker {
1716
}
1817

1918
#[zpm_enum(error = ConfigurationError, or_else = |s| Err(ConfigurationError::EnumError(s.to_string())))]
20-
#[derive(Debug, Clone, Copy, Encode, Decode, PartialEq, Eq)]
19+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2120
pub enum PnpFallbackMode {
2221
#[literal("none")]
2322
None,

packages/zpm-git/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = "zpm-git"
33
edition = "2024"
44

55
[dependencies]
6-
bincode = { version = "2.0.0-rc.3" }
76
fancy-regex = "0.13.0"
7+
rkyv = { version = "0.8", features = ["bytecheck"] }
88
serde = { version = "1.0.207", features = ["derive"] }
99
thiserror = "1.0.63"
1010
urlencoding = "2.1.3"

packages/zpm-git/src/range.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
use bincode::{Decode, Encode};
1+
use rkyv::Archive;
22
use zpm_utils::{DataType, FromFileString, QueryString, QueryStringValue, ToFileString, ToHumanString, UnwrapInfallible};
33

44
use crate::{is_git_url, normalize_git_url, Error, GitSource, GitTreeish};
55

6-
#[derive(Clone, Default, Debug, Decode, Encode, PartialEq, Eq, Hash, PartialOrd, Ord)]
6+
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Archive, rkyv::Serialize, rkyv::Deserialize)]
7+
#[rkyv(derive(PartialEq, Eq, Hash, PartialOrd, Ord))]
78
pub struct PrepareParams {
89
pub cwd: Option<String>,
910
pub workspace: Option<String>,
1011
}
1112

12-
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, Hash, PartialOrd, Ord)]
13+
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Archive, rkyv::Serialize, rkyv::Deserialize)]
14+
#[rkyv(derive(PartialEq, Eq, Hash, PartialOrd, Ord))]
1315
pub struct GitRange {
1416
pub repo: GitSource,
1517
pub treeish: GitTreeish,

packages/zpm-git/src/reference.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use bincode::{Decode, Encode};
1+
use rkyv::Archive;
22

33
use zpm_utils::{DataType, FromFileString, QueryString, QueryStringValue, ToFileString, ToHumanString, UnwrapInfallible};
44

55
use crate::{range::PrepareParams, Error, GitRange, GitSource, GitTreeish};
66

7-
#[derive(Clone, Debug, Decode, Encode, PartialEq, Eq, Hash, PartialOrd, Ord)]
7+
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Archive, rkyv::Serialize, rkyv::Deserialize)]
8+
#[rkyv(derive(PartialEq, Eq, Hash, PartialOrd, Ord))]
89
pub struct GitReference {
910
pub repo: GitSource,
1011
pub commit: String,

packages/zpm-git/src/source.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use std::convert::Infallible;
22

3-
use bincode::{Decode, Encode};
3+
use rkyv::Archive;
44
use serde::{Deserialize, Serialize};
55
use zpm_utils::{DataType, FromFileString, ToFileString, ToHumanString};
66

77
use crate::{normalize_git_url, GH_TARBALL_URL, GH_URL};
88

9-
#[derive(Clone, Debug, Decode, Deserialize, Encode, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)]
9+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Archive, rkyv::Serialize, rkyv::Deserialize)]
10+
#[rkyv(derive(PartialEq, Eq, Hash, PartialOrd, Ord))]
1011
pub enum GitSource {
1112
GitHub { owner: String, repository: String },
1213
Url(String),

packages/zpm-git/src/treeish.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
use bincode::{Decode, Encode};
1+
use rkyv::Archive;
22
use serde::{Deserialize, Serialize};
33
use zpm_utils::ToFileString;
44

5-
#[derive(Clone, Debug, Decode, Deserialize, Encode, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)]
5+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Archive, rkyv::Serialize, rkyv::Deserialize)]
6+
#[rkyv(derive(PartialEq, Eq, Hash, PartialOrd, Ord))]
67
pub enum GitTreeish {
78
AnythingGoes(String),
89
Head(String),

0 commit comments

Comments
 (0)