-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow importing as native browser module, tests
- Loading branch information
1 parent
7b37f12
commit 8c48e49
Showing
19 changed files
with
270 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
TARGETS=nodejs browser | ||
TARGETS=nodejs browser web | ||
MODE=dev | ||
|
||
RUST_WASM_SRC = $(wildcard rs/wasm/src/*.rs) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as blake3 from './esm/browser'; | ||
|
||
/** | ||
* Manually loads the WebAssembly module, returning a promise that resolves | ||
* to the BLAKE3 implementation once available. | ||
*/ | ||
export default function load(module: string | URL | Request | object): Promise<typeof blake3>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { provideWasm } from './esm/browser/wasm.js'; | ||
import * as wasm from './dist/wasm/web/blake3_js.js'; | ||
import * as blake3 from './esm/browser/index.js'; | ||
|
||
let cached; | ||
|
||
/** | ||
* Manually loads the WebAssembly module, returning a promise that resolves | ||
* to the BLAKE3 implementation once available. | ||
*/ | ||
export default function load(module) { | ||
if (!cached) { | ||
cached = wasm.default(module).then(() => { | ||
provideWasm(wasm); | ||
return blake3; | ||
}); | ||
} | ||
|
||
return cached; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>blake3 import async test</title> | ||
</head> | ||
|
||
<body> | ||
<script type="module"> | ||
import init from './browser-async.js'; | ||
init().then(blake3 => window.blake3 = blake3).catch(console.error); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
import { provideWasm } from './esm/browser/wasm'; | ||
import * as wasm from './dist/wasm/browser'; | ||
|
||
provideWasm(wasm); | ||
|
||
export * from './esm/browser'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.