95 lines
3.4 KiB
JavaScript
95 lines
3.4 KiB
JavaScript
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT license.
|
|
/*
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
/* global __fbBatchedBridge, self, importScripts, postMessage, onmessage: true */
|
|
/* eslint @typescript-eslint/no-unused-vars: 0 */
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
const fetch = require("node-fetch");
|
|
process.on("message", (message) => {
|
|
let shouldQueueMessages = false;
|
|
const messageQueue = [];
|
|
const processEnqueuedMessages = () => {
|
|
while (messageQueue.length) {
|
|
const messageProcess = messageQueue.shift();
|
|
if (messageProcess) {
|
|
messageProcess();
|
|
}
|
|
}
|
|
shouldQueueMessages = false;
|
|
};
|
|
const messageHandlers = {
|
|
executeApplicationScript(message) {
|
|
for (const key in message.inject) {
|
|
global[key] = JSON.parse(message.inject[key]);
|
|
}
|
|
shouldQueueMessages = true;
|
|
function evalJS(js) {
|
|
try {
|
|
/* eslint-disable-next-line no-eval */
|
|
eval(js.replace(/this\["webpackHotUpdate"\]/g, 'self["webpackHotUpdate"]').replace("GLOBAL", "global"));
|
|
}
|
|
catch (error) {
|
|
console.log(`Error Message: ${error.message}`);
|
|
console.log(`Error stack: ${error.stack}`);
|
|
}
|
|
finally {
|
|
if (process.send) {
|
|
process.send({ replyID: message.id });
|
|
processEnqueuedMessages();
|
|
}
|
|
}
|
|
}
|
|
// load platform bundles
|
|
if (global.__platformBundles != undefined) {
|
|
const platformBundles = global.__platformBundles.concat();
|
|
delete global.__platformBundles;
|
|
for (const [index, pb] of platformBundles.entries()) {
|
|
//console.log(`PB start ${index + 1}/${platformBundles.length}`);
|
|
eval(pb); // eslint-disable-line no-eval
|
|
//console.log(`PB done ${index + 1}/${platformBundles.length}`);
|
|
}
|
|
}
|
|
fetch
|
|
.default(message.url)
|
|
.then((resp) => resp.text())
|
|
.then(evalJS);
|
|
},
|
|
};
|
|
const processMessage = () => {
|
|
const sendReply = function (result, error) {
|
|
if (process.send) {
|
|
process.send({ replyID: message.id, result, error });
|
|
}
|
|
};
|
|
const handler = messageHandlers[message.method];
|
|
// Special cased handlers
|
|
if (handler) {
|
|
handler(message);
|
|
return;
|
|
}
|
|
// Other methods get called on the bridge
|
|
let returnValue = [[], [], [], 0];
|
|
try {
|
|
if (typeof __fbBatchedBridge === "object") {
|
|
returnValue = __fbBatchedBridge[message.method].apply(null, message.arguments);
|
|
}
|
|
}
|
|
finally {
|
|
sendReply(JSON.stringify(returnValue));
|
|
}
|
|
};
|
|
if (shouldQueueMessages) {
|
|
messageQueue.push(processMessage);
|
|
}
|
|
else {
|
|
processMessage();
|
|
}
|
|
});
|
|
//# sourceMappingURL=debuggerWorker.js.map
|