Skip to content
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

"webpacker:yarn_install" Task removes dev dependencies #1330

Closed
odlp opened this issue Mar 9, 2018 · 3 comments
Closed

"webpacker:yarn_install" Task removes dev dependencies #1330

odlp opened this issue Mar 9, 2018 · 3 comments

Comments

@odlp
Copy link
Contributor

odlp commented Mar 9, 2018

On CircleCI, with a Rails 4.2 app, our RSpec test suite precompiles assets. This triggers a webpacker:yarn_install and webpacker:compile:

def enhance_assets_precompile
Rake::Task["assets:precompile"].enhance do
unless Rake::Task.task_defined?("yarn:install")
# For Rails < 5.1
Rake::Task["webpacker:yarn_install"].invoke
end
Rake::Task["webpacker:compile"].invoke
end
end

Unfortunately the webpacker:yarn_install task isn't environment-aware:

system "yarn install --no-progress --production"

The --production flag ends up removing the JS dev dependencies. On CI this means we'd have to re-run yarn install before running JS unit tests or redefine the Rake task.

Rough overview of the steps on CI:

yarn install
ls node_modules | wc -l # 966

bundle exec rspec
ls node_modules | wc -l # 666

yarn test

# yarn run v1.5.1
# $ RAILS_ENV=test node_modules/.bin/karma start --single-run
# sh: node_modules/.bin/karma: No such file or directory
@luccasmaso
Copy link

Nice one, spent some hours until discover this )=

@odlp
Copy link
Contributor Author

odlp commented Apr 11, 2018

As a temporary workaround one can redefine the Rake task:

# lib/tasks/webpacker.rake

# Redefining task so we don't remove the dev dependencies when running on CI
Rake::Task["webpacker:yarn_install"].clear

namespace :webpacker do
  desc "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
  task :yarn_install do
    if ENV["RAILS_ENV"] == "production"
      system "yarn install --no-progress --frozen-lockfile --production"
    else
      system "yarn install --no-progress"
    end
  end
end

hallelujah added a commit to 3scale/porta that referenced this issue Oct 11, 2018
Reported issue rails/webpacker#1330
Making it environment aware allow CI build to precompile assets
@odlp
Copy link
Contributor Author

odlp commented Dec 6, 2018

Closing - fixed in #1331

@odlp odlp closed this as completed Dec 6, 2018
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

No branches or pull requests

2 participants