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

Commit f48e4ce

Browse files
author
Je
committed
refactor: rename interface 'Module' to 'RouteModule'
1 parent e88d4e6 commit f48e4ce

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

aleph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { ComponentType, useCallback, useEffect, useRef, useState } from '
22
import { DataContext, RouterContext } from './context.ts'
33
import { E400MissingDefaultExportAsComponent, E404Page, ErrorBoundary } from './error.ts'
44
import events from './events.ts'
5-
import { createPageProps, Module, Routing } from './routing.ts'
5+
import { createPageProps, RouteModule, Routing } from './routing.ts'
66
import type { RouterURL } from './types.ts'
77
import util, { hashShort, reModuleExt } from './util.ts'
88

@@ -87,7 +87,7 @@ export function ALEPH({ initial }: {
8787
console.log('[DATA]', data)
8888
setStaticData(data)
8989
}
90-
const onAddModule = async (mod: Module) => {
90+
const onAddModule = async (mod: RouteModule) => {
9191
switch (mod.id) {
9292
case '/404.js': {
9393
const { default: Component } = await import(getModuleImportUrl(baseUrl, mod, true))
@@ -215,6 +215,6 @@ export async function redirect(url: string, replace?: boolean) {
215215
events.emit('popstate', { type: 'popstate', scrollTo: 0 })
216216
}
217217

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

bootstrap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { ComponentType } from 'https://esm.sh/react'
22
import { hydrate, render } from 'https://esm.sh/react-dom'
33
import { ALEPH, getModuleImportUrl } from './aleph.ts'
4-
import { Module, Route, Routing } from './routing.ts'
4+
import { Route, RouteModule, Routing } from './routing.ts'
55
import { reModuleExt } from './util.ts'
66

77
export default async function bootstrap({
@@ -15,7 +15,7 @@ export default async function bootstrap({
1515
baseUrl: string
1616
defaultLocale: string
1717
locales: string[]
18-
preloadModules: Module[]
18+
preloadModules: RouteModule[]
1919
}) {
2020
const { document } = window as any
2121
const mainEl = document.querySelector('main')

project.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AlephAPIRequest, AlephAPIResponse } from './api.ts'
55
import { EventEmitter } from './events.ts'
66
import { createHtml } from './html.ts'
77
import log from './log.ts'
8-
import { Routing } from './routing.ts'
8+
import { RouteModule, Routing } from './routing.ts'
99
import { colors, ensureDir, path, ServerRequest, Sha1, walk } from './std.ts'
1010
import { compile } from './tsc/compile.ts'
1111
import type { AlephRuntime, APIHandle, Config, RouterURL } from './types.ts'
@@ -513,14 +513,14 @@ export class Project {
513513
if (existsDirSync(apiDir)) {
514514
for await (const { path: p } of walk(apiDir, walkOptions)) {
515515
const mod = await this._compile('/api' + util.trimPrefix(p, apiDir))
516-
this.#apiRouting.update(this._getPageModule(mod))
516+
this.#apiRouting.update(this._getRouteModule(mod))
517517
}
518518
}
519519

520520
for await (const { path: p } of walk(pagesDir, { ...walkOptions, exts: [...walkOptions.exts, '.jsx', '.tsx', '.md', '.mdx'] })) {
521521
const rp = util.trimPrefix(p, pagesDir)
522522
const mod = await this._compile('/pages' + rp)
523-
this.#routing.update(this._getPageModule(mod))
523+
this.#routing.update(this._getRouteModule(mod))
524524
}
525525

526526
const precompileUrls = [
@@ -647,9 +647,9 @@ export class Project {
647647
}
648648
}
649649
if (moduleID.startsWith('/pages/')) {
650-
this.#routing.update(this._getPageModule(mod))
650+
this.#routing.update(this._getRouteModule(mod))
651651
} else if (moduleID.startsWith('/api/')) {
652-
this.#apiRouting.update(this._getPageModule(mod))
652+
this.#apiRouting.update(this._getRouteModule(mod))
653653
}
654654
if (shouldUpdateMainModule) {
655655
this._createMainModule()
@@ -683,7 +683,7 @@ export class Project {
683683
}
684684
}
685685

686-
private _getPageModule({ id, hash }: Module) {
686+
private _getRouteModule({ id, hash }: Module): RouteModule {
687687
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ async, ...rest }) => rest)
688688
return { id, hash, asyncDeps: asyncDeps.length > 0 ? asyncDeps : undefined }
689689
}
@@ -716,7 +716,7 @@ export class Project {
716716
locales: [],
717717
routes: this.#routing.routes,
718718
preloadModules: ['/404.js', '/app.js', '/data.js'].filter(id => this.#modules.has(id)).map(id => {
719-
return this._getPageModule(this.#modules.get(id)!)
719+
return this._getRouteModule(this.#modules.get(id)!)
720720
})
721721
}
722722
const module = this._moduleFromURL('/main.js')
@@ -1008,7 +1008,7 @@ export class Project {
10081008
mod.hash = getHash(mod.jsContent)
10091009
}
10101010

1011-
log.debug(`compile ${url} in ${Math.round(performance.now() - t)}ms`)
1011+
log.debug(`compile '${url}' in ${Math.round(performance.now() - t)}ms`)
10121012

10131013
if (!fsync) {
10141014
fsync = true

routing.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { E400MissingDefaultExportAsComponent } from './error.ts'
22
import type { RouterURL } from './types.ts'
33
import util, { reMDExt, reModuleExt } from './util.ts'
44

5-
export interface Module {
6-
readonly id: string
7-
readonly hash: string
8-
readonly asyncDeps?: { url: string, hash: string }[]
9-
}
10-
115
export interface Route {
126
path: string
13-
module: Module
7+
module: RouteModule
148
children?: Route[]
159
}
1610

11+
export interface RouteModule {
12+
readonly id: string
13+
readonly hash: string
14+
readonly asyncDeps?: { url: string, hash: string }[]
15+
}
16+
1717
export interface PageProps {
1818
Page: any
1919
pageProps: Partial<PageProps> & { name?: string }
@@ -54,7 +54,7 @@ export class Routing {
5454
return JSON.parse(JSON.stringify(this._routes))
5555
}
5656

57-
update(module: Module) {
57+
update(module: RouteModule) {
5858
const newRoute: Route = { path: getPagePath(module.id), module }
5959
const dirtyRoutes: Set<Route[]> = new Set()
6060
let exists = false
@@ -109,15 +109,15 @@ export class Routing {
109109
})
110110
}
111111

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

116116
let locale = this._defaultLocale
117117
let pathname = util.cleanPath(util.trimPrefix(loc.pathname, this._baseUrl))
118118
let pagePath = ''
119119
let params: Record<string, string> = {}
120-
let tree: Module[] = []
120+
let tree: RouteModule[] = []
121121

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

0 commit comments

Comments
 (0)