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

Fix usage of RAILS_ENV #366

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/shakapacker/dev_server_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def load_config
@config = Configuration.new(
root_path: app_root,
config_path: Pathname.new(@shakapacker_config),
env: ENV["RAILS_ENV"]
env: ENV["RAILS_ENV"] || "development"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would there be no RAILS_ENV?

This is probably ok, as maybe it's weird to run the the dev_server_runner outside of development?

The part of the shakapacker.yml used is based on the RAILS_ENV.

https://github.com/shakacode/shakapacker/blob/master/lib/shakapacker/configuration.rb#L130

)

dev_server = DevServer.new(@config)
Expand Down
2 changes: 1 addition & 1 deletion lib/shakapacker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Shakapacker
class Runner
def self.run(argv)
$stdout.sync = true
ENV["NODE_ENV"] ||= (ENV["RAILS_ENV"] == "production") ? "production" : "development"
ENV["NODE_ENV"] ||= ENV["RAILS_ENV"] || "development"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if you have a RAILS_ENV of staging or something else.

The only fully supported value of NODE_ENV is 'production'.

Otherewise, we want to use 'development'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with supporting only the production or development here is that in some cases, you may have some assets that may need to be compiled in against test environment.
We, at decidim had a very strange issue, when our compiling was ok, which meant that assets were successfuly built, but in the same time, when running bundle exec rspec with no assets, the pipeline failed due to different compiling strategy between prod and test.

Please see a more detailed explanation the bug #365.

Additionally you may want to see the decidim/decidim#11728, in which, in order to fully fix the issue explained, i have ended up in having the TerserPlugin enabled on all my environments.

I will shortly post a comment on #365 explaining how i got into this mess, and maybe the proposed fix, does not to be applied :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment was added #365 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alecslupu if you want a custom NODE_ENV, then why not just set it before running the scripts that invoke this command?

new(argv).run
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/shakapacker/compile.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $stdout.sync = true
namespace :shakapacker do
desc "Compile JavaScript packs using webpack for production with digests"
task compile: ["shakapacker:verify_install", :environment] do
Shakapacker.with_node_env(ENV.fetch("NODE_ENV", "production")) do
Shakapacker.with_node_env(ENV.fetch("NODE_ENV", ENV["RAILS_ENV"] || "production")) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see prior comment

Shakapacker.ensure_log_goes_to_stdout do
exit! unless Shakapacker.compile
end
Expand Down