1
0

Plug manger rebuild

This commit is contained in:
Zef Hemel
2022-05-11 11:49:27 +02:00
parent f6758dbbaf
commit f9ddb49ec6
7 changed files with 57 additions and 62 deletions
+8 -4
View File
@@ -4,22 +4,26 @@ import path from "path";
export async function compile(
filePath: string,
functionName: string = "",
functionName: string | undefined = undefined,
debug: boolean = false,
excludeModules: string[] = [],
meta = false
): Promise<string> {
let outFile = path.join(path.dirname(filePath), "_out.tmp");
let outFile = path.resolve(path.dirname(filePath), "_out.tmp");
let inFile = filePath;
if (functionName) {
// Generate a new file importing just this one function and exporting it
inFile = "_in.ts";
inFile = path.resolve(path.dirname(filePath), "_in.ts");
await writeFile(
inFile,
`import {${functionName}} from "./${filePath}";export default ${functionName};`
`import {${functionName}} from "./${path.basename(
filePath
)}";export default ${functionName};`
);
}
// console.log("In:", inFile);
// console.log("Outfile:", outFile);
// TODO: Figure out how to make source maps work correctly with eval() code
let result = await esbuild.build({
@@ -93,7 +93,8 @@ self.addEventListener("message", (event: { data: WorkerMessage }) => {
id: data.id,
error: e.message,
});
throw e;
console.error("Error invoking function", data.name, e.message);
// throw e;
}
break;
+5 -2
View File
@@ -15,7 +15,8 @@ export function esbuildSyscalls(): SysCallMapping {
"esbuild.compile": async (
ctx,
filename: string,
code: string
code: string,
functionName?: string
): Promise<string> => {
let tmpDir = `${tmpdir()}/plugos-${Math.random()}`;
await mkdir(tmpDir, { recursive: true });
@@ -34,7 +35,9 @@ export function esbuildSyscalls(): SysCallMapping {
}
await writeFile(`${tmpDir}/${filename}`, code);
let jsCode = await compile(`${tmpDir}/${filename}`, "", false, ["yaml"]);
let jsCode = await compile(`${tmpDir}/${filename}`, functionName, false, [
"yaml",
]);
await rm(tmpDir, { recursive: true });
return jsCode;
},