-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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: create NpmInstaller
#27626
base: main
Are you sure you want to change the base?
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.
A lot of the initialization code previously in the npm module has been shifted up here.
This now allows us to construct an npm installer without needing to have a managed cli resolver.
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.
The internals of the methods are the same. What's changed is the high level structure.
&self, | ||
packages: &[PackageReq], | ||
) -> Result<(), JsErrorBox> { | ||
self.npm_resolution_initializer.ensure_initialized().await?; |
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.
Actually, these statements are new.
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.
Moved from cli/npm/managed/mod.rs
|
||
/// An npm resolver where the resolution is managed by Deno rather than | ||
/// the user bringing their own node_modules (BYONM) on the file system. | ||
pub struct ManagedCliNpmResolver { |
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.
This struct existed before.
} | ||
|
||
#[derive(Debug)] | ||
pub struct NpmResolutionInitializer { |
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.
This is new. It initializes the NpmResolutionCell
with the npm resolution.
} | ||
} | ||
|
||
impl CliNpmResolver for ManagedCliNpmResolver { |
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.
All code that was previously around.
warned_pkgs: Default::default(), | ||
} | ||
} | ||
|
||
// todo(dsherret): move this off CliResolver as CliResolver is acting | ||
// like a factory by doing this (it's beyond its responsibility) |
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.
Resolved this todo. This is no longer a factory which means we can construct the CliResolver with less dependencies.
{ | ||
if let Ok(size) = crate::util::fs::dir_size(&folder) { | ||
self.package_sizes.insert(package.id.clone(), size); | ||
} |
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.
Inlined package_size
to here.
This separates npm resolution code from npm installation (more work towards moving resolution code out of the CLI and cleaning up this code).