-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add crypto
to Polyfills improving Blueprint compatibility for Node
#1000
Conversation
To fix the e2e failure you might need to add |
Hm maybe I was wrong. It seems to dislike the |
Thank you @sejas! |
@adamziel , this fix seems to not be working when the JS is in NPM package. The "transpiled" JS is like:
Where
It shouldn't import from Should we pivot and use a custom plain function, instead of Should we use a third party library? Should be handled on node clients directly? |
Yeah let’s pivot to a custom randomString() function, we could move the one that’s already implemented to generate WP secrets |
|
I'll prepare a PR 🤞 |
…1016) - Remove the crypto polyfill introduced on #1000 - Move the `randomString` from `remote` package to `@php-wasm/util` - Created a new custom function `randomFilename` - Replace the usage of `crypto.randomUUID` with `randomFilename()` ## What problem is it solving? `crypto` is a library that is available, but needs to be imported on node apps. ## How is the problem addressed? It replaces the function that generates a random value with our custom library ## Testing Instructions - CI tests pass
What is this PR doing?
It imports the native library
crypto
and makes it globally available in the runtime.What problem is it solving?
When using blueprints that install plugins or themes, it generates a random folder using
crypto
`. That library is available in the browsers by default, but for node we need to import it.Note that it do not install any dependency since Crypto is already built in NodeJS, but it's not imported by default.
I decided to use
node:crypto
which haswebcrypto
and will be a better match. It's available sine Node v15.The other alternative is normal crypto https://nodejs.org/docs/latest-v14.x/api/crypto.html, which also has
crypto.randomUUID
. It's available since Node v14.How is the problem addressed?
It adds a new Polyfill for crypto.
Testing Instructions
import './crypto';
onpackages/php-wasm/node-polyfills/src/lib/crypto.spec.ts
npx nx test php-wasm-node-polyfills
import './crypto';
onpackages/php-wasm/node-polyfills/src/lib/crypto.spec.ts
npx nx test php-wasm-node-polyfills