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

Return false in production environments #1179

Merged
merged 4 commits into from
Jan 15, 2018
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Check for dev server config instead
gauravtiwari committed Jan 14, 2018

Verified

This commit was created on github.com and signed with GitHub’s verified signature. The key has expired.
commit b09ff29f1410f9ee73ff423d6459d1799a2e4b2f
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

## [Unreleased]

- Disable dev server running? check in production environments [#1179](https://github.com/rails/webpacker/pull/1179)
- Disable dev server running? check if no dev server config is present in that environment [#1179](https://github.com/rails/webpacker/pull/1179)

## [3.2.0] - 2017-12-16

6 changes: 3 additions & 3 deletions lib/webpacker/dev_server.rb
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@ def initialize(webpacker)
end

def running?
if env.production?
false
else
if config.dev_server.present?
Socket.tcp(host, port, connect_timeout: connect_timeout).close
true
else
false
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be inverted and check env.development? instead. We have production-like envs (staging, beta) that we want skipped too.

if env.development?
  Socket.tcp(host, port, connect_timeout: connect_timeout).close
  true
else
  false
end

Copy link
Member Author

Choose a reason for hiding this comment

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

All production like environments will have NODE_ENV=production and that will evaluate env.production? to true so the logic will work for all production like environments as long as NODE_ENV is set. Would that work?

  def env
    (ENV["NODE_ENV"].presence_in(available_environments) ||
      Rails.env.presence_in(available_environments) ||
        "production".freeze).inquiry
  end

Reason for scoping to production was that, in case someone wants to use dev server in test environment. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can check if dev_server is configured? Since, by default, it's only in development:

development:
<<: *default
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh yes, good idea 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Done 👍

rescue
false
2 changes: 1 addition & 1 deletion test/dev_server_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "test_helper"

class DevServerTest < Webpacker::Test
def test_running
def test_running?
with_node_env("production") do
reloaded_config
refute Webpacker.dev_server.running?