@wasm-fmt/gofmt 0.4.0 → 0.4.1

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.
package/.editorconfig CHANGED
@@ -6,6 +6,6 @@ root = true
6
6
  charset = utf-8
7
7
  trim_trailing_whitespace = true
8
8
  end_of_line = lf
9
- indent_style = space
9
+ indent_style = tab
10
10
  insert_final_newline = true
11
11
  indent_size = 4
package/gen_patch.sh CHANGED
@@ -4,20 +4,20 @@ tmp_dir=$(mktemp -d)
4
4
  cd $tmp_dir
5
5
  git init
6
6
 
7
- cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js $tmp_dir/go_wasm.js
7
+ cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js $tmp_dir/gofmt.js
8
8
  git add -f .
9
9
  git commit -m "init"
10
10
 
11
- cp $current_dir/go_wasm.js $tmp_dir/go_wasm.js
11
+ cp $current_dir/gofmt.js $tmp_dir/gofmt.js
12
12
  git add -f .
13
13
 
14
14
  git diff \
15
- --cached \
16
- --no-color \
17
- --ignore-space-at-eol \
18
- --no-ext-diff \
19
- --src-prefix=a/ \
20
- --dst-prefix=b/ \
21
- >$current_dir/go_wasm.patch
15
+ --cached \
16
+ --no-color \
17
+ --ignore-space-at-eol \
18
+ --no-ext-diff \
19
+ --src-prefix=a/ \
20
+ --dst-prefix=b/ \
21
+ >$current_dir/gofmt.patch
22
22
 
23
23
  rm -rf $tmp_dir
@@ -1,9 +1,9 @@
1
1
  export type InitInput =
2
- | RequestInfo
3
- | URL
4
- | Response
5
- | BufferSource
6
- | WebAssembly.Module;
2
+ | RequestInfo
3
+ | URL
4
+ | Response
5
+ | BufferSource
6
+ | WebAssembly.Module;
7
7
 
8
8
  export default function init(wasm_url?: InitInput): Promise<void>;
9
9
  export declare function format(input: string): string;
@@ -3,11 +3,10 @@
3
3
  // license that can be found in the LICENSE file.
4
4
  //
5
5
  // This file has been modified for use by the TinyGo compiler.
6
-
7
6
  const encoder = new TextEncoder("utf-8");
8
7
  const decoder = new TextDecoder("utf-8");
9
8
 
10
- export class Go {
9
+ class Go {
11
10
  constructor() {
12
11
  this._callbackTimeouts = new Map();
13
12
  this._nextCallbackTimeoutID = 1;
@@ -356,3 +355,72 @@
356
355
  };
357
356
  }
358
357
  }
358
+ /**
359
+ * ================== End of wasm_exec.js ==================
360
+ */
361
+ /**/let wasm;
362
+ /**/export default async function init(input) {
363
+ /**/ if (wasm) {
364
+ /**/ await wasm;
365
+ /**/ return;
366
+ /**/ }
367
+ /**/ const go = new Go();
368
+ /**/ wasm = load(input, go.importObject);
369
+ /**/ wasm = await wasm;
370
+ /**/ go.run(wasm.instance);
371
+ /**/}
372
+ /**/
373
+ /**/async function load(module, importObject) {
374
+ /**/ switch (typeof module) {
375
+ /**/ case "undefined":
376
+ /**/ module = "gofmt.wasm";
377
+ /**/ case "string":
378
+ /**/ module = new URL(module, import.meta.url);
379
+ /**/ }
380
+ /**/ if (module instanceof URL || module instanceof Request) {
381
+ /**/ if (
382
+ /**/ typeof __webpack_require__ !== "function" &&
383
+ /**/ module.protocol === "file:"
384
+ /**/ ) {
385
+ /**/ const fs = await import("node:fs/promises");
386
+ /**/ module = await fs.readFile(module);
387
+ /**/ } else {
388
+ /**/ module = await fetch(module);
389
+ /**/ }
390
+ /**/ }
391
+ /**/ if (module instanceof Response) {
392
+ /**/ if ("instantiateStreaming" in WebAssembly) {
393
+ /**/ try {
394
+ /**/ return await WebAssembly.instantiateStreaming(
395
+ /**/ module,
396
+ /**/ importObject
397
+ /**/ );
398
+ /**/ } catch (e) {
399
+ /**/ if (module.headers.get("Content-Type") != "application/wasm") {
400
+ /**/ console.warn(
401
+ /**/ "`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
402
+ /**/ e
403
+ /**/ );
404
+ /**/ } else {
405
+ /**/ throw e;
406
+ /**/ }
407
+ /**/ }
408
+ /**/ }
409
+ /**/ const bytes = await module.arrayBuffer();
410
+ /**/ return await WebAssembly.instantiate(bytes, importObject);
411
+ /**/ }
412
+ /**/ const instance = await WebAssembly.instantiate(module, importObject);
413
+ /**/ if (instance instanceof WebAssembly.Instance) {
414
+ /**/ return { instance, module };
415
+ /**/ }
416
+ /**/ return instance;
417
+ /**/}
418
+ /**/
419
+ /**/export function format(input) {
420
+ /**/ const [err, result] = wasm.instance.format(input);
421
+ /**/ if (err) {
422
+ /**/ throw new Error(result);
423
+ /**/ }
424
+ /**/ return result;
425
+ /**/}
426
+ /**/
package/package.json CHANGED
@@ -1,50 +1,50 @@
1
1
  {
2
- "name": "@wasm-fmt/gofmt",
3
- "description": "A wasm based golang formatter",
4
- "author": "magic-akari <akari.ccino@gamil.com>",
5
- "version": "0.4.0",
6
- "license": "MIT",
7
- "keywords": [
8
- "wasm",
9
- "golang",
10
- "formatter"
11
- ],
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/wasm-fmt/gofmt"
15
- },
16
- "homepage": "https://github.com/wasm-fmt/gofmt",
17
- "bugs": {
18
- "url": "https://github.com/wasm-fmt/gofmt/issues"
19
- },
20
- "type": "module",
21
- "main": "lib.js",
22
- "module": "lib.js",
23
- "types": "lib.d.ts",
24
- "exports": {
25
- ".": {
26
- "types": "./lib.d.ts",
27
- "default": "./lib.js"
28
- },
29
- "./vite": {
30
- "types": "./lib.d.ts",
31
- "default": "./vite.js"
32
- },
33
- "./package.json": "./package.json",
34
- "./*": "./*"
35
- },
36
- "scripts": {
37
- "go_wasm": "cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js ./go_wasm.js",
38
- "patch": "git apply ./go_wasm.patch",
39
- "build": "tinygo build -o=lib.wasm -target=wasm -no-debug -stack-size=24kb ./src/lib.go",
40
- "postbuild": "npm run go_wasm && npm run patch",
41
- "test": "node --test"
42
- },
43
- "engines": {
44
- "node": ">=16.17.0"
45
- },
46
- "publishConfig": {
47
- "access": "public",
48
- "provenance": true
49
- }
2
+ "name": "@wasm-fmt/gofmt",
3
+ "description": "A wasm based golang formatter",
4
+ "author": "magic-akari <akari.ccino@gamil.com>",
5
+ "version": "0.4.1",
6
+ "license": "MIT",
7
+ "keywords": [
8
+ "wasm",
9
+ "golang",
10
+ "formatter"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/wasm-fmt/gofmt"
15
+ },
16
+ "homepage": "https://github.com/wasm-fmt/gofmt",
17
+ "bugs": {
18
+ "url": "https://github.com/wasm-fmt/gofmt/issues"
19
+ },
20
+ "type": "module",
21
+ "main": "gofmt.js",
22
+ "module": "gofmt.js",
23
+ "types": "gofmt.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./gofmt.d.ts",
27
+ "default": "./gofmt.js"
28
+ },
29
+ "./vite": {
30
+ "types": "./gofmt.d.ts",
31
+ "default": "./vite.js"
32
+ },
33
+ "./package.json": "./package.json",
34
+ "./*": "./*"
35
+ },
36
+ "scripts": {
37
+ "gofmt": "cp $(tinygo env TINYGOROOT)/targets/wasm_exec.js ./gofmt.js",
38
+ "patch": "git apply ./gofmt.patch",
39
+ "build": "tinygo build -o=gofmt.wasm -target=wasm -no-debug -stack-size=24kb ./src/lib.go",
40
+ "postbuild": "npm run gofmt && npm run patch",
41
+ "test": "node --test"
42
+ },
43
+ "engines": {
44
+ "node": ">=16.17.0"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public",
48
+ "provenance": true
49
+ }
50
50
  }
