@@ -43,7 +43,8 @@ interface RenderResult {
43
43
export class Project {
44
44
readonly mode : 'development' | 'production'
45
45
readonly appRoot : string
46
- readonly config : Config
46
+ readonly config : Readonly < Config >
47
+ readonly importMap : Readonly < { imports : Record < string , string > } >
47
48
readonly ready : Promise < void >
48
49
49
50
#modules: Map < string , Module > = new Map ( )
@@ -67,11 +68,9 @@ export class Project {
67
68
} ,
68
69
buildTarget : mode === 'development' ? 'es2018' : 'es2015' ,
69
70
sourceMap : false ,
70
- importMap : {
71
- imports : { }
72
- } ,
73
71
env : { }
74
72
}
73
+ this . importMap = { imports : { } }
75
74
this . ready = ( async ( ) => {
76
75
const t = performance . now ( )
77
76
await this . _loadConfig ( )
@@ -400,13 +399,13 @@ export class Project {
400
399
const { ALEPH_IMPORT_MAP } = globalThis as any
401
400
if ( ALEPH_IMPORT_MAP ) {
402
401
const { imports } = ALEPH_IMPORT_MAP
403
- Object . assign ( this . config . importMap , { imports : Object . assign ( { } , this . config . importMap . imports , imports ) } )
402
+ Object . assign ( this . importMap , { imports : Object . assign ( { } , this . importMap . imports , imports ) } )
404
403
}
405
404
406
405
const importMapFile = path . join ( this . appRoot , 'import_map.json' )
407
406
if ( existsFileSync ( importMapFile ) ) {
408
407
const { imports } = JSON . parse ( await Deno . readTextFile ( importMapFile ) )
409
- Object . assign ( this . config . importMap , { imports : Object . assign ( { } , this . config . importMap . imports , imports ) } )
408
+ Object . assign ( this . importMap , { imports : Object . assign ( { } , this . importMap . imports , imports ) } )
410
409
}
411
410
412
411
const config : Record < string , any > = { }
@@ -712,8 +711,7 @@ export class Project {
712
711
}
713
712
714
713
private _moduleFromURL ( url : string ) : Module {
715
- const { importMap } = this . config
716
- const isRemote = reHttp . test ( url ) || ( url in importMap . imports && reHttp . test ( importMap . imports [ url ] ) )
714
+ const isRemote = reHttp . test ( url ) || ( url in this . importMap . imports && reHttp . test ( this . importMap . imports [ url ] ) )
717
715
const sourceFilePath = renameImportUrl ( url )
718
716
const id = ( isRemote ? '//' + util . trimPrefix ( sourceFilePath , '/-/' ) : sourceFilePath ) . replace ( reModuleExt , '.js' )
719
717
return {
@@ -797,7 +795,7 @@ export class Project {
797
795
return this . #modules. get ( mod . id ) !
798
796
}
799
797
800
- const { importMap } = this . config
798
+ const { importMap } = this
801
799
const name = path . basename ( mod . sourceFilePath ) . replace ( reModuleExt , '' )
802
800
const saveDir = path . join ( this . buildDir , path . dirname ( mod . sourceFilePath ) )
803
801
const metaFile = path . join ( saveDir , `${ name } .meta.json` )
@@ -1143,10 +1141,9 @@ export class Project {
1143
1141
}
1144
1142
1145
1143
private _rewriteImportPath ( mod : Module , importPath : string , async ?: boolean ) : string {
1146
- const { importMap } = this . config
1147
1144
let rewrittenPath : string
1148
- if ( importPath in importMap . imports ) {
1149
- importPath = importMap . imports [ importPath ]
1145
+ if ( importPath in this . importMap . imports ) {
1146
+ importPath = this . importMap . imports [ importPath ]
1150
1147
}
1151
1148
if ( reHttp . test ( importPath ) ) {
1152
1149
if ( mod . isRemote ) {
0 commit comments