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

Commit 4fb9940

Browse files
committed
Rename baseURL to basePath
1 parent e11681d commit 4fb9940

File tree

11 files changed

+56
-54
lines changed

11 files changed

+56
-54
lines changed

bundler/mod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import {
1616

1717
export const bundlerRuntimeCode = (`
1818
window.__ALEPH = {
19-
baseURL: '/',
19+
basePath: '/',
2020
pack: {},
2121
bundledFiles: {},
2222
import: function(u, F) {
23-
var b = this.baseURL,
23+
var b = this.basePath,
2424
a = this.pack,
2525
l = this.bundledFiles;
2626
if (u in a) {

framework/core/module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ export function trimModuleExt(url: string) {
2525
return url
2626
}
2727

28-
export function importModule(baseUrl: string, url: string, forceRefetch = false): Promise<any> {
28+
export function importModule(basePath: string, url: string, forceRefetch = false): Promise<any> {
2929
const { __ALEPH: ALEPH } = window as any
3030

3131
if (ALEPH) {
3232
return ALEPH.import(url, forceRefetch)
3333
}
3434

35-
let src = util.cleanPath(baseUrl + '/_aleph/' + trimModuleExt(url) + '.js')
35+
let src = util.cleanPath(basePath + '/_aleph/' + trimModuleExt(url) + '.js')
3636
if (forceRefetch) {
3737
src += '?t=' + Date.now()
3838
}

framework/core/routing.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,36 @@ export type RouteModule = {
1616
}
1717

1818
export type RoutingOptions = {
19-
baseURL?: string
19+
basePath?: string
2020
defaultLocale?: string
2121
locales?: string[]
2222
routes?: Route[]
2323
rewrites?: Record<string, string>
2424
}
2525

2626
export class Routing {
27-
private _baseURL: string
27+
private _basePath: string
2828
private _defaultLocale: string
2929
private _locales: string[]
3030
private _routes: Route[]
3131
private _rewrites: Record<string, string>
3232

3333
constructor({
34-
baseURL = '/',
34+
basePath = '/',
3535
defaultLocale = 'en',
3636
locales = [],
3737
routes = [],
3838
rewrites = {}
3939
}: RoutingOptions) {
40-
this._baseURL = baseURL
40+
this._basePath = basePath
4141
this._defaultLocale = defaultLocale
4242
this._locales = locales
4343
this._routes = routes
4444
this._rewrites = rewrites
4545
}
4646

47-
get baseURL() {
48-
return this._baseURL
47+
get basePath() {
48+
return this._basePath
4949
}
5050

5151
get paths() {
@@ -128,7 +128,7 @@ export class Routing {
128128

129129
createRouter(location?: { pathname: string, search?: string }): [RouterURL, RouteModule[]] {
130130
const loc = location || (window as any).location || { pathname: '/' }
131-
const url = rewriteURL(loc.pathname + (loc.search || ''), this._baseURL, this._rewrites)
131+
const url = rewriteURL(loc.pathname + (loc.search || ''), this._basePath, this._rewrites)
132132

133133
let locale = this._defaultLocale
134134
let pathname = decodeURI(url.pathname)
@@ -163,7 +163,7 @@ export class Routing {
163163

164164
return [
165165
{
166-
baseURL: this._baseURL,
166+
basePath: this._basePath,
167167
locale,
168168
pathname,
169169
routePath,
@@ -235,9 +235,9 @@ function matchPath(routePath: string, locPath: string): [Record<string, string>,
235235
return [params, true]
236236
}
237237

238-
export function createBlankRouterURL(baseURL = '/', locale = 'en'): RouterURL {
238+
export function createBlankRouterURL(basePath = '/', locale = 'en'): RouterURL {
239239
return {
240-
baseURL,
240+
basePath,
241241
locale,
242242
routePath: '',
243243
pathname: '/',
@@ -249,10 +249,10 @@ export function createBlankRouterURL(baseURL = '/', locale = 'en'): RouterURL {
249249
}
250250

251251
/** `rewriteURL` returns a rewrited URL */
252-
export function rewriteURL(reqUrl: string, baseURL: string, rewrites: Record<string, string>): URL {
252+
export function rewriteURL(reqUrl: string, basePath: string, rewrites: Record<string, string>): URL {
253253
const url = new URL('http://localhost' + reqUrl)
254-
if (baseURL !== '/') {
255-
url.pathname = util.trimPrefix(decodeURI(url.pathname), baseURL)
254+
if (basePath !== '/') {
255+
url.pathname = util.trimPrefix(decodeURI(url.pathname), basePath)
256256
}
257257
for (const path in rewrites) {
258258
const to = rewrites[path]

framework/react/bootstrap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ type BootstrapOptions = Required<RoutingOptions> & {
1212
}
1313

1414
export default async function bootstrap(options: BootstrapOptions) {
15-
const { baseURL, defaultLocale, locales, routes, rewrites, sharedModules, renderMode } = options
15+
const { basePath, defaultLocale, locales, routes, rewrites, sharedModules, renderMode } = options
1616
const { document } = window as any
1717
const customComponents: Record<string, { C: ComponentType, useDeno?: boolean }> = {}
1818
await Promise.all(sharedModules.map(async ({ url, useDeno }) => {
19-
const { default: C } = await importModule(baseURL, url)
19+
const { default: C } = await importModule(basePath, url)
2020
switch (trimModuleExt(url)) {
2121
case '/404':
2222
customComponents['E404'] = { C, useDeno }
@@ -26,10 +26,10 @@ export default async function bootstrap(options: BootstrapOptions) {
2626
break
2727
}
2828
}))
29-
const routing = new Routing({ routes, rewrites, baseURL, defaultLocale, locales })
29+
const routing = new Routing({ routes, rewrites, basePath, defaultLocale, locales })
3030
const [url, nestedModules] = routing.createRouter()
3131
const imports = nestedModules.map(async mod => {
32-
const { default: Component } = await importModule(baseURL, mod.url)
32+
const { default: Component } = await importModule(basePath, mod.url)
3333
return {
3434
url: mod.url,
3535
Component

framework/react/components/Router.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ export default function Router({
4747
})
4848
const [route, setRoute] = useState<PageRoute>(pageRoute)
4949
const onpopstate = useCallback(async (e: any) => {
50-
const { baseURL } = routing
50+
const { basePath } = routing
5151
const [url, nestedModules] = routing.createRouter()
5252
if (url.routePath !== '') {
5353
const imports = nestedModules.map(async mod => {
54-
const { default: Component } = await importModule(baseURL, mod.url, e.forceRefetch)
54+
const { default: Component } = await importModule(basePath, mod.url, e.forceRefetch)
5555
return {
5656
url: mod.url,
5757
Component
@@ -81,11 +81,11 @@ export default function Router({
8181

8282
useEffect(() => {
8383
const isDev = !('__ALEPH' in window)
84-
const { baseURL } = routing
84+
const { basePath } = routing
8585
const onAddModule = async (mod: RouteModule & { routePath?: string, isIndex?: boolean }) => {
8686
switch (mod.url) {
8787
case '/404.js': {
88-
const { default: Component } = await importModule(baseURL, mod.url, true)
88+
const { default: Component } = await importModule(basePath, mod.url, true)
8989
if (isLikelyReactComponent(Component)) {
9090
setE404({ Component })
9191
} else {
@@ -94,7 +94,7 @@ export default function Router({
9494
break
9595
}
9696
case '/app.js': {
97-
const { default: Component } = await importModule(baseURL, mod.url, true)
97+
const { default: Component } = await importModule(basePath, mod.url, true)
9898
if (isLikelyReactComponent(Component)) {
9999
setApp({ Component })
100100
} else {
@@ -133,7 +133,7 @@ export default function Router({
133133
const [url, nestedModules] = routing.createRouter({ pathname })
134134
if (url.routePath !== '') {
135135
nestedModules.map(mod => {
136-
importModule(baseURL, mod.url)
136+
importModule(basePath, mod.url)
137137
})
138138
if (appUseDeno || nestedModules.findIndex(mod => !!mod.useDeno) > -1) {
139139
loadPageData(url)

framework/react/pagedata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { RouterURL } from '../../types.ts'
33

44
const global = window as any
55

6-
export async function loadPageData({ baseURL, pathname }: RouterURL) {
6+
export async function loadPageData({ basePath, pathname }: RouterURL) {
77
const url = `pagedata://${pathname}`
88
if (url in global) {
99
const { expires, keys } = global[url]
@@ -15,7 +15,7 @@ export async function loadPageData({ baseURL, pathname }: RouterURL) {
1515
delete global[`${url}#${key}`]
1616
})
1717
}
18-
const dataUrl = `${util.trimSuffix(baseURL, '/')}/_aleph/data${pathname === '/' ? '/index' : pathname}.json`
18+
const dataUrl = `${util.trimSuffix(basePath, '/')}/_aleph/data${pathname === '/' ? '/index' : pathname}.json`
1919
const data = await (await fetch(dataUrl)).json()
2020
if (util.isPlainObject(data)) {
2121
storeData(data, pathname)

server/app.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,9 @@ export class Application implements ServerApplication {
638638
getMainJS(bundleMode = false): string {
639639
const alephPkgUri = getAlephPkgUri()
640640
const alephPkgPath = alephPkgUri.replace('https://', '').replace('http://localhost:', 'http_localhost_')
641-
const { baseUrl: baseURL, defaultLocale, framework } = this.config
641+
const { basePath: basePath, defaultLocale, framework } = this.config
642642
const config: Record<string, any> = {
643-
baseURL,
643+
basePath,
644644
defaultLocale,
645645
locales: [],
646646
routes: this.#pageRouting.routes,
@@ -664,13 +664,15 @@ export class Application implements ServerApplication {
664664

665665
if (bundleMode) {
666666
return [
667-
`__ALEPH.baseURL = ${JSON.stringify(baseURL)};`,
667+
`__ALEPH.basePath = ${JSON.stringify(basePath)};`,
668668
`__ALEPH.pack["${alephPkgUri}/framework/${framework}/bootstrap.ts"].default(${JSON.stringify(config)});`
669669
].join('')
670670
}
671671

672672
let code = [
673+
this.isDev && `import { connect } from "./-/${alephPkgPath}/framework/core/hmr.js";`,
673674
`import bootstrap from "./-/${alephPkgPath}/framework/${framework}/bootstrap.js";`,
675+
this.isDev && `connect(${JSON.stringify(basePath)});`,
674676
`bootstrap(${JSON.stringify(config, undefined, this.isDev ? 2 : undefined)});`
675677
].filter(Boolean).join('\n')
676678
this.#injects.get('compilation')?.forEach(transform => {
@@ -682,9 +684,9 @@ export class Application implements ServerApplication {
682684
/** get ssr html scripts */
683685
getSSRHTMLScripts(entryFile?: string) {
684686
const { framework } = this.config
685-
const baseUrl = util.trimSuffix(this.config.baseUrl, '/')
687+
const basePath = util.trimSuffix(this.config.basePath, '/')
686688
const alephPkgPath = getAlephPkgUri().replace('https://', '').replace('http://localhost:', 'http_localhost_')
687-
const fullAlephPkgPath = `${baseUrl}/_aleph/-/${alephPkgPath}`
689+
const fullAlephPkgPath = `${basePath}/_aleph/-/${alephPkgPath}`
688690

689691
if (this.isDev) {
690692
const preload: string[] = [
@@ -699,21 +701,21 @@ export class Application implements ServerApplication {
699701
Array.from(this.#modules.keys()).forEach(url => {
700702
switch (trimModuleExt(url)) {
701703
case '/app':
702-
preload.push(`${baseUrl}/_aleph/app.js`)
704+
preload.push(`${basePath}/_aleph/app.js`)
703705
break
704706
case '/404':
705-
preload.push(`${baseUrl}/_aleph/404.js`)
707+
preload.push(`${basePath}/_aleph/404.js`)
706708
break
707709
}
708710
})
709711

710712
if (entryFile) {
711-
preload.push(`${baseUrl}/_aleph${entryFile}`)
713+
preload.push(`${basePath}/_aleph${entryFile}`)
712714
}
713715

714716
return [
715717
...preload.map(src => ({ src, type: 'module', preload: true })),
716-
{ src: `${baseUrl}/_aleph/main.js`, type: 'module' },
718+
{ src: `${basePath}/_aleph/main.js`, type: 'module' },
717719
{ src: `${fullAlephPkgPath}/nomodule.js`, nomodule: true },
718720
]
719721
}
@@ -723,7 +725,7 @@ export class Application implements ServerApplication {
723725
...['polyfill', 'deps', 'shared', 'main', entryFile ? util.trimSuffix(entryFile, '.js') : '']
724726
.filter(name => name !== "" && this.#bundler.getBundledFile(name) !== null)
725727
.map(name => ({
726-
src: `${baseUrl}/_aleph/${this.#bundler.getBundledFile(name)}`
728+
src: `${basePath}/_aleph/${this.#bundler.getBundledFile(name)}`
727729
}))
728730
]
729731
}

server/config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface RequiredConfig extends Required<Omit<Config, 'css'>> {
1717
export const defaultConfig: Readonly<RequiredConfig> = {
1818
framework: 'react',
1919
buildTarget: 'es2015',
20-
baseUrl: '/',
20+
basePath: '/',
2121
srcDir: '/',
2222
outputDir: '/dist',
2323
defaultLocale: 'en',
@@ -40,7 +40,7 @@ export const defaultConfig: Readonly<RequiredConfig> = {
4040

4141
/** load config from `aleph.config.(ts|js|json)` */
4242
export async function loadConfig(workingDir: string): Promise<Config> {
43-
let data: Config = {}
43+
let data: Record<string, any> = {}
4444
for (const name of ['ts', 'js', 'json'].map(ext => 'aleph.config.' + ext)) {
4545
const p = join(workingDir, name)
4646
if (existsFileSync(p)) {
@@ -68,7 +68,7 @@ export async function loadConfig(workingDir: string): Promise<Config> {
6868
framework,
6969
srcDir,
7070
outputDir,
71-
baseUrl,
71+
basePath,
7272
buildTarget,
7373
defaultLocale,
7474
locales,
@@ -94,8 +94,8 @@ export async function loadConfig(workingDir: string): Promise<Config> {
9494
if (util.isNEString(outputDir)) {
9595
config.outputDir = util.cleanPath(outputDir)
9696
}
97-
if (util.isNEString(baseUrl)) {
98-
config.baseUrl = util.cleanPath(baseUrl)
97+
if (util.isNEString(basePath)) {
98+
config.basePath = util.cleanPath(basePath)
9999
}
100100
if (isBuildTarget(buildTarget)) {
101101
config.buildTarget = buildTarget

server/server.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export class Server {
2828
}
2929

3030
const app = this.#app
31-
const { baseUrl, compress, headers, rewrites } = app.config
32-
const url = rewriteURL(r.url, baseUrl, rewrites)
31+
const { basePath, compress, headers, rewrites } = app.config
32+
const url = rewriteURL(r.url, basePath, rewrites)
3333
const pathname = decodeURI(url.pathname)
3434
const req = new Request(r, {}, url.searchParams, !app.isDev && compress)
3535

@@ -63,7 +63,7 @@ export class Server {
6363
socket.send(JSON.stringify({
6464
type: 'update',
6565
url: mod.url,
66-
updateUrl: util.cleanPath(`${baseUrl}/_aleph/${trimModuleExt(mod.url)}.js`),
66+
updateUrl: util.cleanPath(`${basePath}/_aleph/${trimModuleExt(mod.url)}.js`),
6767
hash,
6868
}))
6969
})
@@ -215,7 +215,7 @@ export async function serve({ app, port, hostname, certFile, keyFile }: ServeOpt
215215
} else {
216216
s = stdServe({ port, hostname })
217217
}
218-
log.info(`Server ready on http://${hostname || 'localhost'}:${port}${app.config.baseUrl}`)
218+
log.info(`Server ready on http://${hostname || 'localhost'}:${port}${app.config.basePath}`)
219219
for await (const r of s) {
220220
server.handle(r)
221221
}

server/ssr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export class Renderer {
194194

195195
/** render custom loading page for SPA mode. */
196196
async renderSPAIndexPage(): Promise<string> {
197-
const { baseUrl, defaultLocale } = this.#app.config
197+
const { basePath, defaultLocale } = this.#app.config
198198
const loadingModule = this.#app.findModuleByName('loading')
199199

200200
if (loadingModule) {
@@ -205,7 +205,7 @@ export class Renderer {
205205
body,
206206
scripts
207207
} = await this.#renderer.render(
208-
createBlankRouterURL(baseUrl, defaultLocale),
208+
createBlankRouterURL(basePath, defaultLocale),
209209
undefined,
210210
[{ url: loadingModule.url, Component: Loading }],
211211
styles

0 commit comments

Comments
 (0)