This repository was archived by the owner on Jul 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +28
-30
lines changed Expand file tree Collapse file tree 6 files changed +28
-30
lines changed Original file line number Diff line number Diff line change @@ -206,7 +206,7 @@ async function load(module, imports) {
206
206
try {
207
207
return await WebAssembly . instantiateStreaming ( module , imports ) ;
208
208
} catch ( e ) {
209
- if ( module . headers . get ( "Content-Type" ) != "application/wasm" ) {
209
+ if ( module . headers . get ( "Content-Type" ) !== "application/wasm" ) {
210
210
console . warn (
211
211
"`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" ,
212
212
e ,
Original file line number Diff line number Diff line change @@ -5,10 +5,23 @@ export async function init(aleph: Aleph) {
5
5
if ( aleph . mode === 'development' ) {
6
6
const alephPkgUri = getAlephPkgUri ( )
7
7
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
+ ` )
9
22
aleph . onTransform ( 'mainscript' , ( { code } ) => ( {
10
23
code : [
11
- `import "./-/ ${ alephPkgPath } /framework/react/refresh.js ";` ,
24
+ `import ".${ refreshModule . jsFile } ";` ,
12
25
code
13
26
] . join ( '\n' )
14
27
} ) )
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -501,26 +501,23 @@ export class Aleph implements IAleph {
501
501
}
502
502
503
503
/** 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 ,
515
510
}
511
+ } )
512
+ if ( specifier . startsWith ( 'pages/' ) || specifier . startsWith ( 'api/' ) ) {
513
+ specifier = '/' + specifier
516
514
}
517
- await this . compile ( specifier , { source } )
518
515
if ( specifier . startsWith ( '/pages/' ) ) {
519
516
this . #pageRouting. update ( ...this . createRouteUpdate ( specifier ) )
520
517
} else if ( specifier . startsWith ( '/api/' ) && ! specifier . startsWith ( '/api/_middlewares.' ) ) {
521
518
this . #apiRouting. update ( ...this . createRouteUpdate ( specifier ) )
522
519
}
523
- return
520
+ return module
524
521
}
525
522
526
523
/** add a dist. */
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ export default {
100
100
debounce < T extends Function > ( callback : T , delay : number ) : T {
101
101
let timer : number | null = null
102
102
return ( ( ...args : any [ ] ) => {
103
- if ( timer != null ) {
103
+ if ( timer !== null ) {
104
104
clearTimeout ( timer )
105
105
}
106
106
timer = setTimeout ( ( ) => {
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export interface Aleph {
6
6
readonly workingDir : string
7
7
readonly config : RequiredConfig
8
8
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 } >
10
10
fetchModule ( specifier : string ) : Promise < { content : Uint8Array , contentType : string | null } >
11
11
onResolve ( test : RegExp , resolve : ( specifier : string ) => ResolveResult ) : void
12
12
onLoad ( test : RegExp , load : ( input : LoadInput ) => LoadOutput | Promise < LoadOutput > ) : void
You can’t perform that action at this time.
0 commit comments