Enables advanced hot reloading in monaco playground server.

This commit is contained in:
Henning Dieterichs 2024-07-02 10:17:19 +02:00 committed by Henning Dieterichs
parent 0a16d3c1be
commit ad50f01dc1

View file

@ -235,13 +235,15 @@ function handleGetFileChangesRequest(watcher: DirWatcher, fileServer: FileServer
function makeLoaderJsHotReloadable(loaderJsCode: string, fileChangesUrl: URL): string {
loaderJsCode = loaderJsCode.replace(
/constructor\(env, scriptLoader, defineFunc, requireFunc, loaderAvailableTimestamp = 0\) {/,
'$&globalThis.___globalModuleManager = this;'
'$&globalThis.___globalModuleManager = this; globalThis.vscode = { process: { env: { VSCODE_DEV: true } } }'
);
const ___globalModuleManager: any = undefined;
// This code will be appended to loader.js
function $watchChanges(fileChangesUrl: string) {
interface HotReloadConfig { }
let reloadFn;
if (globalThis.$sendMessageToParent) {
reloadFn = () => globalThis.$sendMessageToParent({ kind: 'reload' });
@ -345,7 +347,7 @@ function makeLoaderJsHotReloadable(loaderJsCode: string, fileChangesUrl: URL): s
}
// Check if we can reload
const g: GlobalThisAddition = globalThis as any;
const g = globalThis as any;
// A frozen copy of the previous exports
const oldExports = Object.freeze({ ...oldModule.exports });