-
Notifications
You must be signed in to change notification settings - Fork 253
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-4927): exports in package.json for react native and document how to polyfill for BSON #550
feat(NODE-4927): exports in package.json for react native and document how to polyfill for BSON #550
Changes from all commits
493cbe3
e08bf78
5cefe2f
a84c658
c85cea4
dff0028
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,11 +75,11 @@ | |
}, | ||
"main": "./lib/bson.cjs", | ||
"module": "./lib/bson.mjs", | ||
"browser": "./lib/bson.mjs", | ||
"exports": { | ||
"browser": "./lib/bson.mjs", | ||
"import": "./lib/bson.mjs", | ||
"require": "./lib/bson.cjs" | ||
"require": "./lib/bson.cjs", | ||
"react-native": "./lib/bson.cjs", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure on this, but I think the Was this manually tested in a React Native project? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I made a new project with We can get this into an alpha release and maybe you have projects with more diverse tooling worth testing to see if it gets pulled in correctly, I'll ping you on slack when its available |
||
"browser": "./lib/bson.mjs" | ||
}, | ||
"engines": { | ||
"node": ">=14.20.1" | ||
|
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.
It would be great if these could be included in the React Native bundle though.
I don't think it's too much to warn users and have them optionally import the
react-native-get-random-values
package for added security, but having these polyfills as strict requirement for React Native users (hence all Realm JS users) is a no-go in my opinion.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.
That's a valid concern.
@nbbeeken would know better than I about the difficultly of bundling these the required dependencies in the react native build.
As an alternative, could realm provide these polyfills for users instead of BSON?
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.
Let's file a ticket for providing a polyfilled bundle for RN and we can fill it out with more detail on how the bundle should behave given that there is a mix of platforms and javascript engines that can be combined here.
Just adding background, one of our goals was to move away from bundling polyfills since they became part of the semantic version of this package despite being outside of our control. We became unable to pull in updates to the polyfills as they would break existing users but prevented other users from puling in the needed updates. Keeping polyfilling outside of a library's responsibility understandably adds friction but allows those that need the specific APIs working in a specific way to have control over that since not every polyfill is perfect for every use case.
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 understand that problem, we have similar issues in the Realm JS package. Ideally the bson package's source code should be runtime independent and therefore not rely on these globals in the first place. Instead it could have these functions "injected" by a platform specific index.ts wrapping the actual library. We're doing similar tricks on the upcoming refactor of the Realm JS SDK.
Technically the
base-64
package could be a peer dependency and not included in the bundle, while it's still being imported by bson and injected into the "common" part of its code.