@flowscripter/template-bun-wasm-rust-library 1.3.2 → 1.3.4

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/README.md CHANGED
@@ -58,7 +58,7 @@ Lint:
58
58
 
59
59
  `cargo fmt && bunx oxlint index.ts src/ tests/`
60
60
 
61
- Generate HTML API Documentation:
61
+ Generate HTML API documentation:
62
62
 
63
63
  `bunx typedoc index.ts`
64
64
 
package/dist/index.js CHANGED
@@ -1,101 +1 @@
1
- // @bun
2
- // pkg/flowscripter_template_bun_wasm_rust_library.js
3
- function add(a, b) {
4
- const ret = wasm.add(a, b);
5
- return ret;
6
- }
7
- function __wbg_get_imports() {
8
- const import0 = {
9
- __proto__: null,
10
- __wbindgen_init_externref_table: function() {
11
- const table = wasm.__wbindgen_externrefs;
12
- const offset = table.grow(4);
13
- table.set(0, undefined);
14
- table.set(offset + 0, undefined);
15
- table.set(offset + 1, null);
16
- table.set(offset + 2, true);
17
- table.set(offset + 3, false);
18
- }
19
- };
20
- return {
21
- __proto__: null,
22
- "./flowscripter_template_bun_wasm_rust_library_bg.js": import0
23
- };
24
- }
25
- var wasmModule;
26
- var wasmInstance;
27
- var wasm;
28
- function __wbg_finalize_init(instance, module) {
29
- wasmInstance = instance;
30
- wasm = instance.exports;
31
- wasmModule = module;
32
- wasm.__wbindgen_start();
33
- return wasm;
34
- }
35
- async function __wbg_load(module, imports) {
36
- if (typeof Response === "function" && module instanceof Response) {
37
- if (typeof WebAssembly.instantiateStreaming === "function") {
38
- try {
39
- return await WebAssembly.instantiateStreaming(module, imports);
40
- } catch (e) {
41
- const validResponse = module.ok && expectedResponseType(module.type);
42
- if (validResponse && module.headers.get("Content-Type") !== "application/wasm") {
43
- console.warn("`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", e);
44
- } else {
45
- throw e;
46
- }
47
- }
48
- }
49
- const bytes = await module.arrayBuffer();
50
- return await WebAssembly.instantiate(bytes, imports);
51
- } else {
52
- const instance = await WebAssembly.instantiate(module, imports);
53
- if (instance instanceof WebAssembly.Instance) {
54
- return { instance, module };
55
- } else {
56
- return instance;
57
- }
58
- }
59
- function expectedResponseType(type) {
60
- switch (type) {
61
- case "basic":
62
- case "cors":
63
- case "default":
64
- return true;
65
- }
66
- return false;
67
- }
68
- }
69
- async function __wbg_init(module_or_path) {
70
- if (wasm !== undefined)
71
- return wasm;
72
- if (module_or_path !== undefined) {
73
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
74
- ({ module_or_path } = module_or_path);
75
- } else {
76
- console.warn("using deprecated parameters for the initialization function; pass a single object instead");
77
- }
78
- }
79
- if (module_or_path === undefined) {
80
- module_or_path = new URL("flowscripter_template_bun_wasm_rust_library_bg.wasm", import.meta.url);
81
- }
82
- const imports = __wbg_get_imports();
83
- if (typeof module_or_path === "string" || typeof Request === "function" && module_or_path instanceof Request || typeof URL === "function" && module_or_path instanceof URL) {
84
- module_or_path = fetch(module_or_path);
85
- }
86
- const { instance, module } = await __wbg_load(await module_or_path, imports);
87
- return __wbg_finalize_init(instance, module);
88
- }
89
-
90
- // pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm
91
- var flowscripter_template_bun_wasm_rust_library_bg_default = "./flowscripter_template_bun_wasm_rust_library_bg-rbwp754y.wasm";
92
-
93
- // src/lib.ts
94
- var wasmBuffer = typeof Bun !== "undefined" ? await Bun.file(flowscripter_template_bun_wasm_rust_library_bg_default).arrayBuffer() : await fetch(flowscripter_template_bun_wasm_rust_library_bg_default).then((response) => response.arrayBuffer());
95
- async function world() {
96
- await __wbg_init({ module_or_path: wasmBuffer });
97
- console.info(`World ${add(3, 3)}`);
98
- }
99
- export {
100
- world
101
- };
1
+ export * from "./src/lib.js";
@@ -1 +1 @@
1
- {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AASA;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C"}
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../src/lib.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,wBAAsB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAM3C"}
@@ -0,0 +1,17 @@
1
+ // oxlint-disable-next-line typescript/triple-slash-reference -- ambient .wasm module type must ship alongside this file for consumers
2
+ /// <reference path="./wasm-module.d.ts" />
3
+ import init, { add } from "../pkg/flowscripter_template_bun_wasm_rust_library.js";
4
+ // TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be removed
5
+ import wasm from "../pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm";
6
+ const wasmBuffer = typeof Bun !== "undefined"
7
+ ? await Bun.file(wasm).arrayBuffer()
8
+ : await fetch(wasm).then((response) => response.arrayBuffer());
9
+ /**
10
+ * Adds 3 and 3 and logs the result as "World 6"
11
+ */
12
+ export async function world() {
13
+ // init WASM module
14
+ // TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be simply `await init();`
15
+ await init({ module_or_path: wasmBuffer });
16
+ console.info(`World ${add(3, 3)}`);
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowscripter/template-bun-wasm-rust-library",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Project template for a Rust library compiled to WASM exposed as a Bun module",
5
5
  "keywords": [
6
6
  "bun",
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "scripts": {
42
- "build": "wasm-pack build --target web --release --no-pack && rm pkg/.gitignore && bun build index.ts --outdir dist --target bun && tsc -p tsconfig.build.json"
42
+ "build": "wasm-pack build --target web --release --no-pack && rm pkg/.gitignore && rm pkg/flowscripter_template_bun_wasm_rust_library_bg.wasm.d.ts && bun build index.ts --outdir dist --target bun && tsc -p tsconfig.build.json"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/bun": "^1.3.14",
package/src/lib.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // oxlint-disable-next-line typescript/triple-slash-reference -- ambient .wasm module type must ship alongside this file for consumers
2
+ /// <reference path="./wasm-module.d.ts" />
1
3
  import init, { add } from "../pkg/flowscripter_template_bun_wasm_rust_library.js";
2
4
 
3
5
  // TODO: when https://github.com/oven-sh/bun/pull/20503 is released I believe the following can be removed
@@ -0,0 +1,4 @@
1
+ declare module "*.wasm" {
2
+ const path: string;
3
+ export default path;
4
+ }
@@ -1,21 +0,0 @@
1
- /**
2
- * Adds two numbers together.
3
- *
4
- *
5
- * # Examples
6
- * ```
7
- * let arg1 = 3;
8
- * let arg2 = 3;
9
- * let answer = flowscripter_template_bun_wasm_rust_library::add(arg1, arg2);
10
- *
11
- * assert_eq!(6, answer);
12
- * ```
13
- * @param {number} a
14
- * @param {number} b
15
- * @returns {number}
16
- */
17
- export function add(a: number, b: number): number;
18
- export function initSync(module: any): any;
19
- declare function __wbg_init(module_or_path: any): Promise<any>;
20
- export { __wbg_init as default };
21
- //# sourceMappingURL=flowscripter_template_bun_wasm_rust_library.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"flowscripter_template_bun_wasm_rust_library.d.ts","sourceRoot":"","sources":["../../pkg/flowscripter_template_bun_wasm_rust_library.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,uBAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAKlB;AAgED,2CAkBC;AAED,+DAwBC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=world_test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"world_test.d.ts","sourceRoot":"","sources":["../../tests/world_test.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- /* tslint:disable */
2
- /* eslint-disable */
3
- export const memory: WebAssembly.Memory;
4
- export const add: (a: number, b: number) => number;
5
- export const __wbindgen_externrefs: WebAssembly.Table;
6
- export const __wbindgen_start: () => void;