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(),
|
"Downloading packages".to_string(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
cfg_if! {
|
||||||
|
if #[cfg(feature = "wally")] {
|
||||||
|
let sourcemap_generator = manifest.sourcemap_generator.clone();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
project.convert_manifests(&lockfile, |path| {
|
let convert_job = project.convert_manifests(&lockfile, move |path| {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(feature = "wally")] {
|
if #[cfg(feature = "wally")] {
|
||||||
if let Some(sourcemap_generator) = &manifest.sourcemap_generator {
|
if let Some(sourcemap_generator) = &sourcemap_generator {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(target_os = "windows")] {
|
if #[cfg(target_os = "windows")] {
|
||||||
std::process::Command::new("pwsh")
|
std::process::Command::new("powershell")
|
||||||
.args(["-C", &sourcemap_generator])
|
.args(["-C", &sourcemap_generator])
|
||||||
.current_dir(path)
|
.current_dir(path)
|
||||||
.output()
|
.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);
|
let project = Lazy::force_mut(&mut project);
|
||||||
|
|
||||||
|
|
|
@ -321,11 +321,11 @@ impl Project {
|
||||||
|
|
||||||
/// Converts the manifests of the project's dependencies
|
/// Converts the manifests of the project's dependencies
|
||||||
#[cfg(feature = "wally")]
|
#[cfg(feature = "wally")]
|
||||||
pub fn convert_manifests<F: Fn(PathBuf)>(
|
pub fn convert_manifests<F: Fn(PathBuf) + Send + Sync + 'static>(
|
||||||
&self,
|
&self,
|
||||||
lockfile: &RootLockfileNode,
|
lockfile: &RootLockfileNode,
|
||||||
generate_sourcemap: F,
|
generate_sourcemap: F,
|
||||||
) -> Result<(), ConvertManifestsError> {
|
) -> MultithreadedJob<ConvertManifestsError> {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct SourcemapNode {
|
struct SourcemapNode {
|
||||||
|
@ -333,46 +333,57 @@ impl Project {
|
||||||
file_paths: Vec<relative_path::RelativePathBuf>,
|
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 versions in lockfile.children.values() {
|
||||||
for resolved_package in versions.values() {
|
for resolved_package in versions.values().cloned() {
|
||||||
let source = match &resolved_package.pkg_ref {
|
let generate_sourcemap = generate_sourcemap.clone();
|
||||||
PackageRef::Wally(_) | PackageRef::Git(_) => {
|
let self_path = self.path().to_path_buf();
|
||||||
resolved_package.directory(self.path()).1
|
|
||||||
}
|
|
||||||
_ => continue,
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut manifest = match &resolved_package.pkg_ref {
|
job.execute(&tx, move || {
|
||||||
PackageRef::Git(git) => {
|
let source = match &resolved_package.pkg_ref {
|
||||||
crate::dependencies::git::manifest(&source, &git.repo_url)?
|
PackageRef::Wally(_) | PackageRef::Git(_) => {
|
||||||
}
|
resolved_package.directory(self_path).1
|
||||||
_ => crate::manifest::Manifest::from_path_or_convert(&source)?,
|
}
|
||||||
};
|
_ => 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");
|
generate_sourcemap(source.to_path_buf());
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
manifest.exports.lib = sourcemap
|
let sourcemap = source.join("sourcemap.json");
|
||||||
.file_paths
|
let sourcemap: SourcemapNode = if sourcemap.exists() {
|
||||||
.into_iter()
|
serde_json::from_str(&std::fs::read_to_string(&sourcemap)?)?
|
||||||
.find(|path| {
|
} else {
|
||||||
path.extension()
|
log::warn!("sourcemap for {resolved_package} not found, skipping...");
|
||||||
.is_some_and(|ext| ext == "lua" || ext == "luau")
|
return Ok(());
|
||||||
})
|
};
|
||||||
.or_else(|| Some(relative_path::RelativePathBuf::from("true")));
|
|
||||||
|
|
||||||
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
|
/// Errors if dependencies don't have manifests, enable the `wally` feature to convert them
|
||||||
|
|
Loading…
Reference in a new issue