-
Notifications
You must be signed in to change notification settings - Fork 271
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
Polyfills for Node.js v18 and JSDOM runtimes #875
Merged
Merged
Conversation
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
adamziel
added
[Type] Enhancement
New feature or request
[Aspect] Node.js
[Type] Reliability
Playground uptime, reliability, not crashing
labels
Dec 17, 2023
adamziel
changed the title
Polyfills: Node.js v18 and JSDOM runtimes
Polyfills for Node.js v18 and JSDOM runtimes
Dec 17, 2023
This was referenced Dec 17, 2023
adamziel
added a commit
that referenced
this pull request
Dec 19, 2023
Makes Playground Blueprints compatible with Node.js v18 by using a set of polyfills shiped in #875. Test plan: Confirm the CI checks passed
This was referenced Dec 19, 2023
adamziel
added a commit
that referenced
this pull request
Dec 19, 2023
Makes Playground Blueprints compatible with Node.js v18 by using a set of polyfills shiped in #875. ## Test plan Confirm the CI checks passed
This was referenced Dec 19, 2023
adamziel
pushed a commit
that referenced
this pull request
Feb 5, 2024
…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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
[Aspect] Node.js
[Type] Enhancement
New feature or request
[Type] Reliability
Playground uptime, reliability, not crashing
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds a new
@php-wasm/node-polyfills
package to polyfills the features missing in Node 18 and/or JSDOM environments. The goal is to make wp-now and other Playground-based Node.js packages work in Node 18, which is the current LTS release.The polyfilled JavaScript features are:
CustomEvent
classFile
classBlob.text()
andBlob.arrayBuffer()
methodsBlob.arrayBuffer()
andFile.text()
methodsBlob.stream()
andFile.stream()
methodsFile.stream().getReader({ mode: 'byob' })
is supported – this is relevant for Explorations: Stream API #851I adapted the Blob methods from https://github.com/bjornstar/blob-polyfill/blob/master/Blob.js as they seemed to provide just the logic needed here and they also worked right away.
This PR is a part of #851 split out into a separate PR to make it easier to review and reason about.
Supersedes #865
Testing instructions
Confirm the unit tests pass. This PR ships a set of vite tests to confirm the polyfills work both in vanilla Node.js and in jsdom runtime environments.
Alternatives considered
Related:
package.json
#591cc @danielbachhuber @sejas @eliot-akira @dmsnell