@@ -274,11 +274,12 @@ export class Application implements ServerApplication {
274274 log . info ( type , url )
275275 this . compile ( url , { forceCompile : true } ) . then ( mod => {
276276 const hmrable = this . isHMRable ( mod . url )
277- const update = ( { url } : Module ) => {
277+ const applyEffect = ( url : string ) => {
278278 if ( trimModuleExt ( url ) === '/app' ) {
279279 this . #renderer. clearCache ( )
280280 } else if ( url . startsWith ( '/pages/' ) ) {
281- this . #renderer. clearCache ( toPagePath ( url ) )
281+ const [ pagePath ] = this . createRouteUpdate ( url )
282+ this . #renderer. clearCache ( pagePath )
282283 this . #pageRouting. update ( ...this . createRouteUpdate ( url ) )
283284 } else if ( url . startsWith ( '/api/' ) ) {
284285 this . #apiRouting. update ( ...this . createRouteUpdate ( url ) )
@@ -287,12 +288,12 @@ export class Application implements ServerApplication {
287288 if ( hmrable ) {
288289 let pagePath : string | undefined = undefined
289290 let useDeno : boolean | undefined = undefined
290- let isIndexModule : boolean | undefined = undefined
291+ let isIndex : boolean | undefined = undefined
291292 if ( mod . url . startsWith ( '/pages/' ) ) {
292293 const [ path , _ , options ] = this . createRouteUpdate ( mod . url )
293294 pagePath = path
294295 useDeno = options . useDeno
295- isIndexModule = options . isIndexModule
296+ isIndex = options . isIndex
296297 } else {
297298 if ( [ '/app' , '/404' ] . includes ( trimModuleExt ( mod . url ) ) ) {
298299 this . lookupDeps ( mod . url , dep => {
@@ -305,17 +306,17 @@ export class Application implements ServerApplication {
305306 }
306307 if ( type === 'add' ) {
307308 this . #fsWatchListeners. forEach ( e => {
308- e . emit ( 'add' , { url : mod . url , pagePath, isIndexModule , useDeno } )
309+ e . emit ( 'add' , { url : mod . url , pagePath, isIndex , useDeno } )
309310 } )
310311 } else {
311312 this . #fsWatchListeners. forEach ( e => {
312313 e . emit ( 'modify-' + mod . url , { useDeno } )
313314 } )
314315 }
315316 }
316- update ( mod )
317+ applyEffect ( mod . url )
317318 this . applyCompilationSideEffect ( url , ( mod ) => {
318- update ( mod )
319+ applyEffect ( mod . url )
319320 if ( ! hmrable && this . isHMRable ( mod . url ) ) {
320321 this . #fsWatchListeners. forEach ( w => w . emit ( 'modify-' + mod . url ) )
321322 }
@@ -596,7 +597,7 @@ export class Application implements ServerApplication {
596597 }
597598
598599 /** get ssr html scripts */
599- getSSRHTMLScripts ( pagePath ?: string ) {
600+ getSSRHTMLScripts ( entryFile ?: string ) {
600601 const { framework } = this . config
601602 const baseUrl = util . trimSuffix ( this . config . baseUrl , '/' )
602603 const alephPkgPath = getAlephPkgUri ( ) . replace ( 'https://' , '' ) . replace ( 'http://localhost:' , 'http_localhost_' )
@@ -623,8 +624,8 @@ export class Application implements ServerApplication {
623624 }
624625 } )
625626
626- if ( pagePath ) {
627- preload . push ( `${ baseUrl } /_aleph/pages/ ${ pagePath . replace ( / \/ $ / , '/index' ) } .js ` )
627+ if ( entryFile ) {
628+ preload . push ( `${ baseUrl } /_aleph${ entryFile } ` )
628629 }
629630
630631 return [
@@ -636,7 +637,7 @@ export class Application implements ServerApplication {
636637
637638 return [
638639 bundlerRuntimeCode ,
639- ...[ 'polyfill' , 'deps' , 'shared' , 'main' , pagePath ? '/pages' + pagePath . replace ( / \/ $ / , '/index ' ) : '' ]
640+ ...[ 'polyfill' , 'deps' , 'shared' , 'main' , entryFile ? util . trimSuffix ( entryFile , '.js ' ) : '' ]
640641 . filter ( name => name !== "" && this . #bundler. getBundledFile ( name ) !== null )
641642 . map ( name => ( {
642643 src : `${ baseUrl } /_aleph/${ this . #bundler. getBundledFile ( name ) } `
@@ -717,10 +718,12 @@ export class Application implements ServerApplication {
717718 return dir
718719 }
719720
720- private createRouteUpdate ( url : string ) : [ string , string , { isIndexModule ?: boolean , useDeno ?: boolean } ] {
721- let pathPath = toPagePath ( url )
721+ private createRouteUpdate ( url : string ) : [ string , string , { isIndex ?: boolean , useDeno ?: boolean } ] {
722+ const isBuiltinModule = moduleExts . some ( ext => url . endsWith ( '.' + ext ) )
723+ let pagePath = isBuiltinModule ? toPagePath ( url ) : util . trimSuffix ( url , '/pages' )
722724 let useDeno : boolean | undefined = undefined
723- let isIndexModule : boolean | undefined = undefined
725+ let isIndex : boolean | undefined = undefined
726+
724727 if ( this . config . ssr !== false ) {
725728 this . lookupDeps ( url , dep => {
726729 if ( dep . url . startsWith ( '#useDeno-' ) ) {
@@ -729,15 +732,31 @@ export class Application implements ServerApplication {
729732 }
730733 } )
731734 }
732- if ( pathPath !== '/' ) {
735+
736+ if ( ! isBuiltinModule ) {
737+ for ( const plugin of this . config . plugins ) {
738+ if ( plugin . type === 'loader' && plugin . test . test ( url ) && plugin . pagePathResolve ) {
739+ const { path, isIndex : _isIndex } = plugin . pagePathResolve ( url )
740+ if ( ! util . isNEString ( path ) ) {
741+ throw new Error ( `bad pagePathResolve result of '${ plugin . name } ' plugin` )
742+ }
743+ pagePath = path
744+ if ( ! ! _isIndex ) {
745+ isIndex = true
746+ }
747+ break
748+ }
749+ }
750+ } else if ( pagePath !== '/' ) {
733751 for ( const ext of moduleExts ) {
734752 if ( url . endsWith ( '/index.' + ext ) ) {
735- isIndexModule = true
753+ isIndex = true
736754 break
737755 }
738756 }
739757 }
740- return [ pathPath , url , { isIndexModule, useDeno } ]
758+
759+ return [ pagePath , url , { isIndex, useDeno } ]
741760 }
742761
743762 /** apply loaders recurively. */
@@ -766,6 +785,7 @@ export class Application implements ServerApplication {
766785 }
767786 }
768787 }
788+
769789 return { code, map }
770790 }
771791
@@ -1149,11 +1169,11 @@ export class Application implements ServerApplication {
11491169 { url, hash }
11501170 )
11511171 await Deno . writeTextFile ( mod . jsFile , jsContent )
1172+ dep . hash = hash
11521173 mod . hash = computeHash ( mod . sourceHash + mod . deps . map ( ( { hash } ) => hash ) . join ( '' ) )
11531174 callback ( mod )
11541175 log . debug ( 'compilation side-effect:' , mod . url , dim ( '<-' ) , url )
11551176 this . applyCompilationSideEffect ( mod . url , callback )
1156- break
11571177 }
11581178 }
11591179 }
0 commit comments