Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/wapython
Path: blob/main/core/dash-wasm/src/node.ts
1067 views
1
import { syncKernel, asyncKernel, FileSystemSpec } from "@cowasm/kernel";
2
import { join } from "path";
3
import debug from "debug";
4
5
const log = debug("dash-wasm:node");
6
7
import { Options, DashWasmAsync, DashWasmSync, getEnv } from "./common";
8
9
const { USR, ENV } = getEnv("/cowasm");
10
11
const fs_zip = join(__dirname, "fs.zip");
12
const dash_wasm = join(USR, "bin", "sh");
13
14
// This is used for build testing (all packages have a path).
15
export const path = __dirname;
16
17
export async function syncDash(opts?: Options): Promise<DashWasmSync> {
18
log("creating sync CoWasm kernel...");
19
const fs = getFilesystem(opts);
20
const kernel = await syncKernel({ env: ENV, fs });
21
log("done");
22
return new DashWasmSync(kernel, dash_wasm);
23
}
24
25
export async function asyncDash(opts?: Options): Promise<DashWasmAsync> {
26
log("creating async CoWasm kernel...");
27
const fs = getFilesystem(opts);
28
const kernel = await asyncKernel({
29
env: ENV,
30
fs,
31
noStdio: opts?.noStdio,
32
});
33
log("done");
34
return new DashWasmAsync(kernel, dash_wasm);
35
}
36
37
export default asyncDash; // consistency with browser
38
39
function getFilesystem(_opts?: Options): FileSystemSpec[] {
40
return [
41
{ type: "native" },
42
{
43
type: "zipfile",
44
zipfile: fs_zip,
45
mountpoint: USR,
46
},
47
];
48
}
49
50