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
70 changes: 26 additions & 44 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions crates/pm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ path = "src/main.rs"

[dependencies]
anyhow = { workspace = true }
async-compression = { version = "0.3", features = ["gzip", "tokio"] }
atty = "0.2"
bytes = "1.11.0"
chrono = { version = "0.4", features = ["serde"] }
clap = { workspace = true }
colored = "2.1"
Expand All @@ -25,9 +25,11 @@ futures = { workspace = true }
glob = "0.3.1"
indicatif = "0.17.8"
libc = "0.2"
libdeflater = "1.25"
once_cell = "1.19"
owo-colors = { workspace = true }
petgraph = "0.6"
rayon = { workspace = true }
regex = "1.10"
reqwest = { version = "0.12", default-features = false, features = [
"gzip",
Expand All @@ -44,8 +46,7 @@ tempfile = "3.15.0"
term_size = "0.3"
tokio-fs-ext = { workspace = true }
tokio-retry = "0.3"
tokio-tar = "0.3.1"
tokio-util = { version = "0.7", features = ["io"] }
tokio-util = { version = "0.7" }
toml = { workspace = true }
tracing = { workspace = true }
tracing-appender = "0.2"
Expand Down
6 changes: 2 additions & 4 deletions crates/pm/src/cmd/deps.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
use anyhow::{Context as _, Result};
use std::path::Path;
use utoo_ruborist::lock::PackageLock;
use utoo_ruborist::service::build_deps as ruborist_build_deps;

use crate::helper::fs::Context;
use crate::helper::lock::save_package_lock;
use crate::helper::ruborist_context::Context;
use crate::service::workspace::WorkspaceService;
use crate::util::logger::{finish_progress_bar, start_progress_bar};

pub async fn build_deps(cwd: &Path) -> Result<PackageLock> {
start_progress_bar();

let options = Context::build_deps_options(cwd.to_path_buf()).await;
let package_lock = ruborist_build_deps(options).await?;
let package_lock = Context::build_deps(cwd.to_path_buf()).await?;

finish_progress_bar("package-lock.json resolved");

Expand Down
13 changes: 8 additions & 5 deletions crates/pm/src/cmd/install.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use anyhow::Result;
use std::path::Path;

use crate::service::install::InstallService;
use crate::util::config::get_omit;
use crate::util::save_type::{PackageAction, SaveType};

pub async fn update_packages(
Expand All @@ -15,13 +17,14 @@ pub async fn update_packages(
return Err(anyhow::anyhow!("No package specifications provided"));
}

// Dispatch to service
InstallService::update_packages(action, specs, workspace, ignore_scripts, save_type).await
let omit = get_omit();
InstallService::update_packages(action, specs, workspace, ignore_scripts, save_type, &omit)
.await
}

pub async fn install(ignore_scripts: bool, root_path: &std::path::Path) -> Result<()> {
// Dispatch to service
InstallService::install(ignore_scripts, root_path).await
pub async fn install(ignore_scripts: bool, root_path: &Path) -> Result<()> {
let omit = get_omit();
InstallService::install(ignore_scripts, root_path, &omit).await
}

pub async fn install_global_package(npm_spec: &str, prefix: Option<&str>) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/cmd/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use utoo_ruborist::registry::resolve_package;
use utoo_ruborist::service::fetch_full_manifest;
use utoo_ruborist::util::parse_package_spec;

use crate::helper::fs::Context;
use crate::helper::ruborist_context::Context;
use crate::util::config::get_registry;
use crate::util::format_print::print_grid;

Expand Down
45 changes: 18 additions & 27 deletions crates/pm/src/helper/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ use serde_json::Value;
use std::collections::HashMap;
use std::path::{Path, PathBuf};

use super::fs::Context;
use super::ruborist_context::Context;
use crate::helper::workspace::find_workspaces;
use crate::util::config::get_legacy_peer_deps;
use crate::util::json::{load_package_json_from_path, load_package_lock_json_from_path};
use crate::util::logger::{finish_progress_bar, start_progress_bar};
use crate::util::save_type::{PackageAction, SaveType};
use crate::util::{cloner::clone_package, downloader::download};
use crate::util::{cloner::clone_package, downloader::download_to_cache};
use utoo_ruborist::lock::{LockPackage, PackageLock};
use utoo_ruborist::manifest::PackageJson;
use utoo_ruborist::registry::resolve_package;
use utoo_ruborist::service::build_deps as ruborist_build_deps;
use utoo_ruborist::util::parse_package_spec;

use super::workspace::find_workspace_path;
Expand Down Expand Up @@ -92,7 +91,9 @@ pub async fn ensure_package_lock(root_path: &Path) -> Result<PackageLock> {
if needs_regenerate {
tracing::debug!("Resolving dependencies");
start_progress_bar();
let package_lock = build_deps_with_download(root_path).await?;

let package_lock = Context::build_deps(root_path.to_path_buf()).await?;

finish_progress_bar("package-lock.json resolved");

// Write to disk asynchronously in background
Expand Down Expand Up @@ -236,23 +237,20 @@ pub async fn prepare_global_package_json(npm_spec: &str, prefix: Option<&str>) -
.as_ref()
.ok_or_else(|| anyhow!("Failed to get tarball URL from manifest"))?;

// Download and extract package
let cache_dir = crate::util::cache::get_cache_dir();
let cache_path = cache_dir.join(format!("{}/{}", name, resolved.version));
let cache_flag_path = cache_dir.join(format!("{}/{}/_resolved", name, resolved.version));

// Download if not cached
if !crate::fs::try_exists(&cache_flag_path).await? {
tracing::debug!("Downloading {} to {}", tarball_url, cache_path.display());
download(tarball_url, &cache_path)
// Download and extract package to cache
let cache_path = download_to_cache(&name, &resolved.version, tarball_url)
.await
.ok_or_else(|| anyhow!("Failed to download package {name}"))?;

// If the package has install scripts, create a flag file
// in linux, we can use hardlink when FICLONE is not supported
// so we need to copy the file to the package directory to avoid effect other packages
if resolved.manifest.has_install_script == Some(true) {
let has_install_script_flag_path = cache_path.join("_hasInstallScript");
if !crate::fs::try_exists(&has_install_script_flag_path)
.await
.context("Failed to download package")?;

// If the package has install scripts, create a flag file
// in linux, we can use hardlink when FICLONE is not supported
// so we need to copy the file to the package directory to avoid effect other packages
if resolved.manifest.has_install_script == Some(true) {
let has_install_script_flag_path = cache_path.join("_hasInstallScript");
.unwrap_or(false)
{
crate::fs::write(has_install_script_flag_path, "").await?;
}
}
Expand Down Expand Up @@ -409,13 +407,6 @@ pub async fn is_pkg_lock_outdated(root_path: &Path) -> Result<bool> {
Ok(false)
}

/// Build dependencies with tgz download.
/// Used by `utoo install` command for faster installation.
async fn build_deps_with_download(cwd: &Path) -> Result<PackageLock> {
let options = Context::build_deps_options(cwd.to_path_buf()).await;
ruborist_build_deps(options).await
}

/// Save PackageLock to disk synchronously
pub async fn save_package_lock(path: &Path, package_lock: &PackageLock) -> Result<()> {
let temp_path = path.join("package-lock.json.tmp");
Expand Down
2 changes: 1 addition & 1 deletion crates/pm/src/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub mod auto_update;
pub mod deps;
pub mod fs;
pub mod fuzzy_select;
pub mod global_bin;
pub mod install_runtime;
pub mod lock;
pub mod package;
pub mod ruborist_context;
pub mod tree_builder;
pub mod workspace;
Loading