Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ package-lock.json
yarn-error.log
/typescript
/example-multi
.DS_Store
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ rust({

// Allows you to customize the behavior for loading the .wasm file, this is for advanced users only!
importHook: function (path) { return JSON.stringify(path); },

// Allows you to define a custom path to wasm-pack.
// Use of a '~' prefix will be converted to `os.homedir()`
wasmPackPath: "~/.cargo/bin/wasm-pack"
})
```

Expand Down
4 changes: 1 addition & 3 deletions example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ console_error_panic_hook = "0.1.6"

[dependencies.web-sys]
version = "0.3.35"
features = [
"console",
]
features = ["console"]
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
"rimraf": "^3.0.2",
"rollup": "^1.31.0"
}
}
}
19 changes: 17 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const $path = require("path");
const $child = require("child_process");
const $toml = require("toml");
const $rimraf = require("rimraf");
const $os = require("os");
const { createFilter } = require("rollup-pluginutils");


Expand Down Expand Up @@ -128,6 +129,21 @@ async function get_target_dir(dir) {
//return JSON.parse(metadata).target_directory;
}

function wasm_pack_path(options) {
if (options.wasmPackPath !== undefined) {
if (typeof (options.wasmPackPath) === "string") {
// Quick hack to allow use of "~" for home directory?
return (options.wasmPackPath.startsWith("~") ? options.wasmPackPath.replace("~", $os.homedir()) : options.wasmPackPath);
} else {
throw new Error("'wasmPackPath' must be a string")
}
} else if (process.platform === "win32") {
// TODO pretty hacky, but needed to make it work on Windows
return "wasm-pack.cmd"
} else {
return "wasm-pack"
}
}

async function wasm_pack(cx, state, dir, source, id, options) {
const target_dir = await get_target_dir(dir);
Expand All @@ -150,8 +166,7 @@ async function wasm_pack(cx, state, dir, source, id, options) {
"--",
].concat(options.cargoArgs);

// TODO pretty hacky, but needed to make it work on Windows
const command = (process.platform === "win32" ? "wasm-pack.cmd" : "wasm-pack");
const command = wasm_pack_path(options);

try {
// TODO what if it tries to build the same crate multiple times ?
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@wasm-tool/rollup-plugin-rust",
"author": "Pauan <[email protected]>",
"description": "Rollup plugin for bundling and importing Rust crates.",
"version": "1.0.7",
"version": "1.0.8",
"license": "MIT",
"repository": "github:wasm-tool/rollup-plugin-rust",
"homepage": "https://github.com/wasm-tool/rollup-plugin-rust#readme",
Expand All @@ -26,6 +26,9 @@
"rimraf": "^3.0.0",
"rollup-pluginutils": "^2.8.2",
"toml": "^3.0.0",
"os": "^0.1.2"
},
"optionalDependencies": {
"wasm-pack": "^0.10.0"
}
}
}