Skip to content

Commit 1eaeed4

Browse files
authored
feat: use webassembly-loader internally (#26)
* feat: use webassembly-loader internally * ci: lock Rust version to 1.28.0 * test: reconfigure due to integration and lockup ♦️ rename .babelrc to babel.config.js to make babel respect node_modules/ ♦️ force jest to use "module" instead of "main" in package.json when doing import/require for some packages ♦️ remove use of #[wasm_import_module] macro since Rust v1.28 not support it * docs: update README due to loader integration
1 parent 8a3d861 commit 1eaeed4

File tree

13 files changed

+145
-158
lines changed

13 files changed

+145
-158
lines changed

.babelrc

Lines changed: 0 additions & 16 deletions
This file was deleted.

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ rustup_nightly: &rustup_nightly
55
name: Install Cargo and Rust compiler
66
command: |
77
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> $BASH_ENV
8-
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly
8+
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain 1.28.0
99
source $BASH_ENV
10-
rustup target add wasm32-unknown-unknown --toolchain nightly
10+
rustup target add wasm32-unknown-unknown
1111
1212
smoke_tests: &smoke_tests
1313
steps:

README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
</div>
99

1010
[![npm][npm]][npm-url]
11-
[![node][node]][node-url]
1211
[![size][size]][size-url]
1312
[![npm][npm-download]][npm-url]
1413
[![deps][deps]][deps-url]
@@ -28,6 +27,20 @@ This is a rollup plugin that loads Rust code so it can be interop with Javascrip
2827

2928
## Requirements
3029

30+
<ul>
31+
<li>Node v8 or later</li>
32+
<li>Rollup v0.64 or later</li>
33+
<li><details>
34+
<summary>Rust v1.28.0 with wasm32-uknown-unknown installed</summary>
35+
36+
```console
37+
rustup default 1.28.0
38+
rustup target add wasm32-unknown-unknown
39+
```
40+
41+
</details></li>
42+
</ul>
43+
3144
This module requires a minimum of Node v8.9.0, Rollup v0.64.0, and Rust in [nightly channel][].
3245

3346
## Getting Started
@@ -89,17 +102,7 @@ And run `rollup` via your preferred method.
89102
<details>
90103
<summary><b><code>export</code></b></summary>
91104

92-
- Type: `string`
93-
- Default: `promise`
94-
- Expected value:
95-
- `buffer` will export wasm code as [Buffer][]
96-
- `module` will export wasm code as [WebAssembly.Module][]
97-
- `instance` will export wasm code as [WebAssembly.Instance][]
98-
- `async` will [instantiate][webassembly.instantiate] wasm code asynchronously, return promise of both [WebAssembly.Module][] and [WebAssembly.Instance][]
99-
- `async-module` will [compile][webassembly.compile] wasm code asynchronously, return promise of [WebAssembly.Module][]
100-
- `async-instance` will [instantiate][webassembly.instantiate] wasm code asynchronously, return promise of [WebAssembly.Instance][]
101-
102-
How wasm code would be exported. (see [examples](#examples))
105+
How wasm code would be exported. This options is identical with [option `export` in webassembly-loader][webassembly-loader]. (see [examples](#examples))
103106

104107
```js
105108
// in your rollup.config.js
@@ -333,17 +336,10 @@ wasmCompile(importObject | undefined).then(module => {
333336

334337
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2FDrSensor%2Frollup-plugin-rust.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2FDrSensor%2Frollup-plugin-rust?ref=badge_large)
335338

336-
[nightly channel]: https://rustwasm.github.io/book/game-of-life/setup.html#the-wasm32-unknown-unknown-target
337-
[buffer]: https://nodejs.org/api/buffer.html
338-
[webassembly.module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module
339-
[webassembly.instance]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance
340-
[webassembly.instantiate]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate
341-
[webassembly.compile]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile
339+
[webassembly-loader]: https://github.com/DrSensor/webassembly-loader#export
342340
[npm]: https://img.shields.io/npm/v/rollup-plugin-rust.svg
343341
[npm-url]: https://npmjs.com/package/rollup-plugin-rust
344342
[npm-download]: https://img.shields.io/npm/dm/rollup-plugin-rust.svg
345-
[node]: https://img.shields.io/node/v/rollup-plugin-rust.svg
346-
[node-url]: https://nodejs.org
347343
[deps]: https://david-dm.org/DrSensor/rollup-plugin-rust.svg
348344
[deps-url]: https://david-dm.org/DrSensor/rollup-plugin-rust
349345
[tests]: https://img.shields.io/circleci/project/github/DrSensor/rollup-plugin-rust.svg

babel.config.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
presets: [
3+
[
4+
"@babel/env",
5+
{
6+
targets: {node: 8},
7+
modules: false
8+
}
9+
],
10+
"@babel/flow"
11+
],
12+
plugins: ["@babel/proposal-export-namespace-from"],
13+
env: {
14+
test: {
15+
presets: ["@babel/env", "@babel/flow"]
16+
}
17+
}
18+
}

jest.config.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
module.exports = {
2-
projects: [
3-
{
4-
displayName: "test",
5-
testEnvironment: "node",
6-
setupTestFrameworkScriptFile: "./jest.setup.js"
7-
},
8-
{
9-
displayName: "lint",
10-
runner: "jest-runner-eslint",
11-
testMatch: ["<rootDir>/src/**/*.js"]
12-
}
2+
testEnvironment: "node",
3+
resolver: "./script/resolveModule.js",
4+
setupTestFrameworkScriptFile: "./jest.setup.js",
5+
transformIgnorePatterns: [
6+
"node_modules/(?!(rollup.*)|(estree.*)|(webassembly-loader)/)"
137
]
148
}

package-lock.json

Lines changed: 39 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "dist/index.js",
66
"typings": "index.d.ts",
77
"scripts": {
8-
"build": "flow && rollup -c",
8+
"build": "rollup -c",
99
"dev": "flow && rollup -c -w || true",
1010
"lint": "flow && eslint --cache src test flow-typed/*.js || true",
1111
"lint:fix": "eslint --fix src test flow-typed/*.js",
@@ -76,7 +76,8 @@
7676
"rollup-plugin-node-resolve": "^3.3.0",
7777
"rollup-plugin-prettier": "^0.4.0",
7878
"rust-native-wasm-loader": "^0.8.1",
79-
"standard-version": "^4.4.0"
79+
"standard-version": "^4.4.0",
80+
"webassembly-loader": "^1.1.0"
8081
},
8182
"lint-staged": {
8283
"*.js": ["flow focus-check", "eslint"]

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ export default [
3737
experimentalCodeSplitting: true,
3838
plugins: [
3939
eslint(),
40-
resolve(),
4140
babel(),
4241
commonjs(),
42+
resolve(),
4343
autoExternal(),
4444
prettier(prettierrc.files("*.js"))
4545
]

0 commit comments

Comments
 (0)