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

Commit 5ae56eb

Browse files
author
Je
committed
refactor: rename 'RouteModule' to 'Module'
1 parent 7e0671e commit 5ae56eb

File tree

6 files changed

+25
-26
lines changed

6 files changed

+25
-26
lines changed

aleph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DataContext, RouterContext } from './context.ts'
33
import { E404Page, E501App, E501Page, ErrorBoundary } from './error.ts'
44
import events from './events.ts'
55
import type { Routing } from './router.ts'
6-
import type { PageProps, RouteModule, RouterURL } from './types.ts'
6+
import type { Module, PageProps, RouterURL } from './types.ts'
77
import util, { hashShort, reModuleExt } from './util.ts'
88

99
export function ALEPH({ initial }: {
@@ -91,7 +91,7 @@ export function ALEPH({ initial }: {
9191
console.log('[DATA]', data)
9292
setStaticData(data)
9393
}
94-
const onAddModule = async (mod: RouteModule) => {
94+
const onAddModule = async (mod: Module) => {
9595
switch (mod.id) {
9696
case '/404.js': {
9797
const { default: Component } = await import(getModuleImportUrl(baseUrl, mod, true))
@@ -196,6 +196,6 @@ export async function redirect(url: string, replace?: boolean) {
196196
events.emit('popstate', { type: 'popstate' })
197197
}
198198

199-
export function getModuleImportUrl(baseUrl: string, mod: RouteModule, forceFetch = false) {
199+
export function getModuleImportUrl(baseUrl: string, mod: Module, forceFetch = false) {
200200
return util.cleanPath(baseUrl + '/_aleph/' + util.trimSuffix(mod.id, '.js') + `.${mod.hash.slice(0, hashShort)}.js` + (forceFetch ? `?t=${Date.now()}` : ''))
201201
}

bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { hydrate, render } from 'https://esm.sh/react-dom'
33
import { ALEPH, getModuleImportUrl } from './aleph.ts'
44
import { E501Page } from './error.ts'
55
import { Routing } from './router.ts'
6-
import type { PageProps, Route, RouteModule } from './types.ts'
6+
import type { Module, PageProps, Route } from './types.ts'
77
import util, { reModuleExt } from './util.ts'
88

99
export default async function bootstrap({
@@ -17,7 +17,7 @@ export default async function bootstrap({
1717
baseUrl: string
1818
defaultLocale: string
1919
locales: string[]
20-
preloadModules: RouteModule[]
20+
preloadModules: Module[]
2121
}) {
2222
const { document } = window as any
2323
const mainEl = document.querySelector('main')

project.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import log from './log.ts'
88
import { Routing } from './router.ts'
99
import { colors, ensureDir, path, ServerRequest, Sha1, walk } from './std.ts'
1010
import { compile } from './tsc/compile.ts'
11-
import type { AlephRuntime, APIHandle, Config, RouteModule, RouterURL } from './types.ts'
11+
import type { AlephRuntime, APIHandle, Config, RouterURL } from './types.ts'
1212
import util, { existsDirSync, existsFileSync, hashShort, reHashJs, reHttp, reMDExt, reModuleExt, reStyleModuleExt } from './util.ts'
1313
import { cleanCSS, Document, less } from './vendor/mod.ts'
1414
import { version } from './version.ts'
@@ -33,7 +33,7 @@ interface RenderResult {
3333
body: string
3434
}
3535

36-
export default class Project {
36+
export class Project {
3737
readonly mode: 'development' | 'production'
3838
readonly appRoot: string
3939
readonly config: Config
@@ -414,7 +414,6 @@ export default class Project {
414414

415415
for await (const { path: p, } of walk(this.srcDir, { ...walkOptions, maxDepth: 1, exts: [...walkOptions.exts, '.jsx', '.tsx'] })) {
416416
const name = path.basename(p)
417-
console.log(name)
418417
switch (name.replace(reModuleExt, '')) {
419418
case 'app':
420419
case 'data':
@@ -427,14 +426,14 @@ export default class Project {
427426
if (existsDirSync(apiDir)) {
428427
for await (const { path: p } of walk(apiDir, walkOptions)) {
429428
const mod = await this._compile('/api' + util.trimPrefix(p, apiDir))
430-
this.#apiRouting.update(this._getRouteModule(mod))
429+
this.#apiRouting.update(this._getPageModule(mod))
431430
}
432431
}
433432

434433
for await (const { path: p } of walk(pagesDir, { ...walkOptions, exts: [...walkOptions.exts, '.jsx', '.tsx', '.md', '.mdx'] })) {
435434
const rp = util.trimPrefix(p, pagesDir)
436435
const mod = await this._compile('/pages' + rp)
437-
this.#routing.update(this._getRouteModule(mod))
436+
this.#routing.update(this._getPageModule(mod))
438437
}
439438

440439
const precompileUrls = [
@@ -523,9 +522,9 @@ export default class Project {
523522
}
524523
}
525524
if (moduleID.startsWith('/pages/')) {
526-
this.#routing.update(this._getRouteModule(mod))
525+
this.#routing.update(this._getPageModule(mod))
527526
} else if (moduleID.startsWith('/api/')) {
528-
this.#apiRouting.update(this._getRouteModule(mod))
527+
this.#apiRouting.update(this._getPageModule(mod))
529528
}
530529
this._updateDependency(path, mod.hash, ({ id: moduleID }) => {
531530
if (!hmrable && this.isHMRable(moduleID)) {
@@ -553,7 +552,7 @@ export default class Project {
553552
}
554553
}
555554

556-
private _getRouteModule({ id, hash }: Module): RouteModule {
555+
private _getPageModule({ id, hash }: Module) {
557556
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ async, ...rest }) => rest)
558557
return { id, hash, asyncDeps }
559558
}
@@ -586,7 +585,7 @@ export default class Project {
586585
locales: [],
587586
routes: this.#routing.routes,
588587
preloadModules: ['/404.js', '/app.js', '/data.js'].filter(id => this.#modules.has(id)).map(id => {
589-
return this._getRouteModule(this.#modules.get(id)!)
588+
return this._getPageModule(this.#modules.get(id)!)
590589
})
591590
}
592591
const module = this._moduleFromURL('/main.js')

router.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Route, RouteModule, RouterURL } from './types.ts'
1+
import type { Module, Route, RouterURL } from './types.ts'
22
import util, { reMDExt } from './util.ts'
33

44
const ghostRoute: Route = { path: '', module: { id: '', hash: '' } }
@@ -36,7 +36,7 @@ export class Routing {
3636
return JSON.parse(JSON.stringify(this._routes))
3737
}
3838

39-
update(module: RouteModule) {
39+
update(module: Module) {
4040
const newRoute: Route = { path: getPagePath(module.id), module }
4141
const dirtyRoutes: Set<Route[]> = new Set()
4242
let exists = false
@@ -91,15 +91,15 @@ export class Routing {
9191
}, true)
9292
}
9393

94-
createRouter(location?: { pathname: string, search?: string }): [RouterURL, RouteModule[]] {
94+
createRouter(location?: { pathname: string, search?: string }): [RouterURL, Module[]] {
9595
const loc = location || (window as any).location || { pathname: '/' }
9696
const query = new URLSearchParams(loc.search)
9797

9898
let locale = this._defaultLocale
9999
let pathname = util.cleanPath(util.trimPrefix(loc.pathname, this._baseUrl))
100100
let pagePath = ''
101101
let params: Record<string, string> = {}
102-
let tree: RouteModule[] = []
102+
let tree: Module[] = []
103103

104104
if (pathname !== '/' && this._locales.length > 0) {
105105
const a = pathname.split('/')

server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createHtml } from './html.ts'
22
import log from './log.ts'
33
import { getContentType } from './mime.ts'
4-
import Project, { injectHmr } from './project.ts'
4+
import { injectHmr, Project } from './project.ts'
55
import { path, serve, ws } from './std.ts'
66
import util, { hashShort } from './util.ts'
77

types.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,18 @@ export interface APIHandle {
5050
(req: APIRequest, res: APIResponse): void
5151
}
5252

53-
export interface Route {
54-
path: string
55-
module: RouteModule
56-
children?: Route[]
57-
}
58-
59-
export interface RouteModule {
53+
export interface Module {
6054
readonly id: string
6155
readonly hash: string
6256
readonly asyncDeps?: { url: string, hash: string }[]
6357
}
6458

59+
export interface Route {
60+
path: string
61+
module: Module
62+
children?: Route[]
63+
}
64+
6565
export interface RouterURL {
6666
readonly locale: string
6767
readonly pathname: string

0 commit comments

Comments
 (0)