@@ -4,8 +4,8 @@ class StartupError extends Error {}
4
4
* We need to know the bundle path before we can fetch the sourcemap files. In a production environment, we can guess
5
5
* it using this.
6
6
*/
7
- async function getBundleName ( ) {
8
- const res = await fetch ( "../ index.html") ;
7
+ async function getBundleName ( baseUrl ) {
8
+ const res = await fetch ( new URL ( " index.html", baseUrl ) . toString ( ) ) ;
9
9
if ( ! res . ok ) {
10
10
throw new StartupError ( `Couldn't fetch index.html to prefill bundle; ${ res . status } ${ res . statusText } ` ) ;
11
11
}
@@ -25,15 +25,15 @@ function validateBundle(value) {
25
25
* The purpose of this is just to validate that the user entered a real bundle, and provide feedback.
26
26
*/
27
27
const bundleCache = new Map ( ) ;
28
- function bundleSubject ( bundle ) {
28
+ function bundleSubject ( baseUrl , bundle ) {
29
29
if ( ! bundle . match ( / ^ [ 0 - 9 a - f ] { 20 } $ / ) ) throw new Error ( "Bad input" ) ;
30
30
if ( bundleCache . has ( bundle ) ) {
31
31
return bundleCache . get ( bundle ) ;
32
32
}
33
33
const fetcher = new rxjs . BehaviorSubject ( Pending . of ( ) ) ;
34
34
bundleCache . set ( bundle , fetcher ) ;
35
35
36
- fetch ( `../ bundles/${ bundle } /bundle.js.map`) . then ( ( res ) => {
36
+ fetch ( new URL ( ` bundles/${ bundle } /bundle.js.map`, baseUrl ) . toString ( ) ) . then ( ( res ) => {
37
37
res . body . cancel ( ) ; /* Bail on the download immediately - it could be big! */
38
38
const status = res . ok ;
39
39
if ( status ) {
@@ -145,6 +145,7 @@ function ProgressBar({ fetchStatus }) {
145
145
* The main component.
146
146
*/
147
147
function BundlePicker ( ) {
148
+ const [ baseUrl , setBaseUrl ] = React . useState ( new URL ( ".." , window . location ) . toString ( ) ) ;
148
149
const [ bundle , setBundle ] = React . useState ( "" ) ;
149
150
const [ file , setFile ] = React . useState ( "" ) ;
150
151
const [ line , setLine ] = React . useState ( "1" ) ;
@@ -153,19 +154,25 @@ function BundlePicker() {
153
154
const [ bundleFetchStatus , setBundleFetchStatus ] = React . useState ( None ) ;
154
155
const [ fileFetchStatus , setFileFetchStatus ] = React . useState ( None ) ;
155
156
156
- /* At startup , try to fill in the bundle name for the user */
157
+ /* On baseUrl change , try to fill in the bundle name for the user */
157
158
React . useEffect ( ( ) => {
158
- getBundleName ( ) . then ( ( name ) => {
159
+ console . log ( "DEBUG" , baseUrl ) ;
160
+ getBundleName ( baseUrl ) . then ( ( name ) => {
161
+ console . log ( "DEBUG" , name ) ;
159
162
if ( bundle === "" && validateBundle ( name ) !== None ) {
160
163
setBundle ( name ) ;
161
164
}
162
165
} , console . log . bind ( console ) ) ;
163
- } , [ ] ) ;
164
-
166
+ } , [ baseUrl ] ) ;
165
167
166
168
/* ------------------------- */
167
169
/* Follow user state changes */
168
170
/* ------------------------- */
171
+ const onBaseUrlChange = React . useCallback ( ( event ) => {
172
+ const value = event . target . value ;
173
+ setBaseUrl ( value ) ;
174
+ } , [ ] ) ;
175
+
169
176
const onBundleChange = React . useCallback ( ( event ) => {
170
177
const value = event . target . value ;
171
178
setBundle ( value ) ;
@@ -195,14 +202,14 @@ function BundlePicker() {
195
202
React . useEffect ( ( ) =>
196
203
validateBundle ( bundle ) . fold ( {
197
204
some : ( value ) => {
198
- const subscription = bundleSubject ( value )
205
+ const subscription = bundleSubject ( baseUrl , value )
199
206
. pipe ( rxjs . operators . map ( Some . of ) )
200
207
. subscribe ( setBundleFetchStatus ) ;
201
208
return ( ) => subscription . unsubscribe ( ) ;
202
209
} ,
203
210
none : ( ) => setBundleFetchStatus ( None ) ,
204
211
} ) ,
205
- [ bundle ] ) ;
212
+ [ baseUrl , bundle ] ) ;
206
213
207
214
/* Whenever a valid javascript file is input, see if it corresponds to a sourcemap file and initiate a fetch
208
215
* if so. */
@@ -211,7 +218,7 @@ function BundlePicker() {
211
218
setFileFetchStatus ( None ) ;
212
219
return ;
213
220
}
214
- const observable = fetchAsSubject ( `../ bundles/${ bundle } /${ file } .map`)
221
+ const observable = fetchAsSubject ( new URL ( ` bundles/${ bundle } /${ file } .map`, baseUrl ) . toString ( ) )
215
222
. pipe (
216
223
rxjs . operators . map ( ( fetchStatus ) => fetchStatus . flatMap ( value => {
217
224
try {
@@ -224,7 +231,7 @@ function BundlePicker() {
224
231
) ;
225
232
const subscription = observable . subscribe ( setFileFetchStatus ) ;
226
233
return ( ) => subscription . unsubscribe ( ) ;
227
- } , [ bundle , file ] ) ;
234
+ } , [ baseUrl , bundle , file ] ) ;
228
235
229
236
/*
230
237
* Whenever we have a valid fetched sourcemap, and a valid line, attempt to find the original position from the
@@ -255,6 +262,16 @@ function BundlePicker() {
255
262
/* ------ */
256
263
return e ( 'div' , { } ,
257
264
e ( 'div' , { className : 'inputs' } ,
265
+ e ( 'div' , { className : 'baseUrl' } ,
266
+ e ( 'label' , { htmlFor : 'baseUrl' } , 'Base URL' ) ,
267
+ e ( 'input' , {
268
+ name : 'baseUrl' ,
269
+ required : true ,
270
+ pattern : ".+" ,
271
+ onChange : onBaseUrlChange ,
272
+ value : baseUrl ,
273
+ } ) ,
274
+ ) ,
258
275
e ( 'div' , { className : 'bundle' } ,
259
276
e ( 'label' , { htmlFor : 'bundle' } , 'Bundle' ) ,
260
277
e ( 'input' , {
0 commit comments