Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/install/NetworkTask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub enum Callback {

#[derive(Default, Clone, Copy)]
pub struct DedupeMapEntry {
/// Once `failed`, this says whether the failure was an error or a warning, and stays.
pub(crate) is_required: bool,
/// Set once the download/extract for this task id has terminally failed so a
/// later `enqueue_*_for_download` can observe the failure instead of
Expand Down
8 changes: 8 additions & 0 deletions src/install/PackageInstaller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct PackageInstaller<'a> {
pub(crate) destination_dir_subpath_buf: PathBuffer,
pub(crate) folder_path_buf: PathBuffer,
pub(crate) successfully_installed: Bitset,
pub(crate) required_packages: lockfile::tree::RequiredPackages<'a>,
pub(crate) command_ctx: Command::Context<'a>,
pub(crate) current_tree_id: lockfile::tree::Id,
/// Trees that live under a self-contained workspace: packages there are copied
Expand Down Expand Up @@ -1607,6 +1608,9 @@ impl<'a> PackageInstaller<'a> {
} else {
patch_name_and_version_hash
};
let is_required =
self.required_packages
.contains(self.manager(), dependency_id, package_id);
match resolution.tag {
resolution::Tag::Git => {
if package_manager::enqueue_git_for_checkout(
Comment thread
robobun marked this conversation as resolved.
Resolved
Expand All @@ -1616,6 +1620,7 @@ impl<'a> PackageInstaller<'a> {
resolution,
context,
download_patch_hash,
is_required,
) == package_manager::GitEnqueueResult::OfflineMiss
{
self.increment_tree_install_count(
Expand All @@ -1635,6 +1640,7 @@ impl<'a> PackageInstaller<'a> {
&url,
context,
download_patch_hash,
is_required,
) {
Ok(()) => {}
Err(ForTarballError::OutOfMemory) => bun_core::out_of_memory(),
Expand Down Expand Up @@ -1667,6 +1673,7 @@ impl<'a> PackageInstaller<'a> {
resolution.remote_tarball().slice(string_buf!()),
context,
download_patch_hash,
is_required,
) {
Ok(()) => {}
Err(ForTarballError::OutOfMemory) => bun_core::out_of_memory(),
Expand Down Expand Up @@ -1705,6 +1712,7 @@ impl<'a> PackageInstaller<'a> {
npm.url.slice(string_buf!()),
context,
download_patch_hash,
is_required,
) {
Ok(()) => {}
Err(ForTarballError::OutOfMemory) => bun_core::out_of_memory(),
Expand Down
67 changes: 42 additions & 25 deletions src/install/PackageManager/PackageManagerEnqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,21 @@ pub fn enqueue_dependency_list(
this.drain_dependency_list();
}

/// `is_required` is `RequiredPackages::contains`, not the behavior of `dependency_id` alone.
pub fn enqueue_tarball_for_download(
this: &mut PackageManager,
dependency_id: DependencyID,
package_id: PackageID,
url: &[u8],
task_context: TaskCallbackContext,
patch_name_and_version_hash: Option<u64>,
is_required: bool,
) -> Result<(), EnqueueTarballForDownloadError> {
let task_id = Task::Id::for_tarball(url);
if this.network_task_has_failed(task_id) {
if download_already_failed(this, task_id, is_required) {
return Err(EnqueueTarballForDownloadError::AlreadyFailed);
}
if this.options.offline == crate::package_manager_real::options::OfflineMode::Offline {
let is_required = this.lockfile.buffers.dependencies[dependency_id as usize]
.behavior
.is_required();
let name = this
.lockfile
.str(&this.lockfile.packages.get(package_id as usize).name)
Expand All @@ -181,9 +180,6 @@ pub fn enqueue_tarball_for_download(
return Ok(());
}

let is_required = this.lockfile.buffers.dependencies[dependency_id as usize]
.behavior
.is_required();
let package = *this.lockfile.packages.get(package_id as usize);
if let Some(task) = run_tasks::generate_network_task_for_tarball(
this,
Expand Down Expand Up @@ -261,13 +257,15 @@ pub enum GitEnqueueResult {
OfflineMiss,
}

/// `is_required`: see `enqueue_tarball_for_download`.
pub fn enqueue_git_for_checkout(
this: &mut PackageManager,
dependency_id: DependencyID,
alias: &[u8],
resolution: &Resolution,
task_context: TaskCallbackContext,
patch_name_and_version_hash: Option<u64>,
is_required: bool,
) -> GitEnqueueResult {
// SAFETY: caller passes `resolution.tag == Git`; the `git` arm is the
// active union field. Copy out so the value no longer borrows
Expand All @@ -285,13 +283,10 @@ pub fn enqueue_git_for_checkout(
let checkout_id = Task::Id::for_git_checkout(url, resolved);
// --offline: decide before any queue registration, so an optional miss leaves
// nothing behind and a later required edge still reaches the report
if this.git_repositories.get(&clone_id).is_none() {
let is_required = this.lockfile.buffers.dependencies[dependency_id as usize]
.behavior
.is_required();
if offline_git_miss(this, clone_id, alias, is_required) {
return GitEnqueueResult::OfflineMiss;
}
if this.git_repositories.get(&clone_id).is_none()
&& offline_git_miss(this, clone_id, alias, is_required)
{
return GitEnqueueResult::OfflineMiss;
}
let checkout_queue = this
.task_queue
Expand Down Expand Up @@ -340,6 +335,28 @@ pub fn enqueue_git_for_checkout(
GitEnqueueResult::Queued
}

/// An optional-only failure was reported as a warning, so a required request downloads again.
fn download_already_failed(
this: &mut PackageManager,
task_id: Task::Id,
is_required: bool,
) -> bool {
let Some(entry) = this.network_dedupe_map.get_mut(&task_id) else {
return false;
};
if !entry.failed {
Comment thread
robobun marked this conversation as resolved.
Resolved
entry.is_required |= is_required;
return false;
}
if entry.is_required || !is_required {
return true;
}
let _ = this.network_dedupe_map.remove(&task_id);
// No task runs for this id, so nothing would call the callbacks left in its queue.
let _ = this.task_queue.remove(&task_id);
false
}

/// Under `--offline`, an install-phase request for a package that is not in the cache
/// (these helpers are only reached after the cache lookup missed): report it once if
/// required, skip if optional, and never register a task nobody will complete.
Expand Down Expand Up @@ -452,6 +469,7 @@ pub unsafe fn enqueue_parse_npm_package(
unsafe { &raw mut (*task.as_ptr()).threadpool_task }
}

/// `is_required`: see `enqueue_tarball_for_download`.
pub fn enqueue_package_for_download(
this: &mut PackageManager,
name: &[u8],
Expand All @@ -461,18 +479,14 @@ pub fn enqueue_package_for_download(
url: &[u8],
task_context: TaskCallbackContext,
patch_name_and_version_hash: Option<u64>,
is_required: bool,
) -> Result<(), EnqueuePackageForDownloadError> {
let task_id = Task::Id::for_npm_package(name, version);
if this.network_task_has_failed(task_id) {
if download_already_failed(this, task_id, is_required) {
return Err(EnqueuePackageForDownloadError::AlreadyFailed);
}
{
let is_required = this.lockfile.buffers.dependencies[dependency_id as usize]
.behavior
.is_required();
if offline_tarball_miss(this, task_id, name, is_required) {
return Err(EnqueuePackageForDownloadError::Offline);
}
if offline_tarball_miss(this, task_id, name, is_required) {
return Err(EnqueuePackageForDownloadError::Offline);
}
let task_queue = this.task_queue.get_or_put(task_id)?;
if !task_queue.found_existing {
Expand All @@ -485,9 +499,6 @@ pub fn enqueue_package_for_download(
return Ok(());
}

let is_required = this.lockfile.buffers.dependencies[dependency_id as usize]
.behavior
.is_required();
let package = *this.lockfile.packages.get(package_id as usize);

if let Some(task) = run_tasks::generate_network_task_for_tarball(
Expand Down Expand Up @@ -3201,6 +3212,7 @@ impl PackageManager {
url: &[u8],
task_context: TaskCallbackContext,
patch_name_and_version_hash: Option<u64>,
is_required: bool,
) -> Result<(), EnqueueTarballForDownloadError> {
enqueue_tarball_for_download(
self,
Expand All @@ -3209,6 +3221,7 @@ impl PackageManager {
url,
task_context,
patch_name_and_version_hash,
is_required,
)
}

Expand Down Expand Up @@ -3239,6 +3252,7 @@ impl PackageManager {
resolution: &Resolution,
task_context: TaskCallbackContext,
patch_name_and_version_hash: Option<u64>,
is_required: bool,
) -> GitEnqueueResult {
enqueue_git_for_checkout(
self,
Expand All @@ -3247,6 +3261,7 @@ impl PackageManager {
resolution,
task_context,
patch_name_and_version_hash,
is_required,
)
}

Expand All @@ -3260,6 +3275,7 @@ impl PackageManager {
url: &[u8],
task_context: TaskCallbackContext,
patch_name_and_version_hash: Option<u64>,
is_required: bool,
) -> Result<(), EnqueuePackageForDownloadError> {
enqueue_package_for_download(
self,
Expand All @@ -3270,6 +3286,7 @@ impl PackageManager {
url,
task_context,
patch_name_and_version_hash,
is_required,
)
}
}
8 changes: 3 additions & 5 deletions src/install/PackageManager/runTasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1918,11 +1918,9 @@ pub fn has_created_network_task(
.expect("unreachable");

// if there's an existing network task that is optional, we want to make it non-optional if this one would be required
gpe.value_ptr.is_required = if !gpe.found_existing {
is_required
} else {
gpe.value_ptr.is_required || is_required
};
if !gpe.value_ptr.failed {
gpe.value_ptr.is_required |= is_required;
}

gpe.found_existing
}
Expand Down
4 changes: 4 additions & 0 deletions src/install/auto_installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,9 @@ impl hooks::AutoInstaller for PackageManager {
// preserves the tag/union pairing.
let npm = *r.npm();
let url = self.lockfile.str(&npm.url).to_vec();
let is_required = self.lockfile.buffers.dependencies[dependency_id as usize]
.behavior
.is_required();
enqueue::enqueue_package_for_download(
self,
name,
Expand All @@ -361,6 +364,7 @@ impl hooks::AutoInstaller for PackageManager {
&url,
crate::TaskCallbackContext::RootRequestId(ctx.root_request_id),
patch_name_and_version_hash,
is_required,
)
.map_err(|e| crate::Error::from(e).into())
}
Expand Down
5 changes: 5 additions & 0 deletions src/install/hoisted_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ pub(crate) fn install_hoisted_packages(
summary: &mut summary,
force_install,
successfully_installed: Bitset::init_empty(pkg_len)?,
required_packages: tree::RequiredPackages::new(
workspace_filters,
install_root_dependencies,
packages_to_install,
),
command_ctx: ctx,
tree_ids_to_trees_the_id_depends_on,
completed_trees,
Expand Down
14 changes: 13 additions & 1 deletion src/install/isolated_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use bun_wyhash::{Wyhash, Wyhash11};
use crate::analytics;
use crate::bun_bunfig::Arguments as Command;
use crate::bun_progress::{Node as ProgressNode, Progress};
use crate::lockfile::tree::is_filtered_dependency_or_workspace;
use crate::lockfile::tree::{RequiredPackages, is_filtered_dependency_or_workspace};
use crate::lockfile::{self, Lockfile};
use crate::package_manager::{self, PackageManager, WorkspaceFilter, run_tasks};
use crate::package_manager_real::ProgressStrings;
Expand Down Expand Up @@ -2100,6 +2100,12 @@ pub(crate) fn install_isolated_packages(
);
}

let mut required_packages = RequiredPackages::new(
workspace_filters,
install_root_dependencies,
packages_to_install,
);

// add the pending task count upfront
installer
.manager_mut()
Expand Down Expand Up @@ -2409,6 +2415,8 @@ pub(crate) fn install_isolated_packages(
let ctx = install::TaskCallbackContext::IsolatedPackageInstallContext(entry_id);

let dep = &lockfile_ro.buffers.dependencies[dep_id as usize];
let is_required =
required_packages.contains(installer.manager(), dep_id, pkg_id);

match pkg_res_tag {
ResolutionTag::Npm => {
Expand All @@ -2420,6 +2428,7 @@ pub(crate) fn install_isolated_packages(
pkg_res.npm().url.slice(string_buf),
ctx,
patch_info.name_and_version_hash(),
is_required,
) {
Ok(()) => {}
Err(e) if e == crate::Error::Alloc(bun_alloc::AllocError) => {
Expand Down Expand Up @@ -2468,6 +2477,7 @@ pub(crate) fn install_isolated_packages(
&pkg_res,
ctx,
patch_info.name_and_version_hash(),
is_required,
) == crate::package_manager::GitEnqueueResult::OfflineMiss
{
// --offline and not cached: nothing was queued
Expand All @@ -2490,6 +2500,7 @@ pub(crate) fn install_isolated_packages(
&url,
ctx,
patch_info.name_and_version_hash(),
is_required,
) {
Ok(()) => {}
Err(e) if e == crate::Error::Alloc(bun_alloc::AllocError) => {
Expand Down Expand Up @@ -2546,6 +2557,7 @@ pub(crate) fn install_isolated_packages(
pkg_res.remote_tarball().slice(string_buf),
ctx,
patch_info.name_and_version_hash(),
is_required,
) {
Ok(()) => {}
Err(e) if e == crate::Error::Alloc(bun_alloc::AllocError) => {
Expand Down
Loading
Loading