@@ -11,7 +11,7 @@ import type { Config, DependencyDescriptor, ImportMap, Module, RenderResult, Rou
11
11
import { VERSION } from '../version.ts'
12
12
import { Request } from './api.ts'
13
13
import { defaultConfig , loadConfig } from './config.ts'
14
- import { AlephRuntimeCode , cleanupCompilation , computeHash , createHtml , formatBytesWithColor , getAlephPkgUrl , getRelativePath , reFullVersion , reHashJs , reHashResolve , respondErrorJSON } from './util.ts'
14
+ import { AlephRuntimeCode , cleanupCompilation , computeHash , createHtml , formatBytesWithColor , getAlephModuleUrl , getRelativePath , reFullVersion , reHashJs , reHashResolve , respondErrorJSON } from './util.ts'
15
15
16
16
/**
17
17
* The Aleph Server Application class.
@@ -349,7 +349,7 @@ export class Application {
349
349
/** initialize project */
350
350
private async init ( reload : boolean ) {
351
351
const t = performance . now ( )
352
- const alephPkgUrl = getAlephPkgUrl ( )
352
+ const alephModuleUrl = getAlephModuleUrl ( )
353
353
const { env, framework, plugins, ssr } = this . config
354
354
const walkOptions = { includeDirs : false , exts : moduleExts , skip : [ / ^ \. / , / \. d \. t s $ / i, / \. ( t e s t | s p e c | e 2 e ) \. m ? ( j | t ) s x ? $ / i] }
355
355
const apiDir = path . join ( this . srcDir , 'api' )
@@ -437,20 +437,20 @@ export class Application {
437
437
}
438
438
439
439
// pre-compile framework modules
440
- await this . compile ( `${ alephPkgUrl } /framework/${ framework } /bootstrap.ts` )
440
+ await this . compile ( `${ alephModuleUrl } /framework/${ framework } /bootstrap.ts` )
441
441
if ( this . isDev ) {
442
442
const mods = [ 'hmr.ts' , 'nomodule.ts' ]
443
443
for ( const mod of mods ) {
444
- await this . compile ( `${ alephPkgUrl } /framework/core/${ mod } ` )
444
+ await this . compile ( `${ alephModuleUrl } /framework/core/${ mod } ` )
445
445
}
446
446
if ( framework === 'react' ) {
447
- await this . compile ( `${ alephPkgUrl } /framework/react/refresh.ts` )
447
+ await this . compile ( `${ alephModuleUrl } /framework/react/refresh.ts` )
448
448
}
449
449
}
450
450
451
451
// compile and import framework renderer when ssr is enable
452
452
if ( ssr ) {
453
- const rendererUrl = `${ alephPkgUrl } /framework/${ framework } /renderer.ts`
453
+ const rendererUrl = `${ alephModuleUrl } /framework/${ framework } /renderer.ts`
454
454
await this . compile ( rendererUrl )
455
455
const { render } = await import ( 'file://' + this . #modules. get ( rendererUrl ) ! . jsFile )
456
456
this . #renderer = { render }
@@ -579,7 +579,7 @@ export class Application {
579
579
580
580
/** get main js. */
581
581
getMainJS ( bundleMode = false ) : string {
582
- const alephPkgUrl = getAlephPkgUrl ( )
582
+ const alephModuleUrl = getAlephModuleUrl ( )
583
583
const { baseUrl, defaultLocale, framework } = this . config
584
584
const config : Record < string , any > = {
585
585
baseUrl,
@@ -600,10 +600,10 @@ export class Application {
600
600
}
601
601
602
602
if ( bundleMode ) {
603
- return `var bootstrap=__ALEPH.pack["${ alephPkgUrl } /framework/${ framework } /bootstrap.ts"].default;bootstrap(${ JSON . stringify ( config ) } )`
603
+ return `var bootstrap=__ALEPH.pack["${ alephModuleUrl } /framework/${ framework } /bootstrap.ts"].default;bootstrap(${ JSON . stringify ( config ) } )`
604
604
}
605
605
606
- const prefix = alephPkgUrl . replace ( 'https://' , '' ) . replace ( 'http://localhost:' , 'http_localhost_' )
606
+ const prefix = alephModuleUrl . replace ( 'https://' , '' ) . replace ( 'http://localhost:' , 'http_localhost_' )
607
607
return [
608
608
( this . config . framework === 'react' && this . isDev ) && `import "./-/${ prefix } /framework/react/refresh.js"` ,
609
609
`import bootstrap from "./-/${ prefix } /framework/${ framework } /bootstrap.js"` ,
@@ -711,7 +711,13 @@ export class Application {
711
711
log . debug ( `init compiler wasm in ${ Math . round ( performance . now ( ) - t ) } ms` )
712
712
}
713
713
714
- return transpileSync ( sourceCode , options )
714
+ return transpileSync ( sourceCode , {
715
+ ...options ,
716
+ importMap : this . importMap ,
717
+ alephModuleUrl : getAlephModuleUrl ( ) ,
718
+ reactVersion : this . config . reactVersion ,
719
+ isDev : this . isDev ,
720
+ } )
715
721
}
716
722
717
723
/** download and compile a moudle by given url, then cache on the disk. */
@@ -724,7 +730,7 @@ export class Application {
724
730
bundledModules ?: string [ ]
725
731
}
726
732
) : Promise < Module > {
727
- const alephPkgUrl = getAlephPkgUrl ( )
733
+ const alephModuleUrl = getAlephModuleUrl ( )
728
734
const isRemote = util . isLikelyHttpURL ( url )
729
735
const localUrl = this . fixImportUrl ( url )
730
736
const name = util . trimModuleExt ( path . basename ( localUrl ) )
@@ -856,7 +862,7 @@ export class Application {
856
862
if ( loader === 'css' ) {
857
863
const css = await this . preprocessCSS ( sourceCode )
858
864
sourceCode = [
859
- `import { applyCSS } from "${ alephPkgUrl } /framework/core/style.ts";` ,
865
+ `import { applyCSS } from "${ alephModuleUrl } /framework/core/style.ts";` ,
860
866
`export default function __applyCSS() {` ,
861
867
` applyCSS(${ JSON . stringify ( url ) } , ${ JSON . stringify ( css ) } );` ,
862
868
`}` ,
@@ -879,14 +885,12 @@ export class Application {
879
885
sourceType : loader ,
880
886
sourceMap : this . isDev ,
881
887
}
888
+ log . debug ( url )
882
889
const { code, map, deps, inlineStyles } = await this . transpile ( sourceCode , {
883
890
url,
884
891
bundleMode,
885
892
bundledModules,
886
- swcOptions,
887
- importMap : this . importMap ,
888
- reactVersion : this . config . reactVersion ,
889
- isDev : this . isDev ,
893
+ swcOptions
890
894
} )
891
895
892
896
fsync = true
@@ -1122,7 +1126,7 @@ export class Application {
1122
1126
1123
1127
/** bundle modules for production. */
1124
1128
private async bundle ( ) {
1125
- const alephPkgUrl = getAlephPkgUrl ( )
1129
+ const alephModuleUrl = getAlephModuleUrl ( )
1126
1130
const refCounter = new Map < string , number > ( )
1127
1131
const lookup = ( url : string ) => {
1128
1132
if ( this . #modules. has ( url ) ) {
@@ -1142,7 +1146,7 @@ export class Application {
1142
1146
const pageModules : Module [ ] = [ ]
1143
1147
1144
1148
// add framework bootstrap
1145
- refCounter . set ( `${ alephPkgUrl } /framework/${ this . config . framework } /bootstrap.ts` , 1 )
1149
+ refCounter . set ( `${ alephModuleUrl } /framework/${ this . config . framework } /bootstrap.ts` , 1 )
1146
1150
if ( appModule ) {
1147
1151
await this . compile ( appModule . url , { bundleMode : true } )
1148
1152
lookup ( appModule . url )
@@ -1196,14 +1200,14 @@ export class Application {
1196
1200
1197
1201
/** create polyfill bundle. */
1198
1202
private async createPolyfillBundle ( ) {
1199
- const alephPkgUrl = getAlephPkgUrl ( )
1203
+ const alephModuleUrl = getAlephModuleUrl ( )
1200
1204
const { buildTarget } = this . config
1201
1205
const hash = computeHash ( AlephRuntimeCode + buildTarget + buildChecksum + Deno . version . deno )
1202
1206
const polyfillFile = path . join ( this . buildDir , `polyfill.bundle.${ util . shortHash ( hash ) } .js` )
1203
1207
const polyfillMod = this . newModule ( '/polyfill.js' )
1204
1208
polyfillMod . hash = polyfillMod . sourceHash = hash
1205
1209
if ( ! existsFileSync ( polyfillFile ) ) {
1206
- const rawPolyfillFile = `${ alephPkgUrl } /compiler/polyfills/${ buildTarget } /polyfill.js`
1210
+ const rawPolyfillFile = `${ alephModuleUrl } /compiler/polyfills/${ buildTarget } /polyfill.js`
1207
1211
await this . runDenoBundle ( rawPolyfillFile , polyfillFile , AlephRuntimeCode , true )
1208
1212
}
1209
1213
log . info ( ` {} polyfill (${ buildTarget . toUpperCase ( ) } ) ${ colors . dim ( '• ' + util . formatBytes ( Deno . statSync ( polyfillFile ) . size ) ) } ` )
0 commit comments