rails / jsbundling-rails

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

How to avoid multiple `yarn install` commands on Heroku #130

Closed rsanheim closed 1 year ago

rsanheim commented 2 years ago

Note: This isn't really a jsbundling-rails issue, but I figured this is going to be fairly common issues as more folks are upgrading Rails / Heroku legacy apps from webpack to jsbundling w/ esbuild or alternative tools.

We are working on converting to esbuild away from webpack / rails-webpacker for a large-ish app that is deployed to Heroku.

So far almost everything is working, but we are seeing multiple calls to yarn install in Heroku deploys now in our esbuild branch. I'm wondering if there is a way to avoid this with Heroku when having both the nodejs and ruby buildpacks installed? The double installs aren't really a problem, but they do clutter up our logs and add time to deployments.

I read through https://github.com/rails/jsbundling-rails/issues/16, and also scanned through the node and ruby buildpack code, but don't see any clear way to tell one or the other to be the 'winner' and the only tool that handles running yarn install.

From what I can tell, the nodejs buildpack sees that we have a a package.json with a build task, so it installs node and yarn and then executes yarn run.

Then the ruby buildpack detects the ruby app, and runs the assets precompile task, which again runs the same steps (which I believe jsbundling-rails wires up).

I suppose we could try to explicitly clear out the precompile task in Rails land, but that feels pretty hacky and not a good long-term solution.

Is there an ENV var or flag we could set to tell the nodejs task to not try to build things, and instead let the ruby build pack be the 'builder' ?

Here are our buildpacks btw:

1. https://github.com/lstoll/heroku-buildpack-monorepo
2. https://github.com/DataDog/heroku-buildpack-datadog.git
3. https://github.com/heroku/heroku-buildpack-nginx
4. heroku/nodejs
5. heroku/ruby

And here is the output of a recent heroku deploy showing the multiple calls to yarn install.

dhh commented 1 year ago

I'd take a SKIP_YARN_INSTALL additional ENV for the build task, if you'd like to work on that.