Skip to content

Commit 6f689e7

Browse files
committed
Fix yarn installation method for yarn > 1.x.x
This commit add a method to check if the yarn version need installation through Corepack instead of NPM. Why? Because Yarn > 1.x.x isn't installable through NPM since 2019. Extract from Yarn documentation : "Why is the yarn package on npm still on 1.x? Modern releases of Yarn haven't been distributed on npm since 2019. The reason is simple: because Yarn wasn't distributed alongside Node.js, many people relied on something like npm install -g yarn as part of their image building. It meant that any breaking change would make their way on everyone using this pattern, and break their deployments. As a result, we decided to retire the yarn npm package and only use it for the few 1.x maintenance releases needed. Yarn is now installed directly from our website, via either Corepack or yarn set version." Update railties/lib/rails/generators/app_base.rb Co-authored-by: zzak <[email protected]> combine RUN on single line
1 parent 3a91006 commit 6f689e7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

railties/lib/rails/generators/app_base.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,11 @@ def dockerfile_yarn_version
539539
"latest"
540540
end
541541

542+
def yarn_through_corepack?
543+
true if dockerfile_yarn_version == "latest"
544+
dockerfile_yarn_version >= "2"
545+
end
546+
542547
def dockerfile_bun_version
543548
using_bun? and `bun --version`[/\d+\.\d+\.\d+/]
544549
rescue

railties/lib/rails/generators/rails/app/templates/Dockerfile.tt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ RUN apt-get update -qq && \
3838
ARG NODE_VERSION=<%= node_version %>
3939
ARG YARN_VERSION=<%= dockerfile_yarn_version %>
4040
ENV PATH=/usr/local/node/bin:$PATH
41+
<% if yarn_through_corepack? -%>
42+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
43+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
44+
rm -rf /tmp/node-build-master
45+
RUN corepack enable && yarn set version $YARN_VERSION
46+
<% else -%>
4147
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
4248
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
4349
npm install -g yarn@$YARN_VERSION && \
4450
rm -rf /tmp/node-build-master
51+
<% end -%>
4552

4653
<% end -%>
4754
<% if using_bun? -%>
@@ -61,7 +68,7 @@ RUN bundle install && \
6168
<% if using_node? -%>
6269
# Install node modules
6370
COPY package.json yarn.lock ./
64-
RUN yarn install --frozen-lockfile
71+
RUN yarn install --immutable
6572

6673
<% end -%>
6774
<% if using_bun? -%>

0 commit comments

Comments
 (0)