Skip to content

Commit ce73b2f

Browse files
authored
fix: support yarn classic (#350)
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent e12bc82 commit ce73b2f

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

docker-image/Dockerfiles/Dockerfile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ RUN curl -kL https://services.gradle.org/distributions/gradle-9.2.1-bin.zip -o /
2121
RUN curl -kL https://go.dev/dl/go1.25.5.linux-amd64.tar.gz -o /tmp/golang-package.tar.gz \
2222
&& tar xvzf /tmp/golang-package.tar.gz -C /usr/
2323

24-
# install corepack and package managers (pnpm, yarn) - stage to /usr/local for easy copying
24+
# install corepack and package managers (pnpm, yarn classic + berry) - stage to /usr/local for easy copying
2525
ENV COREPACK_HOME=/usr/local/corepack/cache
2626
RUN npm install -g corepack@latest \
2727
&& corepack enable \
2828
&& corepack prepare pnpm@10.1.0 --activate \
29+
&& corepack prepare yarn@1.22.22 \
2930
&& corepack prepare yarn@4.9.1 --activate \
3031
&& NPM_PREFIX=$(npm config get prefix) \
3132
&& mkdir -p /usr/local/corepack/bin \
@@ -111,12 +112,15 @@ ENV GRADLE_HOME=/usr/gradle-9.2.1
111112
COPY --from=builder /usr/local/corepack/ /usr/local/corepack/
112113
ENV COREPACK_HOME=/usr/local/corepack/cache
113114

114-
# Install Python via microdnf and fix corepack cache permissions
115+
# Install Python via microdnf, create yarn wrapper scripts, and fix permissions
115116
USER root
116117
RUN microdnf install -y python3 python3-pip \
117118
&& microdnf clean all \
118119
&& chown -R 1001:0 /usr/local/corepack/cache \
119-
&& chmod -R g+rwX /usr/local/corepack/cache
120+
&& chmod -R g+rwX /usr/local/corepack/cache \
121+
&& printf '#!/bin/sh\nexec corepack yarn@1.22.22 "$@"\n' > /usr/local/bin/yarn-classic \
122+
&& printf '#!/bin/sh\nexec corepack yarn@4.9.1 "$@"\n' > /usr/local/bin/yarn-berry \
123+
&& chmod +x /usr/local/bin/yarn-classic /usr/local/bin/yarn-berry
120124
USER 1001
121125

122126
# Update PATH (corepack bin first for pnpm/yarn to be found reliably)

docker-image/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ Ecosystem | Version
2222
Maven | 3.9.12 |
2323
Gradle | 9.2.1 |
2424
Go | 1.25.5 |
25-
NPM | 10.8.2 |
25+
NPM | 11.6.2 |
2626
PNPM | 10.1.0 |
27-
Yarn | 4.9.1 |
27+
Yarn Classic | 4.9.1 |
28+
Yarn Berry | 1.22.22 |
2829
Python | 3.9.25 |
2930

3031
## Usage Notes

docker-image/scripts/trustify-da.sh

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@ output_file_path="$2"
55

66
printf "Analyzing the stack. Please wait..\n\n"
77

8+
# Get the directory containing the manifest file
9+
manifest_dir=$(dirname "$manifest_file_path")
10+
manifest_name=$(basename "$manifest_file_path")
11+
12+
# Detect and set the correct yarn version if this is a yarn project
13+
if [ "$manifest_name" = "package.json" ] && [ -f "$manifest_dir/yarn.lock" ]; then
14+
# Check if packageManager is already declared in package.json
15+
package_manager=$(jq -r '.packageManager // empty' "$manifest_file_path" 2>/dev/null)
16+
17+
if [ -z "$package_manager" ]; then
18+
# No packageManager declared, detect based on project files
19+
if [ -f "$manifest_dir/.yarnrc.yml" ]; then
20+
# .yarnrc.yml exists = Yarn Berry
21+
printf "Detected Yarn Berry project (found .yarnrc.yml), using yarn@4.9.1\n"
22+
export TRUSTIFY_DA_YARN_PATH=/usr/local/bin/yarn-berry
23+
else
24+
# No .yarnrc.yml = Yarn Classic
25+
printf "Detected Yarn Classic project, using yarn@1.22.22\n"
26+
export TRUSTIFY_DA_YARN_PATH=/usr/local/bin/yarn-classic
27+
fi
28+
else
29+
printf "Using declared packageManager: %s\n" "$package_manager"
30+
fi
31+
fi
32+
833
# Getting RHDA stack analysis report using Exhort Javascript CLI.
934
report=$(trustify-da-javascript-client stack $manifest_file_path 2>error.log)
1035

@@ -90,5 +115,5 @@ printf "=%.0s" {1..50}
90115
$output_file_path
91116

92117
printf "\nFull report is saved into file: $output_file_path"
93-
printf "\nTask is completed."
118+
printf "\nTask is completed.\n"
94119
fi

0 commit comments

Comments
 (0)