1
- import { buildChecksum , ImportMap , SourceType , transform , TransformOptions } from '../compiler/mod.ts'
1
+ import { buildChecksum , ImportMap , parseExportNames , SourceType , transform , TransformOptions } from '../compiler/mod.ts'
2
2
import { colors , createHash , ensureDir , path , walk } from '../deps.ts'
3
3
import { EventEmitter } from '../framework/core/events.ts'
4
4
import { moduleExts , toPagePath , trimModuleExt } from '../framework/core/module.ts'
5
- import { Routing , RouteModule } from '../framework/core/routing.ts'
5
+ import { RouteModule , Routing } from '../framework/core/routing.ts'
6
6
import { defaultReactVersion , minDenoVersion } from '../shared/constants.ts'
7
7
import {
8
8
ensureTextFile ,
@@ -73,12 +73,16 @@ export class Application implements ServerApplication {
73
73
74
74
/** initiate application */
75
75
private async init ( reload : boolean ) {
76
- const t = performance . now ( )
76
+ let t = performance . now ( )
77
+
77
78
const [ config , importMap ] = await Promise . all ( [
78
79
loadConfig ( this . workingDir ) ,
79
80
loadImportMap ( this . workingDir )
80
81
] )
81
82
83
+ log . debug ( `load config in ${ Math . round ( performance . now ( ) - t ) } ms` )
84
+ t = performance . now ( )
85
+
82
86
Object . assign ( this . config , config )
83
87
Object . assign ( this . importMap , importMap )
84
88
this . #pageRouting. config ( this . config )
@@ -538,7 +542,7 @@ export class Application implements ServerApplication {
538
542
}
539
543
540
544
/** get ssr html scripts */
541
- getSSRHTMLScripts ( ) {
545
+ getSSRHTMLScripts ( pagePath ?: string ) {
542
546
const { baseUrl } = this . config
543
547
544
548
if ( this . isDev ) {
@@ -550,8 +554,8 @@ export class Application implements ServerApplication {
550
554
551
555
return [
552
556
bundlerRuntimeCode ,
553
- ...[ 'polyfill' , 'deps' , 'shared' , 'main' ]
554
- . filter ( name => this . #bundler. getBundledFile ( name ) !== null )
557
+ ...[ 'polyfill' , 'deps' , 'shared' , 'main' , pagePath ? '/pages' + pagePath . replace ( / \/ $ / , '/index' ) : '' ]
558
+ . filter ( name => name !== "" && this . #bundler. getBundledFile ( name ) !== null )
555
559
. map ( name => ( {
556
560
src : util . cleanPath ( `${ baseUrl } /_aleph/${ this . #bundler. getBundledFile ( name ) } ` )
557
561
} ) )
@@ -939,12 +943,14 @@ export class Application implements ServerApplication {
939
943
940
944
const t = performance . now ( )
941
945
const [ sourceCode , sourceType ] = source
942
- const { code, map , deps } = await transform ( url , sourceCode , {
946
+ const { code, deps , starExports , map } = await transform ( url , sourceCode , {
943
947
...this . defaultCompileOptions ,
944
948
swcOptions : {
945
949
target : 'es2020' ,
946
950
sourceType
947
951
} ,
952
+ // workaround for https://github.com/denoland/deno/issues/9849
953
+ resolveStarExports : ! this . isDev && Deno . version . deno . replace ( / \. \d + $ / , '' ) === '1.8' ,
948
954
sourceMap : this . isDev ,
949
955
loaders : this . config . plugins . filter ( isLoaderPlugin )
950
956
} )
@@ -955,6 +961,16 @@ export class Application implements ServerApplication {
955
961
jsSourceMap = map
956
962
}
957
963
964
+ // workaround for https://github.com/denoland/deno/issues/9849
965
+ if ( starExports && starExports . length > 0 ) {
966
+ for ( let index = 0 ; index < starExports . length ; index ++ ) {
967
+ const url = starExports [ index ]
968
+ const [ sourceCode , sourceType ] = await this . resolveModule ( url )
969
+ const names = await parseExportNames ( url , sourceCode , { sourceType } )
970
+ jsContent = jsContent . replace ( `export * from "${ url } :` , `export {${ names . filter ( name => name !== 'default' ) . join ( ',' ) } } from "` )
971
+ }
972
+ }
973
+
958
974
mod . deps = deps . map ( ( { specifier, isDynamic } ) => {
959
975
const dep : DependencyDescriptor = { url : specifier , hash : '' }
960
976
if ( isDynamic ) {
0 commit comments