-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat(clean): deno clean --except <paths>
, remove all cache data except what's needed to run paths
#28424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for an entrypoint-based clean subcommand in Deno by extending the clean functionality to accept new clean flags. Key changes include:
- Modifying the Clean subcommand in cli/main.rs to accept a CleanFlags argument and await the clean operation.
- Introducing a new CleanFlags struct and updating the clean_parse function in cli/args/flags.rs to extract flags for the clean command.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
cli/main.rs | Updates the Clean subcommand to forward clean_flags and await the clean function. |
cli/args/flags.rs | Adds the CleanFlags struct and updates the clean_parse function to extract and handle new flags. |
4cabc70
to
903fe38
Compare
2af5b12
to
eedebb9
Compare
697096e
to
2dd71a8
Compare
2dd71a8
to
7d66ed3
Compare
|
||
let npm_cache = factory.npm_cache()?; | ||
let snap = npm_resolver.as_managed().unwrap().resolution().snapshot(); | ||
// TODO(nathanwhit): remove once we don't need packuments for creating the snapshot from lockfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the case with lockfile v5?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but we don't know if it's actually lockfile v5. they could still be using v4
we could maybe add an API to deno_lockfile to get the version of the original lockfile text, but there isn't one atm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point 👍 let's keep it for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, would be sweet to add this. I think it would help netlify too.
.map(deno_resolver::npm::get_package_folder_id_folder_name) | ||
.collect::<HashSet<_>>(); | ||
|
||
// TODO(nathanwhit): this probably shouldn't reach directly into this code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what's the problem here - is this touching some internal implementation details?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort of. it's just everywhere else in the code we expose more generic methods on e.g. NpmInstaller
. This just uses some of the code from the local installer directly. It's not incorrect, but it feels sort of wrong to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could expose it as a public API down the road?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that's pretty much what the todo is, just to make/use a more public api
5c8e5d9
to
696f457
Compare
cli/npm/installer/mod.rs
Outdated
@@ -12,6 +12,7 @@ use deno_npm::NpmSystemInfo; | |||
use deno_resolver::npm::managed::NpmResolutionCell; | |||
use deno_runtime::colors; | |||
use deno_semver::package::PackageReq; | |||
pub(crate) use local::SetupCache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick because this is the cli crate:
pub(crate) use local::SetupCache; | |
pub use local::SetupCache; |
cli/tools/clean.rs
Outdated
#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
enum Found { | ||
Match, | ||
Prefix, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Maybe move this about PathTree so that the PathTrie struct w/ impl is beside each other?
cli/tools/clean.rs
Outdated
.build_graph_with_npm_resolution( | ||
graph, | ||
CreateGraphOptions { | ||
// loader: Some(&mut NoLoader), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
|
||
let npm_cache = factory.npm_cache()?; | ||
let snap = npm_resolver.as_managed().unwrap().resolution().snapshot(); | ||
// TODO(nathanwhit): remove once we don't need packuments for creating the snapshot from lockfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, would be sweet to add this. I think it would help netlify too.
cli/tools/clean.rs
Outdated
continue; | ||
} | ||
if !entry.path().starts_with(base) { | ||
panic!("VERY BAD"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better message? 😄
cli/tools/clean.rs
Outdated
if dry_run { | ||
#[allow(clippy::print_stderr)] | ||
{ | ||
eprintln!("would remove dir: {}", entry.path().display()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use a tree view here similar to deno compile/info's output? This prefix text for each entry seems a little repetitive btw. Maybe we should just list the paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just list the paths for now
if meta.is_symlink() { | ||
std::fs::remove_dir(path).with_context(|| { | ||
format!("Failed to remove symlink: {}", path.display()) | ||
})?; | ||
return Ok(()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does remove_dir work for file symlinks on windows?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, only directory symlinks AFAICT. that's why it tries remove_file, and falls back to remove_dir if that failed
cli/tools/clean.rs
Outdated
dry_run: bool, | ||
) -> Result<(), AnyError> { | ||
if !dir.ends_with("node_modules") || !dir.is_dir() { | ||
bail!("not a node_modules directory"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include the path in the error message?
if !base.exists() { | ||
return Ok(()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not like it will ever happen, but perhaps we should handle this in the std::fs::read_dir(&base)?
error case and also handle when ErrorKind::NotADirectory.
cli/tools/clean.rs
Outdated
} else if dry_run { | ||
#[allow(clippy::print_stderr)] | ||
{ | ||
eprintln!( | ||
"would remove dir from node modules: {}", | ||
entry.path().display() | ||
); | ||
} | ||
} else { | ||
rm_rf(state, &entry.path())?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use strategy pattern here in the future (reporting strategy and remove strategy).
8c030e3
to
6f5433f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Closes #27229.
TODO:
deno_cache_dir
so we can get the paths for the local http cacheHandle code cache and other sqlite caches?