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

Commit b295e56

Browse files
author
Je
committed
refactor: rename 'AlephRuntime' to 'AlephEnv'
1 parent e6a2824 commit b295e56

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,11 @@ async function main() {
123123
const match = String(imports['https://deno.land/x/aleph/']).match(/^http:\/\/(localhost|127.0.0.1):(\d+)\/$/)
124124
if (match) {
125125
const port = parseInt(match[2])
126+
const cwd = Deno.cwd()
126127
listenAndServe({ port }, async (req: ServerRequest) => {
127128
const url = new URL('http://localhost' + req.url)
128129
const resp = new Request(req, { pathname: util.cleanPath(url.pathname), params: {}, query: url.searchParams })
129-
const filepath = path.join(Deno.cwd(), url.pathname)
130+
const filepath = path.join(cwd, url.pathname)
130131
try {
131132
const info = await Deno.lstat(filepath)
132133
if (info.isDirectory) {

head.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Children, createElement, isValidElement, PropsWithChildren, ReactElement, ReactNode, useEffect } from 'https://esm.sh/react'
2-
import type { AlephRuntime } from './types.ts'
2+
import type { AlephEnv } from './types.ts'
33
import util, { hashShort } from './util.ts'
44

55
export default function Head({ children }: PropsWithChildren<{}>) {
@@ -112,7 +112,7 @@ const serverHeadElements: Map<string, { type: string, props: Record<string, any>
112112
const serverStyles: Map<string, { css: string, asLink: boolean }> = new Map()
113113

114114
export async function renderHead(styles?: { url: string, hash: string, async?: boolean }[]) {
115-
const { __appRoot, __buildMode, __buildTarget } = (window as any).ALEPH as AlephRuntime
115+
const { __buildMode, __buildTarget } = (window as any).ALEPH.ENV as AlephEnv
116116
const tags: string[] = []
117117
serverHeadElements.forEach(({ type, props }) => {
118118
if (type === 'title') {
@@ -136,7 +136,7 @@ export async function renderHead(styles?: { url: string, hash: string, async?: b
136136
}
137137
})
138138
await Promise.all(styles?.filter(({ async }) => !!async).map(({ url, hash }) => {
139-
return import('file://' + util.cleanPath(`${__appRoot}/.aleph/${__buildMode}.${__buildTarget}/${url}.${hash.slice(0, hashShort)}.js`))
139+
return import('file://' + util.cleanPath(`${Deno.cwd()}/.aleph/${__buildMode}.${__buildTarget}/${url}.${hash.slice(0, hashShort)}.js`))
140140
}) || [])
141141
styles?.forEach(({ url }) => {
142142
if (serverStyles.has(url)) {

project.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import log from './log.ts'
88
import { getPagePath, RouteModule, Routing } from './routing.ts'
99
import { colors, ensureDir, path, ServerRequest, Sha1, walk } from './std.ts'
1010
import { compile } from './tsc/compile.ts'
11-
import type { AlephRuntime, APIHandler, Config, RouterURL } from './types.ts'
11+
import type { AlephEnv, APIHandler, Config, RouterURL } from './types.ts'
1212
import util, { existsDirSync, existsFileSync, hashShort, MB, reHashJs, reHttp, reLocaleID, reMDExt, reModuleExt, reStyleModuleExt } from './util.ts'
1313
import { cleanCSS, Document, less } from './vendor/mod.ts'
1414
import { version } from './version.ts'
@@ -502,14 +502,16 @@ export class Project {
502502
await ensureDir(this.buildDir)
503503
}
504504

505+
Deno.chdir(this.appRoot)
505506
Object.assign(globalThis, {
506507
ALEPH: {
507-
env: { ...this.config.env },
508-
__version: version,
509-
__appRoot: this.appRoot,
510-
__buildMode: this.mode,
511-
__buildTarget: this.config.buildTarget,
512-
} as AlephRuntime,
508+
ENV: {
509+
...this.config.env,
510+
__version: version,
511+
__buildMode: this.mode,
512+
__buildTarget: this.config.buildTarget,
513+
} as AlephEnv
514+
},
513515
document: new Document(),
514516
innerWidth: 1920,
515517
innerHeight: 1080,
@@ -757,6 +759,7 @@ export class Project {
757759
module.jsContent = [
758760
this.isDev && 'import "./-/deno.land/x/aleph/hmr.js";',
759761
'import bootstrap from "./-/deno.land/x/aleph/bootstrap.js";',
762+
`Object.assign(window, ${JSON.stringify({ ALEPH: (globalThis as any)['ALEPH'] }, undefined, this.isDev ? 4 : undefined)});`,
760763
`bootstrap(${JSON.stringify(config, undefined, this.isDev ? 4 : undefined)});`
761764
].filter(Boolean).join(this.isDev ? '\n' : '')
762765
module.hash = getHash(module.jsContent)

types.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
export interface AlephRuntime {
2-
readonly env: Record<string, string>
1+
export interface AlephEnv {
2+
[key: string]: string
33
readonly __version: string
4-
readonly __appRoot: string
54
readonly __buildMode: string
65
readonly __buildTarget: string
76
}
@@ -25,19 +24,16 @@ export interface Config {
2524
env: Record<string, string>
2625
}
2726

27+
export interface APIHandler {
28+
(req: APIRequest): void
29+
}
30+
2831
export interface APIRequestURL {
2932
readonly pathname: string
3033
readonly params: Record<string, string>
3134
readonly query: URLSearchParams
3235
}
3336

34-
export interface Response {
35-
status?: number
36-
headers?: Headers
37-
trailers?: () => Promise<Headers> | Headers
38-
body?: Uint8Array | Deno.Reader | string
39-
}
40-
4137
export interface APIRequest {
4238
readonly method: string
4339
readonly proto: string
@@ -64,8 +60,11 @@ export interface APIRequest {
6460
end(code: number): Promise<void>
6561
}
6662

67-
export interface APIHandler {
68-
(req: APIRequest): void
63+
export interface Response {
64+
status?: number
65+
headers?: Headers
66+
trailers?: () => Promise<Headers> | Headers
67+
body?: Uint8Array | Deno.Reader | string
6968
}
7069

7170
export interface RouterURL {

0 commit comments

Comments
 (0)