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

Commit c8697be

Browse files
committed
Update types
1 parent 9f3e1a4 commit c8697be

File tree

6 files changed

+28
-30
lines changed

6 files changed

+28
-30
lines changed

compiler/dist/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async function load(module, imports) {
206206
try {
207207
return await WebAssembly.instantiateStreaming(module, imports);
208208
} catch (e) {
209-
if (module.headers.get("Content-Type") != "application/wasm") {
209+
if (module.headers.get("Content-Type") !== "application/wasm") {
210210
console.warn(
211211
"`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
212212
e,

framework/react/init.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,23 @@ export async function init(aleph: Aleph) {
55
if (aleph.mode === 'development') {
66
const alephPkgUri = getAlephPkgUri()
77
const alephPkgPath = alephPkgUri.replace('https://', '').replace('http://localhost:', 'http_localhost_')
8-
await aleph.addModule(`${alephPkgUri}/framework/react/refresh.ts`)
8+
const refreshModule = await aleph.addModule(`${alephPkgUri}/framework/react/refresh.ts`, `
9+
import runtime from 'https://esm.sh/[email protected]/runtime'
10+
import util from '../../shared/util.ts'
11+
12+
// react-refresh
13+
// @link https://github.com/facebook/react/issues/16604#issuecomment-528663101
14+
runtime.injectIntoGlobalHook(window)
15+
Object.assign(window, {
16+
$RefreshReg$: () => { },
17+
$RefreshSig$: () => (type: any) => type,
18+
__REACT_REFRESH_RUNTIME__: runtime,
19+
__REACT_REFRESH__: util.debounce(runtime.performReactRefresh, 30)
20+
})
21+
`)
922
aleph.onTransform('mainscript', ({ code }) => ({
1023
code: [
11-
`import "./-/${alephPkgPath}/framework/react/refresh.js";`,
24+
`import ".${refreshModule.jsFile}";`,
1225
code
1326
].join('\n')
1427
}))

framework/react/refresh.ts

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

server/aleph.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,26 +501,23 @@ export class Aleph implements IAleph {
501501
}
502502

503503
/** add a module by given path and optional source code. */
504-
async addModule(specifier: string, sourceCode?: string): Promise<void> {
505-
const source = sourceCode ? {
506-
code: sourceCode,
507-
type: SourceType.TSX,
508-
external: false,
509-
isStyle: false,
510-
} : undefined
511-
if (source !== undefined) {
512-
const type = getSourceType(specifier)
513-
if (type !== SourceType.Unknown) {
514-
source.type = type
504+
async addModule(specifier: string, sourceCode: string): Promise<Module> {
505+
const module = await this.compile(specifier, {
506+
source: {
507+
code: sourceCode,
508+
type: getSourceType(specifier),
509+
isStyle: false,
515510
}
511+
})
512+
if (specifier.startsWith('pages/') || specifier.startsWith('api/')) {
513+
specifier = '/' + specifier
516514
}
517-
await this.compile(specifier, { source })
518515
if (specifier.startsWith('/pages/')) {
519516
this.#pageRouting.update(...this.createRouteUpdate(specifier))
520517
} else if (specifier.startsWith('/api/') && !specifier.startsWith('/api/_middlewares.')) {
521518
this.#apiRouting.update(...this.createRouteUpdate(specifier))
522519
}
523-
return
520+
return module
524521
}
525522

526523
/** add a dist. */

shared/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default {
100100
debounce<T extends Function>(callback: T, delay: number): T {
101101
let timer: number | null = null
102102
return ((...args: any[]) => {
103-
if (timer != null) {
103+
if (timer !== null) {
104104
clearTimeout(timer)
105105
}
106106
timer = setTimeout(() => {

types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface Aleph {
66
readonly workingDir: string
77
readonly config: RequiredConfig
88
addDist(path: string, content: Uint8Array): Promise<void>
9-
addModule(specifier: string, sourceCode?: string): Promise<void>
9+
addModule(specifier: string, sourceCode: string): Promise<{ specifier: string, jsFile: string }>
1010
fetchModule(specifier: string): Promise<{ content: Uint8Array, contentType: string | null }>
1111
onResolve(test: RegExp, resolve: (specifier: string) => ResolveResult): void
1212
onLoad(test: RegExp, load: (input: LoadInput) => LoadOutput | Promise<LoadOutput>): void

0 commit comments

Comments
 (0)