Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/node_binding/napi-binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,7 @@ export interface JsRsdoctorModuleGraph {
dependencies: Array<JsRsdoctorDependency>
chunkModules: Array<JsRsdoctorChunkModules>
connectionsOnlyImports: Array<JsRsdoctorConnectionsOnlyImport>
exportUsageEdges: Array<[number, Array<string> | null, number, Array<string> | null]>
}

export interface JsRsdoctorModuleGraphModule {
Expand Down Expand Up @@ -2939,6 +2940,7 @@ export interface RawRsdoctorPluginOptions {
moduleGraphFeatures: boolean | Array<'graph' | 'ids' | 'sources'>
chunkGraphFeatures: boolean | Array<'graph' | 'assets'>
sourceMapFeatures?: { module?: boolean; cheap?: boolean } | undefined
exportUsageGraph?: boolean
}

export interface RawRslibPluginOptions {
Expand Down
18 changes: 18 additions & 0 deletions crates/rspack_binding_api/src/rsdoctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ impl From<RsdoctorDependency> for JsRsdoctorDependency {
}
}

pub type JsRsdoctorExportUsageEdge = (i32, Option<Vec<String>>, i32, Option<Vec<String>>);

#[napi(object)]
pub struct JsRsdoctorConnection {
pub ukey: i32,
Expand Down Expand Up @@ -394,6 +396,8 @@ pub struct JsRsdoctorModuleGraph {
pub dependencies: Vec<JsRsdoctorDependency>,
pub chunk_modules: Vec<JsRsdoctorChunkModules>,
pub connections_only_imports: Vec<JsRsdoctorConnectionsOnlyImport>,
#[napi(ts_type = "Array<[number, Array<string> | null, number, Array<string> | null]>")]
pub export_usage_edges: Vec<JsRsdoctorExportUsageEdge>,
}

impl From<RsdoctorModuleGraph> for JsRsdoctorModuleGraph {
Expand All @@ -407,6 +411,18 @@ impl From<RsdoctorModuleGraph> for JsRsdoctorModuleGraph {
.into_iter()
.map(|s| s.into())
.collect(),
export_usage_edges: value
.export_usage_edges
.into_iter()
.map(|edge| {
(
edge.origin_module,
edge.origin_export,
edge.target_module,
edge.target_export,
)
})
.collect(),
}
}
}
Expand Down Expand Up @@ -559,6 +575,7 @@ pub struct RawRsdoctorPluginOptions {
pub chunk_graph_features: Either<bool, Vec<String>>,
#[napi(ts_type = "{ module?: boolean; cheap?: boolean } | undefined")]
pub source_map_features: Option<JsRsdoctorSourceMapFeatures>,
pub export_usage_graph: Option<bool>,
}

#[napi(object)]
Expand Down Expand Up @@ -608,6 +625,7 @@ impl From<RawRsdoctorPluginOptions> for RsdoctorPluginOptions {
.collect::<FxHashSet<_>>(),
},
source_map_features,
export_usage_graph: value.export_usage_graph.unwrap_or_default(),
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,25 @@ impl ESMImportSpecifierDependency {
self.ids.first().unwrap_or(&self.name)
}

pub fn get_destructuring_referenced_exports(&self, ids: &[Atom]) -> Vec<Vec<Atom>> {
let mut refs = Vec::new();
if let Some(referenced_properties) = &self.referenced_properties_in_destructuring {
referenced_properties.traverse_on_leaf(&mut |stack| {
let mut ids = ids.to_vec();
ids.extend(stack.iter().map(|p| p.id.clone()));
refs.push(ids);
});
}
refs
}

pub fn get_referenced_exports_in_destructuring(
&self,
ids: Option<&[Atom]>,
) -> Vec<ExtendedReferencedExport> {
if let Some(referenced_properties) = &self.referenced_properties_in_destructuring {
let mut refs = Vec::new();
referenced_properties.traverse_on_leaf(&mut |stack| {
let ids_in_destructuring = stack.iter().map(|p| p.id.clone());
if let Some(ids) = ids {
let mut ids = ids.to_vec();
ids.extend(ids_in_destructuring);
refs.push(ids);
} else {
refs.push(ids_in_destructuring.collect::<Vec<_>>());
}
});
refs
let destructuring_refs = self.get_destructuring_referenced_exports(ids.unwrap_or_default());
if !destructuring_refs.is_empty() {
destructuring_refs
.into_iter()
// Do not inline if there are any places where used as destructuring
.map(|name| {
Expand Down Expand Up @@ -173,6 +175,10 @@ impl ESMImportSpecifierDependency {
self.used_by_exports = used_by_exports;
}

pub fn used_by_exports(&self) -> Option<&UsedByExports> {
self.used_by_exports.as_ref()
}

pub fn add_branch_guards(&mut self, guards: impl IntoIterator<Item = DependencyBranchGuard>) {
self.branch_guards.get_or_insert_default().extend(guards);
}
Expand Down
33 changes: 17 additions & 16 deletions crates/rspack_plugin_rsdoctor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
atomic_refcell = { workspace = true }
futures = { workspace = true }
json = { workspace = true }
rayon = { workspace = true }
rspack_collections = { workspace = true }
rspack_core = { workspace = true }
rspack_error = { workspace = true }
rspack_hook = { workspace = true }
rspack_paths = { workspace = true }
rspack_plugin_devtool = { workspace = true }
rspack_plugin_json = { workspace = true }
rspack_util = { workspace = true }
rustc-hash = { workspace = true }
thread_local = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
atomic_refcell = { workspace = true }
futures = { workspace = true }
json = { workspace = true }
rayon = { workspace = true }
rspack_collections = { workspace = true }
rspack_core = { workspace = true }
rspack_error = { workspace = true }
rspack_hook = { workspace = true }
rspack_paths = { workspace = true }
rspack_plugin_devtool = { workspace = true }
rspack_plugin_javascript = { workspace = true }
rspack_plugin_json = { workspace = true }
rspack_util = { workspace = true }
rustc-hash = { workspace = true }
thread_local = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

[package.metadata.cargo-shear]
ignored = ["tracing"]
Expand Down
20 changes: 19 additions & 1 deletion crates/rspack_plugin_rsdoctor/src/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rspack_collections::Identifier;
use rspack_core::{BuildMetaExportsType, DependencyType};
use rspack_core::{BuildMetaExportsType, DependencyId, DependencyType};
use rustc_hash::FxHashSet as HashSet;

pub type ConnectionUkey = i32;
Expand Down Expand Up @@ -72,6 +72,23 @@ pub struct RsdoctorDependency {
pub dependency: ModuleUkey,
}

#[derive(Debug, Default, Clone)]
pub struct RsdoctorExportUsageDependency {
pub dependency_id: DependencyId,
pub origin_module_identifier: Identifier,
pub target_module_identifier: Identifier,
pub origin_export: Option<Vec<String>>,
pub target_export: Option<Vec<String>>,
}

#[derive(Debug, Default)]
pub struct RsdoctorExportUsageEdge {
pub origin_module: ModuleUkey,
pub origin_export: Option<Vec<String>>,
pub target_module: ModuleUkey,
pub target_export: Option<Vec<String>>,
}

#[derive(Debug, Default)]
pub struct RsdoctorConnection {
pub ukey: ConnectionUkey,
Expand Down Expand Up @@ -206,6 +223,7 @@ pub struct RsdoctorModuleGraph {
pub dependencies: Vec<RsdoctorDependency>,
pub chunk_modules: Vec<RsdoctorChunkModules>,
pub connections_only_imports: Vec<RsdoctorConnectionsOnlyImport>,
pub export_usage_edges: Vec<RsdoctorExportUsageEdge>,
}

#[derive(Debug, Default)]
Expand Down
Loading
Loading