-
Notifications
You must be signed in to change notification settings - Fork 597
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
Trim production dependencies #1536
Comments
Actually, apologies on the |
I'd love some feedback here – I keep seeing |
@mhart well said. I was looking into const base64Decode = require('fast-base64-decode')
const getRandomBase64 = require('react-native').NativeModules.RNGetRandomValues.getRandomBase64
class TypeMismatchError extends Error {}
class QuotaExceededError extends Error {}
global.crypto.getRandomValues = function (array) {
if (!(array instanceof Int8Array || array instanceof Uint8Array || array instanceof Int16Array || array instanceof Uint16Array || array instanceof Int32Array || array instanceof Uint32Array || array instanceof Uint8ClampedArray)) {
throw new TypeMismatchError('Expected an integer array')
}
if (array.byteLength > 65536) {
throw new QuotaExceededError('Can only request a maximum of 65536 bytes')
}
base64Decode(getRandomBase64(array.byteLength), new Uint8Array(array.buffer, array.byteOffset, array.byteLength))
return array
} Where cc #1797 |
@mhart There are pros and cons to both, but someone "loses" either way - the fact that it's got empty JS files however is less optimal and in theory should be resolvable.
This will mean that users using |
@G-Rath @aws-sdk/types is only required for TypeScript users if they want type information – which is definitely not a runtime concern. You wouldn't install |
@mhart The problem effectively boils down to that we currently have no way of marking a dependency as being required for compiling vs being required for actually running. As I said above, there are two ways forward in lue of that: marking them as *I personally don't mind either route, since they both result in the same thing |
The |
FYI Would be great to get this moved to be properly optional - happy to help with this if desired. |
@G-Rath is correct. To revert back to the npm@6 behavior we can use Alternatively, we can explicitly omit peer dependencies: |
The By investigating the
A comment on the previous line points out to https://github.com/uuidjs/uuid#getrandomvalues-not-supported. My understanding of this is:
In my understanding, we have two options here:
IMHO, it must be done upstream as the package is React Native specific but AWS SDK isn't. I mean I think peoples which explicitly require See
|
What @tuarrep says is exactly why I created this issue and noted:
|
That is how it's done upstream: The AWS SDK does not require @mhart I'm wondering if someone should just open a PR implementing this change, as the patch should be relatively small. I'd be happy to help support such a PR (I can't commit the time right now to doing the opening, otherwise I'd be happy to do that too 🙂) |
I'm not a React Native expert and I haven't a setup to test neither I'm comfortable with this repository conventions (ES version support?) if(!'getRandomValues' in crypto)
import 'react-native-get-random-values'; I could blindly craft a PR if it can help. |
@tuarrep You're wanting to do something like this:
We'd also want to add {
// ...
"peerDependencies": {
"react-native-get-random-values": "^1.5.0"
},
"peerDependenciesMeta": {
"react-native-get-random-values": {
"optional": true
}
}
// ...
} |
Thanks, @G-Rath for your explanation, I like your approach. I'll draft a PR tomorrow if no one else has done that before. |
A request is created upstream to add react-native as an optional peerDependency LinusU/react-native-get-random-values#27 |
@trivikr except that it doesn't make sense for them to have Also, you can't just go around to every |
That's right. I've closed the issues with react-native polyfills repos:
Decision taken by the team during post-scrum on 3/26: Make react-native polyfills as optional peer dependencies in aws-sdk-js-v3. Question yet to be answered:
|
Just got hit by this as well, unexpectedly. I just looked thorugh all the middleware code, and I couldn't seem to find where the get random value code was even being used. Is this something that could be externalized as the responsibility of the library consumers to pull in, when targeting native environments? Or even a different package that wraps the client sdk, and includes this as part of the main entry point? It seems like the library is attempting to polyfill for native environments in a middleware library, which just seems odd. |
Related to aws#1536 Co-authored-by: Nicolas Perraut <[email protected]>
Related to aws#1536 Co-authored-by: Nicolas Perraut <[email protected]>
Related to aws#1536 Co-authored-by: Nicolas Perraut <[email protected]>
The react-native polyfills were removed in #2191 |
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. |
Is your feature request related to a problem? Please describe.
I'm hoping to switch to aws-sdk-js-v3 for its modularity, in the hope that the package sizes are smaller than v2, but I notice a lot of dependencies being installed that don't seem necessary at runtime, which actually make it quite a large npm install.
For example, middleware-retry has as production dependencies:
react-native-get-random-values
This only seems to be needed for very specific environments (react native) and so users who need it should install it as a peer dependency, but to have everyone install it (and therefore have to maintain it, and patch it if there are security issues, etc) seems an overreach.
- `@aws-sdk/types`This seems to a module made up of TS and empty *.js files. My guess is it should be a dev dependency only for typescript, and possibly reworked so the js files aren't included at all.
(addressed in #1649)
- `tslib`This should only be used at dev time too – for bundling. I doubt that this is used during runtime (but could be wrong?)
Describe the solution you'd like
Ensure that each module only has the very minimum that it needs in terms of production (non-dev) dependencies.
Additional context
One HUGE advantage of aws-sdk v2 as it stands right now is that it has very few dependencies – this means that users don't end up having to constantly patch sub-sub-dependencies of modules they don't even use. It would be great if v3 could also carry this philosophy over, as well as its goal of providing small individual modules for tree shaking
Right now I'm quite surprised at the size. Eg, installing just a single client, eg
@aws-sdk/client-ssm
, results in 102 packages being installed (half of which seem to be non-AWS modules) and a 19.2MB node_modules. That's almost half the size of the entire aws-sdk v2 for just one client – and a lot more packages to potentially patch and maintainThe text was updated successfully, but these errors were encountered: