@@ -471,6 +471,10 @@ export class Aleph implements IAleph {
471
471
return this . #ready
472
472
}
473
473
474
+ get transformListeners ( ) {
475
+ return this . #transformListeners
476
+ }
477
+
474
478
/** get the module by given specifier. */
475
479
getModule ( specifier : string ) : Module | null {
476
480
if ( specifier === 'app' ) {
@@ -532,21 +536,23 @@ export class Aleph implements IAleph {
532
536
if ( sourceType === SourceType . Unknown ) {
533
537
throw new Error ( "addModule: unknown souce type" )
534
538
}
539
+ const source = {
540
+ code : sourceCode ,
541
+ type : sourceType ,
542
+ }
535
543
const module = await this . compile ( specifier , {
536
- source : {
537
- code : sourceCode ,
538
- type : sourceType ,
539
- } ,
544
+ source,
540
545
forceRefresh,
541
546
} )
542
547
if ( specifier . startsWith ( 'pages/' ) || specifier . startsWith ( 'api/' ) ) {
543
548
specifier = '/' + specifier
544
549
}
545
- if ( specifier . startsWith ( '/pages/' ) ) {
550
+ if ( specifier . startsWith ( '/pages/' ) && this . isPageModule ( specifier ) ) {
546
551
this . #pageRouting. update ( ...this . createRouteUpdate ( specifier ) )
547
552
} else if ( specifier . startsWith ( '/api/' ) && ! specifier . startsWith ( '/api/_middlewares.' ) ) {
548
553
this . #apiRouting. update ( ...this . createRouteUpdate ( specifier ) )
549
554
}
555
+ Object . assign ( module , { source } )
550
556
return module
551
557
}
552
558
@@ -1025,6 +1031,21 @@ export class Aleph implements IAleph {
1025
1031
} )
1026
1032
}
1027
1033
1034
+ resolveImport ( { jsFile, sourceHash } : Module , importer : string , bundleMode ?: boolean , timeStamp ?: boolean ) : string {
1035
+ const relPath = toRelativePath (
1036
+ dirname ( toLocalPath ( importer ) ) ,
1037
+ jsFile
1038
+ )
1039
+ if ( bundleMode ) {
1040
+ return util . trimSuffix ( relPath , '.js' ) + '.bundling.js'
1041
+ }
1042
+ let hash = '#' + sourceHash . slice ( 0 , 8 )
1043
+ if ( timeStamp ) {
1044
+ hash += '-' + Date . now ( )
1045
+ }
1046
+ return relPath + hash
1047
+ }
1048
+
1028
1049
async resolveModuleSource ( specifier : string , data ?: any ) : Promise < ModuleSource > {
1029
1050
let sourceCode : string = ''
1030
1051
let sourceType : SourceType = SourceType . Unknown
@@ -1152,14 +1173,9 @@ export class Aleph implements IAleph {
1152
1173
1153
1174
if ( ! forceRefresh && await existsFile ( metaFp ) ) {
1154
1175
try {
1155
- const { specifier : _specifier , sourceHash, deps, isStyle, ssrPropsFn, ssgPathsFn, denoHooks } = JSON . parse ( await Deno . readTextFile ( metaFp ) )
1156
- if ( _specifier === specifier && util . isFilledString ( sourceHash ) && util . isArray ( deps ) ) {
1157
- mod . sourceHash = sourceHash
1158
- mod . deps = deps
1159
- mod . isStyle = Boolean ( isStyle ) || undefined
1160
- mod . ssrPropsFn = util . isFilledString ( ssrPropsFn ) ? ssrPropsFn : undefined
1161
- mod . ssgPathsFn = Boolean ( ssgPathsFn ) || undefined
1162
- mod . denoHooks = util . isFilledArray ( denoHooks ) ? denoHooks : undefined
1176
+ const meta = JSON . parse ( await Deno . readTextFile ( metaFp ) )
1177
+ if ( meta . specifier === specifier && util . isFilledString ( meta . sourceHash ) && util . isArray ( meta . deps ) ) {
1178
+ Object . assign ( mod , meta )
1163
1179
} else {
1164
1180
log . warn ( `removing invalid metadata '${ name } .meta.json'` )
1165
1181
Deno . remove ( metaFp )
@@ -1413,22 +1429,14 @@ export class Aleph implements IAleph {
1413
1429
}
1414
1430
1415
1431
private async cacheModule ( module : Module , sourceMap ?: string ) {
1416
- const { specifier , jsBuffer, jsFile } = module
1432
+ const { jsBuffer, jsFile, ready , ... rest } = module
1417
1433
if ( jsBuffer ) {
1418
1434
const cacheFp = join ( this . #buildDir, jsFile )
1419
1435
const metaFp = cacheFp . slice ( 0 , - 3 ) + '.meta.json'
1420
1436
await ensureDir ( dirname ( cacheFp ) )
1421
1437
await Promise . all ( [
1422
1438
Deno . writeFile ( cacheFp , jsBuffer ) ,
1423
- Deno . writeTextFile ( metaFp , JSON . stringify ( {
1424
- specifier,
1425
- sourceHash : module . sourceHash ,
1426
- isStyle : module . isStyle ,
1427
- ssrPropsFn : module . ssrPropsFn ,
1428
- ssgPathsFn : module . ssgPathsFn ,
1429
- denoHooks : module . denoHooks ,
1430
- deps : module . deps ,
1431
- } , undefined , 2 ) ) ,
1439
+ Deno . writeTextFile ( metaFp , JSON . stringify ( { ...rest } , undefined , 2 ) ) ,
1432
1440
sourceMap ? Deno . writeTextFile ( `${ cacheFp } .map` , sourceMap ) : Promise . resolve ( ) ,
1433
1441
lazyRemove ( cacheFp . slice ( 0 , - 3 ) + '.bundling.js' ) ,
1434
1442
] )
0 commit comments