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

Commit 281000c

Browse files
author
ije
committed
breaking: remove AlephEnv and useEnv Hook
1 parent 6d46e39 commit 281000c

File tree

4 files changed

+13
-37
lines changed

4 files changed

+13
-37
lines changed

hooks.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,3 @@ export function useDeno<T = any>(callback: () => (T | Promise<T>), browser?: boo
5252

5353
return data
5454
}
55-
56-
export function useEnv<T>(predicate: (env: AlephEnv) => T): T {
57-
const env = useDeno<T>(() => {
58-
return predicate((globalThis as any).ALEPH.ENV)
59-
})
60-
return env
61-
}

project.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import log from './log.ts'
1111
import { getPagePath, RouteModule, Routing } from './routing.ts'
1212
import { colors, ensureDir, fromStreamReader, path, ServerRequest, Sha1, walk } from './std.ts'
1313
import { compile } from './tsc/compile.ts'
14-
import type { AlephEnv, APIHandler, Config, RouterURL } from './types.ts'
14+
import type { APIHandler, Config, RouterURL } from './types.ts'
1515
import util, { hashShort, MB, reHashJs, reHttp, reLocaleID, reMDExt, reModuleExt, reStyleModuleExt } from './util.ts'
1616
import { createHTMLDocument } from './vendor/deno-dom/document.ts'
1717
import less from './vendor/less/less.js'
@@ -593,18 +593,13 @@ export class Project {
593593
this.#postcssPlugins[name] = Plugin
594594
}))
595595

596-
// inject ALEPH global variable
597-
Object.assign(globalThis, {
598-
ALEPH: {
599-
ENV: {
600-
...Deno.env.toObject(),
601-
...this.config.env,
602-
__version: version,
603-
__buildMode: this.mode,
604-
__buildTarget: this.config.buildTarget,
605-
} as AlephEnv
606-
}
607-
})
596+
// inject env variables
597+
Object.entries({
598+
...this.config.env,
599+
__version: version,
600+
__buildMode: this.mode,
601+
__buildTarget: this.config.buildTarget,
602+
}).forEach(([key, value]) => Deno.env.set(key, value))
608603

609604
// change current work dir to appDoot
610605
Deno.chdir(this.appRoot)

renderer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AsyncUseDenoError, E400MissingDefaultExportAsComponent, E404Page } from
55
import events from './events.ts'
66
import { serverStyles } from './head.ts'
77
import { createPageProps } from './routing.ts'
8-
import type { AlephEnv, RouterURL } from './types.ts'
8+
import type { RouterURL } from './types.ts'
99
import util, { hashShort } from './util.ts'
1010

1111
interface RenderResult {
@@ -63,7 +63,8 @@ export async function renderPage(
6363
scriptsElements: new Map()
6464
}
6565
const { __createHTMLDocument } = (window as any)
66-
const { __buildMode, __buildTarget } = (window as any).ALEPH.ENV as AlephEnv
66+
const buildMode = Deno.env.get('__buildMode')
67+
const buildTarget = Deno.env.get('__buildTarget')
6768
const data: Record<string, any> = {}
6869
const useDenEvent = `useDeno://${url.pathname + '?' + url.query.toString()}`
6970
const useDenoAsyncCalls: Array<Promise<any>> = []
@@ -167,7 +168,7 @@ export async function renderPage(
167168
rendererCache.scriptsElements.clear()
168169

169170
await Promise.all(styles?.map(({ url, hash }) => {
170-
return import('file://' + util.cleanPath(`${Deno.cwd()}/.aleph/${__buildMode}.${__buildTarget}/${url}.${hash.slice(0, hashShort)}.js`))
171+
return import('file://' + util.cleanPath(`${Deno.cwd()}/.aleph/${buildMode}.${buildTarget}/${url}.${hash.slice(0, hashShort)}.js`))
171172
}) || [])
172173
styles?.forEach(({ url }) => {
173174
if (serverStyles.has(url)) {

types.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
import type { ServerRequest } from './std.ts';
22

3-
/**
4-
* The **ENV** of Aleph.js runtime, you can access it with `window.ALEPH.ENV[key]`.
5-
*/
6-
export interface AlephEnv {
7-
[key: string]: string
8-
/** The version of **Aleph.js** */
9-
readonly __version: string
10-
/** The build mode of the appliaction (possible values: '**development**' | '**production**') */
11-
readonly __buildMode: string
12-
/** The build target of the appliaction (possible values: '**ES2015**' - '**ES2020**' | '**ESNext**') */
13-
readonly __buildTarget: string
14-
}
15-
163
/**
174
* A plugin for **Aleph.js** application.
185
*/
@@ -71,7 +58,7 @@ export interface Config {
7158
buildTarget?: string
7259
/** Enable sourceMap in **production** mode (default is **false**). */
7360
sourceMap?: boolean
74-
/** `env` defines the `Window.ALEPH.ENV` object in the application. */
61+
/** `env` appends env variables (use `Deno.env.get(key)` to get an env variable) */
7562
env?: Record<string, string>
7663
}
7764

0 commit comments

Comments
 (0)