Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 4605bfb

Browse files
author
Je
committed
refactor: update types
1 parent 12f41c1 commit 4605bfb

File tree

2 files changed

+23
-29
lines changed

2 files changed

+23
-29
lines changed

project.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ interface RenderResult {
4343
export class Project {
4444
readonly mode: 'development' | 'production'
4545
readonly appRoot: string
46-
readonly config: Config
46+
readonly config: Readonly<Config>
47+
readonly importMap: Readonly<{ imports: Record<string, string> }>
4748
readonly ready: Promise<void>
4849

4950
#modules: Map<string, Module> = new Map()
@@ -67,11 +68,9 @@ export class Project {
6768
},
6869
buildTarget: mode === 'development' ? 'es2018' : 'es2015',
6970
sourceMap: false,
70-
importMap: {
71-
imports: {}
72-
},
7371
env: {}
7472
}
73+
this.importMap = { imports: {} }
7574
this.ready = (async () => {
7675
const t = performance.now()
7776
await this._loadConfig()
@@ -400,13 +399,13 @@ export class Project {
400399
const { ALEPH_IMPORT_MAP } = globalThis as any
401400
if (ALEPH_IMPORT_MAP) {
402401
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) })
404403
}
405404

406405
const importMapFile = path.join(this.appRoot, 'import_map.json')
407406
if (existsFileSync(importMapFile)) {
408407
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) })
410409
}
411410

412411
const config: Record<string, any> = {}
@@ -712,8 +711,7 @@ export class Project {
712711
}
713712

714713
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]))
717715
const sourceFilePath = renameImportUrl(url)
718716
const id = (isRemote ? '//' + util.trimPrefix(sourceFilePath, '/-/') : sourceFilePath).replace(reModuleExt, '.js')
719717
return {
@@ -797,7 +795,7 @@ export class Project {
797795
return this.#modules.get(mod.id)!
798796
}
799797

800-
const { importMap } = this.config
798+
const { importMap } = this
801799
const name = path.basename(mod.sourceFilePath).replace(reModuleExt, '')
802800
const saveDir = path.join(this.buildDir, path.dirname(mod.sourceFilePath))
803801
const metaFile = path.join(saveDir, `${name}.meta.json`)
@@ -1143,10 +1141,9 @@ export class Project {
11431141
}
11441142

11451143
private _rewriteImportPath(mod: Module, importPath: string, async?: boolean): string {
1146-
const { importMap } = this.config
11471144
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]
11501147
}
11511148
if (reHttp.test(importPath)) {
11521149
if (mod.isRemote) {

types.ts

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export interface AlephRuntime {
2-
env: Record<string, string>
3-
__version: string
4-
__appRoot: string
5-
__buildMode: string
6-
__buildTarget: string
2+
readonly env: Record<string, string>
3+
readonly __version: string
4+
readonly __appRoot: string
5+
readonly __buildMode: string
6+
readonly __buildTarget: string
77
}
88

99
export interface SSROptions {
@@ -14,18 +14,15 @@ export interface SSROptions {
1414
}
1515

1616
export interface Config {
17-
readonly srcDir: string
18-
readonly outputDir: string
19-
readonly baseUrl: string
20-
readonly defaultLocale: string
21-
readonly locales: string[]
22-
readonly ssr: boolean | SSROptions
23-
readonly buildTarget: string
24-
readonly sourceMap: boolean
25-
readonly env: Record<string, string>
26-
readonly importMap: {
27-
imports: Record<string, string>
28-
}
17+
srcDir: string
18+
outputDir: string
19+
baseUrl: string
20+
defaultLocale: string
21+
locales: string[]
22+
ssr: boolean | SSROptions
23+
buildTarget: string
24+
sourceMap: boolean
25+
env: Record<string, string>
2926
}
3027

3128
export interface APIRequestURL {

0 commit comments

Comments
 (0)