package/test.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import assert from "node:assert/strict";
2
2
  import fs from "node:fs/promises";
3
3
  import test from "node:test";
4
- import init, { format } from "./lib.js";
4
+ import init, { format } from "./gofmt.js";
5
5
 
6
6
  await init();
7
7
 
package/vite.js CHANGED
@@ -1,8 +1,8 @@
1
- import init from "./lib.js";
2
- import wasm_url from "./lib.wasm?url";
1
+ import init from "./gofmt.js";
2
+ import wasm_url from "./gofmt.wasm?url";
3
3
 
4
4
  export default function (input = wasm_url) {
5
- return init(input);
5
+ return init(input);
6
6
  }
7
7
 
8
- export * from "./lib.js";
8
+ export * from "./gofmt.js";
package/lib.js DELETED
@@ -1,75 +0,0 @@
1
- import { Go } from "./go_wasm.js";
2
- const go = new Go();
3
-
4
- let wasm;
5
-
6
- export default async function init(input) {
7
- if (wasm) {
8
- await wasm;
9
- return;
10
- }
11
-
12
- wasm = load(input, go.importObject);
13
- wasm = await wasm;
14
- go.run(wasm.instance);
15
- }
16
-
17
- async function load(module, importObject) {
18
- switch (typeof module) {
19
- case "undefined":
20
- module = "lib.wasm";
21
- case "string":
22
- module = new URL(module, import.meta.url);
23
- }
24
-
25
- if (module instanceof URL || module instanceof Request) {
26
- if (
27
- typeof __webpack_require__ !== "function" &&
28
- module.protocol === "file:"
29
- ) {
30
- const fs = await import("node:fs/promises");
31
- module = await fs.readFile(module);
32
- } else {
33
- module = await fetch(module);
34
- }
35
- }
36
-
37
- if (module instanceof Response) {
38
- if ("instantiateStreaming" in WebAssembly) {
39
- try {
40
- return await WebAssembly.instantiateStreaming(
41
- module,
42
- importObject
43
- );
44
- } catch (e) {
45
- if (module.headers.get("Content-Type") != "application/wasm") {
46
- console.warn(
47
- "`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",
48
- e
49
- );
50
- } else {
51
- throw e;
52
- }
53
- }
54
- }
55
-
56
- const bytes = await module.arrayBuffer();
57
- return await WebAssembly.instantiate(bytes, importObject);
58
- }
59
- const instance = await WebAssembly.instantiate(module, importObject);
60
-
61
- if (instance instanceof WebAssembly.Instance) {
62
- return { instance, module };
63
- }
64
-
65
- return instance;
66
- }
67
-
68
- export function format(input) {
69
- const [err, result] = wasm.instance.format(input);
70
- if (err) {
71
- throw new Error(result);
72
- }
73
-
74
- return result;
75
- }
File without changes