@@ -235,10 +235,10 @@ function handleGetFileChangesRequest(watcher: DirWatcher, fileServer: FileServer
235
235
function makeLoaderJsHotReloadable ( loaderJsCode : string , fileChangesUrl : URL ) : string {
236
236
loaderJsCode = loaderJsCode . replace (
237
237
/ c o n s t r u c t o r \( e n v , s c r i p t L o a d e r , d e f i n e F u n c , r e q u i r e F u n c , l o a d e r A v a i l a b l e T i m e s t a m p = 0 \) { / ,
238
- '$&globalThis.$$globalModuleManager = this;'
238
+ '$&globalThis.___globalModuleManager = this;'
239
239
) ;
240
240
241
- const $$globalModuleManager : any = undefined ;
241
+ const ___globalModuleManager : any = undefined ;
242
242
243
243
// This code will be appended to loader.js
244
244
function $watchChanges ( fileChangesUrl : string ) {
@@ -266,24 +266,26 @@ function makeLoaderJsHotReloadable(loaderJsCode: string, fileChangesUrl: URL): s
266
266
const data = JSON . parse ( line ) ;
267
267
let handled = false ;
268
268
if ( data . changedPath . endsWith ( '.css' ) ) {
269
- console . log ( 'css changed' , data . changedPath ) ;
270
- const styleSheet = [ ...document . querySelectorAll ( `link[rel='stylesheet']` ) ] . find ( ( l : any ) => new URL ( l . href , document . location . href ) . pathname . endsWith ( data . changedPath ) ) as any ;
271
- if ( styleSheet ) {
272
- styleSheet . href = styleSheet . href . replace ( / \? .* / , '' ) + '?' + Date . now ( ) ;
269
+ if ( typeof document !== 'undefined' ) {
270
+ console . log ( 'css changed' , data . changedPath ) ;
271
+ const styleSheet = [ ...document . querySelectorAll ( `link[rel='stylesheet']` ) ] . find ( ( l : any ) => new URL ( l . href , document . location . href ) . pathname . endsWith ( data . changedPath ) ) as any ;
272
+ if ( styleSheet ) {
273
+ styleSheet . href = styleSheet . href . replace ( / \? .* / , '' ) + '?' + Date . now ( ) ;
274
+ }
273
275
}
274
276
handled = true ;
275
277
} else if ( data . changedPath . endsWith ( '.js' ) && data . moduleId ) {
276
278
console . log ( 'js changed' , data . changedPath ) ;
277
- const moduleId = $$globalModuleManager . _moduleIdProvider . getModuleId ( data . moduleId ) ;
278
- if ( $$globalModuleManager . _modules2 [ moduleId ] ) {
279
- const srcUrl = $$globalModuleManager . _config . moduleIdToPaths ( data . moduleId ) ;
279
+ const moduleId = ___globalModuleManager . _moduleIdProvider . getModuleId ( data . moduleId ) ;
280
+ if ( ___globalModuleManager . _modules2 [ moduleId ] ) {
281
+ const srcUrl = ___globalModuleManager . _config . moduleIdToPaths ( data . moduleId ) ;
280
282
const newSrc = await ( await fetch ( srcUrl ) ) . text ( ) ;
281
283
( new Function ( 'define' , newSrc ) ) ( function ( deps , callback ) {
282
- const oldModule = $$globalModuleManager . _modules2 [ moduleId ] ;
283
- delete $$globalModuleManager . _modules2 [ moduleId ] ;
284
+ const oldModule = ___globalModuleManager . _modules2 [ moduleId ] ;
285
+ delete ___globalModuleManager . _modules2 [ moduleId ] ;
284
286
285
- $$globalModuleManager . defineModule ( data . moduleId , deps , callback ) ;
286
- const newModule = $$globalModuleManager . _modules2 [ moduleId ] ;
287
+ ___globalModuleManager . defineModule ( data . moduleId , deps , callback ) ;
288
+ const newModule = ___globalModuleManager . _modules2 [ moduleId ] ;
287
289
const oldExports = { ...oldModule . exports } ;
288
290
289
291
Object . assign ( oldModule . exports , newModule . exports ) ;
0 commit comments