Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
8 changes: 7 additions & 1 deletion src/install/PackageManager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,13 @@ pub fn init(

// Check if this is a workspace; if so, use root package
if subcommand.should_chdir_to_root() {
if !created_package_json && !no_project {
// The install `bunx` spawns has its own package.json in its own
// cache directory. The directories above it are the user's cache
// and home, so a `package.json` there is not a workspace root for
// this install, and a malformed one must not fail it.
Comment thread
robobun marked this conversation as resolved.
Resolved
let is_bunx_install =
bun_core::env_var::feature_flag::BUN_INTERNAL_BUNX_INSTALL.get() == Some(true);
if !created_package_json && !no_project && !is_bunx_install {
Comment thread
robobun marked this conversation as resolved.
Resolved
while let Some(parent) = bun_core::dirname(this_cwd) {
let parent_without_trailing_slash = strings::without_trailing_slash(parent);
let mut parent_path_buf = bun_paths::path_buffer_pool::get();
Expand Down
36 changes: 21 additions & 15 deletions src/install/PackageManager/PackageManagerDirectories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,47 +374,53 @@ unsafe fn ensure_cache_directory(this: *mut PackageManager) -> Dir {

pub struct CacheDir {
pub path: Vec<u8>,
/// True when nothing named a cache directory and `path` is
/// `node_modules/.bun-cache` under the working directory. `bunx` needs a
/// root only the current user can write, and that is not one.
Comment thread
robobun marked this conversation as resolved.
Resolved
pub is_cwd_fallback: bool,
}

impl CacheDir {
fn configured(path: Vec<u8>) -> CacheDir {
CacheDir {
path,
is_cwd_fallback: false,
}
}
}

pub fn fetch_cache_directory_path(env: &mut DotEnvLoader, options: Option<&Options>) -> CacheDir {
if let Some(dir) = env.get(b"BUN_INSTALL_CACHE_DIR") {
return CacheDir {
path: FileSystem::instance().abs(&[dir]).to_vec(),
};
return CacheDir::configured(FileSystem::instance().abs(&[dir]).to_vec());
}

if let Some(opts) = options {
if !opts.cache_directory.is_empty() {
return CacheDir {
path: FileSystem::instance().abs(&[opts.cache_directory]).to_vec(),
};
return CacheDir::configured(
FileSystem::instance().abs(&[opts.cache_directory]).to_vec(),
);
}
}

if let Some(dir) = env.get(b"BUN_INSTALL") {
let parts: [&[u8]; 3] = [dir, b"install/", b"cache/"];
return CacheDir {
path: FileSystem::instance().abs(&parts).to_vec(),
};
return CacheDir::configured(FileSystem::instance().abs(&parts).to_vec());
}

if let Some(dir) = env_var::XDG_CACHE_HOME.get() {
let parts: [&[u8]; 4] = [dir, b".bun/", b"install/", b"cache/"];
return CacheDir {
path: FileSystem::instance().abs(&parts).to_vec(),
};
return CacheDir::configured(FileSystem::instance().abs(&parts).to_vec());
}

if let Some(dir) = env_var::HOME.get() {
let parts: [&[u8]; 4] = [dir, b".bun/", b"install/", b"cache/"];
return CacheDir {
path: FileSystem::instance().abs(&parts).to_vec(),
};
return CacheDir::configured(FileSystem::instance().abs(&parts).to_vec());
}

let fallback_parts: [&[u8]; 1] = [b"node_modules/.bun-cache"];
CacheDir {
path: FileSystem::instance().abs(&fallback_parts).to_vec(),
is_cwd_fallback: true,
}
}

Expand Down
Loading
Loading