@@ -54,28 +54,20 @@ interface FeatureUsage {
54
54
invocationCount : number
55
55
}
56
56
57
- /**
58
- * A vertex in the module graph.
59
- */
60
- interface Module {
61
- type : string
62
- identifier ( ) : string
63
- }
64
-
65
57
/**
66
58
* An edge in the module graph.
67
59
*/
68
60
interface Connection {
69
61
originModule : unknown
70
62
}
71
63
72
- // Map of a feature module to the file it belongs in the next package.
64
+ // Map of a feature module to the request it belongs to
73
65
const FEATURE_MODULE_MAP : ReadonlyMap < Feature , string > = new Map ( [
74
- [ 'next/image' , '/ next/image.js ' ] ,
75
- [ 'next/future/image' , '/ next/future/image.js ' ] ,
76
- [ 'next/legacy/image' , '/ next/legacy/image.js ' ] ,
77
- [ 'next/script' , '/ next/script.js ' ] ,
78
- [ 'next/dynamic' , '/ next/dynamic.js ' ] ,
66
+ [ 'next/image' , 'next/image' ] ,
67
+ [ 'next/future/image' , 'next/future/image' ] ,
68
+ [ 'next/legacy/image' , 'next/legacy/image' ] ,
69
+ [ 'next/script' , 'next/script' ] ,
70
+ [ 'next/dynamic' , 'next/dynamic' ] ,
79
71
] )
80
72
const FEATURE_MODULE_REGEXP_MAP : ReadonlyMap < Feature , RegExp > = new Map ( [
81
73
[ '@next/font/google' , / \/ @ n e x t \/ f o n t \/ g o o g l e \/ t a r g e t .c s s ? .+ $ / ] ,
@@ -127,16 +119,16 @@ const useCacheTracker = createUseCacheTracker()
127
119
/**
128
120
* Determine if there is a feature of interest in the specified 'module'.
129
121
*/
130
- function findFeatureInModule ( module : Module ) : Feature | undefined {
122
+ function findFeatureInModule ( module : webpack . Module ) : Feature | undefined {
131
123
if ( module . type !== 'javascript/auto' ) {
132
124
return
133
125
}
134
- const normalizedIdentifier = module . identifier ( ) . replace ( / \\ / g, '/' )
135
- for ( const [ feature , path ] of FEATURE_MODULE_MAP ) {
136
- if ( normalizedIdentifier . endsWith ( path ) ) {
126
+ for ( const [ feature , rawRequest ] of FEATURE_MODULE_MAP ) {
127
+ if ( ( module as webpack . NormalModule ) . rawRequest === rawRequest ) {
137
128
return feature
138
129
}
139
130
}
131
+ const normalizedIdentifier = module . identifier ( ) . replace ( / \\ / g, '/' )
140
132
for ( const [ feature , regexp ] of FEATURE_MODULE_REGEXP_MAP ) {
141
133
if ( regexp . test ( normalizedIdentifier ) ) {
142
134
return feature
@@ -151,7 +143,7 @@ function findFeatureInModule(module: Module): Feature | undefined {
151
143
*/
152
144
function findUniqueOriginModulesInConnections (
153
145
connections : Connection [ ] ,
154
- originModule : Module
146
+ originModule : webpack . Module
155
147
) : Set < unknown > {
156
148
const originModules = new Set ( )
157
149
for ( const connection of connections ) {
@@ -206,7 +198,7 @@ export class TelemetryPlugin implements webpack.WebpackPluginInstance {
206
198
async ( compilation : webpack . Compilation , callback : ( ) => void ) => {
207
199
compilation . hooks . finishModules . tapAsync (
208
200
TelemetryPlugin . name ,
209
- async ( modules : Iterable < Module > , modulesFinish : ( ) => void ) => {
201
+ async ( modules , modulesFinish ) => {
210
202
for ( const module of modules ) {
211
203
const feature = findFeatureInModule ( module )
212
204
if ( ! feature ) {
0 commit comments