@@ -515,7 +515,7 @@ export class Aleph implements IAleph {
515
515
async addModule ( specifier : string , sourceCode : string , forceRefresh ?: boolean ) : Promise < Module > {
516
516
let sourceType = getSourceType ( specifier )
517
517
if ( sourceType === SourceType . Unknown ) {
518
- throw new Error ( "addModule: unknown souce type" )
518
+ throw new Error ( "addModule: unknown source type" )
519
519
}
520
520
const source = {
521
521
code : sourceCode ,
@@ -937,9 +937,9 @@ export class Aleph implements IAleph {
937
937
async getModuleJS ( module : Module , injectHMRCode = false ) : Promise < Uint8Array | null > {
938
938
const { specifier, jsFile, jsBuffer } = module
939
939
if ( ! jsBuffer ) {
940
- const cacheFp = join ( this . #buildDir, jsFile )
941
- if ( await existsFile ( cacheFp ) ) {
942
- module . jsBuffer = await Deno . readFile ( cacheFp )
940
+ const cacheFile = join ( this . #buildDir, jsFile )
941
+ if ( await existsFile ( cacheFile ) ) {
942
+ module . jsBuffer = await Deno . readFile ( cacheFile )
943
943
log . debug ( `load '${ jsFile } '` + dim ( ' • ' + util . formatBytes ( module . jsBuffer . length ) ) )
944
944
}
945
945
}
@@ -1119,10 +1119,9 @@ export class Aleph implements IAleph {
1119
1119
1120
1120
const isRemote = util . isLikelyHttpURL ( specifier ) && ! isLocalUrl ( specifier )
1121
1121
const localPath = toLocalPath ( specifier )
1122
- const name = trimBuiltinModuleExts ( basename ( localPath ) )
1123
- const jsFile = join ( dirname ( localPath ) , `${ name } .js` )
1124
- const cacheFp = join ( this . #buildDir, jsFile )
1125
- const metaFp = cacheFp . slice ( 0 , - 3 ) + '.meta.json'
1122
+ const jsFile = trimBuiltinModuleExts ( localPath ) + '.js'
1123
+ const cacheFile = join ( this . #buildDir, jsFile )
1124
+ const metaFile = cacheFile . slice ( 0 , - 3 ) + '.meta.json'
1126
1125
const isNew = ! mod
1127
1126
1128
1127
let defer = ( err ?: Error ) => { }
@@ -1152,14 +1151,14 @@ export class Aleph implements IAleph {
1152
1151
this . #appModule = mod
1153
1152
}
1154
1153
1155
- if ( ! forceRefresh && await existsFile ( metaFp ) ) {
1154
+ if ( ! forceRefresh && await existsFile ( metaFile ) ) {
1156
1155
try {
1157
- const meta = JSON . parse ( await Deno . readTextFile ( metaFp ) )
1156
+ const meta = JSON . parse ( await Deno . readTextFile ( metaFile ) )
1158
1157
if ( meta . specifier === specifier && util . isFilledString ( meta . sourceHash ) && util . isArray ( meta . deps ) ) {
1159
1158
Object . assign ( mod , meta )
1160
1159
} else {
1161
- log . warn ( `removing invalid metadata '${ name } .meta.json '` )
1162
- Deno . remove ( metaFp )
1160
+ log . warn ( `removing invalid metadata of '${ basename ( specifier ) } '` )
1161
+ Deno . remove ( metaFile )
1163
1162
}
1164
1163
} catch ( e ) { }
1165
1164
}
@@ -1169,7 +1168,7 @@ export class Aleph implements IAleph {
1169
1168
return [ mod , null ]
1170
1169
}
1171
1170
1172
- if ( ! isRemote || this . #reloading || mod . sourceHash === '' || ! await existsFile ( cacheFp ) ) {
1171
+ if ( ! isRemote || this . #reloading || mod . sourceHash === '' || ! await existsFile ( cacheFile ) ) {
1173
1172
try {
1174
1173
const src = customSource || await this . resolveModuleSource ( specifier , data )
1175
1174
const sourceHash = computeHash ( src . code )
@@ -1429,14 +1428,14 @@ export class Aleph implements IAleph {
1429
1428
private async cacheModule ( module : Module , sourceMap ?: string ) {
1430
1429
const { jsBuffer, jsFile, ready, ...rest } = module
1431
1430
if ( jsBuffer ) {
1432
- const cacheFp = join ( this . #buildDir, jsFile )
1433
- const metaFp = cacheFp . slice ( 0 , - 3 ) + '.meta.json'
1434
- await ensureDir ( dirname ( cacheFp ) )
1431
+ const cacheFile = join ( this . #buildDir, jsFile )
1432
+ const metaFile = cacheFile . slice ( 0 , - 3 ) + '.meta.json'
1433
+ await ensureDir ( dirname ( cacheFile ) )
1435
1434
await Promise . all ( [
1436
- Deno . writeFile ( cacheFp , jsBuffer ) ,
1437
- Deno . writeTextFile ( metaFp , JSON . stringify ( { ...rest } , undefined , 2 ) ) ,
1438
- sourceMap ? Deno . writeTextFile ( `${ cacheFp } .map` , sourceMap ) : Promise . resolve ( ) ,
1439
- lazyRemove ( cacheFp . slice ( 0 , - 3 ) + '.bundling.js' ) ,
1435
+ Deno . writeFile ( cacheFile , jsBuffer ) ,
1436
+ Deno . writeTextFile ( metaFile , JSON . stringify ( { ...rest } , undefined , 2 ) ) ,
1437
+ sourceMap ? Deno . writeTextFile ( `${ cacheFile } .map` , sourceMap ) : Promise . resolve ( ) ,
1438
+ lazyRemove ( cacheFile . slice ( 0 , - 3 ) + '.bundling.js' ) ,
1440
1439
] )
1441
1440
}
1442
1441
}
0 commit comments