Skip to content

Commit

Permalink
chore: dev dependencies removed
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonneal committed Jan 23, 2025
1 parent e1277ce commit ca49088
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docker/rpc-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ COPY ./package.json ./package.json
COPY ./turbo.json ./turbo.json
COPY ./yarn.lock ./yarn.lock
COPY ./tsconfig.json ./tsconfig.json
COPY ./docker/rpc-proxy/adjust-packages.sh ./adjust-packages.sh

# Install all the dependencies and build the app
RUN yarn install && yarn build

# Clean the package.json files ready for production
RUN apk add --no-cache jq
RUN chmod +x ./adjust-packages.sh
RUN /bin/sh ./adjust-packages.sh ./

# Stage 2: Serve the app using node
FROM node:20.17.0-alpine3.20 AS runner

Expand Down
48 changes: 48 additions & 0 deletions docker/rpc-proxy/adjust-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash

# -----------------------------------------------------------------------------
# Info:
# - input: directory to search for package.json files
# - output:
# package.json without devDependencies section
# package.json without version selectors in dependencies
# -----------------------------------------------------------------------------

# Check if the search directory is provided
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-directory>"
exit 1
fi
SEARCH_DIR="$1"

# Check if the search directory exists
if [ ! -d "$SEARCH_DIR" ]; then
echo "Error: Directory '$SEARCH_DIR' not found."
exit 1
fi


# Find all package.json files in the specified directory (excluding node_modules)
find "$SEARCH_DIR" -type f -name "package.json" ! -path "*/node_modules/*" | while read PACKAGE_JSON; do
echo "Processing: $PACKAGE_JSON"


# Remove the "devDependencies" section and overwrite the file
if jq -e '.devDependencies' "$PACKAGE_JSON" > /dev/null; then
jq 'del(.devDependencies)' "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
echo "devDependencies removed from $PACKAGE_JSON"
else
echo "No devDependencies section found in $PACKAGE_JSON. No changes made."
fi

# Remove version selectors from dependencies
# Check if the dependencies section exists in the package.json file
if jq -e '.dependencies' "$PACKAGE_JSON" > /dev/null; then
# Remove version selectors from dependencies
jq '(.dependencies |= with_entries(.value |= ltrimstr("^") | ltrimstr("~")))' "$PACKAGE_JSON" > temp.json && mv temp.json "$PACKAGE_JSON"
echo "Version selectors (caret/tilde) removed from dependencies in $PACKAGE_JSON"
else
echo "No dependencies section found in $PACKAGE_JSON. No changes made."
fi

done

0 comments on commit ca49088

Please sign in to comment.