@@ -17,9 +17,9 @@ import { clearCompilation, computeHash, createHtml, formatBytesWithColor, getAle
17
17
/** A module includes the compilation details. */
18
18
export type Module = {
19
19
url : string
20
- hash : string
21
- sourceHash : string
22
20
deps : DependencyDescriptor [ ]
21
+ sourceHash : string
22
+ hash : string
23
23
jsFile : string
24
24
}
25
25
@@ -90,16 +90,19 @@ export class Application implements ServerApplication {
90
90
try {
91
91
const bm = JSON . parse ( await Deno . readTextFile ( buildManifestFile ) )
92
92
shouldRebuild = bm . compiler !== buildChecksum
93
- if ( shouldRebuild ) {
94
- log . debug ( 'rebuild...' )
95
- }
96
93
} catch ( e ) { }
97
94
}
95
+ if ( shouldRebuild ) {
96
+ log . debug ( 'rebuild...' )
97
+ ensureTextFile ( buildManifestFile , JSON . stringify ( {
98
+ aleph : VERSION ,
99
+ compiler : buildChecksum ,
100
+ deno : Deno . version . deno ,
101
+ } , undefined , 2 ) )
102
+ }
98
103
104
+ this . #reloading = reload
99
105
if ( reload || shouldRebuild ) {
100
- if ( reload && ! shouldRebuild ) {
101
- this . #reloading = true
102
- }
103
106
if ( existsDirSync ( this . buildDir ) ) {
104
107
await Deno . remove ( this . buildDir , { recursive : true } )
105
108
}
@@ -201,12 +204,6 @@ export class Application implements ServerApplication {
201
204
this . #reloading = false
202
205
}
203
206
204
- ensureTextFile ( buildManifestFile , JSON . stringify ( {
205
- aleph : VERSION ,
206
- compiler : buildChecksum ,
207
- deno : Deno . version . deno ,
208
- } ) )
209
-
210
207
log . debug ( `init project in ${ Math . round ( performance . now ( ) - t ) } ms` )
211
208
212
209
if ( this . isDev ) {
@@ -614,9 +611,9 @@ export class Application implements ServerApplication {
614
611
} else {
615
612
mod = {
616
613
url,
617
- hash : '' ,
618
- sourceHash : '' ,
619
614
deps : [ ] ,
615
+ sourceHash : '' ,
616
+ hash : '' ,
620
617
jsFile : '' ,
621
618
}
622
619
if ( ! once ) {
@@ -650,39 +647,27 @@ export class Application implements ServerApplication {
650
647
mod . sourceHash = sourceHash
651
648
shouldCompile = true
652
649
}
653
- } else if ( isRemote ) {
650
+ } else {
654
651
let shouldFetch = true
655
- if ( mod . sourceHash !== '' && ! url . startsWith ( 'http://localhost:' ) ) {
652
+ if (
653
+ ! this . #reloading &&
654
+ ( isRemote && ! url . startsWith ( 'http://localhost:' ) ) &&
655
+ mod . sourceHash !== ''
656
+ ) {
656
657
const jsFile = util . cleanPath ( saveDir + '/' + name + '.js' )
657
658
if ( existsFileSync ( jsFile ) ) {
658
659
shouldFetch = false
659
660
}
660
661
}
661
662
if ( shouldFetch ) {
662
- const [ content , headers ] = await this . fetchModule ( url )
663
+ const { content, contentType : ctype } = await this . fetchModule ( url )
663
664
const sourceHash = computeHash ( content )
664
665
sourceContent = content
665
- contentType = headers . get ( 'content-type' )
666
- if ( mod . sourceHash === '' || mod . sourceHash !== sourceHash ) {
667
- mod . sourceHash = sourceHash
668
- shouldCompile = true
669
- }
670
- }
671
- } else {
672
- const filepath = path . join ( this . srcDir , url )
673
- try {
674
- sourceContent = await Deno . readFile ( filepath )
675
- const sourceHash = computeHash ( sourceContent )
666
+ contentType = ctype
676
667
if ( mod . sourceHash === '' || mod . sourceHash !== sourceHash ) {
677
668
mod . sourceHash = sourceHash
678
669
shouldCompile = true
679
670
}
680
- } catch ( err ) {
681
- if ( err instanceof Deno . errors . NotFound ) {
682
- log . error ( `local module '${ url } ' not found` )
683
- return mod
684
- }
685
- throw err
686
671
}
687
672
}
688
673
@@ -826,7 +811,7 @@ export class Application implements ServerApplication {
826
811
url,
827
812
sourceHash : mod . sourceHash ,
828
813
deps : mod . deps ,
829
- } , undefined , 4 ) ) ,
814
+ } , undefined , 2 ) ) ,
830
815
] )
831
816
}
832
817
@@ -952,8 +937,14 @@ export class Application implements ServerApplication {
952
937
}
953
938
}
954
939
955
- /** fetch remote module content */
956
- async fetchModule ( url : string ) : Promise < [ Uint8Array , Headers ] > {
940
+ /** fetch module content */
941
+ async fetchModule ( url : string ) : Promise < { content : Uint8Array , contentType : string | null } > {
942
+ if ( ! util . isLikelyHttpURL ( url ) ) {
943
+ const filepath = path . join ( this . srcDir , util . trimPrefix ( url , 'file://' ) )
944
+ const content = await Deno . readFile ( filepath )
945
+ return { content, contentType : null }
946
+ }
947
+
957
948
const u = new URL ( url )
958
949
if ( url . startsWith ( 'https://esm.sh/' ) ) {
959
950
if ( this . isDev && ! u . searchParams . has ( 'dev' ) ) {
@@ -983,10 +974,10 @@ export class Application implements ServerApplication {
983
974
] )
984
975
try {
985
976
const { headers } = JSON . parse ( meta )
986
- return [
977
+ return {
987
978
content,
988
- new Headers ( headers )
989
- ]
979
+ contentType : headers [ 'content-type' ] || null
980
+ }
990
981
} catch ( e ) { }
991
982
}
992
983
@@ -1017,9 +1008,12 @@ export class Application implements ServerApplication {
1017
1008
return m
1018
1009
} , { } as Record < string , string > ) ,
1019
1010
url
1020
- } , undefined , 4 ) )
1011
+ } , undefined , 2 ) )
1012
+ }
1013
+ return {
1014
+ content,
1015
+ contentType : resp . headers . get ( 'content-type' )
1021
1016
}
1022
- return [ content , resp . headers ]
1023
1017
} catch ( e ) {
1024
1018
err = e
1025
1019
}
0 commit comments