mirror of
https://github.com/pesde-pkg/pesde.git
synced 2024-12-12 11:00:36 +00:00
feat: parallel sourcemap generation
This commit is contained in:
parent
39102908cb
commit
06ed5d94ae
2 changed files with 66 additions and 37 deletions
|
@ -109,14 +109,20 @@ pub fn root_command(cmd: Command) -> anyhow::Result<()> {
|
|||
"Downloading packages".to_string(),
|
||||
)?;
|
||||
|
||||
#[allow(unused_variables)]
|
||||
project.convert_manifests(&lockfile, |path| {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "wally")] {
|
||||
if let Some(sourcemap_generator) = &manifest.sourcemap_generator {
|
||||
let sourcemap_generator = manifest.sourcemap_generator.clone();
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
let convert_job = project.convert_manifests(&lockfile, move |path| {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "wally")] {
|
||||
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);
|
||||
|
||||
|
|
|
@ -321,11 +321,11 @@ impl Project {
|
|||
|
||||
/// Converts the manifests of the project's dependencies
|
||||
#[cfg(feature = "wally")]
|
||||
pub fn convert_manifests<F: Fn(PathBuf)>(
|
||||
pub fn convert_manifests<F: Fn(PathBuf) + Send + Sync + 'static>(
|
||||
&self,
|
||||
lockfile: &RootLockfileNode,
|
||||
generate_sourcemap: F,
|
||||
) -> Result<(), ConvertManifestsError> {
|
||||
) -> MultithreadedJob<ConvertManifestsError> {
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct SourcemapNode {
|
||||
|
@ -333,13 +333,21 @@ impl Project {
|
|||
file_paths: Vec<relative_path::RelativePathBuf>,
|
||||
}
|
||||
|
||||
let (job, tx) = MultithreadedJob::new();
|
||||
|
||||
let generate_sourcemap = Arc::new(generate_sourcemap);
|
||||
|
||||
for versions in lockfile.children.values() {
|
||||
for resolved_package in versions.values() {
|
||||
for resolved_package in versions.values().cloned() {
|
||||
let generate_sourcemap = generate_sourcemap.clone();
|
||||
let self_path = self.path().to_path_buf();
|
||||
|
||||
job.execute(&tx, move || {
|
||||
let source = match &resolved_package.pkg_ref {
|
||||
PackageRef::Wally(_) | PackageRef::Git(_) => {
|
||||
resolved_package.directory(self.path()).1
|
||||
resolved_package.directory(self_path).1
|
||||
}
|
||||
_ => continue,
|
||||
_ => return Ok(()),
|
||||
};
|
||||
|
||||
let mut manifest = match &resolved_package.pkg_ref {
|
||||
|
@ -356,7 +364,7 @@ impl Project {
|
|||
serde_json::from_str(&std::fs::read_to_string(&sourcemap)?)?
|
||||
} else {
|
||||
log::warn!("sourcemap for {resolved_package} not found, skipping...");
|
||||
continue;
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
manifest.exports.lib = sourcemap
|
||||
|
@ -369,10 +377,13 @@ impl Project {
|
|||
.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
|
||||
|
|
Loading…
Reference in a new issue