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

Commit 5ab4c4b

Browse files
author
Je
committed
refactor: cleanup
1 parent 730cc1f commit 5ab4c4b

File tree

5 files changed

+45
-55
lines changed

5 files changed

+45
-55
lines changed

cli/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default async function (appDir: string, options: Record<string, string |
4141

4242
log.info('Done')
4343
log.info('---')
44-
log.info(colors.dim('App is ready to Go.'))
44+
log.info(colors.dim('Aleph is ready to Go.'))
4545
log.info(`${colors.dim('$')} cd ` + path.basename(appDir))
4646
log.info(`start(dev) : ${colors.dim('$')} ${colors.bold('aleph')} dev`)
4747
log.info(`start(prod): ${colors.dim('$')} ${colors.bold('aleph')} start`)

importor.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,7 @@ export function StyleLoader({ path, rawPath, resolveDir }: LoaderProps) {
3939

4040
useEffect(() => {
4141
import(util.cleanPath(`/_aleph/${resolveDir}/${path}`))
42-
return () => {
43-
const moduleId = util.cleanPath(`/${resolveDir}/${rawPath}`)
44-
const { document } = (window as any)
45-
Array.from(document.head.children).forEach((el: any) => {
46-
if (el.getAttribute('data-module-id') === moduleId) {
47-
document.head.removeChild(el)
48-
}
49-
})
50-
}
42+
return () => { }
5143
}, [])
5244

5345
return null

project.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,46 @@ export default class Project {
11161116

11171117
}
11181118

1119+
export function injectHmr({ id, sourceFilePath, jsContent }: Module): string {
1120+
let hmrImportPath = path.relative(
1121+
path.dirname(sourceFilePath),
1122+
'/-/deno.land/x/aleph/hmr.js'
1123+
)
1124+
if (!hmrImportPath.startsWith('.') && !hmrImportPath.startsWith('/')) {
1125+
hmrImportPath = './' + hmrImportPath
1126+
}
1127+
1128+
const text = [
1129+
`import { createHotContext, RefreshRuntime, performReactRefresh } from ${JSON.stringify(hmrImportPath)};`,
1130+
`import.meta.hot = createHotContext(${JSON.stringify(id)});`
1131+
]
1132+
const reactRefresh = id.endsWith('.js')
1133+
if (reactRefresh) {
1134+
text.push('')
1135+
text.push(
1136+
`const prevRefreshReg = window.$RefreshReg$;`,
1137+
`const prevRefreshSig = window.$RefreshSig$;`,
1138+
`Object.assign(window, {`,
1139+
` $RefreshReg$: (type, id) => RefreshRuntime.register(type, ${JSON.stringify(id)} + " " + id),`,
1140+
` $RefreshSig$: RefreshRuntime.createSignatureFunctionForTransform`,
1141+
`});`,
1142+
)
1143+
}
1144+
text.push('')
1145+
text.push(jsContent)
1146+
text.push('')
1147+
if (reactRefresh) {
1148+
text.push(
1149+
'window.$RefreshReg$ = prevRefreshReg;',
1150+
'window.$RefreshSig$ = prevRefreshSig;',
1151+
'import.meta.hot.accept(performReactRefresh);'
1152+
)
1153+
} else {
1154+
text.push('import.meta.hot.accept();')
1155+
}
1156+
return text.join('\n')
1157+
}
1158+
11191159
function relativePath(from: string, to: string): string {
11201160
let r = path.relative(from, to)
11211161
if (!r.startsWith('.') && !r.startsWith('/')) {

server/server.ts

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createHtml } from '../html.ts'
22
import log from '../log.ts'
3-
import Project from '../project.ts'
3+
import Project, { injectHmr } from '../project.ts'
44
import { createRouter } from '../router.ts'
55
import { path, serve, ws } from '../std.ts'
66
import util, { hashShort } from '../util.ts'
@@ -134,11 +134,7 @@ export async function start(appDir: string, port: number, isDev = false) {
134134
} else {
135135
body = mod.jsContent
136136
if (project.isHMRable(mod.id)) {
137-
body = injectHmr({
138-
id: mod.id,
139-
sourceFilePath: mod.sourceFilePath,
140-
jsContent: body
141-
})
137+
body = injectHmr({ ...mod, jsContent: body })
142138
}
143139
}
144140
req.respond({
@@ -213,42 +209,4 @@ export async function start(appDir: string, port: number, isDev = false) {
213209
}
214210
}
215211

216-
function injectHmr({ id, sourceFilePath, jsContent }: { id: string, sourceFilePath: string, jsContent: string }) {
217-
let hmrImportPath = path.relative(
218-
path.dirname(sourceFilePath),
219-
'/-/deno.land/x/aleph/hmr.js'
220-
)
221-
if (!hmrImportPath.startsWith('.') && !hmrImportPath.startsWith('/')) {
222-
hmrImportPath = './' + hmrImportPath
223-
}
224212

225-
const text = [
226-
`import { createHotContext, RefreshRuntime, performReactRefresh } from ${JSON.stringify(hmrImportPath)};`,
227-
`import.meta.hot = createHotContext(${JSON.stringify(id)});`
228-
]
229-
const reactRefresh = id.endsWith('.js')
230-
if (reactRefresh) {
231-
text.push('')
232-
text.push(
233-
`const prevRefreshReg = window.$RefreshReg$;`,
234-
`const prevRefreshSig = window.$RefreshSig$;`,
235-
`Object.assign(window, {`,
236-
` $RefreshReg$: (type, id) => RefreshRuntime.register(type, ${JSON.stringify(id)} + " " + id),`,
237-
` $RefreshSig$: RefreshRuntime.createSignatureFunctionForTransform`,
238-
`});`,
239-
)
240-
}
241-
text.push('')
242-
text.push(jsContent)
243-
text.push('')
244-
if (reactRefresh) {
245-
text.push(
246-
'window.$RefreshReg$ = prevRefreshReg;',
247-
'window.$RefreshSig$ = prevRefreshSig;',
248-
'import.meta.hot.accept(performReactRefresh);'
249-
)
250-
} else {
251-
text.push('import.meta.hot.accept();')
252-
}
253-
return text.join('\n')
254-
}

std.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export { ensureDir } from 'https://deno.land/[email protected]/fs/ensure_dir.ts'
44
export { ensureFile } from 'https://deno.land/[email protected]/fs/ensure_file.ts'
55
export { walk } from 'https://deno.land/[email protected]/fs/walk.ts'
66
export { Sha1 } from 'https://deno.land/[email protected]/hash/sha1.ts'
7-
export * from 'https://deno.land/[email protected]/http/server.ts'
7+
export { listenAndServe, serve, ServerRequest } from 'https://deno.land/[email protected]/http/server.ts'
88
export { fromStreamReader } from 'https://deno.land/[email protected]/io/mod.ts'
99
export * as path from 'https://deno.land/[email protected]/path/mod.ts'
1010
export * as ws from 'https://deno.land/[email protected]/ws/mod.ts'

0 commit comments

Comments
 (0)