Skip to content

Commit 8874217

Browse files
authored
do that
1 parent 4e5b3cd commit 8874217

File tree

5 files changed

+867
-5
lines changed

5 files changed

+867
-5
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,60 @@ console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
3131
| <a href="https://github.com/jcbhmr/hello-world-rust-wasm-component-lib">WASM project</a>
3232
</p>
3333

34+
🏷️ Using v1.0.0 of [jcbhmr/hello-world-rust-wasm-component-lib] \
35+
🦀 WASM is written in Rust \
36+
🟦 Includes TypeScript type definitions \
37+
📦 Published as an npm package \
38+
👩‍⚖️ [0BSD licensed] template
39+
3440
## Installation
3541

42+
![npm](https://img.shields.io/static/v1?style=for-the-badge&message=npm&color=CB3837&logo=npm&logoColor=FFFFFF&label=)
43+
![Yarn](https://img.shields.io/static/v1?style=for-the-badge&message=Yarn&color=2C8EBB&logo=Yarn&logoColor=FFFFFF&label=)
44+
![pnpm](https://img.shields.io/static/v1?style=for-the-badge&message=pnpm&color=222222&logo=pnpm&logoColor=F69220&label=)
45+
![Deno](https://img.shields.io/static/v1?style=for-the-badge&message=Deno&color=000000&logo=Deno&logoColor=FFFFFF&label=)
46+
![Bun](https://img.shields.io/static/v1?style=for-the-badge&message=Bun&color=000000&logo=Bun&logoColor=FFFFFF&label=)
47+
![jsDelivr](https://img.shields.io/static/v1?style=for-the-badge&message=jsDelivr&color=E84D3D&logo=jsDelivr&logoColor=FFFFFF&label=)
48+
49+
You can install this package using your favorite npm package manager like npm,
50+
[Yarn], [pnpm], or [Bun].
51+
3652
```sh
3753
npm install hello-world-rust-wasm-component-lib
3854
```
3955

56+
If you're using [Deno] you can import it straight from npm:
57+
58+
```js
59+
import {} from "npm:hello-world-rust-wasm-component-lib";
60+
```
61+
62+
If you prefer to go buildless in the browser you can use an npm CDN like
63+
[jsDelivr] or [esm.sh].
64+
65+
```html
66+
<script type="module">
67+
import {} from "https://esm.run/hello-world-rust-wasm-component-lib";
68+
</script>
69+
```
70+
4071
## Usage
4172

73+
![Node.js](https://img.shields.io/static/v1?style=for-the-badge&message=Node.js&color=339933&logo=Node.js&logoColor=FFFFFF&label=)
74+
![Deno](https://img.shields.io/static/v1?style=for-the-badge&message=Deno&color=000000&logo=Deno&logoColor=FFFFFF&label=)
75+
![Bun](https://img.shields.io/static/v1?style=for-the-badge&message=Bun&color=000000&logo=Bun&logoColor=FFFFFF&label=)
76+
![Browser](https://img.shields.io/static/v1?style=for-the-badge&message=Browser&color=4285F4&logo=Google+Chrome&logoColor=FFFFFF&label=)
77+
78+
You should be able to just import and use this JavaScript package like any
79+
other. The WASM magic is hidden behind a really nice wrapper layer.
80+
4281
```js
4382
import {
44-
greet,
4583
greetMany,
4684
run,
4785
getReport,
4886
computeArea,
49-
} from "./dist/hello_world_rust_wasm_component_lib.js";
87+
} from "hello-world-rust-wasm-component-lib";
5088

5189
run();
5290
//=> Hello Alan Turing!
@@ -66,3 +104,29 @@ console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
66104
//=> Hello, Alan Turing!
67105
// Hello, Ada Lovelace!
68106
```
107+
108+
[📚 Read more about the API surface on the documentation website](https://tsdocs.dev/docs/hello-world-rust-wasm-component-lib)
109+
110+
## Development
111+
112+
![Node.js](https://img.shields.io/static/v1?style=for-the-badge&message=Node.js&color=339933&logo=Node.js&logoColor=FFFFFF&label=)
113+
![JavaScript](https://img.shields.io/static/v1?style=for-the-badge&message=JavaScript&color=222222&logo=JavaScript&logoColor=F7DF1E&label=)
114+
115+
**Versioning scheme:** Use `1.2.3+4.5.6` where `1.2.3` is the main JS bindings
116+
API version (this package) and `4.5.6` is the version of the upstream WASM
117+
underlying library that was used to generate the JavaScript bindings. The
118+
`1.2.3+4.5.6` versioning scheme was adopted so that users of a particular
119+
version can quickly see which version of the WASM library was used. Note that
120+
the `+4.5.6` part is **just metadata**. You can't publish both `1.2.3+4.5.6` and
121+
`1.2.3+7.8.9`. Think of it like a super important `"description"` field.
122+
123+
<!-- prettier-ignore-start -->
124+
[jcbhmr/hello-world-rust-wasm-component-lib]: https://github.com/jcbhmr/hello-world-rust-wasm-component-lib
125+
[Yarn]: https://yarnpkg.com/
126+
[pnpm]: https://pnpm.io/
127+
[Bun]: https://bun.sh/
128+
[Deno]: https://deno.com/
129+
[jsDelivr]: https://www.jsdelivr.com/
130+
[esm.sh]: https://esm.sh/
131+
[0BSD licensed]: https://github.com/jcbhmr/hello-world-rust-wasm-component-lib.js/blob/main/LICENSE
132+
<!-- prettier-ignore-end -->

index (2).html

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<p>Check DevTools for more info</p>
2+
<pre id="pre"></pre>
3+
<script type="module">
4+
const tests = [];
5+
const test = (name, fn) => tests.push({ name, fn });
6+
setTimeout(async () => {
7+
for (const { name, fn } of tests) {
8+
try {
9+
await fn();
10+
console.log(`%c✔ ${name}`, "color: green");
11+
pre.append(`✔ ${name}\n`);
12+
} catch (error) {
13+
console.log(`%c✘ ${name}`, "color: red");
14+
pre.append(`✘ ${name}\n`);
15+
console.error(error);
16+
pre.append(`${error}\n`);
17+
}
18+
}
19+
}, 100);
20+
import assert from "node:assert";
21+
import * as hello_world_rust_wasm_component_lib from "./dist/hello_world_rust_wasm_component_lib.js";
22+
import {
23+
greet,
24+
greetMany,
25+
run,
26+
getReport,
27+
computeArea,
28+
} from "./dist/hello_world_rust_wasm_component_lib.js";
29+
30+
console.log(hello_world_rust_wasm_component_lib);
31+
32+
test("greet() works", () => {
33+
console.log(greet("Alan Turing"));
34+
});
35+
36+
test("greetMany() works", () => {
37+
console.log(greetMany(["Alan Turing", "Ada Lovelace"]));
38+
});
39+
40+
test("run() works", () => {
41+
run();
42+
});
43+
44+
test("getReport() works", () => {
45+
console.log(getReport());
46+
});
47+
48+
test("computeArea() works", () => {
49+
console.log(
50+
computeArea({
51+
center: { x: 0, y: 0 },
52+
radius: 6,
53+
})
54+
);
55+
console.log("from JS", Math.PI * 6 * 6);
56+
});
57+
</script>

just

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ set -e
33

44
build()(
55
wasm_version=$(echo "${npm_package_version:?}" | cut -d+ -f2)
6+
67
echo "Downloading hello_world_rust_wasm_component_lib.wasm v$wasm_version"
78
mkdir -p out
89
curl -fsSL "https://github.com/jcbhmr/hello-world-rust-wasm-component-lib/releases/download/v$wasm_version/hello_world_rust_wasm_component_lib.wasm" \
910
-o out/hello_world_rust_wasm_component_lib.wasm
11+
1012
echo "Creating JavaScript for hello_world_rust_wasm_component_lib.wasm"
1113
jco transpile out/hello_world_rust_wasm_component_lib.wasm -o dist \
1214
--map print=../print.js
15+
1316
echo "Fixing imports in hello_world_rust_wasm_component_lib.d.ts"
1417
sed -i.bak 's/\.\.\/interfaces/.\/interfaces/g' \
1518
dist/hello_world_rust_wasm_component_lib.d.ts

0 commit comments

Comments
 (0)