@@ -8,6 +8,7 @@ import { compile } from './tsc/compile.ts'
88import type { APIHandle , Config , Location , RouterURL } from './types.ts'
99import util , { hashShort } from './util.ts'
1010import './vendor/clean-css-builds/v4.2.2.js'
11+ import { Document } from './vendor/deno-dom/document.ts'
1112import less from './vendor/less/less.js'
1213
1314const reHttp = / ^ h t t p s ? : \/ \/ / i
@@ -162,8 +163,12 @@ export default class Project {
162163 if ( path ) {
163164 const importPath = '.' + path + '.js'
164165 if ( this . #modules. has ( importPath ) ) {
165- const { default : handle } = await import ( "file://" + this . #modules. get ( importPath ) ! . jsFile )
166- return handle
166+ try {
167+ const { default : handle } = await import ( "file://" + this . #modules. get ( importPath ) ! . jsFile )
168+ return handle
169+ } catch ( error ) {
170+ log . error ( error )
171+ }
167172 }
168173 }
169174 return null
@@ -215,15 +220,19 @@ export default class Project {
215220 async getData ( ) {
216221 const mod = this . #modules. get ( './data.js' ) || this . #modules. get ( './data/index.js' )
217222 if ( mod ) {
218- const { default : Data } = await import ( "file://" + mod . jsFile )
219- let data : any = Data
220- if ( util . isFunction ( Data ) ) {
221- data = await Data ( )
222- }
223- if ( util . isPlainObject ( data ) ) {
224- return data
225- } else {
226- log . warn ( `module '${ mod . url } ' should return a plain object as default` )
223+ try {
224+ const { default : Data } = await import ( "file://" + mod . jsFile )
225+ let data : any = Data
226+ if ( util . isFunction ( Data ) ) {
227+ data = await Data ( )
228+ }
229+ if ( util . isPlainObject ( data ) ) {
230+ return data
231+ } else {
232+ log . warn ( `module '${ mod . url } ' should return a plain object as default` )
233+ }
234+ } catch ( error ) {
235+ log . error ( error )
227236 }
228237 }
229238 return { }
@@ -388,6 +397,9 @@ export default class Project {
388397 ALEPH_ENV : {
389398 appDir : this . rootDir ,
390399 } ,
400+ document : new Document ( ) ,
401+ innerWidth : 1920 ,
402+ innerHeight : 1080 ,
391403 $RefreshReg$ : ( ) => { } ,
392404 $RefreshSig$ : ( ) => ( type : any ) => type ,
393405 } )
@@ -433,7 +445,7 @@ export default class Project {
433445 }
434446
435447 const preCompileUrls = [
436- 'https://deno.land/x/aleph/app .ts' ,
448+ 'https://deno.land/x/aleph/bootstrap .ts' ,
437449 'https://deno.land/x/aleph/renderer.ts' ,
438450 'https://deno.land/x/aleph/vendor/tslib/tslib.js' ,
439451 ]
@@ -646,7 +658,7 @@ export default class Project {
646658 module . jsContent = [
647659 this . isDev && 'import "./-/deno.land/x/aleph/hmr.js";' ,
648660 'import "./-/deno.land/x/aleph/vendor/tslib/tslib.js";' ,
649- 'import { bootstrap } from "./-/deno.land/x/aleph/app .js";' ,
661+ 'import bootstrap from "./-/deno.land/x/aleph/bootstrap .js";' ,
650662 `bootstrap(${ JSON . stringify ( config , undefined , this . isDev ? 4 : undefined ) } );`
651663 ] . filter ( Boolean ) . join ( this . isDev ? '\n' : '' )
652664 module . hash = ( new Sha1 ( ) ) . update ( module . jsContent ) . hex ( )
@@ -1036,18 +1048,28 @@ export default class Project {
10361048 const cache = page . rendered . get ( url . pathname ) !
10371049 return { ...cache }
10381050 }
1051+ Object . assign ( window , {
1052+ location : {
1053+ protocol : 'http:' ,
1054+ host : 'localhost' ,
1055+ hostname : 'localhost' ,
1056+ port : '' ,
1057+ href : 'http://localhost' + url . pathname ,
1058+ origin : 'http://localhost' ,
1059+ pathname : url . pathname ,
1060+ search : '' ,
1061+ hash : '' ,
1062+ reload ( ) { } ,
1063+ replace ( ) { } ,
1064+ toString ( ) { return this . href } ,
1065+ }
1066+ } )
10391067 try {
10401068 const appModule = this . #modules. get ( './app.js' )
10411069 const pageModule = this . #modules. get ( page . moduleId ) !
1042- const [
1043- { renderPage, renderHead } ,
1044- { default : App } ,
1045- { default : Page }
1046- ] = await Promise . all ( [
1047- import ( "file://" + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile ) ,
1048- appModule ? await import ( "file://" + appModule . jsFile ) : Promise . resolve ( { } ) ,
1049- await import ( "file://" + pageModule . jsFile )
1050- ] )
1070+ const { renderPage, renderHead } = await import ( "file://" + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
1071+ const { default : App } = appModule ? await import ( "file://" + appModule . jsFile ) : { } as any
1072+ const { default : Page } = await import ( "file://" + pageModule . jsFile )
10511073 const data = await this . getData ( )
10521074 const html = renderPage ( data , url , appModule ? App : undefined , Page )
10531075 const head = renderHead ( [
0 commit comments