wasm-idle 0.2.3 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,7 +33,11 @@ export default class Clang {
33
33
  compile(options: any): Promise<App | null>;
34
34
  link(obj: string, wasm: string): Promise<App | null>;
35
35
  run(module: WebAssembly.Module, out: boolean, ...args: string[]): Promise<App | null>;
36
- compileLink(code: string): Promise<any>;
37
- compileLinkRun(code: string): Promise<App | null>;
36
+ compileLink(code: string, { args }?: {
37
+ args?: never[] | undefined;
38
+ }): Promise<any>;
39
+ compileLinkRun(code: string, { args }?: {
40
+ args?: never[] | undefined;
41
+ }): Promise<App | null>;
38
42
  }
39
43
  export {};
@@ -108,7 +108,7 @@ export default class Clang {
108
108
  await this.ready;
109
109
  this.memfs.addFile(input, code);
110
110
  const clang = await this.getModule(clangUrl(this.path));
111
- return await this.run(clang, true, 'clang', '-cc1', '-emit-obj', ...clangCommonArgs, '-O' + opt, '-o', obj, '-std=c++17', '-x', 'c++', input);
111
+ return await this.run(clang, true, 'clang', '-cc1', '-emit-obj', ...clangCommonArgs, '-O' + opt, '-o', obj, '-std=c++17', '-x', 'c++', input, ...(options.args || []));
112
112
  }
