From 2ec82f91adca149b4fb13fadec6a3a85a432ca78 Mon Sep 17 00:00:00 2001 From: Ruben Romero Montes Date: Mon, 19 Jan 2026 12:25:11 +0100 Subject: [PATCH] fix: support yarn classic Signed-off-by: Ruben Romero Montes --- docker-image/Dockerfiles/Dockerfile | 10 +++++++--- docker-image/README.md | 5 +++-- docker-image/scripts/trustify-da.sh | 27 ++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/docker-image/Dockerfiles/Dockerfile b/docker-image/Dockerfiles/Dockerfile index 2a1b2a2e..c6843174 100644 --- a/docker-image/Dockerfiles/Dockerfile +++ b/docker-image/Dockerfiles/Dockerfile @@ -21,11 +21,12 @@ RUN curl -kL https://services.gradle.org/distributions/gradle-9.2.1-bin.zip -o / RUN curl -kL https://go.dev/dl/go1.25.5.linux-amd64.tar.gz -o /tmp/golang-package.tar.gz \ && tar xvzf /tmp/golang-package.tar.gz -C /usr/ -# install corepack and package managers (pnpm, yarn) - stage to /usr/local for easy copying +# install corepack and package managers (pnpm, yarn classic + berry) - stage to /usr/local for easy copying ENV COREPACK_HOME=/usr/local/corepack/cache RUN npm install -g corepack@latest \ && corepack enable \ && corepack prepare pnpm@10.1.0 --activate \ + && corepack prepare yarn@1.22.22 \ && corepack prepare yarn@4.9.1 --activate \ && NPM_PREFIX=$(npm config get prefix) \ && mkdir -p /usr/local/corepack/bin \ @@ -111,12 +112,15 @@ ENV GRADLE_HOME=/usr/gradle-9.2.1 COPY --from=builder /usr/local/corepack/ /usr/local/corepack/ ENV COREPACK_HOME=/usr/local/corepack/cache -# Install Python via microdnf and fix corepack cache permissions +# Install Python via microdnf, create yarn wrapper scripts, and fix permissions USER root RUN microdnf install -y python3 python3-pip \ && microdnf clean all \ && chown -R 1001:0 /usr/local/corepack/cache \ - && chmod -R g+rwX /usr/local/corepack/cache + && chmod -R g+rwX /usr/local/corepack/cache \ + && printf '#!/bin/sh\nexec corepack yarn@1.22.22 "$@"\n' > /usr/local/bin/yarn-classic \ + && printf '#!/bin/sh\nexec corepack yarn@4.9.1 "$@"\n' > /usr/local/bin/yarn-berry \ + && chmod +x /usr/local/bin/yarn-classic /usr/local/bin/yarn-berry USER 1001 # Update PATH (corepack bin first for pnpm/yarn to be found reliably) diff --git a/docker-image/README.md b/docker-image/README.md index 55baf0bd..079f870c 100644 --- a/docker-image/README.md +++ b/docker-image/README.md @@ -22,9 +22,10 @@ Ecosystem | Version Maven | 3.9.12 | Gradle | 9.2.1 | Go | 1.25.5 | -NPM | 10.8.2 | +NPM | 11.6.2 | PNPM | 10.1.0 | -Yarn | 4.9.1 | +Yarn Classic | 4.9.1 | +Yarn Berry | 1.22.22 | Python | 3.9.25 | ## Usage Notes diff --git a/docker-image/scripts/trustify-da.sh b/docker-image/scripts/trustify-da.sh index ae6eb580..6792e84b 100644 --- a/docker-image/scripts/trustify-da.sh +++ b/docker-image/scripts/trustify-da.sh @@ -5,6 +5,31 @@ output_file_path="$2" printf "Analyzing the stack. Please wait..\n\n" +# Get the directory containing the manifest file +manifest_dir=$(dirname "$manifest_file_path") +manifest_name=$(basename "$manifest_file_path") + +# Detect and set the correct yarn version if this is a yarn project +if [ "$manifest_name" = "package.json" ] && [ -f "$manifest_dir/yarn.lock" ]; then + # Check if packageManager is already declared in package.json + package_manager=$(jq -r '.packageManager // empty' "$manifest_file_path" 2>/dev/null) + + if [ -z "$package_manager" ]; then + # No packageManager declared, detect based on project files + if [ -f "$manifest_dir/.yarnrc.yml" ]; then + # .yarnrc.yml exists = Yarn Berry + printf "Detected Yarn Berry project (found .yarnrc.yml), using yarn@4.9.1\n" + export TRUSTIFY_DA_YARN_PATH=/usr/local/bin/yarn-berry + else + # No .yarnrc.yml = Yarn Classic + printf "Detected Yarn Classic project, using yarn@1.22.22\n" + export TRUSTIFY_DA_YARN_PATH=/usr/local/bin/yarn-classic + fi + else + printf "Using declared packageManager: %s\n" "$package_manager" + fi +fi + # Getting RHDA stack analysis report using Exhort Javascript CLI. report=$(trustify-da-javascript-client stack $manifest_file_path 2>error.log) @@ -90,5 +115,5 @@ printf "=%.0s" {1..50} $output_file_path printf "\nFull report is saved into file: $output_file_path" - printf "\nTask is completed." + printf "\nTask is completed.\n" fi