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 {
2525 getDeclarationIdentifier ,
2626 getExportIdentifierStatement ,
2727} from './utils' ;
28- import { isWebpack5orRspack } from '@/build-utils/common/module-graph' ;
28+ import { hasModuleGraphApi , isRspack } from '@/build-utils/common/module-graph' ;
2929
3030type ExportData = Map < WebExportInfo , ExportInfo > ;
3131
@@ -161,7 +161,8 @@ export function appendTreeShaking(
161161 moduleGraph : ModuleGraph ,
162162 compilation : Plugin . BaseCompilation ,
163163) {
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 ) ) {
165166 return moduleGraph ;
166167 }
167168
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
1818 getImportKind ,
1919 isImportDependency ,
2020 removeNoImportStyle ,
21+ isRspack ,
2122} from '@/build-utils/common/module-graph' ;
2223import { hasSetEsModuleStatement } from '../parser' ;
2324import { isFunction } from 'lodash' ;
@@ -146,6 +147,7 @@ async function appendModuleData(
146147 wbFs : WebpackFs ,
147148 features ?: Plugin . RsdoctorWebpackPluginFeatures ,
148149 context ?: TransformContext ,
150+ isRspack ?: Boolean ,
149151) {
150152 const module = graph . getModuleByWebpackId ( getWebpackModuleId ( origin ) ) ;
151153
@@ -218,8 +220,8 @@ async function appendModuleData(
218220 module . meta . strictHarmonyModule =
219221 origin . buildMeta ?. strictHarmonyModule ?? false ;
220222 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 ) {
223225 // lite bundle Mode don't have dependency;
224226 // Record dependent data.
225227 Array . from ( origin . dependencies )
@@ -261,6 +263,7 @@ export async function appendModuleGraphByCompilation(
261263 fileSystemInfo ,
262264 features ,
263265 context ,
266+ isRspack ( compilation ) ,
264267 ) ;
265268 } ) ,
266269 ) ;
Original file line number Diff line number Diff line change 11import 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' ;
33import { Plugin } from '@rsdoctor/types' ;
44
55export type IHook =
@@ -49,7 +49,7 @@ export function interceptCompilationHooks(
4949 * Compilation.hooks.normalModuleLoader is deprecated
5050 * MIGRATION: Use NormalModule.getCompilationHooks(compilation).loader instead
5151 */
52- if ( hook === 'normalModuleLoader' && isWebpack5orRspack ( compilation ) ) {
52+ if ( hook === 'normalModuleLoader' && hasModuleGraphApi ( compilation ) ) {
5353 return ;
5454 }
5555
Original file line number Diff line number Diff line change @@ -46,8 +46,15 @@ export function getPositionByStatsLocation(
4646 }
4747}
4848
49- export function isWebpack5orRspack (
49+ export function hasModuleGraphApi (
5050 compilation : Plugin . BaseCompilation ,
5151) : Boolean {
5252 return 'moduleGraph' in compilation && Boolean ( compilation . moduleGraph ) ;
5353}
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 = (
6262 'Rspack currently does not support treeShaking capabilities.' ,
6363 ) ,
6464 ) ;
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+ ] ) ;
7674
77- debug (
78- Process . getMemoryUsageMessage ,
79- '[After AppendTreeShaking to ModuleGraph]' ,
80- ) ;
75+ debug (
76+ Process . getMemoryUsageMessage ,
77+ '[After AppendTreeShaking to ModuleGraph]' ,
78+ ) ;
79+ }
8180 }
8281
8382 /** transform modules graph */
You can’t perform that action at this time.
0 commit comments