Conversation
Now we look for the standard Web Cryptography API before attempting to
check for Node.js support. This allows Node.js ES6 module users to add
a polyfill like:
```js
import {webcrypto} from 'crypto'
globalThis.crypto = webcrypto
```
as described in #256 (comment)
Signed-off-by: Joe Richey <joerichey@google.com>
This allows users to get an actionable error message about this particular problem. We also add detection for this problem. Signed-off-by: Joe Richey <joerichey@google.com>
newpavlov
left a comment
There was a problem hiding this comment.
Looks fine to me, but note that I am not familiar enough with the JS targets to judge quality of this solution.
I'm not so sure about the implementation quality myself, I did try changing around some of the names of functions to make sure errors occurred when they "should". The main feedback I was looking to get was mostly on the documentation, and error messages. |
maccesch
left a comment
There was a problem hiding this comment.
I'm not an expert for this either but from what I can see this looks like a nice solution.
|
I left some comments on the related issue. In short, there's a lingering problem in wasm-pack's |
Both look good to me. |
|
Is this going to be merged soon? I could really use this in my project 🙂 |
Yes, I just need to run a few more checks that we are correctly handling errors when in a Node.js ES module. |
Signed-off-by: Joe Richey <joerichey@google.com>
This call throws an exception if module isn't defined. Signed-off-by: Joe Richey <joerichey@google.com>
Signed-off-by: Joe Richey <joerichey@google.com>
|
I added e0c93b1 which makes the error @josephg pointed out in #256 (comment) much nicer. Now, if we try to use an ES module from Node.js, we get an error like: Then if we apply the workaround in our docs, everything works!! This should hopefully allow users to (a) figure out what's going wrong, and (b) figure out how to fix the error. |
|
Awesome! Is this going to be published as 0.2.8 ? |
See #294 |
Rework JS feature detection
This PR tries to incorporate some of the suggestions from #256
The first commit changes our detection logic to first look for the Web Cryptography API before attempting to check for Node.js support. This allows Node.js ES6 module users to add a polyfill like:
as described in #256 (comment)
We also rename
BroswerCryptotoWebCryptoand update some of the outdated error messages and package comments.The Second commit adds better detection for why we failed to call
module.require("crypto"), returning a different error code ifmodule.requireis not a function,I think this fixes #256 about as well as we can.
Signed-off-by: Joe Richey joerichey@google.com