Skip to content

Commit 93397c7

Browse files
authored
Merge pull request #666 from aws-samples/features/reduce-tarball-size
chore(packaging): optimize package size for Nexus vending
2 parents 98afa18 + ea4996d commit 93397c7

File tree

8 files changed

+161
-118
lines changed

8 files changed

+161
-118
lines changed

.npmignore

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,85 @@
1+
# Development files
2+
test/
3+
tests/
4+
__tests__/
5+
*.test.js
6+
*.spec.js
7+
jest.config.js
8+
coverage/
9+
10+
# Source maps and TypeScript sources (we only need compiled JS)
11+
*.map
112
*.ts
213
!*.d.ts
14+
# Keep GraphQL generated TypeScript files
15+
!lib/user-interface/react-app/src/API.ts
16+
!lib/user-interface/react-app/src/graphql/*.ts
17+
18+
# Documentation (except README.md which is needed)
19+
docs/
20+
documentation/
21+
*.md
22+
!README.md
23+
!aws-genai-llm-chatbot/README.md
24+
25+
# Build artifacts and config files
26+
.github/
27+
.gitlab/
28+
.circleci/
29+
.travis.yml
30+
.eslintrc*
31+
.prettierrc*
32+
tsconfig.json
33+
tslint.json
34+
.vscode/
35+
.idea/
36+
37+
# Git files
38+
.git/
39+
.gitignore
40+
.gitattributes
41+
42+
# Temporary files
43+
.DS_Store
44+
.env
45+
.env.*
46+
*.log
47+
npm-debug.log*
48+
yarn-debug.log*
49+
yarn-error.log*
50+
.cache/
51+
52+
# Build directories
53+
.aws-sam/
54+
.cdk.staging/
55+
cdk.out/
56+
dist/
57+
build/
58+
59+
# Large directories that can be rebuilt
60+
node_modules
61+
lib/user-interface/react-app/node_modules
62+
aws-genai-llm-chatbot/modules/chatbot/lib/user-interface/react-app/node_modules
63+
64+
# Scripts directory (except essential scripts)
65+
scripts/
66+
!scripts/vend-prep.sh
67+
68+
# Examples and samples
69+
examples/
70+
samples/
71+
72+
# CI/CD configuration
73+
buildspec.yml
74+
.npmrc
75+
.nvmrc
76+
77+
# Backup files
78+
*.bak
79+
*~
80+
*.swp
81+
*.swo
382

4-
# CDK asset staging directory
5-
.cdk.staging
6-
cdk.out
83+
# Unnecessary package files
84+
package-lock.json
85+
yarn.lock

aws-genai-llm-chatbot/assets/chatbot-icon.svg

Lines changed: 0 additions & 5 deletions
This file was deleted.

aws-genai-llm-chatbot/assets/chatbot-thumbnail.svg

Lines changed: 0 additions & 6 deletions
This file was deleted.

aws-genai-llm-chatbot/modules/chatbot/deployspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ deploy:
33
install:
44
commands:
55
- npm ci
6+
- npx @aws-amplify/cli codegen add --yes
67
build:
78
commands:
89
- env | grep NEXUS | sort | awk -F= '{printf "%-30s = %s\n", $1, $2}'

aws-genai-llm-chatbot/package/package/capability.yaml

Lines changed: 0 additions & 102 deletions
This file was deleted.

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,23 @@
88
"engines": {
99
"node": ">=18.0.0 <21.0.0"
1010
},
11+
"files": [
12+
"aws-genai-llm-chatbot",
13+
"bin",
14+
"lib",
15+
"cdk.json"
16+
],
1117
"scripts": {
18+
"tsc": "tsc",
1219
"build": "amplify codegen && tsc",
1320
"cdk": "cdk",
1421
"deploy": "npx cdk deploy",
1522
"hotswap": "cdk deploy --hotswap",
1623
"watch": "cdk watch",
1724
"test": "jest",
1825
"pytest": "pytest tests/",
19-
"prevend": "./scripts/vend-prep.sh --pre",
20-
"postvend": "./scripts/vend-prep.sh --post",
26+
"prepack": "./scripts/vend-prep.sh --pre",
27+
"postpack": "./scripts/vend-prep.sh --post",
2128
"test-all": "npm run test && npm run pytest",
2229
"integtest": "pytest integtests/",
2330
"test:integration": "python -m pytest tests/integration/ -xvs",

scripts/tarball-size.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
# tarball-size.sh - Script to create a tarball and analyze its size
3+
# This implements suggestion #9 from the tarball size reduction plan
4+
5+
set -e # Exit immediately if a command exits with a non-zero status
6+
7+
# Print header
8+
echo "===== Tarball Size Analysis ====="
9+
echo "Creating tarball with npm pack..."
10+
11+
# Create the package without publishing
12+
npm pack
13+
14+
# Get the name of the created tarball (should be the only .tgz file)
15+
TARBALL=$(ls -t *.tgz | head -1)
16+
17+
if [ -z "$TARBALL" ]; then
18+
echo "Error: No tarball was created"
19+
exit 1
20+
fi
21+
22+
echo -e "\n===== Tarball Information ====="
23+
echo "Tarball name: $TARBALL"
24+
25+
# Check the size
26+
echo -e "\n===== Size Information ====="
27+
du -h "$TARBALL"
28+
29+
# Get total size in bytes for more precise comparison (macOS compatible)
30+
BYTES=$(stat -f %z "$TARBALL" 2>/dev/null || stat --format=%s "$TARBALL" 2>/dev/null)
31+
echo "Size in bytes: $BYTES"
32+
33+
# Create a temporary directory for extraction
34+
TEMP_DIR=$(mktemp -d)
35+
echo -e "\n===== Extracting to $TEMP_DIR ====="
36+
37+
# Extract the tarball
38+
tar -xzf "$TARBALL" -C "$TEMP_DIR"
39+
40+
# Show the largest files/directories
41+
echo -e "\n===== 20 Largest Files/Directories ====="
42+
find "$TEMP_DIR" -type f -exec du -h {} \; | sort -hr | head -20
43+
44+
# Show directory sizes
45+
echo -e "\n===== Directory Sizes ====="
46+
find "$TEMP_DIR" -type d -depth 2 -exec du -sh {} \; | sort -hr | head -10
47+
48+
# Count files by extension
49+
echo -e "\n===== Files by Extension ====="
50+
find "$TEMP_DIR" -type f | grep -v "node_modules" | sed 's/.*\.//' | sort | uniq -c | sort -nr | head -10
51+
52+
# Clean up
53+
echo -e "\n===== Cleaning Up ====="
54+
rm -rf "$TEMP_DIR"
55+
echo "Temporary directory removed"
56+
57+
echo -e "\n===== Recommendations ====="
58+
echo "Consider the following to reduce tarball size:"
59+
echo "1. Add large files/directories to .npmignore"
60+
echo "2. Use the 'files' field in package.json to include only necessary files"
61+
echo "3. Remove development dependencies before packaging"
62+
echo "4. Compress images and other assets"
63+
echo "5. Remove source maps and debug files"
64+
65+
echo -e "\nAnalysis complete!"

scripts/vend-prep.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ show_usage() {
3535

3636
# Function to prepare for vending (copy files)
3737
pre_vend() {
38+
npx @aws-amplify/cli codegen --yes
39+
npx rimraf lib/**/*.js.map
40+
npx rimraf ./**/node_modules
41+
3842
# Check if module directory exists
3943
if [ ! -d "$MODULE_DIR" ]; then
4044
echo "Module directory does not exist: $MODULE_DIR"

0 commit comments

Comments
 (0)