@@ -584,9 +584,13 @@ export default class Project {
584
584
baseUrl,
585
585
defaultLocale,
586
586
locales : [ ] ,
587
- routes : this . #routing. routes
587
+ routes : this . #routing. routes ,
588
+ preloadModules : [ '/404.js' , '/app.js' , '/data.js' ] . filter ( id => this . #modules. has ( id ) ) . map ( id => {
589
+ return this . _getRouteModule ( this . #modules. get ( id ) ! )
590
+ } )
588
591
}
589
592
const module = this . _moduleFromURL ( '/main.js' )
593
+ const metaFile = path . join ( this . buildDir , 'main.meta.json' )
590
594
const deps = [
591
595
this . isDev && 'https://deno.land/x/aleph/hmr.ts' ,
592
596
'https://deno.land/x/aleph/bootstrap.ts'
@@ -595,10 +599,6 @@ export default class Project {
595
599
hash : this . #modules. get ( String ( url ) . replace ( reHttp , '//' ) . replace ( reModuleExt , '.js' ) ) ?. hash || ''
596
600
} ) )
597
601
598
- config . preloadModules = [ '/data.js' , '/app.js' , '/404.js' ] . filter ( id => this . #modules. has ( id ) ) . map ( id => {
599
- return this . _getRouteModule ( this . #modules. get ( id ) ! )
600
- } )
601
-
602
602
module . jsContent = [
603
603
this . isDev && 'import "./-/deno.land/x/aleph/hmr.js";' ,
604
604
'import bootstrap from "./-/deno.land/x/aleph/bootstrap.js";' ,
@@ -608,16 +608,24 @@ export default class Project {
608
608
module . jsFile = path . join ( this . buildDir , `main.${ module . hash . slice ( 0 , hashShort ) } .js` )
609
609
module . deps = deps
610
610
611
- if ( this . #modules. has ( module . id ) ) {
612
- const prevHash = this . #modules. get ( module . id ) ! . hash
613
- try {
611
+ try {
612
+ let prevHash = ''
613
+ if ( this . #modules. has ( module . id ) ) {
614
+ prevHash = this . #modules. get ( module . id ) ! . hash
615
+ } else if ( existsFileSync ( metaFile ) ) {
616
+ const { hash } = JSON . parse ( await Deno . readTextFile ( metaFile ) )
617
+ if ( util . isNEString ( hash ) ) {
618
+ prevHash = hash
619
+ }
620
+ }
621
+ if ( prevHash !== '' ) {
614
622
await Deno . remove ( path . join ( this . buildDir , `main.${ prevHash . slice ( 0 , hashShort ) } .js` ) )
615
- } catch ( e ) { }
616
- }
623
+ }
624
+ } catch ( e ) { }
617
625
618
626
await Promise . all ( [
619
627
writeTextFile ( module . jsFile , module . jsContent ) ,
620
- writeTextFile ( path . join ( this . buildDir , 'main.meta.json' ) , JSON . stringify ( {
628
+ writeTextFile ( metaFile , JSON . stringify ( {
621
629
url : '/main.js' ,
622
630
sourceHash : module . hash ,
623
631
hash : module . hash ,
@@ -1036,6 +1044,7 @@ export default class Project {
1036
1044
} )
1037
1045
try {
1038
1046
const appModule = this . #modules. get ( '/app.js' )
1047
+ const { E501Page } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/error.js' ) ! . jsFile )
1039
1048
const { renderPage, renderHead } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
1040
1049
const { default : App } = appModule ? await import ( 'file://' + appModule . jsFile ) : { } as any
1041
1050
const staticData = await this . getStaticData ( )
@@ -1045,7 +1054,11 @@ export default class Project {
1045
1054
const { default : C } = await import ( 'file://' + mod . jsFile )
1046
1055
const pc = pageComponentTree . find ( pc => pc . id === mod . id )
1047
1056
if ( pc ) {
1048
- pc . Component = C
1057
+ if ( util . isLikelyReactComponent ( C ) ) {
1058
+ pc . Component = C
1059
+ } else {
1060
+ pc . Component = E501Page
1061
+ }
1049
1062
}
1050
1063
} )
1051
1064
await Promise . all ( imports )
@@ -1084,7 +1097,6 @@ export default class Project {
1084
1097
} )
1085
1098
return a
1086
1099
}
1087
-
1088
1100
}
1089
1101
1090
1102
export function injectHmr ( { id, sourceFilePath, jsContent } : Module ) : string {
0 commit comments