Transfer buffers in WorkerManager replaceOwnWorker
MODIFY
packages/@romejs/core/common/bridges/WorkerBridge.ts
packages/@romejs/core/common/bridges/WorkerBridge.ts
@@ -239,6 +239,17 @@ export default class WorkerBridge extends Bridge {
AnyRoot
>({name: "parse", direction: "server->client"});
+ getFileBuffers = this.createEvent<
+ void,
+ Array<{
+ filename: string;
+ content: string;
+ }>
+ >({
+ name: "getFileBuffers",
+ direction: "server->client",
+ });
+
updateBuffer = this.createEvent<
{
file: JSONFileReference;

MODIFY
packages/@romejs/core/server/WorkerManager.ts
packages/@romejs/core/server/WorkerManager.ts
@@ -20,8 +20,7 @@ import {
createBridgeFromLocal,
} from "@romejs/events";
import child = require("child_process");
-
-import {AbsoluteFilePath} from "@romejs/path";
+import {AbsoluteFilePath, createAbsoluteFilePath} from "@romejs/path";
export type WorkerContainer = {
id: number;
@@ -171,6 +170,18 @@ export default class WorkerManager {
// Spawn a new worker
const newWorker = await this.spawnWorker(this.getNextWorkerId(), true);
+ // Transfer buffers to the new worker
+ const buffers = await serverWorker.bridge.getFileBuffers.call();
+
+ for (const {filename, content} of buffers) {
+ await newWorker.bridge.updateBuffer.call({
+ file: this.server.projectManager.getTransportFileReference(
+ createAbsoluteFilePath(filename),
+ ),
+ content,
+ });
+ }
+
// End the old worker, will automatically cleanup
serverWorker.bridge.end();

MODIFY
packages/@romejs/core/worker/Worker.ts
packages/@romejs/core/worker/Worker.ts
@@ -236,6 +236,10 @@ export default class Worker {
bridge.clearBuffer.subscribe((payload) => {
return this.clearBuffer(convertTransportFileReference(payload.file));
});
+
+ bridge.getFileBuffers.subscribe(() => {
+ return this.getFileBuffers();
+ });
}
clearBuffer({real}: FileReference) {
@@ -250,6 +254,13 @@ export default class Worker {
this.evict(ref.real);
}
+ getFileBuffers() {
+ return Array.from(
+ this.buffers,
+ ([path, content]) => ({filename: path.join(), content}),
+ );
+ }
+
async getTypeCheckProvider(
projectId: number,
prefetchedModuleSignatures: PrefetchedModuleSignatures = {},

Transfer buffers in WorkerManager replaceOwnWorker (#708)