From b171e8e00fc2516d7a76191d6a744cf7da9795ee Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 18 Oct 2023 14:28:05 +0200 Subject: [PATCH] Update the script to be sh and workspace agnostic --- hosting/single/Dockerfile.v2 | 5 +-- scripts/removeWorkspaceDependencies.sh | 47 +++++++------------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/hosting/single/Dockerfile.v2 b/hosting/single/Dockerfile.v2 index b1abe6d53e..ad11545a22 100644 --- a/hosting/single/Dockerfile.v2 +++ b/hosting/single/Dockerfile.v2 @@ -19,13 +19,14 @@ COPY packages/string-templates/package.json packages/string-templates/package.js COPY scripts/removeWorkspaceDependencies.sh scripts/removeWorkspaceDependencies.sh RUN chmod +x ./scripts/removeWorkspaceDependencies.sh -RUN ./scripts/removeWorkspaceDependencies.sh +RUN ./scripts/removeWorkspaceDependencies.sh packages/server/package.json +RUN ./scripts/removeWorkspaceDependencies.sh packages/worker/package.json # We will never want to sync pro, but the script is still required RUN echo '' > scripts/syncProPackage.js RUN jq 'del(.scripts.postinstall)' package.json > temp.json && mv temp.json package.json -RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production +RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn yarn install --production # copy the actual code COPY packages/server/dist packages/server/dist diff --git a/scripts/removeWorkspaceDependencies.sh b/scripts/removeWorkspaceDependencies.sh index 627058c92a..850dea924c 100755 --- a/scripts/removeWorkspaceDependencies.sh +++ b/scripts/removeWorkspaceDependencies.sh @@ -1,31 +1,17 @@ -#!/bin/bash +#!/bin/sh -packages_to_remove=( - @budibase/backend-core - @budibase/bbui - @budibase/builder - @budibase/cli - @budibase/client - @budibase/frontend-core - @budibase/pro - @budibase/sdk - @budibase/server - @budibase/shared-core # We cannot remove string-templates yet because it cannot be bundled by esbuild as a dependency - @budibase/string-templates - @budibase/types - @budibase/worker -) +packages_to_remove="@budibase/backend-core @budibase/bbui @budibase/builder @budibase/cli @budibase/client @budibase/frontend-core @budibase/pro @budibase/sdk @budibase/server @budibase/shared-core @budibase/types @budibase/worker" - -root_package_json=$(cat "package.json") +package_json_path="$1" +package_json=$(cat "$package_json_path") process_package() { - local pkg="$1" - local package_json=$(cat "$pkg/package.json") - local has_changes=false + pkg_path="$1" + package_json=$(cat "$pkg_path") + has_changes=false - for package_name in "${packages_to_remove[@]}"; do + for package_name in $packages_to_remove; do if echo "$package_json" | jq -e --arg package_name "$package_name" '.dependencies | has($package_name)' > /dev/null; then package_json=$(echo "$package_json" | jq "del(.dependencies[\"$package_name\"])") has_changes=true @@ -33,20 +19,11 @@ process_package() { done if [ "$has_changes" = true ]; then - echo "$package_json" > "$1/package.json" + echo "$package_json" > "$pkg_path" fi } +process_package "$package_json_path" -for pkg in $(echo "$root_package_json" | jq -r '.workspaces.packages[]' ); do - if [[ "$pkg" == *"*"* ]]; then - # Use find to iterate through immediate subdirectories - find "$pkg" -maxdepth 1 -type d -print | while read -r workspace_package; do - process_package "$workspace_package" - done - else - process_package "$pkg" - fi -done - -echo "$root_package_json" | jq "del(.resolutions)" > "package.json" \ No newline at end of file +package_json=$(cat "$package_json_path") +echo "$package_json" | jq "del(.resolutions)" > "$1"