-
Notifications
You must be signed in to change notification settings - Fork 254
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
feat(NODE-4938): improve react native bundle experience #578
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated the title to focus on the intended feature, feel free to fix it further. Let's also update the readme's section on RN with the new instructions and the intended support for this bundle
Readme updated. |
README.md
Outdated
@@ -188,23 +188,17 @@ try { | |||
|
|||
## React Native | |||
|
|||
BSON requires that `TextEncoder`, `TextDecoder`, `atob`, `btoa`, and `crypto.getRandomValues` are available globally. These are present in most Javascript runtimes but require polyfilling in React Native. Polyfills for the missing functionality can be installed with the following command: | |||
BSON vendors the required polyfills for `TextEncoder`, `TextDecoder`, `atob`, `btoa` when using React Native. One |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect the term "vendors" might not be clear enough for publicly facing documentation. Perhaps it would make sense to include an explanation on what that means for the user.
BSON vendors the required polyfills for `TextEncoder`, `TextDecoder`, `atob`, `btoa` when using React Native. One | |
BSON vendors the required polyfills for `TextEncoder`, `TextDecoder`, `atob`, `btoa` imported from React Native and therefore doesn't expect users to polyfill these. One |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
README.md
Outdated
@@ -188,23 +188,17 @@ try { | |||
|
|||
## React Native | |||
|
|||
BSON requires that `TextEncoder`, `TextDecoder`, `atob`, `btoa`, and `crypto.getRandomValues` are available globally. These are present in most Javascript runtimes but require polyfilling in React Native. Polyfills for the missing functionality can be installed with the following command: | |||
BSON vendors the required polyfills for `TextEncoder`, `TextDecoder`, `atob`, `btoa` when using React Native. One | |||
additional polyfill, `crypto.getRandomValues` is required and can be installed with the following command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is required
Isn't this optional?
additional polyfill, `crypto.getRandomValues` is required and can be installed with the following command: | |
additional polyfill, `crypto.getRandomValues` is recommended and can be installed with the following command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
@@ -0,0 +1,30 @@ | |||
import MagicString from 'magic-string'; | |||
|
|||
const REQUIRE_TEXT_ENCODING = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name seam to suggest only one of the polyfills are provided here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed name to REQUIRE_POLYFILLS
.
An alternative I don't know if you've considered: If you had a separate input for the RN bundle (which would setup the polyfills and re-export If you had a separate input file for the RN bundle, it could make sense (not necessarily for this PR) to move this check and warning into the RN bundle to avoid relying on checks of the runtime (as that tends to be brittle in my experience). BTW: I've built the PR and tested ObjectId and UUID in a React Native app 👍 |
I think that may be something we can discuss and potentially ticket in the future. |
Description
Creates a new CJS bundle to be used with React Native.
What is changing?
TextEncoder
,TextDecoder
,btoa
andatob
.Is there new documentation needed for these changes?
None
What is the motivation for this change?
NODE-4938
Release Highlight
Improved React Native experience
The BSON package now ships a bundle made to work on React Native without additional polyfills preconfigured. The necessary APIs (
TextEncoder
/TextDecoder
&atob
/btoa
) are now vendored into the RN bundle directly. Users should still installreact-native-get-random-values
themselves to get securely generated UUIDs and ObjectIds. Read more in the React Native section of our readme.Double check the following
npm run lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript