1
1
import type { ModuleRequest , Resolution } from '@embroider/core' ;
2
- import { cleanUrl } from '@embroider/core' ;
2
+ import { cleanUrl , getUrlQueryParams } from '@embroider/core' ;
3
3
import type { PluginContext , ResolveIdResult } from 'rollup' ;
4
4
5
5
export const virtualPrefix = 'embroider_virtual:' ;
@@ -28,7 +28,24 @@ export class RollupModuleRequest implements ModuleRequest {
28
28
29
29
// strip query params off the importer
30
30
let fromFile = cleanUrl ( nonVirtual ) ;
31
- return new RollupModuleRequest ( context , source , fromFile , custom ?. embroider ?. meta , false , undefined ) ;
31
+ let importerQueryParams = getUrlQueryParams ( nonVirtual ) ;
32
+
33
+ // strip query params off the source but keep track of them
34
+ // we use regexp-based methods over a URL object because the
35
+ // source can be a relative path.
36
+ let cleanSource = cleanUrl ( source , true ) ;
37
+ let queryParams = getUrlQueryParams ( source , true ) ;
38
+
39
+ return new RollupModuleRequest (
40
+ context ,
41
+ cleanSource ,
42
+ fromFile ,
43
+ custom ?. embroider ?. meta ,
44
+ false ,
45
+ undefined ,
46
+ queryParams ,
47
+ importerQueryParams
48
+ ) ;
32
49
}
33
50
}
34
51
@@ -38,7 +55,9 @@ export class RollupModuleRequest implements ModuleRequest {
38
55
readonly fromFile : string ,
39
56
readonly meta : Record < string , any > | undefined ,
40
57
readonly isNotFound : boolean ,
41
- readonly resolvedTo : Resolution < ResolveIdResult > | undefined
58
+ readonly resolvedTo : Resolution < ResolveIdResult > | undefined ,
59
+ private queryParams : string ,
60
+ private importerQueryParams : string
42
61
) { }
43
62
44
63
get debugType ( ) {
@@ -49,14 +68,40 @@ export class RollupModuleRequest implements ModuleRequest {
49
68
return this . specifier . startsWith ( virtualPrefix ) ;
50
69
}
51
70
71
+ private get specifierWithQueryParams ( ) : string {
72
+ return `${ this . specifier } ${ this . queryParams } ` ;
73
+ }
74
+
75
+ private get fromFileWithQueryParams ( ) : string {
76
+ return `${ this . fromFile } ${ this . importerQueryParams } ` ;
77
+ }
78
+
52
79
alias ( newSpecifier : string ) {
53
- return new RollupModuleRequest ( this . context , newSpecifier , this . fromFile , this . meta , false , undefined ) as this;
80
+ return new RollupModuleRequest (
81
+ this . context ,
82
+ newSpecifier ,
83
+ this . fromFile ,
84
+ this . meta ,
85
+ false ,
86
+ undefined ,
87
+ this . queryParams ,
88
+ this . importerQueryParams
89
+ ) as this;
54
90
}
55
91
rehome ( newFromFile : string ) {
56
92
if ( this . fromFile === newFromFile ) {
57
93
return this ;
58
94
} else {
59
- return new RollupModuleRequest ( this . context , this . specifier , newFromFile , this . meta , false , undefined ) as this;
95
+ return new RollupModuleRequest (
96
+ this . context ,
97
+ this . specifier ,
98
+ newFromFile ,
99
+ this . meta ,
100
+ false ,
101
+ undefined ,
102
+ this . queryParams ,
103
+ this . importerQueryParams
104
+ ) as this;
60
105
}
61
106
}
62
107
virtualize ( filename : string ) {
@@ -66,7 +111,9 @@ export class RollupModuleRequest implements ModuleRequest {
66
111
this . fromFile ,
67
112
this . meta ,
68
113
false ,
69
- undefined
114
+ undefined ,
115
+ this . queryParams ,
116
+ this . importerQueryParams
70
117
) as this;
71
118
}
72
119
withMeta ( meta : Record < string , any > | undefined ) : this {
@@ -76,29 +123,40 @@ export class RollupModuleRequest implements ModuleRequest {
76
123
this . fromFile ,
77
124
meta ,
78
125
this . isNotFound ,
79
- this . resolvedTo
126
+ this . resolvedTo ,
127
+ this . queryParams ,
128
+ this . importerQueryParams
80
129
) as this;
81
130
}
82
131
notFound ( ) : this {
83
- return new RollupModuleRequest ( this . context , this . specifier , this . fromFile , this . meta , true , undefined ) as this;
132
+ return new RollupModuleRequest (
133
+ this . context ,
134
+ this . specifier ,
135
+ this . fromFile ,
136
+ this . meta ,
137
+ true ,
138
+ undefined ,
139
+ this . queryParams ,
140
+ this . importerQueryParams
141
+ ) as this;
84
142
}
85
143
async defaultResolve ( ) : Promise < Resolution < ResolveIdResult > > {
86
144
if ( this . isVirtual ) {
87
145
return {
88
146
type : 'found' ,
89
147
filename : this . specifier ,
90
- result : { id : this . specifier , resolvedBy : this . fromFile } ,
148
+ result : { id : this . specifierWithQueryParams , resolvedBy : this . fromFileWithQueryParams } ,
91
149
isVirtual : this . isVirtual ,
92
150
} ;
93
151
}
94
152
if ( this . isNotFound ) {
95
153
// TODO: we can make sure this looks correct in rollup & vite output when a
96
154
// user encounters it
97
- let err = new Error ( `module not found ${ this . specifier } ` ) ;
155
+ let err = new Error ( `module not found ${ this . specifierWithQueryParams } ` ) ;
98
156
( err as any ) . code = 'MODULE_NOT_FOUND' ;
99
157
return { type : 'not_found' , err } ;
100
158
}
101
- let result = await this . context . resolve ( this . specifier , this . fromFile , {
159
+ let result = await this . context . resolve ( this . specifierWithQueryParams , this . fromFileWithQueryParams , {
102
160
skipSelf : true ,
103
161
custom : {
104
162
embroider : {
@@ -108,7 +166,8 @@ export class RollupModuleRequest implements ModuleRequest {
108
166
} ,
109
167
} ) ;
110
168
if ( result ) {
111
- return { type : 'found' , filename : result . id , result, isVirtual : this . isVirtual } ;
169
+ let { pathname } = new URL ( result . id , 'http://example.com' ) ;
170
+ return { type : 'found' , filename : pathname , result, isVirtual : this . isVirtual } ;
112
171
} else {
113
172
return { type : 'not_found' , err : undefined } ;
114
173
}
@@ -121,7 +180,9 @@ export class RollupModuleRequest implements ModuleRequest {
121
180
this . fromFile ,
122
181
this . meta ,
123
182
this . isNotFound ,
124
- resolution
183
+ resolution ,
184
+ this . queryParams ,
185
+ this . importerQueryParams
125
186
) as this;
126
187
}
127
188
}
0 commit comments