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

Commit 30d3750

Browse files
author
Je
committed
feat: add buildId that contains aleph version info
1 parent a4afc90 commit 30d3750

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

head.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ export async function renderHead(styleModules?: string[]) {
2828
}
2929
}
3030
})
31-
await Promise.all(resetImports().map(path => import(path)))
31+
await Promise.all(resetImports().map(p => {
32+
const { appDir, buildId } = (window as any).ALEPH_ENV as { appDir: string, buildId: string }
33+
return util.cleanPath(`${appDir}/.aleph/build-${buildId}/${p}`)
34+
}).map(p => import('file://' + p)))
3235
styleModules?.filter(id => serverStyles.has(id)).forEach(id => {
3336
const { css, asLink } = serverStyles.get(id)!
3437
if (asLink) {

importor.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect } from 'https://esm.sh/react'
2-
import type { Config } from './types.ts'
32
import util, { reStyleModuleExt } from './util.ts'
43

54
const serverImports: Set<string> = new Set()
@@ -33,8 +32,7 @@ interface LoaderProps {
3332

3433
export function StyleLoader({ path, rawPath, resolveDir }: LoaderProps) {
3534
if (typeof Deno !== 'undefined') {
36-
const { appDir, mode, config } = (window as any).ALEPH_ENV as { appDir: string, mode: string, config: Config }
37-
serverImports.add(util.cleanPath(`${appDir}/.aleph/${mode}.${config.buildTarget}/${resolveDir}/${path}`))
35+
serverImports.add(util.cleanPath(`${resolveDir}/${path}`))
3836
}
3937

4038
useEffect(() => {

project.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util, { hashShort, reHashJs, reHttp, reModuleExt, reStyleModuleExt } from
1010
import './vendor/clean-css-builds/v4.2.2.js'
1111
import { Document } from './vendor/deno-dom/document.ts'
1212
import less from './vendor/less/less.js'
13+
import { version } from './version.ts'
1314

1415
const { CleanCSS } = window as any
1516
const cleanCSS = new CleanCSS({ compatibility: '*' /* Internet Explorer 10+ */ })
@@ -40,6 +41,7 @@ export default class Project {
4041
readonly config: Config
4142
readonly ready: Promise<void>
4243

44+
#buildId: string = ''
4345
#modules: Map<string, Module> = new Map()
4446
#pageModules: Map<string, { moduleId: string, rendered: Map<string, RenderResult> }> = new Map()
4547
#fsWatchListeners: Array<EventEmitter> = []
@@ -77,8 +79,12 @@ export default class Project {
7779
return path.join(this.rootDir, this.config.srcDir)
7880
}
7981

82+
get buildId() {
83+
return this.#buildId
84+
}
85+
8086
get buildDir() {
81-
return path.join(this.rootDir, '.aleph', this.mode + '.' + this.config.buildTarget)
87+
return path.join(this.rootDir, '.aleph', 'build-' + this.buildId)
8288
}
8389

8490
get apiPaths() {
@@ -375,6 +381,9 @@ export default class Project {
375381
if (typeof sourceMap === 'boolean') {
376382
Object.assign(this.config, { sourceMap })
377383
}
384+
385+
// Gen build ID after config loaded
386+
this.#buildId = (new Sha1()).update(this.mode + '.' + this.config.buildTarget + '.' + version).hex().slice(0, 18)
378387
}
379388

380389
private async _init() {
@@ -390,6 +399,7 @@ export default class Project {
390399
Object.assign(globalThis, {
391400
ALEPH_ENV: {
392401
appDir: this.rootDir,
402+
buildId: this.buildId,
393403
config: this.config,
394404
mode: this.mode,
395405
},
@@ -845,7 +855,7 @@ export default class Project {
845855
}
846856
mod.jsContent = [
847857
`import { applyCSS } from ${JSON.stringify(relativePath(
848-
path.dirname(path.resolve('/', mod.url)),
858+
path.dirname(mod.url),
849859
'/-/deno.land/x/aleph/head.js'
850860
))};`,
851861
`applyCSS(${JSON.stringify(url)}, ${asLink ? JSON.stringify(path.join(this.config.baseUrl, '_aleph', filepath)) + ', true' : JSON.stringify(this.isDev ? `\n${css}\n` : css)});`,
@@ -1079,8 +1089,8 @@ export default class Project {
10791089
const data = await this.getData()
10801090
const html = renderPage(data, url, appModule ? App : undefined, Page)
10811091
const head = await renderHead([
1092+
appModule ? this._lookupStyles(appModule) : [],
10821093
this._lookupStyles(pageModule),
1083-
appModule ? this._lookupStyles(appModule) : []
10841094
].flat())
10851095
ret.code = 200
10861096
ret.head = head

0 commit comments

Comments
 (0)