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

fix(install): read bunfig install.cache.dir #10699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,7 @@ pub const PackageManager = struct {
noinline fn ensureCacheDirectory(this: *PackageManager) std.fs.Dir {
loop: while (true) {
if (this.options.enable.cache) {
const cache_dir = fetchCacheDirectoryPath(this.env);
const cache_dir = fetchCacheDirectoryPath(this.env, this.options);
this.cache_directory_path = this.allocator.dupe(u8, cache_dir.path) catch bun.outOfMemory();

return std.fs.cwd().makeOpenPath(cache_dir.path, .{}) catch {
Expand Down Expand Up @@ -5296,7 +5296,7 @@ pub const PackageManager = struct {
}

const CacheDir = struct { path: string, is_node_modules: bool };
pub fn fetchCacheDirectoryPath(env: *DotEnv.Loader) CacheDir {
pub fn fetchCacheDirectoryPath(env: *DotEnv.Loader, options: *Options) CacheDir {
if (env.get("BUN_INSTALL_CACHE_DIR")) |dir| {
return CacheDir{ .path = Fs.FileSystem.instance.abs(&[_]string{dir}), .is_node_modules = false };
}
Expand All @@ -5306,6 +5306,10 @@ pub const PackageManager = struct {
return CacheDir{ .path = Fs.FileSystem.instance.abs(&parts), .is_node_modules = false };
}

if (options.cache_directory) |dir| {
return CacheDir{ .path = Fs.FileSystem.instance.abs(&[_]string{dir}), .is_node_modules = false };
}

if (env.get("XDG_CACHE_HOME")) |dir| {
var parts = [_]string{ dir, ".bun/", "install/", "cache/" };
return CacheDir{ .path = Fs.FileSystem.instance.abs(&parts), .is_node_modules = false };
Expand Down Expand Up @@ -6248,6 +6252,10 @@ pub const PackageManager = struct {
this.local_package_features.optional_dependencies = save;
}

if (bun_install.cache_directory) |cache_dir| {
this.cache_directory = cache_dir;
}

this.explicit_global_directory = bun_install.global_dir orelse this.explicit_global_directory;
}

Expand Down