Skip to content

Commit

Permalink
feat(prune): check for an prune extraneous packages, and skip extract…
Browse files Browse the repository at this point in the history
…ing valid ones (#200)

Fixes: #149
Fixes: #177
  • Loading branch information
zkat committed Mar 12, 2023
1 parent d3303b0 commit 544a2c5
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 106 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -100,6 +100,7 @@ tracing-appender = "0.2.2"
tracing-subscriber = "0.3.16"
tsify = "0.4.3"
url = "2.3.1"
walkdir = "2.3.2"
wasm-bindgen = "0.2.84"
wasm-bindgen-futures = "0.4.34"
wasm-streams = "0.2.3"
Expand Down
1 change: 1 addition & 0 deletions crates/node-maintainer/Cargo.toml
Expand Up @@ -33,6 +33,7 @@ url = { workspace = true }
reflink = { workspace = true }
indicatif = { workspace = true }
tempfile = { workspace = true }
walkdir = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = { workspace = true }
Expand Down
5 changes: 5 additions & 0 deletions crates/node-maintainer/src/error.rs
Expand Up @@ -120,6 +120,11 @@ pub enum NodeMaintainerError {
#[error("{0}")]
#[diagnostic(code(node_maintainer::graph_error))]
GraphValidationError(String),

#[cfg(not(target_arch = "wasm32"))]
#[error(transparent)]
#[diagnostic(code(node_maintainer::walkdir_error))]
WalkDirError(#[from] walkdir::Error),
}

impl<T> From<mpsc::TrySendError<T>> for NodeMaintainerError {
Expand Down
16 changes: 9 additions & 7 deletions crates/node-maintainer/src/graph.rs
Expand Up @@ -151,10 +151,7 @@ impl Graph {
}
}

pub(crate) fn package_at_path(
&self,
path: &Path,
) -> Result<Option<Package>, NodeMaintainerError> {
pub(crate) fn node_at_path(&self, path: &Path) -> Option<&Node> {
let mut current = Some(self.root);
let mut in_nm = true;
let slash = OsStr::new("/");
Expand All @@ -179,9 +176,14 @@ impl Graph {
}
}
if current == Some(self.root) {
return Ok(None);
None
} else {
current.map(|idx| &self.inner[idx])
}
Ok(current.map(|idx| self.inner[idx].package.clone()))
}

pub(crate) fn package_at_path(&self, path: &Path) -> Option<Package> {
Some(self.node_at_path(path)?.package.clone())
}

pub(crate) fn find_by_name(
Expand Down Expand Up @@ -264,7 +266,7 @@ impl Graph {
Ok(())
}

fn node_lockfile_node(
pub(crate) fn node_lockfile_node(
&self,
node: NodeIndex,
is_root: bool,
Expand Down

0 comments on commit 544a2c5

Please sign in to comment.