From 9a6536114ce7207ae0a28cf4ff0662605a494fe7 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi Date: Wed, 18 Dec 2024 14:46:07 +0200 Subject: [PATCH 1/4] feat: show remote modules size on deno compile --- cli/standalone/binary.rs | 23 +++++++++++++++++++ .../compile/env_vars_support/compile.out | 2 ++ .../compile.out | 2 ++ .../compile/include/symlink_twice/compile.out | 2 ++ tests/specs/compile/npm_fs/compile.out | 2 ++ .../main_compile_folder.out | 2 ++ 6 files changed, 33 insertions(+) diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 2ed52010fb156c..a357babd40b756 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -575,11 +575,29 @@ impl<'a> DenoCompileBinaryWriter<'a> { None => None, }; let mut vfs = VfsBuilder::new(); + let mut remote_modules_size = 0.0; let npm_snapshot = match self.npm_resolver.as_inner() { InnerCliNpmResolverRef::Managed(managed) => { let snapshot = managed.serialized_valid_snapshot_for_system(&self.npm_system_info); if !snapshot.as_serialized().packages.is_empty() { + let npm_snapshot = managed.snapshot(); + // make sure that graph.npm_packages.is_empty() isn't empty + if !graph.npm_packages.is_empty() { + for module in graph.modules() { + if let deno_graph::Module::Npm(module) = module { + let nv = module.nv_reference.nv(); + if let Ok(package) = + npm_snapshot.resolve_package_from_deno_module(nv) + { + // package.id.clone() is found now + if let Ok(size) = managed.package_size(&package.id) { + remote_modules_size += size as f64; + } + } + } + } + } self.fill_npm_vfs(&mut vfs).context("Building npm vfs.")?; Some(snapshot) } else { @@ -738,6 +756,11 @@ impl<'a> DenoCompileBinaryWriter<'a> { }; output_vfs(&vfs, display_output_filename); + log::info!( + "{} {}\n", + crate::colors::bold("Remote modules size:"), + crate::util::display::human_size(remote_modules_size) + ); let metadata = Metadata { argv: compile_flags.args.clone(), diff --git a/tests/specs/compile/env_vars_support/compile.out b/tests/specs/compile/env_vars_support/compile.out index cba114b1f7c55e..06eace1c192228 100644 --- a/tests/specs/compile/env_vars_support/compile.out +++ b/tests/specs/compile/env_vars_support/compile.out @@ -10,3 +10,5 @@ out[WILDLINE] Size: [WILDLINE] +Remote modules size: [WILDLINE] + diff --git a/tests/specs/compile/global_npm_cache_implicit_read_permission/compile.out b/tests/specs/compile/global_npm_cache_implicit_read_permission/compile.out index fa1dd2bf9fb459..2cfa6b71266657 100644 --- a/tests/specs/compile/global_npm_cache_implicit_read_permission/compile.out +++ b/tests/specs/compile/global_npm_cache_implicit_read_permission/compile.out @@ -47,3 +47,5 @@ main[WILDLINE] Size: [WILDLINE] +Remote modules size: [WILDLINE] + diff --git a/tests/specs/compile/include/symlink_twice/compile.out b/tests/specs/compile/include/symlink_twice/compile.out index 6ae93bf1cb6b92..43c94a89c74cf6 100644 --- a/tests/specs/compile/include/symlink_twice/compile.out +++ b/tests/specs/compile/include/symlink_twice/compile.out @@ -9,3 +9,5 @@ main[WILDLINE] Size: [WILDLINE] +Remote modules size: [WILDLINE] + diff --git a/tests/specs/compile/npm_fs/compile.out b/tests/specs/compile/npm_fs/compile.out index c2ecef40155e20..d8b09b6be7e091 100644 --- a/tests/specs/compile/npm_fs/compile.out +++ b/tests/specs/compile/npm_fs/compile.out @@ -8,3 +8,5 @@ main[WILDLINE] Size: [WILDLINE] +Remote modules size: [WILDLINE] + diff --git a/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out b/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out index 538aaa414c6904..5cb964c8e1a67d 100644 --- a/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out +++ b/tests/testdata/compile/node_modules_symlink_outside/main_compile_folder.out @@ -15,3 +15,5 @@ bin[WILDLINE] Size: [WILDLINE] +Remote modules size: [WILDLINE] + From 79bb8068171cd0049ca74258f46696c0009da4df Mon Sep 17 00:00:00 2001 From: HasanAlrimawi Date: Wed, 18 Dec 2024 15:07:25 +0200 Subject: [PATCH 2/4] trigger checks From 9417786309f6f0c478b079ea2af0a1d986ad8245 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi Date: Mon, 23 Dec 2024 12:10:59 +0200 Subject: [PATCH 3/4] update: get remote size from remote modules store --- cli/standalone/binary.rs | 4 +++- cli/standalone/serialization.rs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 0c1d06740c5e3b..92873c6f464854 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -814,7 +814,9 @@ impl<'a> DenoCompileBinaryWriter<'a> { log::info!( "{} {}\n", crate::colors::bold("Remote modules size:"), - crate::util::display::human_size(remote_modules_size) + crate::util::display::human_size( + remote_modules_store.get_data_byte_len() as f64 + ) ); let metadata = Metadata { diff --git a/cli/standalone/serialization.rs b/cli/standalone/serialization.rs index 30802aa08197dd..95216bc6b61931 100644 --- a/cli/standalone/serialization.rs +++ b/cli/standalone/serialization.rs @@ -271,6 +271,10 @@ impl RemoteModulesStoreBuilder { } } } + + pub fn get_data_byte_len(&self) -> u64 { + self.data_byte_len + } } pub enum DenoCompileModuleSource { From 941e3149a9c93182ced04a3aae7ea440fa6608d7 Mon Sep 17 00:00:00 2001 From: HasanAlrimawi Date: Mon, 23 Dec 2024 14:37:05 +0200 Subject: [PATCH 4/4] remove unneeded variable --- cli/standalone/binary.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 92873c6f464854..86cd480352bea2 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -598,29 +598,11 @@ impl<'a> DenoCompileBinaryWriter<'a> { None => None, }; let mut vfs = VfsBuilder::new(); - let mut remote_modules_size = 0.0; let npm_snapshot = match self.npm_resolver.as_inner() { InnerCliNpmResolverRef::Managed(managed) => { let snapshot = managed.serialized_valid_snapshot_for_system(&self.npm_system_info); if !snapshot.as_serialized().packages.is_empty() { - let npm_snapshot = managed.snapshot(); - // make sure that graph.npm_packages.is_empty() isn't empty - if !graph.npm_packages.is_empty() { - for module in graph.modules() { - if let deno_graph::Module::Npm(module) = module { - let nv = module.nv_reference.nv(); - if let Ok(package) = - npm_snapshot.resolve_package_from_deno_module(nv) - { - // package.id.clone() is found now - if let Ok(size) = managed.package_size(&package.id) { - remote_modules_size += size as f64; - } - } - } - } - } self.fill_npm_vfs(&mut vfs).context("Building npm vfs.")?; Some(snapshot) } else {