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

Commit 34f6f30

Browse files
author
Je
committed
refactor: remove outdated js compilation
1 parent 7668135 commit 34f6f30

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

head.ts

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

55
const serverHeadElements: Array<{ type: string, props: Record<string, any> }> = []
66
const serverStyles: Map<string, { css: string, asLink: boolean }> = new Map()
77

88
export async function renderHead(styles?: { url: string, hash: string, async?: boolean }[]) {
9-
const { __appRoot, __buildID } = (window as any).ALEPH_ENV as AlephEnv
9+
const { __appRoot, __buildID } = (window as any).ALEPH as AlephRuntime
1010
const tags: string[] = []
1111
serverHeadElements.forEach(({ type, props }) => {
1212
if (type === 'title') {

project.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ interface RenderResult {
3333
body: string
3434
}
3535

36-
export interface AlephEnv {
37-
[key: string]: string
36+
export interface AlephRuntime {
37+
env: Record<string, string>
3838
__version: string
3939
__appRoot: string
4040
__buildID: string
@@ -402,12 +402,12 @@ export default class Project {
402402
}
403403

404404
Object.assign(globalThis, {
405-
ALEPH_ENV: {
406-
...this.config.env,
405+
ALEPH: {
406+
env: this.config.env,
407407
__version: version,
408408
__appRoot: this.appRoot,
409409
__buildID: this.buildID,
410-
} as AlephEnv,
410+
} as AlephRuntime,
411411
document: new Document(),
412412
innerWidth: 1920,
413413
innerHeight: 1080,
@@ -632,25 +632,25 @@ export default class Project {
632632
}))
633633
if (this.#modules.has('/data.js')) {
634634
const { id, url, hash } = this.#modules.get('/data.js')!
635-
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ url, hash }) => ({ url, hash }))
635+
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ async, ...rest }) => rest)
636636
config.staticDataModule = { id, hash, asyncDeps }
637637
deps.push({ url, hash })
638638
}
639639
if (this.#modules.has('/app.js')) {
640640
const { id, url, hash } = this.#modules.get('/app.js')!
641-
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ url, hash }) => ({ url, hash }))
641+
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ async, ...rest }) => rest)
642642
config.customAppModule = { id, hash, asyncDeps }
643643
deps.push({ url, hash })
644644
}
645645
if (this.#modules.has('/404.js')) {
646646
const { id, url, hash } = this.#modules.get('/404.js')!
647-
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ url, hash }) => ({ url, hash }))
647+
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ async, ...rest }) => rest)
648648
config.custom404Module = { id: '/404.js', hash, asyncDeps }
649649
deps.push({ url, hash })
650650
}
651651
this.#pageModules.forEach(({ moduleID }, pagePath) => {
652652
const { id, url, hash } = this.#modules.get(moduleID)!
653-
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ url, hash }) => ({ url, hash }))
653+
const asyncDeps = this._lookupStyleDeps(id).filter(({ async }) => !!async).map(({ async, ...rest }) => rest)
654654
config.routing[pagePath] = { id, hash, asyncDeps }
655655
deps.push({ url, hash })
656656
})
@@ -664,6 +664,13 @@ export default class Project {
664664
module.jsFile = path.join(this.buildDir, `main.${module.hash.slice(0, hashShort)}.js`)
665665
module.deps = deps
666666

667+
if (this.#modules.has(module.id)) {
668+
const prevHash = this.#modules.get(module.id)!.hash
669+
try {
670+
await Deno.remove(path.join(this.buildDir, `main.${prevHash.slice(0, hashShort)}.js`))
671+
} catch (e) { }
672+
}
673+
667674
await Promise.all([
668675
writeTextFile(module.jsFile, module.jsContent),
669676
writeTextFile(path.join(this.buildDir, 'main.meta.json'), JSON.stringify({
@@ -940,6 +947,12 @@ export default class Project {
940947
}
941948

942949
if (fsync) {
950+
if (mod.jsFile != "") {
951+
try {
952+
await Deno.remove(mod.jsFile)
953+
await Deno.remove(mod.jsFile + '.map')
954+
} catch (e) { }
955+
}
943956
mod.jsFile = path.join(saveDir, name + (mod.isRemote ? '' : `.${mod.hash.slice(0, hashShort)}`)) + '.js'
944957
await Promise.all([
945958
writeTextFile(metaFile, JSON.stringify({

0 commit comments

Comments
 (0)