1
+ import { delay } from 'https://deno.land/[email protected] /async/delay.ts'
1
2
import { dim } from 'https://deno.land/[email protected] /fmt/colors.ts'
2
3
import { indexOf , copy , equals } from 'https://deno.land/[email protected] /bytes/mod.ts'
3
4
import { ensureDir } from 'https://deno.land/[email protected] /fs/ensure_dir.ts'
@@ -915,8 +916,12 @@ export class Aleph implements IAleph {
915
916
return [ routePath , specifier , isIndex ]
916
917
}
917
918
918
- async importModule < T = any > ( { jsFile, hash, sourceHash } : Module ) : Promise < T > {
919
- return await import ( `file://${ join ( this . #buildDir, jsFile ) } #${ ( hash || sourceHash ) . slice ( 0 , 6 ) } ` )
919
+ async importModule < T = any > ( { specifier, jsFile, hash, sourceHash } : Module ) : Promise < T > {
920
+ const path = join ( this . #buildDir, jsFile )
921
+ if ( existsFile ( path ) ) {
922
+ return await import ( `file://${ path } #${ ( hash || sourceHash ) . slice ( 0 , 6 ) } ` )
923
+ }
924
+ throw new Error ( `import ${ specifier } : file not found: ${ path } ` )
920
925
}
921
926
922
927
async getModuleJS ( module : Module , injectHMRCode = false ) : Promise < Uint8Array | null > {
@@ -1287,23 +1292,7 @@ export class Aleph implements IAleph {
1287
1292
1288
1293
ms . stop ( `transpile '${ specifier } '` )
1289
1294
1290
- const cacheFp = join ( this . #buildDir, jsFile )
1291
- const metaFp = cacheFp . slice ( 0 , - 3 ) + '.meta.json'
1292
- const metaJSON = JSON . stringify ( {
1293
- specifier,
1294
- sourceHash : module . sourceHash ,
1295
- isStyle : module . isStyle ,
1296
- ssrPropsFn : module . ssrPropsFn ,
1297
- ssgPathsFn : module . ssgPathsFn ,
1298
- denoHooks : module . denoHooks ,
1299
- deps : module . deps ,
1300
- } , undefined , 2 )
1301
- await ensureDir ( dirname ( cacheFp ) )
1302
- await Promise . all ( [
1303
- Deno . writeFile ( cacheFp , module . jsBuffer ) ,
1304
- Deno . writeTextFile ( metaFp , metaJSON ) ,
1305
- sourceMap ? Deno . writeTextFile ( `${ cacheFp } .map` , sourceMap ) : Promise . resolve ( ) ,
1306
- ] )
1295
+ await this . cacheModule ( module , sourceMap )
1307
1296
}
1308
1297
1309
1298
if ( module . deps . length > 0 ) {
@@ -1401,7 +1390,7 @@ export class Aleph implements IAleph {
1401
1390
}
1402
1391
}
1403
1392
1404
- private async cacheModule ( module : Module ) {
1393
+ private async cacheModule ( module : Module , sourceMap ?: string ) {
1405
1394
const { specifier, jsBuffer, jsFile } = module
1406
1395
if ( jsBuffer ) {
1407
1396
const cacheFp = join ( this . #buildDir, jsFile )
@@ -1418,6 +1407,7 @@ export class Aleph implements IAleph {
1418
1407
denoHooks : module . denoHooks ,
1419
1408
deps : module . deps ,
1420
1409
} , undefined , 2 ) ) ,
1410
+ sourceMap ? Deno . writeTextFile ( `${ cacheFp } .map` , sourceMap ) : Promise . resolve ( ) ,
1421
1411
lazyRemove ( cacheFp . slice ( 0 , - 3 ) + '.bundling.js' ) ,
1422
1412
] )
1423
1413
}
0 commit comments