Revert "Cache the scripts on disk, in attempt to increase perfrmance, may need to revisit this"
This reverts commit 4a335dc936.
This commit is contained in:
12
worker.ts
12
worker.ts
@@ -8,7 +8,7 @@ const States = Object.freeze({
|
||||
});
|
||||
|
||||
self.onmessage = async (e) => {
|
||||
const { filePath, request, environment, name } = e.data;
|
||||
const { code, request, environment, name } = e.data;
|
||||
const logs: any[] = [];
|
||||
const startTime = performance.now();
|
||||
|
||||
@@ -52,7 +52,15 @@ self.onmessage = async (e) => {
|
||||
status
|
||||
);
|
||||
|
||||
const userModule = await import(filePath);
|
||||
let userModule = moduleCache.get(code);
|
||||
if (!userModule) {
|
||||
// Use a data URL to import the user's code as an ES module.
|
||||
const dataUrl = `data:text/javascript;base64,${btoa(
|
||||
unescape(encodeURIComponent(code))
|
||||
)}`;
|
||||
userModule = await import(dataUrl);
|
||||
moduleCache.set(code, userModule);
|
||||
}
|
||||
|
||||
if (typeof userModule.default !== "function") {
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user