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: create NpmInstaller #27626

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Jan 10, 2025

This separates npm resolution code from npm installation (more work towards moving resolution code out of the CLI and cleaning up this code).

@dsherret dsherret added the ci-draft Run the CI on draft PRs. label Jan 10, 2025
@dsherret dsherret removed the ci-draft Run the CI on draft PRs. label Jan 10, 2025
Copy link
Member Author

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.

Copy link
Member Author

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?;
Copy link
Member Author

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.

Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

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)
Copy link
Member Author

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);
}
Copy link
Member Author

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.

@dsherret dsherret marked this pull request as ready for review January 10, 2025 22:10
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.

1 participant