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

Commit ba300a3

Browse files
author
Je
committed
fix: fix document is not defined
1 parent b61848a commit ba300a3

File tree

10 files changed

+128
-498
lines changed

10 files changed

+128
-498
lines changed

cli.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,43 @@ async function main() {
160160
}
161161
}
162162

163-
import(`./cli/${command}.ts`).then(({ default: cmd }) => {
164-
if (command === 'upgrade') {
165-
cmd(argOptions.v || argOptions.version || 'latest')
166-
} else {
167-
const appDir = path.resolve(args[0] || '.')
168-
if (command !== 'init' && !existsDirSync(appDir)) {
169-
log.fatal('No such directory:', appDir)
170-
}
171-
cmd(appDir, argOptions)
163+
// add virtual browser global objects
164+
if (command !== 'init' && command !== 'upgrade') {
165+
const { createHTMLDocument } = await import('./vendor/deno-dom/document.ts')
166+
Object.assign(globalThis, {
167+
document: createHTMLDocument(),
168+
location: {
169+
protocol: 'http:',
170+
host: 'localhost',
171+
hostname: 'localhost',
172+
port: '',
173+
href: 'https://localhost/',
174+
origin: 'https://localhost',
175+
pathname: '/',
176+
search: '',
177+
hash: '',
178+
reload() { },
179+
replace() { },
180+
toString() { return this.href },
181+
},
182+
innerWidth: 1920,
183+
innerHeight: 1080,
184+
devicePixelRatio: 1,
185+
$RefreshReg$: () => { },
186+
$RefreshSig$: () => (type: any) => type,
187+
})
188+
}
189+
190+
const { default: cmd } = await import(`./cli/${command}.ts`)
191+
if (command === 'upgrade') {
192+
await cmd(argOptions.v || argOptions.version || 'latest')
193+
} else {
194+
const appDir = path.resolve(args[0] || '.')
195+
if (command !== 'init' && !existsDirSync(appDir)) {
196+
log.fatal('No such directory:', appDir)
172197
}
173-
})
198+
await cmd(appDir, argOptions)
199+
}
174200
}
175201

176202
if (import.meta.main) {

examples/hello-world/pages/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import { Import, useDeno } from 'https://deno.land/x/aleph/mod.ts'
22
import React, { useState } from 'https://esm.sh/react'
33
import Logo from '../components/logo.tsx'
4+
import { style } from 'https://esm.sh/typestyle'
45

56
export default function Home() {
67
const [count, setCount] = useState(0)
78
const version = useDeno(() => {
89
return Deno.version
910
})
1011

12+
const red = style({ backgroundColor: 'red' })
13+
1114
return (
1215
<div className="page">
1316
<Import from="../style/index.less" />
1417
<p className="logo"><Logo /></p>
15-
<h1>Welcome to use <strong>Aleph.js</strong>!</h1>
18+
<h1 className={red}>Welcome to use <strong>Aleph.js</strong>!</h1>
1619
<p className="links">
1720
<a href="https://alephjs.org" target="_blank">Website</a>
1821
<span>&middot;</span>

project.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import CleanCSS from 'https://esm.sh/[email protected]?no-check'
12
import marked from 'https://esm.sh/[email protected]'
23
import postcss, { AcceptedPlugin } from 'https://esm.sh/[email protected]'
34
import { minify } from 'https://esm.sh/[email protected]'
@@ -12,7 +13,7 @@ import { colors, ensureDir, fromStreamReader, path, ServerRequest, Sha1, walk }
1213
import { compile } from './tsc/compile.ts'
1314
import type { AlephEnv, APIHandler, Config, RouterURL } from './types.ts'
1415
import util, { hashShort, MB, reHashJs, reHttp, reLocaleID, reMDExt, reModuleExt, reStyleModuleExt } from './util.ts'
15-
import { cleanCSS, less } from './vendor/mod.ts'
16+
import less from './vendor/less/less.js'
1617
import { version } from './version.ts'
1718

1819
interface Module {
@@ -71,6 +72,7 @@ export class Project {
7172
#renderer: { renderPage: CallableFunction } = { renderPage: () => void 0 }
7273
#rendered: Map<string, Map<string, RenderResult>> = new Map()
7374
#postcssPlugins: Record<string, AcceptedPlugin> = {}
75+
#cleanCSS = new CleanCSS({ compatibility: '*' /* Internet Explorer 10+ */ })
7476

7577
constructor(appDir: string, mode: 'development' | 'production', reload = false) {
7678
this.appRoot = path.resolve(appDir)
@@ -1018,7 +1020,7 @@ export class Project {
10181020
if (this.isDev) {
10191021
css = css.trim()
10201022
} else {
1021-
const output = cleanCSS.minify(css)
1023+
const output = this.#cleanCSS.minify(css)
10221024
css = output.styles
10231025
}
10241026
mod.jsContent = [
@@ -1448,30 +1450,6 @@ export class Project {
14481450
}
14491451
}
14501452

1451-
// add virtual browser global objects
1452-
Object.assign(globalThis, {
1453-
// document: new Document(),
1454-
location: {
1455-
protocol: 'http:',
1456-
host: 'localhost',
1457-
hostname: 'localhost',
1458-
port: '',
1459-
href: 'https://localhost/',
1460-
origin: 'https://localhost',
1461-
pathname: '/',
1462-
search: '',
1463-
hash: '',
1464-
reload() { },
1465-
replace() { },
1466-
toString() { return this.href },
1467-
},
1468-
innerWidth: 1920,
1469-
innerHeight: 1080,
1470-
devicePixelRatio: 1,
1471-
$RefreshReg$: () => { },
1472-
$RefreshSig$: () => (type: any) => type,
1473-
})
1474-
14751453
/** inject HMR and React Fast Referesh helper code */
14761454
export function injectHmr({ id, sourceFilePath, jsContent }: Module): string {
14771455
let hmrImportPath = getRelativePath(

vendor/clean-css-builds/LICENSE

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)