Skip to content
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

refactor: use sys_traits #27480

Merged
merged 13 commits into from
Dec 30, 2024
Merged

Conversation

@@ -91,8 +92,9 @@ impl CliLockfile {
// do an atomic write to reduce the chance of multiple deno
// processes corrupting the file
atomic_write_file_with_retries(
&FsSysTraitsAdapter::new_real(),
Copy link
Member Author

@dsherret dsherret Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This FsSysTraitsAdapter is an adapter for the traits in sys_traits and deno_fs::FileSystem. It's temporary though. After this PR, I'll decouple the CLI crate's code from deno_fs as that makes extracting code from the CLI crate a lot easier.

@@ -8,62 +8,6 @@ use deno_semver::jsr::JsrDepPackageReq;
use deno_semver::jsr::JsrPackageReqReference;
use deno_semver::npm::NpmPackageReqReference;

#[cfg(test)] // happens to only be used by the tests at the moment
pub struct DenoConfigFsAdapter<'a>(
Copy link
Member Author

@dsherret dsherret Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benefit of sys_traits is that we can remove all these adapter and fs implementation structs. It makes setup code a lot easier for people using our crates.

@ry
Copy link
Member

ry commented Dec 27, 2024

Is there an impact on binary size?

@dsherret
Copy link
Member Author

Doubt it. Maybe a very tiny reduction.

@@ -1274,7 +1275,7 @@ dependencies = [
"deno_npm",
"deno_npm_cache",
"deno_package_json",
"deno_path_util",
"deno_path_util 0.3.0",
Copy link
Member Author

@dsherret dsherret Dec 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

denoland/deno_doc#684

But I think this is ok to land without because this is a really small dependency -- Will update this pr with that in a bit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was actually too big of a change in deno_doc for me to do the upgrade. We'll have to do that later.

@dsherret dsherret requested a review from bartlomieju December 27, 2024 22:30
@@ -867,6 +867,7 @@ impl CliOptions {
ConfigFlag::Discover => {
if let Some(start_paths) = flags.config_path_args(&initial_cwd) {
WorkspaceDirectory::discover(
&FsSysTraitsAdapter::new_real(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope creating these is rather cheap

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very.

@@ -79,6 +49,37 @@ use node_resolver::errors::ClosestPkgJsonError;
use node_resolver::InNpmPackageChecker;
use node_resolver::NodeResolutionKind;
use node_resolver::ResolutionMode;
use sys_traits::FsRead;

use crate::args::jsr_url;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to shift all of these in various files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slowly doing #26646

@@ -25,10 +25,12 @@ deno_io.workspace = true
deno_path_util.workspace = true
deno_permissions.workspace = true
filetime.workspace = true
getrandom = "0.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used on purpose instead of rand crate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is what the rand crate uses and the SystemRandom trait needs this lower level function

Comment on lines +419 to +423
// todo(dsherret): this is temporary. Instead of using the `FileSystem` trait implementation
// in the CLI, the CLI should instead create it's own file system using `sys_traits` traits
// then that can implement the `FileSystem` trait. Then this `FileSystem` trait can stay here
// for use only for `ext/fs` and not the entire CLI.
#[derive(Debug, Clone)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a follow up PR prepared or is this a TODO for some other time in the future? If the latter, consider opening an issue for it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a PR incoming after this one.

@dsherret dsherret requested a review from bartlomieju December 30, 2024 15:39
@dsherret dsherret merged commit c391ad3 into denoland:main Dec 30, 2024
17 checks passed
@dsherret dsherret deleted the refactor_use_sys_traits branch December 30, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants