awa
This commit is contained in:
82
_internal/editor/esm/vs/base/common/hotReload.js
Normal file
82
_internal/editor/esm/vs/base/common/hotReload.js
Normal file
@@ -0,0 +1,82 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
export function isHotReloadEnabled() {
|
||||
// return env && !!env['VSCODE_DEV_DEBUG'];
|
||||
return false; // TODO@hediet investigate how to get hot reload
|
||||
}
|
||||
export function registerHotReloadHandler(handler) {
|
||||
if (!isHotReloadEnabled()) {
|
||||
return { dispose() { } };
|
||||
}
|
||||
else {
|
||||
const handlers = registerGlobalHotReloadHandler();
|
||||
handlers.add(handler);
|
||||
return {
|
||||
dispose() { handlers.delete(handler); }
|
||||
};
|
||||
}
|
||||
}
|
||||
function registerGlobalHotReloadHandler() {
|
||||
if (!hotReloadHandlers) {
|
||||
hotReloadHandlers = new Set();
|
||||
}
|
||||
const g = globalThis;
|
||||
if (!g.$hotReload_applyNewExports) {
|
||||
g.$hotReload_applyNewExports = args => {
|
||||
const args2 = { config: { mode: undefined }, ...args };
|
||||
const results = [];
|
||||
for (const h of hotReloadHandlers) {
|
||||
const result = h(args2);
|
||||
if (result) {
|
||||
results.push(result);
|
||||
}
|
||||
}
|
||||
if (results.length > 0) {
|
||||
return newExports => {
|
||||
let result = false;
|
||||
for (const r of results) {
|
||||
if (r(newExports)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
}
|
||||
return hotReloadHandlers;
|
||||
}
|
||||
let hotReloadHandlers = undefined;
|
||||
if (isHotReloadEnabled()) {
|
||||
// This code does not run in production.
|
||||
registerHotReloadHandler(({ oldExports, newSrc, config }) => {
|
||||
if (config.mode !== 'patch-prototype') {
|
||||
return undefined;
|
||||
}
|
||||
return newExports => {
|
||||
for (const key in newExports) {
|
||||
const exportedItem = newExports[key];
|
||||
console.log(`[hot-reload] Patching prototype methods of '${key}'`, { exportedItem });
|
||||
if (typeof exportedItem === 'function' && exportedItem.prototype) {
|
||||
const oldExportedItem = oldExports[key];
|
||||
if (oldExportedItem) {
|
||||
for (const prop of Object.getOwnPropertyNames(exportedItem.prototype)) {
|
||||
const descriptor = Object.getOwnPropertyDescriptor(exportedItem.prototype, prop);
|
||||
const oldDescriptor = Object.getOwnPropertyDescriptor(oldExportedItem.prototype, prop);
|
||||
if (descriptor?.value?.toString() !== oldDescriptor?.value?.toString()) {
|
||||
console.log(`[hot-reload] Patching prototype method '${key}.${prop}'`);
|
||||
}
|
||||
Object.defineProperty(oldExportedItem.prototype, prop, descriptor);
|
||||
}
|
||||
newExports[key] = oldExportedItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
});
|
||||
}
|
||||
//# sourceMappingURL=hotReload.js.map
|
||||
Reference in New Issue
Block a user