From 223403e899c934e23ea3012cc1bbba0b1a3ce92a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 3 Sep 2022 15:31:01 +0200 Subject: [PATCH] feat(info): add information about npm modules cache (#15750) --- cli/main.rs | 7 +++++++ cli/npm/cache.rs | 4 ++++ cli/npm/mod.rs | 4 ++++ cli/tests/testdata/041_info_flag.out | 1 + cli/tests/testdata/041_info_flag_location.out | 1 + cli/tests/testdata/info_json.out | 1 + cli/tests/testdata/info_json_location.out | 1 + 7 files changed, 19 insertions(+) diff --git a/cli/main.rs b/cli/main.rs index bffe9c4703..f089eeed6d 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -133,6 +133,7 @@ fn print_cache_info( ) -> Result<(), AnyError> { let deno_dir = &state.dir.root; let modules_cache = &state.file_fetcher.get_http_cache_location(); + let npm_cache = &state.npm_resolver.get_cache_location(); let typescript_cache = &state.dir.gen_cache.location; let registry_cache = &state.dir.root.join(lsp::language_server::REGISTRIES_PATH); @@ -149,6 +150,7 @@ fn print_cache_info( let mut output = json!({ "denoDir": deno_dir, "modulesCache": modules_cache, + "npmCache": npm_cache, "typescriptCache": typescript_cache, "registryCache": registry_cache, "originStorage": origin_dir, @@ -170,6 +172,11 @@ fn print_cache_info( colors::bold("Remote modules cache:"), modules_cache.display() ); + println!( + "{} {}", + colors::bold("npm modules cache:"), + npm_cache.display() + ); println!( "{} {}", colors::bold("Emitted modules cache:"), diff --git a/cli/npm/cache.rs b/cli/npm/cache.rs index e5193c77c5..e39957a6bf 100644 --- a/cli/npm/cache.rs +++ b/cli/npm/cache.rs @@ -162,6 +162,10 @@ impl ReadonlyNpmCache { version: NpmVersion::parse(version).unwrap(), }) } + + pub fn get_cache_location(&self) -> PathBuf { + self.root_dir.clone() + } } /// Stores a single copy of npm packages in a cache. diff --git a/cli/npm/mod.rs b/cli/npm/mod.rs index 5b49afb3d0..8272974bc0 100644 --- a/cli/npm/mod.rs +++ b/cli/npm/mod.rs @@ -184,6 +184,10 @@ impl GlobalNpmPackageResolver { registry_url: self.registry_url.clone(), } } + + pub fn get_cache_location(&self) -> PathBuf { + self.cache.as_readonly().get_cache_location() + } } impl NpmPackageResolver for GlobalNpmPackageResolver { diff --git a/cli/tests/testdata/041_info_flag.out b/cli/tests/testdata/041_info_flag.out index cb94386e80..3506a29e48 100644 --- a/cli/tests/testdata/041_info_flag.out +++ b/cli/tests/testdata/041_info_flag.out @@ -1,5 +1,6 @@ DENO_DIR location: [WILDCARD] Remote modules cache: [WILDCARD]deps +npm modules cache: [WILDCARD]npm Emitted modules cache: [WILDCARD]gen Language server registries cache: [WILDCARD]registries Origin storage: [WILDCARD]location_data diff --git a/cli/tests/testdata/041_info_flag_location.out b/cli/tests/testdata/041_info_flag_location.out index fa111cf189..b9e72f6590 100644 --- a/cli/tests/testdata/041_info_flag_location.out +++ b/cli/tests/testdata/041_info_flag_location.out @@ -1,5 +1,6 @@ DENO_DIR location: [WILDCARD] Remote modules cache: [WILDCARD]deps +npm modules cache: [WILDCARD]npm Emitted modules cache: [WILDCARD]gen Language server registries cache: [WILDCARD]registries Origin storage: [WILDCARD]location_data[WILDCARD] diff --git a/cli/tests/testdata/info_json.out b/cli/tests/testdata/info_json.out index 4ba5a95f49..3215af742b 100644 --- a/cli/tests/testdata/info_json.out +++ b/cli/tests/testdata/info_json.out @@ -1,6 +1,7 @@ { "denoDir": "[WILDCARD]", "modulesCache": "[WILDCARD]deps", + "npmCache": "[WILDCARD]npm", "typescriptCache": "[WILDCARD]gen", "registryCache": "[WILDCARD]registries", "originStorage": "[WILDCARD]location_data" diff --git a/cli/tests/testdata/info_json_location.out b/cli/tests/testdata/info_json_location.out index 6c4cddefbe..510fa77494 100644 --- a/cli/tests/testdata/info_json_location.out +++ b/cli/tests/testdata/info_json_location.out @@ -1,6 +1,7 @@ { "denoDir": "[WILDCARD]", "modulesCache": "[WILDCARD]deps", + "npmCache": "[WILDCARD]npm", "typescriptCache": "[WILDCARD]gen", "registryCache": "[WILDCARD]registries", "originStorage": "[WILDCARD]location_data[WILDCARD]",