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(),
|
||||
)?;
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -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,46 +333,57 @@ 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() {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue