hotswap 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: badcf933f86c51e18eb84dd18518302cf51621e33dc1232385206a1df68d020a
4
- data.tar.gz: cf625050bb3be00cca1b23a95a45a6a3230f3a0dd42e1230766bf8b403f847aa
3
+ metadata.gz: 62ebad7db344b7fe9207d272654825ec184edcc6a975beca1b69da0fd28d6464
4
+ data.tar.gz: ae90b89e45240eeb3ff82e367b397ca72583a479e4f6e8e44266380f72e10e06
5
5
  SHA512:
6
- metadata.gz: a37c15429bc4bf308c122e3eca1258b4916e897cb77f7518e21f6f84f8880c25603340f61f406ede9e628c4aefbfbcd0a40e1259e5d5d0d6990bffdb203b19c1
7
- data.tar.gz: 86bcd2d70ffc9ce32513c609892f854e822cf9656ed9b4f94a7c7a5e1a6171eed70b5cc29adf00f2948912c064ad0874da84bdc0708eeeab34b536b05b4899ce
6
+ metadata.gz: 956acefbe39bdaec50029bdddadec4c72deb31c849c09428949990519dfece496db4d6e939086ff5b0e774d7056a59f858e763b63a60b062068ee17571351a18
7
+ data.tar.gz: 577e3fc013fd8ff08308512ef9a8f999722f4d08f465eb16e99dd088fa569a427f9332800da684e3a5adeaefad992dd9c0840da448feca6baf11bcd488153361
data/exe/hotswap CHANGED
@@ -3,8 +3,8 @@
3
3
  require "socket"
4
4
  require "shellwords"
5
5
 
6
- socket_path = ENV.fetch("HOTSWAP_SOCKET", "tmp/hotswap.sock")
7
- stderr_socket_path = ENV.fetch("HOTSWAP_STDERR_SOCKET", "tmp/hotswap.stderr.sock")
6
+ socket_path = ENV.fetch("HOTSWAP_SOCKET", "tmp/sockets/hotswap.sock")
7
+ stderr_socket_path = ENV.fetch("HOTSWAP_STDERR_SOCKET", "tmp/sockets/hotswap.stderr.sock")
8
8
 
9
9
  unless File.exist?(socket_path)
10
10
  $stderr.puts "ERROR: socket not found at #{socket_path}"
@@ -23,10 +23,15 @@ sock = UNIXSocket.new(socket_path)
23
23
  args = ARGV.map { |a| Shellwords.escape(a) }.join(" ")
24
24
  sock.write(args + "\n")
25
25
 
26
- # Pipe stdin to socket (in background thread)
27
- writer = Thread.new do
28
- IO.copy_stream($stdin, sock) rescue nil
29
- sock.close_write rescue nil
26
+ # Pipe stdin to socket (only if data is being piped in)
27
+ writer = nil
28
+ if !$stdin.tty?
29
+ writer = Thread.new do
30
+ IO.copy_stream($stdin, sock) rescue nil
31
+ sock.close_write rescue nil
32
+ end
33
+ else
34
+ sock.close_write
30
35
  end
31
36
 
32
37
  # Pipe stderr socket to local stderr (in background thread)
@@ -40,7 +45,7 @@ end
40
45
  # Pipe socket output to stdout
41
46
  IO.copy_stream(sock, $stdout) rescue nil
42
47
 
43
- writer.join
48
+ writer&.join
44
49
  stderr_reader&.join
45
50
  stderr_sock&.close rescue nil
46
51
  sock.close rescue nil
data/lib/hotswap/cli.rb CHANGED
@@ -6,7 +6,7 @@ require "sqlite3"
6
6
  module Hotswap
7
7
  class CLI < Thor
8
8
  def self.exit_on_failure?
9
- true
9
+ false
10
10
  end
11
11
 
12
12
  # Thread-safe IO: each connection gets its own IO via thread-local storage
@@ -16,6 +16,8 @@ module Hotswap
16
16
  Thread.current[:hotswap_stdout] = stdout
17
17
  Thread.current[:hotswap_stderr] = stderr
18
18
  start(args)
19
+ rescue SystemExit
20
+ # Thor calls exit on errors — catch it so we don't kill the server
19
21
  ensure
20
22
  Thread.current[:hotswap_stdin] = nil
21
23
  Thread.current[:hotswap_stdout] = nil
@@ -17,13 +17,13 @@ module Hotswap
17
17
  if app.config.hotswap.socket_path
18
18
  Hotswap.socket_path = app.config.hotswap.socket_path
19
19
  else
20
- Hotswap.socket_path = File.join(app.root, "tmp", "hotswap.sock")
20
+ Hotswap.socket_path = File.join(app.root, "tmp", "sockets", "hotswap.sock")
21
21
  end
22
22
 
23
23
  if app.config.hotswap.stderr_socket_path
24
24
  Hotswap.stderr_socket_path = app.config.hotswap.stderr_socket_path
25
25
  else
26
- Hotswap.stderr_socket_path = File.join(app.root, "tmp", "hotswap.stderr.sock")
26
+ Hotswap.stderr_socket_path = File.join(app.root, "tmp", "sockets", "hotswap.stderr.sock")
27
27
  end
28
28
  end
29
29
 
@@ -31,7 +31,7 @@ module Hotswap
31
31
  app.middleware.use Hotswap::Middleware
32
32
  end
33
33
 
34
- initializer "hotswap.socket_server" do
34
+ server do
35
35
  server = Hotswap::SocketServer.new
36
36
  server.start
37
37
 
@@ -21,6 +21,7 @@ module Hotswap
21
21
  cleanup_stale_socket(@socket_path)
22
22
  cleanup_stale_socket(@stderr_socket_path)
23
23
 
24
+ FileUtils.mkdir_p(File.dirname(@socket_path))
24
25
  @server = UNIXServer.new(@socket_path)
25
26
  @stderr_server = UNIXServer.new(@stderr_socket_path)
26
27
 
@@ -1,3 +1,3 @@
1
1
  module Hotswap
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/hotswap.rb CHANGED
@@ -15,6 +15,6 @@ module Hotswap
15
15
  end
16
16
  end
17
17
 
18
- self.socket_path = "tmp/hotswap.sock"
19
- self.stderr_socket_path = "tmp/hotswap.stderr.sock"
18
+ self.socket_path = "tmp/sockets/hotswap.sock"
19
+ self.stderr_socket_path = "tmp/sockets/hotswap.stderr.sock"
20
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotswap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler