Plugin stuff

This commit is contained in:
Zef Hemel
2022-03-28 15:25:05 +02:00
parent 16fa05d4cc
commit bf32d6d0bd
36 changed files with 523 additions and 219 deletions
+3 -4
View File
@@ -28,20 +28,19 @@ async function compile(filePath: string, functionName: string, debug: boolean) {
bundle: true,
format: "iife",
globalName: "mod",
platform: "neutral",
platform: "browser",
sourcemap: false, //sourceMap ? "inline" : false,
minify: !debug,
outfile: outFile,
});
let jsCode = (await readFile(outFile)).toString();
jsCode = jsCode.replace(/^var mod ?= ?/, "");
await unlink(outFile);
if (inFile !== filePath) {
await unlink(inFile);
}
// Strip final ';'
return jsCode.substring(0, jsCode.length - 2);
return `(() => { ${jsCode}
return mod;})()`;
}
async function bundle(manifestPath: string, sourceMaps: boolean) {
+1 -1
View File
@@ -72,7 +72,6 @@ parentPort.on("message", (data: any) => {
result: result && JSON.parse(JSON.stringify(result)),
});
} catch (e: any) {
// console.log("ERROR", e);
parentPort.postMessage({
type: "result",
id: data.id,
@@ -94,6 +93,7 @@ parentPort.on("message", (data: any) => {
}
pendingRequests.delete(syscallId);
if (data.error) {
console.log("Got rejection", data.error);
lookup.reject(new Error(data.error));
} else {
lookup.resolve(data.result);
+2 -1
View File
@@ -52,14 +52,15 @@
"knex": "^1.0.4",
"node-cron": "^3.0.0",
"node-fetch": "2",
"node-watch": "^0.7.3",
"supertest": "^6.2.2",
"vm2": "^3.9.9",
"yaml": "^1.10.2",
"yargs": "^17.3.1"
},
"devDependencies": {
"@parcel/packager-raw-url": "2.3.2",
"@parcel/optimizer-data-url": "2.3.2",
"@parcel/packager-raw-url": "2.3.2",
"@parcel/service-worker": "2.3.2",
"@parcel/transformer-inline-string": "2.3.2",
"@parcel/transformer-sass": "2.3.2",
+12 -9
View File
@@ -1,4 +1,5 @@
import fs, { watch } from "fs/promises";
import fs from "fs/promises";
import watch from "node-watch";
import path from "path";
import { createSandbox } from "./environment/node_sandbox";
import { safeRun } from "../server/util";
@@ -19,14 +20,15 @@ export class DiskPlugLoader<HookT> {
}
watcher() {
safeRun(async () => {
for await (const { filename, eventType } of watch(this.plugPath)) {
if (!filename.endsWith(".plug.json")) {
return;
}
watch(this.plugPath, (eventType, localPath) => {
if (!localPath.endsWith(".plug.json")) {
return;
}
safeRun(async () => {
try {
let localPath = path.join(this.plugPath, filename);
// let localPath = path.join(this.plugPath, filename);
const plugName = extractPlugName(localPath);
console.log("Change detected for", plugName);
try {
await fs.stat(localPath);
} catch (e) {
@@ -34,10 +36,11 @@ export class DiskPlugLoader<HookT> {
await this.system.unload(plugName);
}
const plugDef = await this.loadPlugFromFile(localPath);
} catch {
} catch (e) {
console.log("Ignoring something FYI", e);
// ignore, error handled by loadPlug
}
}
});
});
}
+1
View File
@@ -71,6 +71,7 @@ export class Sandbox {
result: result,
} as WorkerMessage);
} catch (e: any) {
// console.error("Syscall fail", e);
this.worker.postMessage({
type: "syscall-response",
id: data.id,
+9 -3
View File
@@ -28,8 +28,8 @@ export function storeWriteSyscalls(
tableName: string
): SysCallMapping {
const apiObj: SysCallMapping = {
delete: async (ctx, page: string, key: string) => {
await db<Item>(tableName).where({ page, key }).del();
delete: async (ctx, key: string) => {
await db<Item>(tableName).where({ key }).del();
},
deletePrefix: async (ctx, prefix: string) => {
return db<Item>(tableName).andWhereLike("key", `${prefix}%`).del();
@@ -48,9 +48,15 @@ export function storeWriteSyscalls(
});
}
},
// TODO: Optimize
batchSet: async (ctx, kvs: KV[]) => {
for (let { key, value } of kvs) {
await apiObj["store.set"](ctx, key, value);
await apiObj.set(ctx, key, value);
}
},
batchDelete: async (ctx, keys: string[]) => {
for (let key of keys) {
await apiObj.delete(ctx, key);
}
},
};
+5
View File
@@ -4005,6 +4005,11 @@ node-releases@^2.0.2:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.2.tgz#7139fe71e2f4f11b47d4d2986aaf8c48699e0c01"
integrity sha512-XxYDdcQ6eKqp/YjI+tb2C5WM2LgjnZrfYg4vgQt49EK268b6gYCHsBLrK2qvJo4FmCtqmKezb0WZFK4fkrZNsg==
node-watch@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/node-watch/-/node-watch-0.7.3.tgz#6d4db88e39c8d09d3ea61d6568d80e5975abc7ab"
integrity sha512-3l4E8uMPY1HdMMryPRUAl+oIHtXtyiTlIiESNSVSNxcPfzAFzeTbXFQkZfAwBbo0B1qMSG8nUABx+Gd+YrbKrQ==
normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"