Skip to content

fix: resolveData.*_dependencies should work when factorize success #10967

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 9 additions & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ export interface JsBeforeResolveArgs {
context: string
issuer: string
issuerLayer?: string
fileDependencies: Array<string>
missingDependencies: Array<string>
contextDependencies: Array<string>
}

export interface JsBuildMeta {
Expand Down Expand Up @@ -833,6 +836,9 @@ export interface JsFactorizeArgs {
context: string
issuer: string
issuerLayer?: string
fileDependencies: Array<string>
missingDependencies: Array<string>
contextDependencies: Array<string>
}

export interface JsFactoryMeta {
Expand Down Expand Up @@ -991,6 +997,9 @@ export interface JsResolveArgs {
context: string
issuer: string
issuerLayer?: string
fileDependencies: Array<string>
missingDependencies: Array<string>
contextDependencies: Array<string>
}

export interface JsResolveForSchemeArgs {
Expand Down
9 changes: 9 additions & 0 deletions crates/rspack_binding_api/src/normal_module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub struct JsBeforeResolveArgs {
pub context: String,
pub issuer: String,
pub issuer_layer: Option<String>,
pub file_dependencies: Vec<String>,
pub missing_dependencies: Vec<String>,
pub context_dependencies: Vec<String>,
}

pub type JsBeforeResolveOutput = (Option<bool>, JsBeforeResolveArgs);
Expand All @@ -27,6 +30,9 @@ pub struct JsFactorizeArgs {
pub context: String,
pub issuer: String,
pub issuer_layer: Option<String>,
pub file_dependencies: Vec<String>,
pub missing_dependencies: Vec<String>,
pub context_dependencies: Vec<String>,
}

pub type JsFactorizeOutput = JsFactorizeArgs;
Expand All @@ -37,6 +43,9 @@ pub struct JsResolveArgs {
pub context: String,
pub issuer: String,
pub issuer_layer: Option<String>,
pub file_dependencies: Vec<String>,
pub missing_dependencies: Vec<String>,
pub context_dependencies: Vec<String>,
}

pub type JsResolveOutput = JsResolveArgs;
Expand Down
97 changes: 97 additions & 0 deletions crates/rspack_binding_api/src/plugins/interceptor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
hash::Hash,
path::Path,
ptr::NonNull,
sync::{Arc, RwLock},
};
Expand Down Expand Up @@ -1452,12 +1453,42 @@ impl NormalModuleFactoryBeforeResolve for NormalModuleFactoryBeforeResolveTap {
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
file_dependencies: data
.file_dependencies
.iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
context_dependencies: data
.context_dependencies
.iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
missing_dependencies: data
.missing_dependencies
.iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
})
.await
{
Ok((ret, resolve_data)) => {
dependency.set_request(resolve_data.request);
data.context = resolve_data.context.into();
data.file_dependencies = resolve_data
.file_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
data.context_dependencies = resolve_data
.context_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
data.missing_dependencies = resolve_data
.missing_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
Ok(ret)
}
Err(err) => Err(err),
Expand Down Expand Up @@ -1489,12 +1520,45 @@ impl NormalModuleFactoryFactorize for NormalModuleFactoryFactorizeTap {
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
file_dependencies: data
.file_dependencies
.clone()
.into_iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
context_dependencies: data
.context_dependencies
.clone()
.into_iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
missing_dependencies: data
.missing_dependencies
.clone()
.into_iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
})
.await
{
Ok(resolve_data) => {
dependency.set_request(resolve_data.request);
data.context = resolve_data.context.into();
data.file_dependencies = resolve_data
.file_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
data.context_dependencies = resolve_data
.context_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
data.missing_dependencies = resolve_data
.missing_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
// only supports update resolve request for now
Ok(None)
}
Expand Down Expand Up @@ -1527,12 +1591,45 @@ impl NormalModuleFactoryResolve for NormalModuleFactoryResolveTap {
.map(|issuer| issuer.to_string())
.unwrap_or_default(),
issuer_layer: data.issuer_layer.clone(),
file_dependencies: data
.file_dependencies
.clone()
.into_iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
context_dependencies: data
.context_dependencies
.clone()
.into_iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
missing_dependencies: data
.missing_dependencies
.clone()
.into_iter()
.map(|item| item.to_string_lossy().to_string())
.collect::<Vec<_>>(),
})
.await
{
Ok(resolve_data) => {
dependency.set_request(resolve_data.request);
data.context = resolve_data.context.into();
data.file_dependencies = resolve_data
.file_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
data.context_dependencies = resolve_data
.context_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
data.missing_dependencies = resolve_data
.missing_dependencies
.into_iter()
.map(|item| Path::new(&item).into())
.collect();
// only supports update resolve request for now
Ok(None)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_core/src/cache/persistent/occasion/make/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ impl MakeOccasion {
let mut make_failed_dependencies = HashSet::default();
for (dep_id, dep) in mg.dependencies() {
if let Some(info) = FactorizeInfo::get_from(dep) {
file_dep.add_batch_file(info.file_dependencies());
context_dep.add_batch_file(info.context_dependencies());
missing_dep.add_batch_file(info.missing_dependencies());
if !info.is_success() {
make_failed_dependencies.insert(dep_id);
file_dep.add_batch_file(&info.file_dependencies());
context_dep.add_batch_file(&info.context_dependencies());
missing_dep.add_batch_file(&info.missing_dependencies());
}
}
}
Expand Down
24 changes: 11 additions & 13 deletions crates/rspack_core/src/compiler/make/cutout/fix_build_meta.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
use rspack_collections::IdentifierMap;
use rspack_collections::{IdentifierMap, IdentifierSet};
use rspack_error::Diagnosable;

use super::super::MakeArtifact;
use crate::{BuildMeta, Module, ModuleIdentifier};
use crate::{BuildMeta, Module};

#[derive(Debug, Default)]
pub struct FixBuildMeta {
origin_module_build_meta: IdentifierMap<BuildMeta>,
}

impl FixBuildMeta {
pub fn analyze_force_build_module(
&mut self,
artifact: &MakeArtifact,
module_identifier: &ModuleIdentifier,
) {
pub fn analyze_force_build_modules(&mut self, artifact: &MakeArtifact, mids: &IdentifierSet) {
let module_graph = artifact.get_module_graph();
let module = module_graph
.module_by_identifier(module_identifier)
.expect("should have module");
self
.origin_module_build_meta
.insert(*module_identifier, module.build_meta().clone());
for module_identifier in mids {
let module = module_graph
.module_by_identifier(module_identifier)
.expect("should have module");
self
.origin_module_build_meta
.insert(*module_identifier, module.build_meta().clone());
}
}

pub fn fix_artifact(self, artifact: &mut MakeArtifact) {
Expand Down
86 changes: 57 additions & 29 deletions crates/rspack_core/src/compiler/make/cutout/fix_issuers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::collections::VecDeque;

use rspack_collections::{IdentifierMap, IdentifierSet};
use rustc_hash::FxHashSet as HashSet;

use super::super::MakeArtifact;
use crate::{ModuleGraph, ModuleIdentifier, ModuleIssuer};
use crate::{DependencyId, ModuleGraph, ModuleIdentifier, ModuleIssuer};

/// Result of IssuerHelper.is_issuer.
enum IsIssuerResult {
Expand Down Expand Up @@ -110,44 +111,71 @@ pub struct FixIssuers {
}

impl FixIssuers {
/// Analyze force_build_module.
/// Analyze force_build_modules.
///
/// This function will
/// This function will check each force_build_module and
/// 1. save the issuer of force_build_module to self.force_build_module_issuers.
/// 2. add force_build_module and the child module whose issuer is this force_build_module to self.need_check_modules.
pub fn analyze_force_build_module(
pub fn analyze_force_build_modules(&mut self, artifact: &MakeArtifact, mids: &IdentifierSet) {
let module_graph = artifact.get_module_graph();
for module_identifier in mids {
let mgm = module_graph
.module_graph_module_by_identifier(module_identifier)
.expect("should have module graph module");
self
.force_build_module_issuers
.insert(*module_identifier, mgm.issuer().clone());
self.need_check_modules.insert(*module_identifier);

// analyze child module
// if child module issuer is current module,
// add child module to self.need_check_modules
for child_dep_id in mgm.outgoing_connections() {
let child_mid = module_graph
.module_identifier_by_dependency_id(child_dep_id)
.expect("should module exist");
let Some(child_mgm) = module_graph.module_graph_module_by_identifier(child_mid) else {
// peresistent cache recovery module graph will lose some module and mgm.
// TODO replace to .expect() after all modules are cacheable.
self.need_check_modules.insert(*child_mid);
continue;
};

let child_module_issuer = child_mgm.issuer();
if let ModuleIssuer::Some(i) = child_module_issuer
&& i == module_identifier
{
self.need_check_modules.insert(*child_mid);
}
}
}
}

/// Analyze force_build_dependencies.
///
/// This function will check the origin and target module of each force_build_dependencies,
/// if target module is the origin module of current dependency, it is added to self.need_check_modules.
pub fn analyze_force_build_dependencies(
&mut self,
artifact: &MakeArtifact,
module_identifier: &ModuleIdentifier,
dep_ids: &HashSet<DependencyId>,
) {
let module_graph = artifact.get_module_graph();
let mgm = module_graph
.module_graph_module_by_identifier(module_identifier)
.expect("should have module graph module");
self
.force_build_module_issuers
.insert(*module_identifier, mgm.issuer().clone());
self.need_check_modules.insert(*module_identifier);

// analyze child module
// if child module issuer is current module,
// add child module to self.need_check_modules
for child_dep_id in mgm.outgoing_connections() {
let child_mid = module_graph
.module_identifier_by_dependency_id(child_dep_id)
.expect("should module exist");
let Some(child_mgm) = module_graph.module_graph_module_by_identifier(child_mid) else {
// peresistent cache recovery module graph will lose some module and mgm.
// TODO replace to .expect() after all modules are cacheable.
self.need_check_modules.insert(*child_mid);
for dep_id in dep_ids {
let Some(conn) = module_graph.connection_by_dependency_id(dep_id) else {
// maybe factorize failed dep_id
continue;
};

let child_module_issuer = child_mgm.issuer();
if let ModuleIssuer::Some(i) = child_module_issuer
&& i == module_identifier
{
self.need_check_modules.insert(*child_mid);
let parent_mid = &conn.original_module_identifier;
let child_mid = conn.module_identifier();
// peresistent cache recovery module graph will lose some module and mgm.
// TODO replace to .expect() after all modules are cacheable.
if let Some(child_mgm) = module_graph.module_graph_module_by_identifier(child_mid) {
let issuer = child_mgm.issuer().identifier();
if issuer == parent_mid.as_ref() {
self.add_need_check_module(*child_mid)
}
}
}
}
Expand Down
Loading
Loading