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

To solve the npm package size issue #252

Merged
merged 35 commits into from
Sep 16, 2021
Merged

To solve the npm package size issue #252

merged 35 commits into from
Sep 16, 2021

Conversation

TingDaoK
Copy link
Contributor

@TingDaoK TingDaoK commented Sep 9, 2021

Issue #, if available:

  • The current aws-crt npm package size is too huge(200 MB)

Description of changes:

  • Remove C source code from npm package
  • Publish C source code to S3 with publish pipeline, and the build script will download it when needed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lgtm-com
Copy link

lgtm-com bot commented Sep 9, 2021

This pull request introduces 2 alerts when merging 83fb37d into e9bd55f - view on LGTM.com

new alerts:

  • 2 for Unused variable, import, function or class

scripts/build.js Outdated
// There is no native code, we are not building from source.
(async () => {
// AWS common runtime aws-crt-nodejs cloudfront distribution.
const url = "http://d332vdhbectycy.cloudfront.net/";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use github release asset instead of cloudfront deployment when we release. But, AWS is easier to test for now.

@TingDaoK TingDaoK marked this pull request as ready for review September 11, 2021 00:53
Copy link
Contributor

@bretambrose bretambrose left a comment

Choose a reason for hiding this comment

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

Seems reasonable but unless I'm missing something we should test this cloudfront-sourced build on all three platforms just as a sanity check.

@TingDaoK
Copy link
Contributor Author

TingDaoK commented Sep 13, 2021

Seems reasonable but unless I'm missing something we should test this cloudfront-sourced build on all three platforms just as a sanity check.

It's a bit tricky to test it. What I did is download the packed tarball from npm pack(aws-crt-<version>.tgz), and test it by:

  • Remove the binary
  • Run node scripts/install.js locally.

I tested it on mac manually, and it works. I can test it on linux and windows for sure.

README.md Outdated
@@ -40,6 +40,8 @@ You can either add it to package.json (if using a tool like webpack), or just im
npm install aws-crt
```

To reduce the size of package, we put the C source code in the S3 bucket. If the platform you are using doesn't have the prebuilt binary, npm will pull the source from S3 bucket. In case, you don't have the public internet, you can specify the "CRT_SOURCE_CODE_HOST" environment variable for the host of the source code. The build script will fetch source code from that host instead. To fetch the source from S3, you can reach to the cloudfront distribution (Only works for version after v1.9.2) `https://d332vdhbectycy.cloudfront.net/aws-crt-<version>-source.tgz`, the sha256 checksum `https://d332vdhbectycy.cloudfront.net/aws-crt-<version>-source.sha256`
Copy link
Contributor

Choose a reason for hiding this comment

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

couple things:

  • Let's do "BINARY_HOST" instead of "SOURCE_CODE_HOST" since we know we'll be putting binaries there too soon enough. I mean, hey, .tgz files are binaries whether or not they have source code 😬
  • Looks like there is some precedent for letting users customize the host, and it's via the .npmrc file, with a variable like aws_crt_binary_host, instead of an environment variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol, I was confused by the "binary" as those ".node" files are things we talked about a lot.

scripts/build.js Outdated
const version = package["version"];
fetch_native_code(url, version, tmp_path).then(() => {
// Clean up temp directory
fs.rmSync(tmp_path, { recursive: true });
Copy link
Contributor

Choose a reason for hiding this comment

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

to be improved in the future: probably better to cache the download, but then we'd need integrity checks to ensure the cached version is good, so this works for now. Here's prebuild-install explaining their caching strategy

@lgtm-com
Copy link

lgtm-com bot commented Sep 15, 2021

This pull request introduces 1 alert when merging 967aa2f into e9bd55f - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Copy link

@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.

Looks good generally, left a few comments

# now get the tag
CURRENT_TAG=$(git describe --tags | cut -f2 -dv)
# convert v0.2.12-2-g50254a9 to 0.2.12
CURRENT_TAG_VERSION=$(git describe --tags | cut -f1 -d'-' | cut -f2 -dv)

Choose a reason for hiding this comment

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

May be check if the tagged commit at current head? This can prevent updating binaries without bumping versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed a check that was there for testing. Added it back to check if the tag is release. So, in that case, we can prevent updating binaries without proper release, which will also prevent the version is not updated, I think.

@@ -47,6 +47,7 @@
"crypto-js": "^4.0.0",
"fastestsmallesttextencoderdecoder": "^1.0.22",
"mqtt": "^4.2.8",
"tar": "^6.1.11",

Choose a reason for hiding this comment

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

We saw customer complaining of the deprecated dependencies too, are those tackled already?
aws/aws-sdk-js-v3#2750

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw those warnings as well, don't know how to solve them... npm update and npm audit fix is not helping... But, we can probably tackle them after

@TingDaoK TingDaoK merged commit 03a6dd7 into main Sep 16, 2021
@TingDaoK TingDaoK deleted the npm-package branch September 16, 2021 20:54
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.

4 participants