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

Commit a49b8e3

Browse files
committed
refactor: improve init method
1 parent 5b17d94 commit a49b8e3

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

server/app.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ export class Application implements ServerApplication {
7171
private async init(reload: boolean) {
7272
const t = performance.now()
7373
const alephPkgUri = getAlephPkgUri()
74-
const { env, framework, plugins, ssr } = this.config
7574
const walkOptions = { includeDirs: false, skip: [/(^|\/|\\)\./, /\.d\.ts$/i, /(\.|_)(test|spec|e2e)\.(tsx?|jsx?|mjs)?$/i] }
7675
const apiDir = path.join(this.srcDir, 'api')
7776
const pagesDir = path.join(this.srcDir, 'pages')
@@ -109,14 +108,13 @@ export class Application implements ServerApplication {
109108
await ensureDir(this.buildDir)
110109
}
111110

112-
// change current working directory to appDoot
113-
Deno.chdir(this.workingDir)
114-
115111
// inject env variables
116-
Object.entries(env).forEach(([key, value]) => Deno.env.set(key, value))
117112
Deno.env.set('ALEPH_VERSION', VERSION)
118113
Deno.env.set('BUILD_MODE', this.mode)
119114

115+
// change current working directory to appDoot
116+
Deno.chdir(this.workingDir)
117+
120118
const [config, importMap, denoDir] = await Promise.all([
121119
loadConfig(this.workingDir),
122120
loadImportMap(this.workingDir),
@@ -127,29 +125,29 @@ export class Application implements ServerApplication {
127125
this.#dirs.set('denoDir', denoDir)
128126

129127
// apply server plugins
130-
for (const plugin of plugins) {
128+
for (const plugin of this.config.plugins) {
131129
if (plugin.type === 'server') {
132130
await plugin.onInit(this)
133131
}
134132
}
135133

136134
// init framework
137-
const { init } = await import(`../framework/${framework}/init.ts`)
135+
const { init } = await import(`../framework/${this.config.framework}/init.ts`)
138136
await init(this)
139137

140138
log.info('Compiling...')
141139

142140
// pre-compile framework modules
143-
await this.compile(`${alephPkgUri}/framework/${framework}/bootstrap.ts`)
141+
await this.compile(`${alephPkgUri}/framework/${this.config.framework}/bootstrap.ts`)
144142
if (this.isDev) {
145143
await Promise.all(['hmr.ts', 'nomodule.ts'].map(name => {
146144
this.compile(`${alephPkgUri}/framework/core/${name}`)
147145
}))
148146
}
149147

150148
// compile and import framework renderer when ssr is enable
151-
if (ssr) {
152-
const rendererModuleUrl = `${alephPkgUri}/framework/${framework}/renderer.ts`
149+
if (this.config.ssr) {
150+
const rendererModuleUrl = `${alephPkgUri}/framework/${this.config.framework}/renderer.ts`
153151
const { jsFile } = await this.compile(rendererModuleUrl, { once: true })
154152
this.#renderer = await import('file://' + jsFile)
155153
}

0 commit comments

Comments
 (0)