Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions crates/vite_package_manager/src/install.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::{collections::HashMap, iter};

use crate::package_manager::{PackageManager, ResolveCommandResult, format_path_env};

impl PackageManager {
/// Resolve the install command.
pub fn resolve_install_command(&self, args: &Vec<String>) -> ResolveCommandResult {
ResolveCommandResult {
bin_path: self.bin_name.to_string(),
args: iter::once("install")
.chain(args.iter().map(String::as_str))
.map(String::from)
.collect(),
envs: HashMap::from([("PATH".to_string(), format_path_env(self.get_bin_prefix()))]),
}
}
}
1 change: 1 addition & 0 deletions crates/vite_package_manager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod config;
mod install;
pub mod package;
pub mod package_manager;
mod request;
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_package_manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ async fn main() -> Result<(), Error> {
let package_manager = PackageManager::builder(&current_dir).build().await?;
println!("Package manager: {package_manager:#?} for {current_dir:?}");

let resolve_command = package_manager.resolve_command();
let resolve_command = package_manager.resolve_install_command(&vec![]);
println!("Resolve command: {resolve_command:#?}");

Ok(())
Expand Down
11 changes: 2 additions & 9 deletions crates/vite_package_manager/src/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl fmt::Display for PackageManagerType {
#[derive(Debug)]
pub struct ResolveCommandResult {
pub bin_path: String,
pub args: Vec<String>,
pub envs: HashMap<String, String>,
}

Expand Down Expand Up @@ -146,14 +147,6 @@ impl PackageManager {
self.install_dir.join("bin")
}

#[must_use]
pub fn resolve_command(&self) -> ResolveCommandResult {
ResolveCommandResult {
bin_path: self.bin_name.to_string(),
envs: HashMap::from([("PATH".to_string(), format_path_env(self.get_bin_prefix()))]),
}
}

#[must_use]
pub fn get_fingerprint_ignores(&self) -> Vec<Str> {
let mut ignores: Vec<Str> = vec![
Expand Down Expand Up @@ -601,7 +594,7 @@ async fn set_package_manager_field(
Ok(())
}

fn format_path_env(bin_prefix: impl AsRef<Path>) -> String {
pub(crate) fn format_path_env(bin_prefix: impl AsRef<Path>) -> String {
let mut paths = env::split_paths(&env::var_os("PATH").unwrap_or_default()).collect::<Vec<_>>();
paths.insert(0, bin_prefix.as_ref().to_path_buf());
env::join_paths(paths).unwrap().to_string_lossy().to_string()
Expand Down
5 changes: 2 additions & 3 deletions crates/vite_task/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{
env,
io::{self, IsTerminal, Write},
iter,
};

use crossterm::{
Expand Down Expand Up @@ -59,11 +58,11 @@ impl InstallCommand {
Err(e) => return Err(e),
};
let workspace = Workspace::partial_load(self.workspace_root)?;
let resolve_command = package_manager.resolve_command();
let resolve_command = package_manager.resolve_install_command(args);
let resolved_task = ResolvedTask::resolve_from_builtin_with_command_result(
&workspace,
"install",
iter::once("install").chain(args.iter().map(String::as_str)),
resolve_command.args.iter(),
ResolveCommandResult { bin_path: resolve_command.bin_path, envs: resolve_command.envs },
self.ignore_replay,
Some(package_manager.get_fingerprint_ignores()),
Expand Down
Loading