Skip to content

fix(deps): request consumers to install react-native polyfills #2191

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

Merged
merged 10 commits into from
Apr 9, 2021

Conversation

trivikr
Copy link
Member

@trivikr trivikr commented Mar 29, 2021

Co-authored-by: Nicolas Perraut [email protected]

Issue

Related to #1536
Replaces #2108

Fixes: #1797
Fixes: #2051
Fixes: #2192
Fixes: #2199
Fixes: #2219

Description

This PR marks react-native-get-random-values as optional peer dependency to prevent install on non React Native environments.

Testing

Verified that ReactNative E2E tests are successful.

Command line output
$ pwd
/Users/trivikr/workspace/aws-sdk-js-v3/tests/react-native/End2End

$ node launch-app.js --local-publish
...
 PASS  e2e/End2EndTest.spec.js (14.5s)
  S3
    ✓ should upload an object after tapping putObject button (2276ms)
    ✓ after tapping getObject, App should get the same object that uploaded (2224ms)
    ✓ should list Objects after tapping listObjects button (1496ms)
    ✓ should conduct multipart upload after tapping createMultipartUpload, uploadPart, completeMultipartUpload buttons (3096ms)
Details
react-native-e2e-tests.mov

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@G-Rath
Copy link

G-Rath commented Mar 29, 2021

@trivikr have you tested this to confirm it doesn't throw an error on import if the package isn't installed?

I would expect it to, which is why we used a try/catch over in #2108

@trivikr
Copy link
Member Author

trivikr commented Mar 29, 2021

@trivikr have you tested this to confirm it doesn't throw an error on import if the package isn't installed?

The AWS SDK for JavaScript no longer imports react-native polyfills, and expect them to be imported by the app using the SDK in react-native environment.

I'll evaluate the behavior if the react-native app doesn't contain react-native polyfills, and update this PR.

@G-Rath
Copy link

G-Rath commented Mar 29, 2021

Ah right I see - sorry it didn't click that this change was an add, not a modify 😅

@trivikr
Copy link
Member Author

trivikr commented Mar 29, 2021

The reason for removing require/import for react-native-get-random-values dependency is that our react-native End2End tests fail with "Unable to resolve module" error.

Screenshot Unable-to-resolve-module-error

Just like uuid expects it's users to import react-native polyfills, AWS SDK for JavaScript would do the same.

@trivikr
Copy link
Member Author

trivikr commented Mar 31, 2021

This PR is currently pending review from amplify-js team.
cc @Ashish-Nanda @amhinson

@trivikr trivikr requested a review from AllanZhengYP March 31, 2021 17:30
@trivikr
Copy link
Member Author

trivikr commented Mar 31, 2021

Notes from the meeting on 3/31 with Amplify team:

  • Remove requirement of react-native polyfills as peerDependencies, as peerDependenciesMeta just removes the warnings but installs peerDependencies by default.
  • Check if a custom error can be emitted for react-native customers requesting particular polyfill as a requirement for aws-sdk just like uuid does https://github.com/uuidjs/uuid#getrandomvalues-not-supported. Amplify team had tried in the past, and it was not straight-forward.

@trivikr trivikr force-pushed the optional-react-native-get-random-values branch from 31a2f8b to 5baa663 Compare April 7, 2021 15:00
@trivikr
Copy link
Member Author

trivikr commented Apr 7, 2021

  • Remove requirement of react-native polyfills as peerDependencies, as peerDependenciesMeta just removes the warnings but installs peerDependencies by default.

Removed in 5baa663 (#2191)

  • Check if a custom error can be emitted for react-native customers requesting particular polyfill as a requirement for aws-sdk just like uuid does uuidjs/uuid#getrandomvalues-not-supported. Amplify team had tried in the past, and it was not straight-forward.

This isn't possible, as it's an implementation detail in https://github.com/uuidjs/uuid/blob/91805f665c38b691ac2cbda56a99231432b00a1a/src/rng-browser.js#L21-L25

I've updated README to share react-native polyfills import example instead d67256e (#2191)

Nicolas Perraut and others added 10 commits April 8, 2021 18:48
Declaring react-native polyfill in peerDependenciesMeta will just remove
the warning, but will still install peerDependencies
In the testing performed by Amplify, the optional dependencies were installed
by default using npm 7.7.6

We're removing optional peerDeps for react-native polyfills as of now, to be
added in a separate PR.
@trivikr trivikr force-pushed the optional-react-native-get-random-values branch from 7516038 to d3fa8a1 Compare April 8, 2021 18:48
@trivikr trivikr changed the title fix(deps): make react-native-get-random-values optional peerDependecy fix(deps): request consumers to install react-native-get-random-values polyfill Apr 8, 2021
@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • CodeBuild project: sdk-staging-test
  • Commit ID: d3fa8a1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link

@iartemiev iartemiev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after testing the effect of this PR on Amplify RN apps.

Copy link
Contributor

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So nice to get rid of react-native from most users' dependencies.

@trivikr trivikr changed the title fix(deps): request consumers to install react-native-get-random-values polyfill fix(deps): request consumers to install react-native polyfills Apr 9, 2021
@trivikr trivikr merged commit 2d3a7f0 into aws:main Apr 9, 2021
@trivikr trivikr deleted the optional-react-native-get-random-values branch April 9, 2021 16:55
trivikr added a commit to trivikr/aws-sdk-js-v3 that referenced this pull request Apr 9, 2021
@J-Krush
Copy link

J-Krush commented Apr 12, 2021

So much appreciation for this PR! Unblocked on my work now :D

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 27, 2021
@trivikr trivikr mentioned this pull request Jun 30, 2021
@aws aws unlocked this conversation Sep 17, 2021
@github-actions
Copy link

github-actions bot commented Oct 2, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
8 participants