Skip to content

Commit

Permalink
fix(install): read bunfig install.cache.dir
Browse files Browse the repository at this point in the history
Signed-off-by: Chawye Hsu <[email protected]>
  • Loading branch information
chawyehsu committed May 5, 2024
1 parent 989cb79 commit a6481c9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/install/install.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2929,7 +2929,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 @@ -5125,7 +5125,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 @@ -5135,6 +5135,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 @@ -6077,6 +6081,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

0 comments on commit a6481c9

Please sign in to comment.