Skip to content

Commit

Permalink
Merge branch 'master' into fix/load-wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
YufJi authored Nov 27, 2024
2 parents 76dc555 + b6f638d commit 9400f58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
53 changes: 29 additions & 24 deletions crates/mako/src/plugins/duplicate_package_checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::{Arc, RwLock};
use semver::Version;

use crate::compiler::Context;
use crate::module::Module;
use crate::module_graph::ModuleGraph;
use crate::plugin::Plugin;
use crate::resolve::ResolverResource;
Expand Down Expand Up @@ -46,6 +47,30 @@ fn clean_path_relative_to_context(module_path: &Path, context: &Path) -> PathBuf
}
}

fn extract_package_info(module: &Module) -> Option<PackageInfo> {
module
.info
.as_ref()
.and_then(|info| info.resolved_resource.as_ref())
.and_then(|resolver_resource| {
if let ResolverResource::Resolved(resource) = resolver_resource {
let package_json = resource.0.package_json()?;
let name = package_json.name.clone()?;
let raw_json = package_json.raw_json();
let version = raw_json.as_object()?.get("version")?;
let version = semver::Version::parse(version.as_str().unwrap()).ok()?;

Some(PackageInfo {
name,
version,
path: package_json.path.clone(),
})
} else {
None
}
})
}

impl DuplicatePackageCheckerPlugin {
pub fn new() -> Self {
Self::default()
Expand Down Expand Up @@ -92,30 +117,10 @@ impl DuplicatePackageCheckerPlugin {
.read()
.unwrap()
.modules()
.iter()
.for_each(|module| {
if let Some(ResolverResource::Resolved(resource)) = module
.info
.as_ref()
.and_then(|info| info.resolved_resource.as_ref())
{
if let Some(package_json) = resource.0.package_json() {
let raw_json = package_json.raw_json();
if let Some(name) = package_json.name.clone() {
if let Some(version) = raw_json.as_object().unwrap().get("version") {
let version = semver::Version::parse(version.as_str().unwrap());
if let Ok(version) = version {
let package_info = PackageInfo {
name,
version,
path: package_json.path.clone(),
};
packages.push(package_info);
}
}
}
}
}
.into_iter()
.filter_map(extract_package_info)
.for_each(|package_info| {
packages.push(package_info);
});

Self::find_duplicates(packages)
Expand Down
2 changes: 1 addition & 1 deletion crates/mako/src/visitors/async_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub fn mark_async(
.filter_map(|m| {
m.info
.as_ref()
.and_then(|i| if i.is_async { Some(m.id.clone()) } else { None })
.and_then(|i| i.is_async.then(|| m.id.clone()))
})
.collect::<VecDeque<_>>();
let mut visited = HashSet::new();
Expand Down

0 comments on commit 9400f58

Please sign in to comment.