in src/debugger/forkedAppWorker.ts [139:204]
public async postMessage(rnMessage: RNAppMessage): Promise<RNAppMessage> {
// Before sending messages, make sure that the worker is loaded
await new Promise<void>(resolve => {
if (this.workerLoaded) {
resolve();
} else {
const checkWorkerLoaded = setInterval(() => {
if (this.workerLoaded) {
clearInterval(checkWorkerLoaded);
resolve();
}
}, 1000);
}
});
const promise = (async () => {
await this.workerLoaded;
if (rnMessage.method !== "executeApplicationScript") {
// Before sending messages, make sure that the app script executed
await this.bundleLoaded;
return rnMessage;
}
// When packager asks worker to load bundle we download that bundle and
// then set url field to point to that downloaded bundle, so the worker
// will take our modified bundle
if (rnMessage.url) {
const packagerUrl = url.parse(rnMessage.url);
packagerUrl.host = `${this.packagerAddress}:${this.packagerPort}`;
rnMessage = {
...rnMessage,
url: url.format(packagerUrl),
};
logger.verbose(
`Packager requested runtime to load script from ${String(rnMessage.url)}`,
);
const downloadedScript = await this.scriptImporter.downloadAppScript(
<string>rnMessage.url,
this.projectRootPath,
);
this.bundleLoaded = Promise.resolve();
return Object.assign({}, rnMessage, {
url: `${this.pathToFileUrl(downloadedScript.filepath)}`,
});
}
throw ErrorHelper.getInternalError(
InternalErrorCode.RNMessageWithMethodExecuteApplicationScriptDoesntHaveURLProperty,
);
})();
promise.then(
(message: RNAppMessage) => {
if (this.debuggeeProcess) {
this.debuggeeProcess.send({ data: message });
}
},
reason =>
printDebuggingError(
ErrorHelper.getInternalError(
InternalErrorCode.CouldntImportScriptAt,
rnMessage.url,
),
reason,
),
);
return promise;
}