2022-10-10 12:50:21 +00:00
|
|
|
import { sandboxCompile, sandboxCompileModule } from "../compile.ts";
|
|
|
|
import { SysCallMapping } from "../system.ts";
|
2022-10-13 13:16:18 +00:00
|
|
|
import { Manifest } from "../types.ts";
|
2022-04-25 17:46:08 +00:00
|
|
|
|
2022-10-29 09:41:11 +00:00
|
|
|
import importMap from "../../import_map.json" assert { type: "json" };
|
|
|
|
import { base64EncodedDataUrl } from "../asset_bundle/base64.ts";
|
|
|
|
|
2022-10-13 13:16:18 +00:00
|
|
|
export function esbuildSyscalls(
|
|
|
|
imports: Manifest<any>[],
|
|
|
|
): SysCallMapping {
|
2022-04-25 17:46:08 +00:00
|
|
|
return {
|
|
|
|
"esbuild.compile": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
2022-04-25 17:46:08 +00:00
|
|
|
filename: string,
|
2022-05-11 09:49:27 +00:00
|
|
|
code: string,
|
2022-05-13 15:05:52 +00:00
|
|
|
functionName?: string,
|
2022-04-25 17:46:08 +00:00
|
|
|
): Promise<string> => {
|
2022-10-29 09:41:11 +00:00
|
|
|
// Override this to point to a URL
|
|
|
|
importMap.imports["$sb/"] = "https://deno.land/x/silverbullet/plug-api/";
|
|
|
|
const importUrl = new URL(
|
|
|
|
base64EncodedDataUrl(
|
|
|
|
"application/json",
|
|
|
|
new TextEncoder().encode(JSON.stringify(importMap)),
|
|
|
|
),
|
|
|
|
);
|
2022-05-13 15:05:52 +00:00
|
|
|
return await sandboxCompile(
|
|
|
|
filename,
|
|
|
|
code,
|
|
|
|
functionName,
|
2022-10-10 12:50:21 +00:00
|
|
|
{
|
|
|
|
debug: true,
|
2022-10-13 13:16:18 +00:00
|
|
|
imports,
|
2022-10-29 09:41:11 +00:00
|
|
|
importMap: importUrl,
|
2022-10-10 12:50:21 +00:00
|
|
|
},
|
2022-05-13 15:05:52 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
"esbuild.compileModule": async (
|
2022-10-10 12:50:21 +00:00
|
|
|
_ctx,
|
|
|
|
moduleName: string,
|
2022-05-13 15:05:52 +00:00
|
|
|
): Promise<string> => {
|
2022-10-10 12:50:21 +00:00
|
|
|
return await sandboxCompileModule(moduleName, {
|
2022-10-13 13:16:18 +00:00
|
|
|
imports,
|
2022-10-10 12:50:21 +00:00
|
|
|
});
|
2022-04-25 17:46:08 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|