Skip to content

Commit c3e0676

Browse files
authored
Merge pull request #25 from pauldorehill/master
Add ability to run on Apple silicon
2 parents 66bc066 + ab68bc7 commit c3e0676

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ package-lock.json
55
yarn-error.log
66
/typescript
77
/example-multi
8+
.DS_Store

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ rust({
134134

135135
// Allows you to customize the behavior for loading the .wasm file, this is for advanced users only!
136136
importHook: function (path) { return JSON.stringify(path); },
137+
138+
// Allows you to define a custom path to wasm-pack.
139+
// If the path starts with '~' it will be converted to `os.homedir()`
140+
// eg. "~/.cargo/bin/wasm-pack -> "/Users/user_name/.cargo/bin/wasm-pack"
141+
wasmPackPath: "node_modules/.bin/wasm-pack"
137142
})
138143
```
139144

example/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ console_error_panic_hook = "0.1.6"
1515
[dependencies.web-sys]
1616
version = "0.3.35"
1717
features = [
18-
"console",
19-
]
18+
"console"
19+
]

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
"rimraf": "^3.0.2",
1212
"rollup": "^1.31.0"
1313
}
14-
}
14+
}

index.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const $path = require("path");
44
const $child = require("child_process");
55
const $toml = require("toml");
66
const $rimraf = require("rimraf");
7+
const $os = require("os");
78
const { createFilter } = require("rollup-pluginutils");
89

910

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

132+
function wasm_pack_path(options) {
133+
if (options.wasmPackPath !== undefined) {
134+
if (typeof (options.wasmPackPath) === "string") {
135+
// Quick hack to allow use of "~" for home directory?
136+
return (options.wasmPackPath.startsWith("~") ? options.wasmPackPath.replace("~", $os.homedir()) : options.wasmPackPath);
137+
} else {
138+
throw new Error("'wasmPackPath' must be a string")
139+
}
140+
} else if (process.platform === "win32") {
141+
// TODO pretty hacky, but needed to make it work on Windows
142+
return "wasm-pack.cmd"
143+
} else {
144+
return "wasm-pack"
145+
}
146+
}
131147

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

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

156171
try {
157172
// TODO what if it tries to build the same crate multiple times ?

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"glob": "^7.1.6",
2626
"rimraf": "^3.0.0",
2727
"rollup-pluginutils": "^2.8.2",
28-
"toml": "^3.0.0",
28+
"toml": "^3.0.0"
29+
},
30+
"optionalDependencies": {
2931
"wasm-pack": "^0.10.0"
3032
}
31-
}
33+
}

0 commit comments

Comments
 (0)