Skip to content
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

Reduced dependencies and copied signer from aws-amplify #35

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

cgalvan
Copy link
Contributor

@cgalvan cgalvan commented Apr 12, 2024

Issue #, if available:

Fixes #29

Description of changes:

The purpose of this change was to reduce the size of our dependencies. In #29 it was uncovered that our total dependency size was ~280MB. A lot of this came from @aws-amplify/core, which we were using for our sigv4 signing.

Prior to this change, our dependencies were:

"@aws-amplify/core": "^5.5.0",
"@aws-sdk/client-location": "^3.359.0",
"@aws-sdk/credential-providers": "^3.359.0",
"@aws-sdk/types": "^3.347.0"

I updated these to the latest versions, and there had been a lot of dependency trimming, but there was a major API breakage in @aws-amplify/core. They no longer export the Signer, and are intending to deprecate it in favor of another internal signing library (that the Signer currently calls internally), which is also not exported:

https://github.com/aws-amplify/amplify-js/blob/main/packages/core/src/clients/middleware/signing/signer/signatureV4

So, I have copied over the Signer class and left a long comment detailing this move.

This changes our dependencies to:

"@aws-crypto/sha256-js": "^5.2.0",
"@aws-sdk/client-location": "^3.549.0",
"@aws-sdk/credential-providers": "^3.549.0",
"@aws-sdk/types": "^3.535.0",
"@smithy/util-hex-encoding": "^2.0.0"

Installing these dependencies in an empty repo results in only 19MB!

Testing:

Updated the unit tests to test the output of the signer. Ran unit tests and all pass.

> npm test
 PASS  src/index.test.ts
 PASS  src/cognito/index.test.ts
 PASS  src/apikey/index.test.ts
-------------|---------|----------|---------|---------|-------------------
File         | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-------------|---------|----------|---------|---------|-------------------
All files    |   97.47 |    69.56 |   94.44 |   98.27 |
 src         |     100 |      100 |     100 |     100 |
  index.ts   |     100 |      100 |     100 |     100 |
 src/apikey  |     100 |      100 |     100 |     100 |
  index.ts   |     100 |      100 |     100 |     100 |
 src/cognito |     100 |      100 |     100 |     100 |
  index.ts   |     100 |      100 |     100 |     100 |
 src/utils   |   96.73 |    58.82 |    92.3 |   97.75 |
  signer.ts  |   96.73 |    58.82 |    92.3 |   97.75 | 321,349
-------------|---------|----------|---------|---------|-------------------

Test Suites: 3 passed, 3 total
Tests:       19 passed, 19 total
Snapshots:   0 total
Time:        0.953 s, estimated 1 s
Ran all test suites.

Also ran npm run build and used the output in a simple local test app with both API key and cognito and verified a map is loaded properly.

@cgalvan cgalvan requested a review from a team as a code owner April 12, 2024 20:28
juaneslucero
juaneslucero previously approved these changes Apr 12, 2024
src/utils/signer.ts Outdated Show resolved Hide resolved
src/utils/signer.ts Show resolved Hide resolved
@cgalvan cgalvan merged commit 2fe55ce into aws-geospatial:main Apr 12, 2024
1 check passed
@cgalvan cgalvan deleted the ReduceDependencies branch April 12, 2024 21:01
@cgalvan cgalvan mentioned this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

280 MB of dependencies for this?
3 participants