Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/node-runtime-worker-thread/src/worker-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const workerRuntime: WorkerRuntime = {

let interrupted = true;
let evaluationPromise: void | Promise<RuntimeEvaluationResult>;
const previousRequireCache = Object.keys(require.cache);

try {
evaluationPromise = runInterruptible((handle) => {
Expand All @@ -109,6 +110,17 @@ const workerRuntime: WorkerRuntime = {
});
} finally {
evaluationListener.onRunInterruptible(null);

if (interrupted) {
// If we were interrupted, we can't know which newly require()ed modules
// have successfully been loaded, so we restore everything to its
// previous state.
for (const key of Object.keys(require.cache)) {
if (!previousRequireCache.includes(key)) {
delete require.cache[key];
}
}
}
}

let result: void | RuntimeEvaluationResult | UNLOCKED;
Expand Down