113
113
  async link(obj, wasm) {
114
114
  const stackSize = 1024 * 1024;
@@ -133,16 +133,16 @@ export default class Clang {
133
133
  this.stdout(`${green}(${start - instantiate}ms/${end - instantiate}ms)${normal}\n`);
134
134
  return stillRunning ? app : null;
135
135
  }
136
- async compileLink(code) {
136
+ async compileLink(code, { args = [] } = {}) {
137
137
  const input = `test.cc`, obj = `test.o`, wasm = `test.wasm`;
138
138
  if (this.lastCode === code)
139
139
  return this.wasm;
140
- await this.compile({ input, code, obj });
140
+ await this.compile({ input, code, obj, args });
141
141
  await this.link(obj, wasm);
142
142
  this.lastCode = code;
143
143
  return (this.wasm = await this.hostLogAsync(`Compiling ${wasm}`, WebAssembly.compile(this.memfs.getFileContents(wasm))));
144
144
  }
145
- async compileLinkRun(code) {
146
- return await this.run(await this.compileLink(code), true, `test.wasm`);
145
+ async compileLinkRun(code, { args = [] } = {}) {
146
+ return await this.run(await this.compileLink(code, { args }), true, `test.wasm`);
147
147
  }
148
148
  }
@@ -12,11 +12,11 @@ declare class Clang implements Sandbox {
12
12
  uid: number;
13
13
  log: boolean;
14
14
  exit: boolean;
15
- load(path: string, code?: string, log?: boolean): Promise<void>;
15
+ load(path: string, code?: string, log?: boolean, args?: never[]): Promise<void>;
16
16
  write(input: string): void;
17
17
  _write(input: string): void;
18
18
  eof(): void;
19
- run(code: string, prepare: boolean, log?: boolean, prog?: Writable<number>): Promise<string>;
19
+ run(code: string, prepare: boolean, log?: boolean, prog?: Writable<number>, args?: never[]): Promise<string>;
20
20
  terminate(): void;
21
21
  clear(): Promise<void>;
22
22
  }
@@ -10,14 +10,14 @@ class Clang {
10
10
  uid = 0;
11
11
  log = true;
12
12
  exit = true;
13
- load(path, code = '', log = true) {
13
+ load(path, code = '', log = true, args = []) {
14
14
  return new Promise(async (resolve) => {
15
15
  this.log = log;
16
16
  this.internalBuffer = [];
17
17
  if (!this.worker) {
18
18
  this.worker = new (await import('./worker/clang?worker')).default();
19
19
  this.worker.onmessage = () => resolve();
20
- this.worker.postMessage({ load: true, path, log, code });
20
+ this.worker.postMessage({ load: true, path, log, code, args });
21
21
  }
22
22
  else {
23
23
  this.worker.postMessage({ log });
@@ -39,7 +39,7 @@ class Clang {
39
39
  buffer.set(new Int32Array(data.buffer.slice(data.byteOffset), 0));
40
40
  }
41
41
  eof() { }
42
- run(code, prepare, log = this.log, prog) {
42
+ run(code, prepare, log = this.log, prog, args = []) {
43
43
  this.exit = false;
44
44
  return new Promise(async (resolve, reject) => {
45
45
  if (!this.worker)
@@ -78,7 +78,8 @@ class Clang {
78
78
  buffer: this.buffer,
79
79
  interrupt: this.interruptBuffer,
80
80
  context: {},
81
- log
81
+ log,
82
+ args
82
83
  });
83
84
  });
84
85
  }
@@ -33,7 +33,7 @@ async function loadClang(path, log) {
33
33
  });
34
34
  }
35
35
  self.onmessage = async (event) => {
36
- const { code, buffer, load, interrupt, log, path, prepare } = event.data;
36
+ const { code, buffer, load, interrupt, log, path, prepare, args } = event.data;
37
37
  if (load) {
38
38
  await loadClang(path, log);
39
39
  postMessage({ load: true });
@@ -42,7 +42,7 @@ self.onmessage = async (event) => {
42
42
  stdinBufferClang = new Int32Array(buffer);
43
43
  interruptBufferClang = new Uint8Array(interrupt);
44
44
  try {
45
- await clang.compileLink(code);
45
+ await clang.compileLink(code, { args });
46
46
  self.postMessage({ results: true });
47
47
  }
48
48
  catch (error) {
@@ -54,7 +54,7 @@ self.onmessage = async (event) => {
54
54
  stdinBufferClang = new Int32Array(buffer);
55
55
  interruptBufferClang = new Uint8Array(interrupt);
56
56
  try {
57
- await clang.compileLinkRun(code);
57
+ await clang.compileLinkRun(code, { args });
58
58
  self.postMessage({ results: true });
59
59
  }
60
60
  catch (error) {
@@ -103,19 +103,19 @@
103
103
  first = true;
104
104
  await new Promise((r) => setTimeout(r, 100));
105
105
  },
106
- async prepare(language: string, code: string, log = true, prog) {
106
+ async prepare(language: string, code: string, log = true, prog, args) {
107
107
  await Promise.all([
108
108
  initSandbox(language).then(() => sandbox.load(path, code, log)),
109
109
  initTerm(false)
110
110
  ]);
111
- return await runSandbox(sandbox.run(code, true, log, prog));
111
+ return await runSandbox(sandbox.run(code, true, log, prog, args));
112
112
  },
113
- async run(language: string, code: string, log = true, prog) {
113
+ async run(language: string, code: string, log = true, prog, args) {
114
114
  await Promise.all([
115
115
  initSandbox(language).then(() => sandbox.load(path, code, log)),
116
116
  initTerm()
117
117
  ]);
118
- return await runSandbox(sandbox.run(code, false, log, prog));
118
+ return await runSandbox(sandbox.run(code, false, log, prog, args));
119
119
  },
120
120
  async destroy() {
121
121
  await wait();
@@ -8,8 +8,8 @@ declare const Terminal: import("svelte").Component<{
8
8
  onkey?: (e: KeyboardEvent) => void;
9
9
  terminal?: {
10
10
  clear(): Promise<void>;
11
- prepare(language: string, code: string, log: boolean | undefined, prog: any): Promise<boolean>;
12
- run(language: string, code: string, log: boolean | undefined, prog: any): Promise<boolean>;
11
+ prepare(language: string, code: string, log: boolean | undefined, prog: any, args: any): Promise<boolean>;
12
+ run(language: string, code: string, log: boolean | undefined, prog: any, args: any): Promise<boolean>;
13
13
  destroy(): Promise<void>;
14
14
  write(input: string): Promise<void>;
15
15
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wasm-idle",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "A simple web app to run C++/Python code in the browser",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -69,5 +69,10 @@
69
69
  }
70
70
  },
71
71
  "svelte": "./dist/index.js",
72
- "types": "./dist/index.d.ts"
72
+ "types": "./dist/index.d.ts",
73
+ "pnpm": {
74
+ "onlyBuiltDependencies": [
75
+ "esbuild"
76
+ ]
77
+ }
73
78
  }