diff --git a/.github/workflows/pr_lint_and_test.yml b/.github/workflows/pr_lint_and_test.yml index df1cd9dd3b..a903641d9a 100644 --- a/.github/workflows/pr_lint_and_test.yml +++ b/.github/workflows/pr_lint_and_test.yml @@ -61,3 +61,10 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} lcov-file: ./coverage/lcov.info + - name: Packages size report + uses: flochaz/pkg-size-action@v1.2.12 + with: + build-command: mkdir dist && npm run lerna-package && npm run lerna-package-bundle && bash -c "mv ./packages/*/dist/* dist/" && ls dist + dist-directory: /dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/examples/cdk/package.json b/examples/cdk/package.json index f2af873b63..ca016d617d 100644 --- a/examples/cdk/package.json +++ b/examples/cdk/package.json @@ -15,6 +15,7 @@ "watch": "tsc -w", "test": "npm run test:unit", "package": "echo 'Not applicable'", + "package-bundle": "echo 'Not applicable'", "test:unit": "npm run build && jest", "test:e2e": "echo 'To be implemented ...'", "version": "npm install @aws-lambda-powertools/logger@0.7.0 @aws-lambda-powertools/tracer@0.7.0 @aws-lambda-powertools/metrics@0.7.0 && git add package.json", diff --git a/examples/sam/package.json b/examples/sam/package.json index d83c630a6d..b2853064ff 100644 --- a/examples/sam/package.json +++ b/examples/sam/package.json @@ -11,6 +11,7 @@ "build": "sam build --beta-features", "test": "npm run test:unit", "package": "echo 'Not applicable'", + "package-bundle": "echo 'Not applicable'", "test:unit": "npm run build && jest", "test:e2e": "echo 'To be implemented ...'", "version": "npm install @aws-lambda-powertools/logger@0.7.0 @aws-lambda-powertools/tracer@0.7.0 @aws-lambda-powertools/metrics@0.7.0 && git add package.json" diff --git a/package-bundler.sh b/package-bundler.sh new file mode 100755 index 0000000000..eea1fd37da --- /dev/null +++ b/package-bundler.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +set -e + + +usage() { + echo "Uber package Builder" + echo "------------------------" + echo "./package-bundler.sh NAME LOCAL_NPM_PACKAGE_LOCATION" + echo "" +} + + +if [[ "$#" -lt 2 ]]; then + usage + exit 1 +fi + +name=$(basename ${1}) +dist_folder="${2}" + +echo "Will bundle $(ls ${dist_folder}) into ${dist_folder}/${name}.tgz" + +output_folder="$(mktemp -d)" + +docker_image="public.ecr.aws/sam/build-nodejs14.x:latest" +volume_params="-v $output_folder:/bundle" + +package_folder="nodejs/" +mkdir -p "$output_folder/$package_folder" + +cp -r "${2}" "$output_folder/$package_folder/" + +install_command="pushd $package_folder; npm install --save ./*.tgz; popd" +volume_params="$volume_params -v $HOME/.npmrc:/root/.npmrc" + +zip_command="zip -r bundle.zip * && rm -rf $package_folder" + +docker run --rm $volume_params -w "/bundle" "$docker_image" /bin/bash -c "$install_command && $zip_command" + +mv "$output_folder/bundle.zip" "$dist_folder/$name.zip" + +rm -rf $output_folder + +echo "All done" diff --git a/package.json b/package.json index 2e7676dfad..f1f3dc9fb8 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "lerna-test:unit": "lerna exec -- npm run test:unit", "lerna-test:e2e": "lerna exec -- npm run test:e2e", "lerna-package": "lerna exec -- npm run package", + "lerna-package-bundle": "lerna exec -- npm run package-bundle", "lerna-build": "lerna exec -- tsc", "lerna-lint": "lerna exec -- eslint \"./{src,tests}/**/*.ts ./src/*.ts\"", "lerna-format": "lerna exec -- eslint --fix \"./{src,tests}/**/*.ts ./src/*.ts\"", diff --git a/packages/commons/package.json b/packages/commons/package.json index adb237454d..bec06e6b72 100644 --- a/packages/commons/package.json +++ b/packages/commons/package.json @@ -19,6 +19,7 @@ "lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests", "format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests", "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", + "package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/", "prepare": "npm run build", "prepublishOnly": "npm test && npm run lint", "preversion": "npm run lint", diff --git a/packages/logger/package.json b/packages/logger/package.json index c82e147399..7eb657ee8d 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -22,6 +22,7 @@ "lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests", "format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests", "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", + "package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/", "prepare": "npm run build", "prepublishOnly": "npm test && npm run lint", "preversion": "npm run lint", diff --git a/packages/metrics/package.json b/packages/metrics/package.json index bd62059636..b990f16c8f 100644 --- a/packages/metrics/package.json +++ b/packages/metrics/package.json @@ -22,6 +22,7 @@ "lint": "eslint --ext .ts --fix --no-error-on-unmatched-pattern src tests", "format": "eslint --fix --ext .ts --fix --no-error-on-unmatched-pattern src tests", "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", + "package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/", "prepare": "npm run build", "prepublishOnly": "npm test && npm run lint", "preversion": "npm run lint", diff --git a/packages/tracer/package.json b/packages/tracer/package.json index a2dc8b8cbf..fa23013312 100644 --- a/packages/tracer/package.json +++ b/packages/tracer/package.json @@ -26,7 +26,8 @@ "preversion": "npm run lint", "version": "npm run format && git add -A src", "postversion": "git push && git push --tags", - "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/" + "package": "mkdir -p dist/ && npm pack && mv *.tgz dist/", + "package-bundle": "../../package-bundler.sh ${LERNA_PACKAGE_NAME}-bundle ./dist/" }, "homepage": "https://github.com/awslabs/aws-lambda-powertools-typescript/tree/master/packages/tracer#readme", "license": "MIT-0",