@@ -733,7 +733,7 @@ export class Aleph implements IAleph {
733
733
734
734
/** parse the export names of the module. */
735
735
async parseModuleExportNames ( specifier : string ) : Promise < string [ ] > {
736
- const { content, contentType } = await this . fetchModule ( specifier )
736
+ const { content, contentType } = await this . fetchModuleSource ( specifier )
737
737
const sourceType = getSourceType ( specifier , contentType || undefined )
738
738
if ( sourceType === SourceType . Unknown || sourceType === SourceType . CSS ) {
739
739
return [ ]
@@ -873,34 +873,6 @@ export class Aleph implements IAleph {
873
873
return [ routePath , specifier , isIndex ]
874
874
}
875
875
876
- /** fetch module content by the specifier. */
877
- async fetchModule ( specifier : string ) : Promise < { content : Uint8Array , contentType : string | null } > {
878
- if ( ! util . isLikelyHttpURL ( specifier ) ) {
879
- const filepath = join ( this . workingDir , this . config . srcDir , util . trimPrefix ( specifier , 'file://' ) )
880
- if ( await existsFile ( filepath ) ) {
881
- const content = await Deno . readFile ( filepath )
882
- return { content, contentType : getContentType ( filepath ) }
883
- } else {
884
- return Promise . reject ( new Error ( `No such file: ${ util . trimPrefix ( filepath , this . workingDir + '/' ) } ` ) )
885
- }
886
- }
887
-
888
- // append `dev` query for development mode
889
- if ( this . isDev && specifier . startsWith ( 'https://esm.sh/' ) ) {
890
- const u = new URL ( specifier )
891
- if ( ! u . searchParams . has ( 'dev' ) ) {
892
- u . searchParams . set ( 'dev' , '' )
893
- u . search = u . search . replace ( 'dev=' , 'dev' )
894
- specifier = u . toString ( )
895
- }
896
- }
897
-
898
- return await cache ( specifier , {
899
- forceRefresh : this . #reloading,
900
- retryTimes : 10
901
- } )
902
- }
903
-
904
876
async importModule < T = any > ( { jsFile, hash, sourceHash } : Module ) : Promise < T > {
905
877
return await import ( `file://${ join ( this . buildDir , jsFile ) } #${ ( hash || sourceHash ) . slice ( 0 , 6 ) } ` )
906
878
}
@@ -952,7 +924,35 @@ export class Aleph implements IAleph {
952
924
] . join ( '\n' ) )
953
925
}
954
926
955
- async loadModuleSource ( specifier : string , data ?: any ) : Promise < ModuleSource > {
927
+ /** fetch module source by the specifier. */
928
+ async fetchModuleSource ( specifier : string ) : Promise < { content : Uint8Array , contentType : string | null } > {
929
+ if ( ! util . isLikelyHttpURL ( specifier ) ) {
930
+ const filepath = join ( this . workingDir , this . config . srcDir , util . trimPrefix ( specifier , 'file://' ) )
931
+ if ( await existsFile ( filepath ) ) {
932
+ const content = await Deno . readFile ( filepath )
933
+ return { content, contentType : getContentType ( filepath ) }
934
+ } else {
935
+ return Promise . reject ( new Error ( `No such file: ${ util . trimPrefix ( filepath , this . workingDir + '/' ) } ` ) )
936
+ }
937
+ }
938
+
939
+ // append `dev` query for development mode
940
+ if ( this . isDev && specifier . startsWith ( 'https://esm.sh/' ) ) {
941
+ const u = new URL ( specifier )
942
+ if ( ! u . searchParams . has ( 'dev' ) ) {
943
+ u . searchParams . set ( 'dev' , '' )
944
+ u . search = u . search . replace ( 'dev=' , 'dev' )
945
+ specifier = u . toString ( )
946
+ }
947
+ }
948
+
949
+ return await cache ( specifier , {
950
+ forceRefresh : this . #reloading,
951
+ retryTimes : 10
952
+ } )
953
+ }
954
+
955
+ async resolveModuleSource ( specifier : string , data ?: any ) : Promise < ModuleSource > {
956
956
let sourceCode : string = ''
957
957
let sourceType : SourceType = SourceType . Unknown
958
958
let sourceMap : string | null = null
@@ -981,7 +981,7 @@ export class Aleph implements IAleph {
981
981
sourceCode = code
982
982
sourceMap = map || null
983
983
} else {
984
- const source = await this . fetchModule ( specifier )
984
+ const source = await this . fetchModuleSource ( specifier )
985
985
sourceType = getSourceType ( specifier , source . contentType || undefined )
986
986
if ( sourceType !== SourceType . Unknown ) {
987
987
sourceCode = ( new TextDecoder ) . decode ( source . content )
@@ -1104,7 +1104,7 @@ export class Aleph implements IAleph {
1104
1104
)
1105
1105
if ( shouldLoad ) {
1106
1106
try {
1107
- const src = customSource || await this . loadModuleSource ( specifier , data )
1107
+ const src = customSource || await this . resolveModuleSource ( specifier , data )
1108
1108
const sourceHash = computeHash ( src . code )
1109
1109
if ( mod . sourceHash === '' || mod . sourceHash !== sourceHash ) {
1110
1110
mod . sourceHash = sourceHash
0 commit comments