rails / jsbundling-rails

Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.
MIT License
831 stars 143 forks source link

Support environment variable to skip Yarn install #150

Closed aduth closed 1 year ago

aduth commented 1 year ago

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 commented 1 year ago

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.

rserling commented 5 months ago

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

aduth commented 5 months ago

@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 cssbundling-rails@1.3.0 (https://github.com/rails/cssbundling-rails/pull/125) fixed it, as that newer version now supports the same environment variable.

rserling commented 5 months ago

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

aduth commented 5 months ago

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:

rserling commented 5 months ago

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