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

Commit d725578

Browse files
committed
refactor: clean up types
1 parent 274fef4 commit d725578

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

server/app.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ import log from '../shared/log.ts'
3030
import util from '../shared/util.ts'
3131
import type {
3232
Config,
33-
DependencyDescriptor,
3433
LoaderPlugin,
3534
LoaderTransformOutput,
36-
Module,
3735
RouterURL,
3836
ServerApplication,
3937
TransformFn
@@ -53,6 +51,22 @@ import {
5351
} from './helper.ts'
5452
import { Renderer } from './ssr.ts'
5553

54+
/** A module includes the compilation details. */
55+
export type Module = {
56+
url: string
57+
jsFile: string
58+
sourceHash: string
59+
hash: string
60+
deps: DependencyDescriptor[]
61+
}
62+
63+
/** The dependency descriptor. */
64+
export type DependencyDescriptor = {
65+
url: string
66+
hash: string
67+
isDynamic?: boolean
68+
}
69+
5670
/** The application class for aleph server. */
5771
export class Application implements ServerApplication {
5872
readonly workingDir: string
@@ -423,14 +437,14 @@ export class Application implements ServerApplication {
423437
}
424438

425439
/** add a new page module by given path and source code. */
426-
async addModule(url: string, options: { code?: string } = {}): Promise<Module> {
427-
const mod = await this.compile(url, { sourceCode: options.code })
440+
async addModule(url: string, options: { code?: string } = {}): Promise<void> {
441+
await this.compile(url, { sourceCode: options.code })
428442
if (url.startsWith('/pages/')) {
429443
this.#pageRouting.update(...this.createRouteUpdate(url))
430444
} else if (url.startsWith('/api/')) {
431445
this.#apiRouting.update(...this.createRouteUpdate(url))
432446
}
433-
return mod
447+
return
434448
}
435449

436450
/** inject code */
@@ -1065,6 +1079,8 @@ export class Application implements ServerApplication {
10651079
}
10661080
}
10671081

1082+
mod.hash = mod.sourceHash
1083+
10681084
// compile source code
10691085
if (shouldCompile) {
10701086
const source = await this.precompile(url, sourceContent, contentType)
@@ -1136,10 +1152,9 @@ export class Application implements ServerApplication {
11361152
}
11371153
}
11381154

1155+
// update hash by deps
11391156
if (mod.deps.length > 0) {
11401157
mod.hash = computeHash(mod.sourceHash + mod.deps.map(({ hash }) => hash).join(''))
1141-
} else {
1142-
mod.hash = mod.sourceHash
11431158
}
11441159

11451160
if (fsync) {

server/bundler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ import { defaultReactVersion } from '../shared/constants.ts'
77
import { ensureTextFile, existsFileSync, lazyRemove } from '../shared/fs.ts'
88
import log from '../shared/log.ts'
99
import util from '../shared/util.ts'
10-
import { Module } from '../types.ts'
1110
import { VERSION } from '../version.ts'
12-
import type { Application } from './app.ts'
11+
import type { Application, Module } from './app.ts'
1312
import {
1413
clearCompilation,
1514
computeHash,

types.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,14 @@ export interface ServerApplication {
101101
readonly workingDir: string
102102
readonly mode: 'development' | 'production'
103103
readonly config: Required<Config>
104-
addModule(url: string, options?: { code?: string }): Promise<Module>
104+
addModule(url: string, options?: { code?: string }): Promise<void>
105105
injectCode(stage: 'compilation' | 'hmr' | 'ssr', transform: TransformFn): void
106106
}
107107

108108
export type TransformFn = {
109109
(url: string, code: string): string
110110
}
111111

112-
/** A module includes the compilation details. */
113-
export type Module = {
114-
url: string
115-
deps: DependencyDescriptor[]
116-
sourceHash: string
117-
hash: string
118-
jsFile: string
119-
}
120-
121-
/** The dependency descriptor. */
122-
export type DependencyDescriptor = {
123-
url: string
124-
hash: string
125-
isDynamic?: boolean
126-
}
127-
128112
/**
129113
* An interface that aligns to the parts of std http srever's `ServerRequest`.
130114
*/

0 commit comments

Comments
 (0)