File tree Expand file tree Collapse file tree 5 files changed +32
-22
lines changed Expand file tree Collapse file tree 5 files changed +32
-22
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import {
25
25
getDeclarationIdentifier ,
26
26
getExportIdentifierStatement ,
27
27
} from './utils' ;
28
- import { isWebpack5orRspack } from '@/build-utils/common/module-graph' ;
28
+ import { hasModuleGraphApi , isRspack } from '@/build-utils/common/module-graph' ;
29
29
30
30
type ExportData = Map < WebExportInfo , ExportInfo > ;
31
31
@@ -161,7 +161,8 @@ export function appendTreeShaking(
161
161
moduleGraph : ModuleGraph ,
162
162
compilation : Plugin . BaseCompilation ,
163
163
) {
164
- if ( ! isWebpack5orRspack ( compilation ) ) {
164
+ // TODO: Rspack does not support tree shaking analysis for the time being. After subsequent verification.
165
+ if ( ! hasModuleGraphApi ( compilation ) || isRspack ( compilation ) ) {
165
166
return moduleGraph ;
166
167
}
167
168
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
getImportKind ,
19
19
isImportDependency ,
20
20
removeNoImportStyle ,
21
+ isRspack ,
21
22
} from '@/build-utils/common/module-graph' ;
22
23
import { hasSetEsModuleStatement } from '../parser' ;
23
24
import { isFunction } from 'lodash' ;
@@ -146,6 +147,7 @@ async function appendModuleData(
146
147
wbFs : WebpackFs ,
147
148
features ?: Plugin . RsdoctorWebpackPluginFeatures ,
148
149
context ?: TransformContext ,
150
+ isRspack ?: Boolean ,
149
151
) {
150
152
const module = graph . getModuleByWebpackId ( getWebpackModuleId ( origin ) ) ;
151
153
@@ -218,8 +220,8 @@ async function appendModuleData(
218
220
module . meta . strictHarmonyModule =
219
221
origin . buildMeta ?. strictHarmonyModule ?? false ;
220
222
module . meta . packageData = packageData ;
221
-
222
- if ( ! features ?. lite && origin ?. dependencies ) {
223
+ // TODO: Rspack does not appendDependencies current. After subsequent verification.
224
+ if ( ! features ?. lite && origin ?. dependencies && ! isRspack ) {
223
225
// lite bundle Mode don't have dependency;
224
226
// Record dependent data.
225
227
Array . from ( origin . dependencies )
@@ -261,6 +263,7 @@ export async function appendModuleGraphByCompilation(
261
263
fileSystemInfo ,
262
264
features ,
263
265
context ,
266
+ isRspack ( compilation ) ,
264
267
) ;
265
268
} ) ,
266
269
) ;
Original file line number Diff line number Diff line change 1
1
import type { Common } from '@rsdoctor/types' ;
2
- import { isWebpack5orRspack } from '@/build-utils/common/module-graph/compatible' ;
2
+ import { hasModuleGraphApi } from '@/build-utils/common/module-graph/compatible' ;
3
3
import { Plugin } from '@rsdoctor/types' ;
4
4
5
5
export type IHook =
@@ -49,7 +49,7 @@ export function interceptCompilationHooks(
49
49
* Compilation.hooks.normalModuleLoader is deprecated
50
50
* MIGRATION: Use NormalModule.getCompilationHooks(compilation).loader instead
51
51
*/
52
- if ( hook === 'normalModuleLoader' && isWebpack5orRspack ( compilation ) ) {
52
+ if ( hook === 'normalModuleLoader' && hasModuleGraphApi ( compilation ) ) {
53
53
return ;
54
54
}
55
55
Original file line number Diff line number Diff line change @@ -46,8 +46,15 @@ export function getPositionByStatsLocation(
46
46
}
47
47
}
48
48
49
- export function isWebpack5orRspack (
49
+ export function hasModuleGraphApi (
50
50
compilation : Plugin . BaseCompilation ,
51
51
) : Boolean {
52
52
return 'moduleGraph' in compilation && Boolean ( compilation . moduleGraph ) ;
53
53
}
54
+
55
+ export function isRspack ( compilation : Plugin . BaseCompilation ) : Boolean {
56
+ return (
57
+ 'rspackVersion' in compilation . compiler . webpack &&
58
+ Boolean ( compilation . compiler . webpack . rspackVersion )
59
+ ) ;
60
+ }
Original file line number Diff line number Diff line change @@ -62,22 +62,21 @@ export const ensureModulesChunksGraphFn = (
62
62
'Rspack currently does not support treeShaking capabilities.' ,
63
63
) ,
64
64
) ;
65
- return ;
66
- }
67
-
68
- _this . modulesGraph =
69
- ModuleGraphBuildUtils . appendTreeShaking (
70
- _this . modulesGraph ,
71
- stats . compilation ,
72
- ) || _this . modulesGraph ;
73
- _this . sdk . addClientRoutes ( [
74
- Manifest . RsdoctorManifestClientRoutes . TreeShaking ,
75
- ] ) ;
65
+ } else {
66
+ _this . modulesGraph =
67
+ ModuleGraphBuildUtils . appendTreeShaking (
68
+ _this . modulesGraph ,
69
+ stats . compilation ,
70
+ ) || _this . modulesGraph ;
71
+ _this . sdk . addClientRoutes ( [
72
+ Manifest . RsdoctorManifestClientRoutes . TreeShaking ,
73
+ ] ) ;
76
74
77
- debug (
78
- Process . getMemoryUsageMessage ,
79
- '[After AppendTreeShaking to ModuleGraph]' ,
80
- ) ;
75
+ debug (
76
+ Process . getMemoryUsageMessage ,
77
+ '[After AppendTreeShaking to ModuleGraph]' ,
78
+ ) ;
79
+ }
81
80
}
82
81
83
82
/** transform modules graph */
You can’t perform that action at this time.
0 commit comments