From 8ab64d598a6b2a8e2d8b7ed5e65aeed0a10177af Mon Sep 17 00:00:00 2001 From: Clayton Neal Date: Mon, 27 Jan 2025 09:44:40 +0000 Subject: [PATCH] chore: dev dependencies removed (#1742) --- docker/rpc-proxy/Dockerfile | 6 ++++ docker/rpc-proxy/adjust-packages.sh | 48 +++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 docker/rpc-proxy/adjust-packages.sh diff --git a/docker/rpc-proxy/Dockerfile b/docker/rpc-proxy/Dockerfile index 6e7042935..5f8c50ebd 100644 --- a/docker/rpc-proxy/Dockerfile +++ b/docker/rpc-proxy/Dockerfile @@ -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 diff --git a/docker/rpc-proxy/adjust-packages.sh b/docker/rpc-proxy/adjust-packages.sh new file mode 100755 index 000000000..4e900ad92 --- /dev/null +++ b/docker/rpc-proxy/adjust-packages.sh @@ -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 " + 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