Skip to content

Commit

Permalink
Merge pull request #31 from rrbutani/stopgap
Browse files Browse the repository at this point in the history
Update to match the changes in wasm-bindgen
  • Loading branch information
catsigma committed Jun 1, 2020
2 parents c3f73fe + fc57945 commit 098875f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions WASMbindgenAsset.js
Expand Up @@ -133,14 +133,14 @@ class WASMbindgenAsset extends Asset {
outDir,
rustName,
loc: path.join(cargoDir, 'target', RUST_TARGET, 'release')
}
}
} catch (e) {
throw `Building failed... Please install wasm-pack and try again.`
}
}

async wasmPostProcess({cargoDir, loc, outDir, rustName, target_folder}) {
let js_content = (await lib.readFile(path.join(outDir, rustName + '.js'))).toString()
let js_content = (await lib.readFile(path.join(outDir, rustName + '_bg.js'))).toString()
let wasm_path = path.relative(path.dirname(this.name), path.join(loc, rustName + '_bg.wasm'))
if (wasm_path[0] !== '.')
wasm_path = './' + wasm_path
Expand Down Expand Up @@ -188,11 +188,11 @@ class WASMbindgenAsset extends Asset {
const fetchPromise = fetch(wasm_path);
let resultPromise;
if (typeof WebAssembly.instantiateStreaming === 'function') {
resultPromise = WebAssembly.instantiateStreaming(fetchPromise, { './${rustName}.js': __exports });
resultPromise = WebAssembly.instantiateStreaming(fetchPromise, { './${rustName}_bg.js': __exports });
} else {
resultPromise = fetchPromise
.then(response => response.arrayBuffer())
.then(buffer => WebAssembly.instantiate(buffer, { './${rustName}.js': __exports }));
.then(buffer => WebAssembly.instantiate(buffer, { './${rustName}_bg.js': __exports }));
}
return resultPromise.then(({instance}) => {
wasm = init.wasm = instance.exports;
Expand All @@ -211,7 +211,7 @@ class WASMbindgenAsset extends Asset {
}
});
})
.then(data => WebAssembly.instantiate(data, { './${rustName}': __exports }))
.then(data => WebAssembly.instantiate(data, { './${rustName}_bg': __exports }))
.then(({instance}) => {
wasm = init.wasm = instance.exports;
__exports.wasm = wasm;
Expand Down

0 comments on commit 098875f

Please sign in to comment.