Skip to content

Support environment variable to skip Yarn install #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2023

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Mar 1, 2023

Closes #130

These changes allow a project to skip the yarn install prestep of the JavaScript build if, for example, their build pipeline will already ensure that dependencies have been installed.

Open question: Should this logic be contained to the existing build task, rather than spun out as a new prerequisite task as proposed?

@mikker
Copy link

mikker commented May 8, 2023

It feels sort of weird to me as well that they build command has a forced install step. +1 to this, if not removing yarn install completely from the build task.

@dhh dhh merged commit b29e5fe into rails:main Jun 18, 2023
@aduth aduth deleted the skip-yarn-install-env branch June 20, 2023 18:58
tmaier added a commit to tmaier/cssbundling-rails that referenced this pull request Jun 21, 2023
dhh pushed a commit to rails/cssbundling-rails that referenced this pull request Jun 24, 2023
smartech7 pushed a commit to smartech7/ruby-css-bundling that referenced this pull request Aug 4, 2023
@rserling
Copy link

I see there is a condition here for SKIP_YARN_INSTALL variable. Could you clarify:

  • With what values can this var be populated? Assuming I just say SKIP_YARN_INSTALL=true?
  • At what level of execution is it populated? If jsbundling-rails is being called from rails assets:precompile, how do I make sure this var is seen and obeyed? I'm still getting failed attempts to redundantly execute yarn.

@aduth
Copy link
Contributor Author

aduth commented Apr 11, 2024

@rserling Out of curiosity, are you also using cssbundling-rails? I just tested in our project and was able to reproduce the redundant Yarn install, but I tracked it back to the fact that we're running an older version of cssbundling-rails which also had a built-in Yarn install. Updating to at least [email protected] (rails/cssbundling-rails#125) fixed it, as that newer version now supports the same environment variable.

@rserling
Copy link

@aduth thanks for the response, this is a rough blocker. Unfortunately no, my app is not using cssbundling-rails.

@aduth
Copy link
Contributor Author

aduth commented Apr 12, 2024

Ah, bummer! Well, to answer your original question, it's a simple truthy check, so any value should work (1, true, even empty string).

In my testing, SKIP_YARN_INSTALL=true rails assets:precompile does not show "yarn install" as expected. For our project, we configure this in continuous integration using the CI's environment configuration (GitLab variables in our case), though I'd imagine any equivalent way to set an environment variable should work.

I'm not too sure why it's not working for you, but some ideas to check:

  • Is your installed version of jsbundling-rails at least v1.1.2 which included this change?
  • Is there anything else in your project that's hooking to assets:precompile that might be running yarn install?

@rserling
Copy link

rserling commented Apr 12, 2024

Thanks @aduth I've verified that during build we are getting version 1.3.0 of jsbundling-rails.
It is not clear whether something else is calling yarn install. Failure errors involve rake.
I am using docker with s2i to test locally. Here is the relevant output:

Yarn executable was not detected in the system.
Download Yarn at https://yarnpkg.com/en/docs/install
rake aborted!
jsbundling-rails: Command build failed, ensure `yarn build` runs without errors
/opt/app-root/bundle/ruby/3.1.0/gems/jsbundling-rails-1.3.0/lib/tasks/jsbundling/build.rake:14:in `block (2 levels) in <main>'
/opt/app-root/bundle/ruby/3.1.0/gems/rake-13.2.1/exe/rake:27:in `<top (required)>'
Tasks: TOP => assets:precompile => javascript:build
(See full trace by running task with --trace)
Failed assembling
Error: building at STEP "RUN .s2i/bin/assemble": while running runtime: exit status 1

bobryk729 added a commit to bobryk729/cssbundling-rails that referenced this pull request Mar 13, 2025
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.

How to avoid multiple yarn install commands on Heroku
4 participants