@wasm-fmt/gofmt 0.0.3 → 0.1.0

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.
Files changed (3) hide show
  1. package/lib.d.ts +4 -1
  2. package/lib.js +12 -6
  3. package/package.json +1 -1
package/lib.d.ts CHANGED
@@ -1 +1,4 @@
1
- export declare function format(input: string): Promise<string>;
1
+ export declare function format(
2
+ input: string,
3
+ wasm_url?: string | URL
4
+ ): Promise<string>;
package/lib.js CHANGED
@@ -3,18 +3,24 @@ const go = new Go();
3
3
 
4
4
  let mod;
5
5
 
6
- export async function format(input) {
6
+ export async function format(input, wasm_url) {
7
7
  if (!mod) {
8
- const url = new URL("lib.wasm", import.meta.url);
8
+ if (!wasm_url) {
9
+ wasm_url = new URL("lib.wasm", import.meta.url);
10
+ }
11
+
12
+ if (typeof wasm_url === "string") {
13
+ wasm_url = new URL(wasm_url);
14
+ }
9
15
 
10
- if (url.protocol === "file:") {
16
+ if (wasm_url.protocol === "file:") {
11
17
  const fs = await import("node:fs");
12
- const bytes = fs.readFileSync(url);
18
+ const bytes = fs.readFileSync(wasm_url);
13
19
  mod = new WebAssembly.Module(bytes);
14
20
  } else if ("instantiateStreaming" in WebAssembly) {
15
- mod = await WebAssembly.compileStreaming(fetch(url), go.importObject);
21
+ mod = await WebAssembly.compileStreaming(fetch(wasm_url), go.importObject);
16
22
  } else {
17
- const response = await fetch(url);
23
+ const response = await fetch(wasm_url);
18
24
  const bytes = await response.arrayBuffer();
19
25
  mod = new WebAssembly.Module(bytes);
20
26
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wasm-fmt/gofmt",
3
3
  "author": "magic-akari <akari.ccino@gamil.com>",
4
- "version": "0.0.3",
4
+ "version": "0.1.0",
5
5
  "description": "wasm based gofmt",
6
6
  "main": "lib.js",
7
7
  "types": "lib.d.ts",