@@ -406,6 +406,26 @@ export class Application {
406
406
} )
407
407
}
408
408
409
+ // inject browser navigator polyfill
410
+ Object . assign ( globalThis , {
411
+ navigator : {
412
+ connection : {
413
+ downlink : 10 ,
414
+ effectiveType : "4g" ,
415
+ onchange : null ,
416
+ rtt : 50 ,
417
+ saveData : false ,
418
+ } ,
419
+ cookieEnabled : false ,
420
+ deviceMemory : 8 ,
421
+ hardwareConcurrency : 4 ,
422
+ language : 'en' ,
423
+ onLine : true ,
424
+ userAgent : `Deno/${ Deno . version . deno } ` ,
425
+ vendor : 'Deno Land' ,
426
+ }
427
+ } )
428
+
409
429
if ( ! this . isDev ) {
410
430
log . info ( 'Building...' )
411
431
}
@@ -618,21 +638,21 @@ export class Application {
618
638
const url = new URL ( importUrl )
619
639
let pathname = url . pathname
620
640
let ok = [ ...moduleExts , 'css' , 'pcss' ] . includes ( path . extname ( pathname ) . slice ( 1 ) )
621
- if ( ok ) {
641
+ if ( ! ok ) {
622
642
for ( const plugin of this . config . plugins ) {
623
643
if ( plugin . type === 'loader' && plugin . test . test ( pathname ) ) {
624
644
ok = true
625
645
break
626
646
}
627
647
}
628
648
}
629
- if ( ! ok ) {
630
- pathname += '.js'
631
- }
632
649
let search = Array . from ( url . searchParams . entries ( ) ) . map ( ( [ key , value ] ) => value ? `${ key } =${ value } ` : key )
633
650
if ( search . length > 0 ) {
634
651
pathname += '_' + search . join ( ',' )
635
652
}
653
+ if ( ! ok ) {
654
+ pathname += '.js'
655
+ }
636
656
return [
637
657
'/-/' ,
638
658
( url . protocol === 'http:' ? 'http_' : '' ) ,
@@ -777,17 +797,11 @@ export class Application {
777
797
} else if ( isRemote ) {
778
798
const isLocalhost = / ^ h t t p s ? : \/ \/ l o c a l h o s t ( : \d + ) ? \/ / . test ( url )
779
799
if ( [ 'js' , 'ts' , 'jsx' , 'tsx' ] . includes ( mod . loader ) && ! isLocalhost ) {
780
- try {
781
- sourceContent = await this . fetchDependency ( url )
782
- const sourceHash = computeHash ( sourceContent )
783
- if ( mod . sourceHash === '' || mod . sourceHash !== sourceHash ) {
784
- mod . sourceHash = sourceHash
785
- changed = true
786
- }
787
- } catch ( err ) {
788
- log . error ( `dependency '${ url } ' not found` )
789
- mod . error = err
790
- return mod
800
+ sourceContent = await this . fetchDependency ( url )
801
+ const sourceHash = computeHash ( sourceContent )
802
+ if ( mod . sourceHash === '' || mod . sourceHash !== sourceHash ) {
803
+ mod . sourceHash = sourceHash
804
+ changed = true
791
805
}
792
806
} else {
793
807
// todo: cache non-localhost file to local drive
@@ -1112,16 +1126,31 @@ export class Application {
1112
1126
}
1113
1127
1114
1128
// download dep when deno cache failed
1115
- log . info ( 'Download' , url )
1116
- const buffer = await fetch ( u . toString ( ) ) . then ( resp => {
1117
- if ( resp . status !== 200 ) {
1118
- return Promise . reject ( new Error ( resp . statusText ) )
1129
+ const retryTimes = 10
1130
+ let err = new Error ( 'Unknown' )
1131
+ for ( let i = 0 ; i < retryTimes ; i ++ ) {
1132
+ if ( i === 0 ) {
1133
+ log . info ( 'Download' , url )
1134
+ } else {
1135
+ log . debug ( 'Download error:' , err )
1136
+ log . warn ( `Download ${ url } failed, retrying...` )
1119
1137
}
1120
- return resp . arrayBuffer ( )
1121
- } )
1122
- const content = await Deno . readAll ( new Deno . Buffer ( buffer ) )
1123
- await Deno . writeFile ( cacheFilename , content )
1124
- return content
1138
+ try {
1139
+ const buffer = await fetch ( u . toString ( ) ) . then ( resp => {
1140
+ if ( resp . status !== 200 ) {
1141
+ return Promise . reject ( new Error ( resp . statusText ) )
1142
+ }
1143
+ return resp . arrayBuffer ( )
1144
+ } )
1145
+ const content = await Deno . readAll ( new Deno . Buffer ( buffer ) )
1146
+ await Deno . writeFile ( cacheFilename , content )
1147
+ return content
1148
+ } catch ( e ) {
1149
+ err = e
1150
+ }
1151
+ }
1152
+
1153
+ return Promise . reject ( err )
1125
1154
}
1126
1155
1127
1156
/** bundle modules for production. */
0 commit comments