Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
crypto
to Polyfills improving Blueprint compatibility for Node (#…
…1000) - Similar to #875 - Related to WordPress/playground-tools#113 ## 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`](https://developer.mozilla.org/en-US/docs/Web/API/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`](https://nodejs.org/api/webcrypto.html) which has `webcrypto` and will be a better match. It's available sine Node v15. The other alternative is normal [crypto](https://nodejs.org/api/crypto.html) 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 1. Comment the first line `import './crypto';` on `packages/php-wasm/node-polyfills/src/lib/crypto.spec.ts` 2. Run `npx nx test php-wasm-node-polyfills` 3. Observe the tests fail 4. Uncomment first line `import './crypto';` on `packages/php-wasm/node-polyfills/src/lib/crypto.spec.ts` 5. Run `npx nx test php-wasm-node-polyfills` 6. Observe the tests pass
- Loading branch information