Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Commit

Permalink
fix(yarn): setup a fallback strategy for workspace detection and non-…
Browse files Browse the repository at this point in the history
…corepack logic (#862)
  • Loading branch information
JGAntunes authored Oct 26, 2022
1 parent aca5d7a commit 4e36794
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,13 @@ ENV PNPM_VERSION=7.13.4

ENV NETLIFY_NODE_VERSION="16"

# We install an "internal" yarn v1 executable to be used only for workspace detection. We can remove it once we have a better
# strategy in place
RUN /bin/bash -c ". ~/.nvm/nvm.sh && \
nvm install --no-progress $NETLIFY_NODE_VERSION && \
npm install -g grunt-cli bower && \
nvm alias default node && \
bash /usr/local/bin/yarn-installer.sh --version $YARN_VERSION && \
nvm cache clear && \
corepack enable && \
corepack prepare yarn@$YARN_VERSION --activate && \
Expand Down
10 changes: 9 additions & 1 deletion run-build-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ DEFAULT_SWIFT_VERSION="5.4"
# PHP version
DEFAULT_PHP_VERSION="8.0"

# Internal yarn config
# We use an "internal" yarn v1 executable as to not be impacted by corepack yarn selection
INTERNAL_YARN_PATH="$HOME/.yarn/bin"

# Pipenv configuration
export PIPENV_RUNTIME=3.8
export PIPENV_VENV_IN_PROJECT=1
Expand Down Expand Up @@ -107,7 +111,7 @@ restore_node_modules() {
# YARN_IGNORE_PATH will ignore the presence of a local yarn executable (i.e. yarn 2) and default
# to using the global one (which, for now, is always yarn 1.x). See https://yarnpkg.com/configuration/yarnrc#ignorePath
# we can actually use this command for npm workspaces as well
workspace_output="$(YARN_IGNORE_PATH=1 yarn workspaces --json info 2>/dev/null)"
workspace_output="$(YARN_IGNORE_PATH=1 "$INTERNAL_YARN_PATH/yarn" workspaces --json info 2>/dev/null)"
workspace_exit_code=$?
if [ $workspace_exit_code -eq 0 ]
then
Expand Down Expand Up @@ -137,6 +141,10 @@ run_yarn() {
restore_home_cache ".yarn_cache" "yarn cache"

if ! [ $(which corepack) ] || has_feature_flag "$featureFlags" "build-image-disable-node-corepack"; then

# We manually add our internal yarn version to our path as a fallback, as this means the customer won't have a default
# yarn version installed
export PATH=$INTERNAL_YARN_PATH:$PATH
if [ -d $NETLIFY_CACHE_DIR/yarn ]
then
export PATH=$NETLIFY_CACHE_DIR/yarn/bin:$PATH
Expand Down

0 comments on commit 4e36794

Please sign in to comment.