Skip to content

Allow building with Yarn 2+#322

Open
jgyselov wants to merge 1 commit intoRedHatInsights:masterfrom
jgyselov:monorepo_adaptations
Open

Allow building with Yarn 2+#322
jgyselov wants to merge 1 commit intoRedHatInsights:masterfrom
jgyselov:monorepo_adaptations

Conversation

@jgyselov
Copy link
Copy Markdown

We would like to use the frontend builder for our project which uses Yarn 3.

The problem is that the YARN_BUILD_SCRIPT variable is treated as a Yarn config variable and it results in different behavior with Yarn 1 and Yarn 2+.

Renaming the variable fixes this issue.

Finally, note that most settings can also be defined through environment variables (at least for the simpler ones; arrays and objects aren't supported yet). To do this, just prefix the names and write them in snake case: YARN_CACHE_FOLDER will set the cache folder (such values will overwrite any that might have been defined in the RC files - use them sparingly).
https://v3.yarnpkg.com/configuration/yarnrc

The other problem is the network timeout workaround which also doesn't work with Yarn 2+:

# Work around large package timeout; up default from 30s to 5m
yarn config set network-timeout 300000

The easiest solution would be removing it completely (but I'm open to looking at other options).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 17, 2026

Summary by CodeRabbit

  • Chores
    • Standardized build environment variable naming conventions across all deployment configurations and build pipeline stages for improved consistency.
    • Updated and improved Yarn build script configuration handling and management throughout the build process.
    • Removed and simplified Yarn network timeout settings in the build system.
    • Updated documentation to reflect all build system configuration changes.

Walkthrough

The changes rename the Yarn build script environment variable from YARN_BUILD_SCRIPT to APP_YARN_BUILD_SCRIPT across Docker configuration and build scripts, and remove the yarn network-timeout configuration step from the universal build script.

Changes

Cohort / File(s) Summary
Docker Configuration
Dockerfile, src/frontend-build.sh
Renamed build argument and environment variable from YARN_BUILD_SCRIPT to APP_YARN_BUILD_SCRIPT for consistency; updated Docker container invocation to pass the new environment variable.
Build Script
universal_build.sh
Updated to read APP_YARN_BUILD_SCRIPT environment variable instead of YARN_BUILD_SCRIPT; removed yarn network-timeout configuration setting.
Documentation
test/README.md
Updated multi-stage Docker build example to reference APP_YARN_BUILD_SCRIPT as a builder-stage variable unavailable at runtime.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Allow building with Yarn 2+' accurately summarizes the main objective of the changeset, which is to enable compatibility with Yarn 2+ by renaming environment variables and removing incompatible workarounds.
Description check ✅ Passed The description clearly explains the motivation (Yarn 3 compatibility), identifies two specific problems (environment variable naming conflicts and network timeout workaround), and provides the context and rationale for the proposed changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/frontend-build.sh (1)

74-76: Rename is consistent, but is a breaking change for external callers.

Both the default setter (Lines 74–76) and the docker run -e forwarding (Line 168) are correctly updated. Note that callers of this script that previously set YARN_BUILD_SCRIPT in their pr_check / pipeline env will stop taking effect silently — the default build:prod will be used instead. Please call this out in release notes / CHANGELOG or add a short deprecation shim here mirroring the one suggested in universal_build.sh, e.g.:

Optional deprecation shim
+if [ -z "${APP_YARN_BUILD_SCRIPT:-}" ] && [ -n "${YARN_BUILD_SCRIPT:-}" ]; then
+  echo "WARNING: YARN_BUILD_SCRIPT is deprecated; use APP_YARN_BUILD_SCRIPT instead." >&2
+  export APP_YARN_BUILD_SCRIPT="$YARN_BUILD_SCRIPT"
+fi
 if [ -z "$APP_YARN_BUILD_SCRIPT" ]; then
   export APP_YARN_BUILD_SCRIPT="build:prod"
 fi

Also applies to: 168-168

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/frontend-build.sh` around lines 74 - 76, The rename of YARN_BUILD_SCRIPT
to APP_YARN_BUILD_SCRIPT is breaking for external callers; add a deprecation
shim to preserve backward compatibility by checking if YARN_BUILD_SCRIPT is set
and, if so, set APP_YARN_BUILD_SCRIPT from it (and log or echo a deprecation
warning), while keeping the new default export for APP_YARN_BUILD_SCRIPT; also
add a brief note to release notes/CHANGELOG calling out the rename and the
temporary shim (reference symbols: APP_YARN_BUILD_SCRIPT and YARN_BUILD_SCRIPT,
and the docker run -e forwarding change).
universal_build.sh (1)

69-75: Rename looks correct; consider noting the breaking change.

The logic change is straightforward and matches the Dockerfile/src/frontend-build.sh contract (default build:prod when unset). However, this is a breaking rename for any downstream consumer that currently sets YARN_BUILD_SCRIPT in their CI/build environment — they will silently fall back to yarn build:prod without any warning.

Options to consider:

  • Document the rename prominently in the release notes / README.
  • Or temporarily honor YARN_BUILD_SCRIPT as a fallback with a deprecation warning, e.g.:
Optional backward-compat shim
   elif [[ "$USES_YARN" == true ]]; then
     # If APP_YARN_BUILD_SCRIPT env var is set use that
     # Otherwise just build
+    if [[ -z "${APP_YARN_BUILD_SCRIPT:-}" && -n "${YARN_BUILD_SCRIPT:-}" ]]; then
+      echo "WARNING: YARN_BUILD_SCRIPT is deprecated (Yarn 2+ treats YARN_* as config keys); use APP_YARN_BUILD_SCRIPT instead." >&2
+      APP_YARN_BUILD_SCRIPT="$YARN_BUILD_SCRIPT"
+    fi
     if [[ -n "$APP_YARN_BUILD_SCRIPT" ]]; then
       yarn "$APP_YARN_BUILD_SCRIPT"
     else
       yarn build:prod
     fi
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@universal_build.sh` around lines 69 - 75, The change renames
YARN_BUILD_SCRIPT to APP_YARN_BUILD_SCRIPT which breaks consumers still setting
the old var; update the shell logic so that when APP_YARN_BUILD_SCRIPT is unset
but YARN_BUILD_SCRIPT is set, the script uses YARN_BUILD_SCRIPT and emits a
clear deprecation warning to stderr (e.g., echo >&2) advising to switch to
APP_YARN_BUILD_SCRIPT, otherwise default to running yarn build:prod; target the
if-block that checks APP_YARN_BUILD_SCRIPT and add the fallback/deprecation
handling for YARN_BUILD_SCRIPT.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/frontend-build.sh`:
- Around line 74-76: The rename of YARN_BUILD_SCRIPT to APP_YARN_BUILD_SCRIPT is
breaking for external callers; add a deprecation shim to preserve backward
compatibility by checking if YARN_BUILD_SCRIPT is set and, if so, set
APP_YARN_BUILD_SCRIPT from it (and log or echo a deprecation warning), while
keeping the new default export for APP_YARN_BUILD_SCRIPT; also add a brief note
to release notes/CHANGELOG calling out the rename and the temporary shim
(reference symbols: APP_YARN_BUILD_SCRIPT and YARN_BUILD_SCRIPT, and the docker
run -e forwarding change).

In `@universal_build.sh`:
- Around line 69-75: The change renames YARN_BUILD_SCRIPT to
APP_YARN_BUILD_SCRIPT which breaks consumers still setting the old var; update
the shell logic so that when APP_YARN_BUILD_SCRIPT is unset but
YARN_BUILD_SCRIPT is set, the script uses YARN_BUILD_SCRIPT and emits a clear
deprecation warning to stderr (e.g., echo >&2) advising to switch to
APP_YARN_BUILD_SCRIPT, otherwise default to running yarn build:prod; target the
if-block that checks APP_YARN_BUILD_SCRIPT and add the fallback/deprecation
handling for YARN_BUILD_SCRIPT.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fd561b11-9918-40d4-9ec0-a032df64f452

📥 Commits

Reviewing files that changed from the base of the PR and between 46fccd9 and dabe65d.

📒 Files selected for processing (4)
  • Dockerfile
  • src/frontend-build.sh
  • test/README.md
  • universal_build.sh

Comment thread src/frontend-build.sh
if [ -z "$NPM_BUILD_SCRIPT" ]; then
export NPM_BUILD_SCRIPT="build"
fi
if [ -z "$YARN_BUILD_SCRIPT" ]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgyselov thank you for the enhancement!

Removing these env vars will cause current consumers of the common builder utilities to start failing (at least those who use yarn).

Would it be possible to keep the existing env var, add a new one (such as YARN_NEXT_BUILD_SCRIPT), and then short circuit/abort setting the legacy env var if the new one is set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants