diff --git a/src/cli/root.rs b/src/cli/root.rs index 9acd597..4bcb2dc 100644 --- a/src/cli/root.rs +++ b/src/cli/root.rs @@ -109,14 +109,20 @@ pub fn root_command(cmd: Command) -> anyhow::Result<()> { "Downloading packages".to_string(), )?; + cfg_if! { + if #[cfg(feature = "wally")] { + let sourcemap_generator = manifest.sourcemap_generator.clone(); + } + } + #[allow(unused_variables)] - project.convert_manifests(&lockfile, |path| { + let convert_job = project.convert_manifests(&lockfile, move |path| { cfg_if! { if #[cfg(feature = "wally")] { - if let Some(sourcemap_generator) = &manifest.sourcemap_generator { + if let Some(sourcemap_generator) = &sourcemap_generator { cfg_if! { if #[cfg(target_os = "windows")] { - std::process::Command::new("pwsh") + std::process::Command::new("powershell") .args(["-C", &sourcemap_generator]) .current_dir(path) .output() @@ -132,7 +138,19 @@ pub fn root_command(cmd: Command) -> anyhow::Result<()> { } } } - })?; + }); + + cfg_if! { + if #[cfg(feature = "wally")] { + multithreaded_bar( + convert_job, + lockfile.children.values().flat_map(|v| v.values()).filter(|v| matches!(v.pkg_ref, PackageRef::Git(_) | PackageRef::Wally(_))).count() as u64, + "Converting manifests".to_string(), + )?; + } else { + convert_job?; + } + } let project = Lazy::force_mut(&mut project); diff --git a/src/dependencies/mod.rs b/src/dependencies/mod.rs index 449b717..f246093 100644 --- a/src/dependencies/mod.rs +++ b/src/dependencies/mod.rs @@ -321,11 +321,11 @@ impl Project { /// Converts the manifests of the project's dependencies #[cfg(feature = "wally")] - pub fn convert_manifests( + pub fn convert_manifests( &self, lockfile: &RootLockfileNode, generate_sourcemap: F, - ) -> Result<(), ConvertManifestsError> { + ) -> MultithreadedJob { #[derive(Deserialize)] #[serde(rename_all = "camelCase")] struct SourcemapNode { @@ -333,46 +333,57 @@ impl Project { file_paths: Vec, } + let (job, tx) = MultithreadedJob::new(); + + let generate_sourcemap = Arc::new(generate_sourcemap); + for versions in lockfile.children.values() { - for resolved_package in versions.values() { - let source = match &resolved_package.pkg_ref { - PackageRef::Wally(_) | PackageRef::Git(_) => { - resolved_package.directory(self.path()).1 - } - _ => continue, - }; + for resolved_package in versions.values().cloned() { + let generate_sourcemap = generate_sourcemap.clone(); + let self_path = self.path().to_path_buf(); - let mut manifest = match &resolved_package.pkg_ref { - PackageRef::Git(git) => { - crate::dependencies::git::manifest(&source, &git.repo_url)? - } - _ => crate::manifest::Manifest::from_path_or_convert(&source)?, - }; + job.execute(&tx, move || { + let source = match &resolved_package.pkg_ref { + PackageRef::Wally(_) | PackageRef::Git(_) => { + resolved_package.directory(self_path).1 + } + _ => return Ok(()), + }; - generate_sourcemap(source.to_path_buf()); + let mut manifest = match &resolved_package.pkg_ref { + PackageRef::Git(git) => { + crate::dependencies::git::manifest(&source, &git.repo_url)? + } + _ => crate::manifest::Manifest::from_path_or_convert(&source)?, + }; - let sourcemap = source.join("sourcemap.json"); - let sourcemap: SourcemapNode = if sourcemap.exists() { - serde_json::from_str(&std::fs::read_to_string(&sourcemap)?)? - } else { - log::warn!("sourcemap for {resolved_package} not found, skipping..."); - continue; - }; + generate_sourcemap(source.to_path_buf()); - manifest.exports.lib = sourcemap - .file_paths - .into_iter() - .find(|path| { - path.extension() - .is_some_and(|ext| ext == "lua" || ext == "luau") - }) - .or_else(|| Some(relative_path::RelativePathBuf::from("true"))); + let sourcemap = source.join("sourcemap.json"); + let sourcemap: SourcemapNode = if sourcemap.exists() { + serde_json::from_str(&std::fs::read_to_string(&sourcemap)?)? + } else { + log::warn!("sourcemap for {resolved_package} not found, skipping..."); + return Ok(()); + }; - manifest.write(&source)?; + manifest.exports.lib = sourcemap + .file_paths + .into_iter() + .find(|path| { + path.extension() + .is_some_and(|ext| ext == "lua" || ext == "luau") + }) + .or_else(|| Some(relative_path::RelativePathBuf::from("true"))); + + manifest.write(&source)?; + + Ok(()) + }); } } - Ok(()) + job } /// Errors if dependencies don't have manifests, enable the `wally` feature to convert them