File tree Expand file tree Collapse file tree 5 files changed +70
-16
lines changed
crates/node_binding/src/compilation
packages/rspack-test-tools/tests/watchCases/add-include/reuse-deps-for-incremental-make Expand file tree Collapse file tree 5 files changed +70
-16
lines changed Original file line number Diff line number Diff line change @@ -767,24 +767,15 @@ impl JsCompilation {
767767 . into_iter ( )
768768 . map ( |dependency_id| {
769769 let module_graph = compilation. get_module_graph ( ) ;
770- match module_graph. module_graph_module_by_dependency_id ( & dependency_id) {
771- Some ( module) => match module_graph. module_by_identifier ( & module. module_identifier ) {
772- Some ( module) => {
773- let js_module =
774- JsModuleWrapper :: new ( module. identifier ( ) , None , compilation. compiler_id ( ) ) ;
775- ( Either :: B ( ( ) ) , Either :: B ( js_module) )
776- }
777- None => (
778- Either :: A ( format ! (
779- "Module created by {:#?} cannot be found" ,
780- dependency_id
781- ) ) ,
782- Either :: A ( ( ) ) ,
783- ) ,
784- } ,
770+ match module_graph. get_module_by_dependency_id ( & dependency_id) {
771+ Some ( module) => {
772+ let js_module =
773+ JsModuleWrapper :: new ( module. identifier ( ) , None , compilation. compiler_id ( ) ) ;
774+ ( Either :: B ( ( ) ) , Either :: B ( js_module) )
775+ }
785776 None => (
786777 Either :: A ( format ! (
787- "Module created by {:# ?} cannot be found" ,
778+ "Module created by {:?} cannot be found" ,
788779 dependency_id
789780 ) ) ,
790781 Either :: A ( ( ) ) ,
Original file line number Diff line number Diff line change 1+ STATE . foo = 42 ;
Original file line number Diff line number Diff line change 1+ __webpack_require__ ( "./foo.js" ) ;
2+
3+ it ( "should addInclude foo.js" , ( ) => {
4+ expect ( STATE . foo ) . toBe ( 42 ) ;
5+ const builtModules = Object . fromEntries ( __STATS__ . modules . map ( m => [ m . name , m . built ] ) ) ;
6+ expect ( builtModules ) . toEqual ( { "./index.js" : true , "./foo.js" : true } ) ;
7+ } ) ;
Original file line number Diff line number Diff line change 1+ __webpack_require__ ( "./foo.js" ) ;
2+
3+ it ( "should addInclude foo.js" , ( ) => {
4+ expect ( STATE . foo ) . toBe ( 42 ) ;
5+ const builtModules = Object . fromEntries ( __STATS__ . modules . map ( m => [ m . name , m . built ] ) ) ;
6+ expect ( builtModules ) . toEqual ( { "./index.js" : true , "./foo.js" : false } ) ;
7+ } ) ;
Original file line number Diff line number Diff line change 1+ let step = 0 ;
2+ let factorizeRequests = [ ] ;
3+
4+ /** @type {import("@rspack/core").Configuration } */
5+ module . exports = {
6+ plugins : [
7+ function ( compiler ) {
8+ const PLUGIN_NAME = "TEST_PLUGIN" ;
9+ const { EntryPlugin } = compiler . webpack ;
10+ compiler . hooks . finishMake . tapPromise ( PLUGIN_NAME , compilation => {
11+ return new Promise ( ( resolve , reject ) => {
12+ compilation . addInclude (
13+ compiler . context ,
14+ EntryPlugin . createDependency ( "./foo.js" ) ,
15+ { } ,
16+ err => {
17+ if ( err ) return reject ( err ) ;
18+ return resolve ( ) ;
19+ }
20+ ) ;
21+ } ) ;
22+ } ) ;
23+
24+ compiler . hooks . compilation . tap (
25+ PLUGIN_NAME ,
26+ ( compilation , { normalModuleFactory } ) => {
27+ normalModuleFactory . hooks . factorize . tap ( PLUGIN_NAME , data => {
28+ factorizeRequests . push ( data . request ) ;
29+ } ) ;
30+ }
31+ ) ;
32+ compiler . hooks . done . tap ( PLUGIN_NAME , ( ) => {
33+ if ( step === 0 ) {
34+ expect ( factorizeRequests . length ) . toBe ( 2 ) ;
35+ expect ( factorizeRequests . includes ( "./index.js" ) ) . toBe ( true ) ;
36+ expect ( factorizeRequests . includes ( "./foo.js" ) ) . toBe ( true ) ;
37+ } else if ( step === 1 ) {
38+ expect ( factorizeRequests . length ) . toBe ( 1 ) ;
39+ expect ( factorizeRequests . includes ( "./index.js" ) ) . toBe ( true ) ;
40+ } else {
41+ throw new Error ( "Unexpected step" ) ;
42+ }
43+ step += 1 ;
44+ factorizeRequests = [ ] ;
45+ } ) ;
46+ }
47+ ]
48+ } ;
You can’t perform that action at this time.
0 commit comments