nodo 1.5.1 → 1.5.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 +4 -4
- data/README.md +6 -2
- data/lib/nodo/client.rb +4 -4
- data/lib/nodo/core.rb +27 -19
- data/lib/nodo/version.rb +1 -1
- data/lib/nodo.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e46009bcd3e3e8e5fd0f0a6f624c3f263caa09c64225878011e557333ffb8e64
|
4
|
+
data.tar.gz: 98eed61321bae14d89725f6884a16d2c3fccc2eb20f808781b10842e2f22ae25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce0e598a9e6cffb816b53ce802a1a412746d195e387424b3362cc765d1fbd03931322c734a3ee6817487151f9969f414e1d99cfc1a4e9bddce99a7d6c7d95e26
|
7
|
+
data.tar.gz: a628c3765b94bd32600f554c1e973703e90a9dbcb06764b3d3256eb6ceb519997b2241f1f7c02474b8859aa2b4ff0049c863bcf047d38fbeeb8ed1be5e1bedb2
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](http://badge.fury.io/rb/nodo)
|
1
|
+
[](http://badge.fury.io/rb/nodo) [](https://github.com/mtgrosser/nodo/actions/workflows/build.yml)
|
2
2
|
|
3
3
|
# Nōdo – call Node.js from Ruby
|
4
4
|
|
@@ -61,7 +61,7 @@ Install your modules to `node_modules`:
|
|
61
61
|
$ yarn add uuid
|
62
62
|
```
|
63
63
|
|
64
|
-
|
64
|
+
`require`ing your dependencies will make the library available as a `const` with the same name:
|
65
65
|
|
66
66
|
```ruby
|
67
67
|
class Bar < Nodo::Core
|
@@ -78,8 +78,12 @@ bar = Bar.new
|
|
78
78
|
bar.v4 => "b305f5c4-db9a-4504-b0c3-4e097a5ec8b9"
|
79
79
|
```
|
80
80
|
|
81
|
+
|
81
82
|
### Aliasing requires
|
82
83
|
|
84
|
+
If the library name cannot be used as name of the constant, the `const` name
|
85
|
+
can be given using hash syntax:
|
86
|
+
|
83
87
|
```ruby
|
84
88
|
class FooBar < Nodo::Core
|
85
89
|
require commonjs: '@rollup/plugin-commonjs'
|
data/lib/nodo/client.rb
CHANGED
@@ -28,10 +28,10 @@ module Nodo
|
|
28
28
|
|
29
29
|
def connect_unix
|
30
30
|
s = Timeout.timeout(@open_timeout) { UNIXSocket.open(@socket_path) }
|
31
|
-
@socket = Net::BufferedIO.new(s
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
@socket = Net::BufferedIO.new(s, read_timeout: @read_timeout,
|
32
|
+
write_timeout: @write_timeout,
|
33
|
+
continue_timeout: @continue_timeout,
|
34
|
+
debug_output: @debug_output)
|
35
35
|
on_connect
|
36
36
|
end
|
37
37
|
end
|
data/lib/nodo/core.rb
CHANGED
@@ -12,7 +12,6 @@ module Nodo
|
|
12
12
|
@@mutex = Mutex.new
|
13
13
|
|
14
14
|
class << self
|
15
|
-
|
16
15
|
attr_accessor :class_defined
|
17
16
|
|
18
17
|
def inherited(subclass)
|
@@ -80,6 +79,8 @@ module Nodo
|
|
80
79
|
process.exit(1);
|
81
80
|
}
|
82
81
|
|
82
|
+
process.title = `nodo-core ${socket}`;
|
83
|
+
|
83
84
|
const shutdown = () => {
|
84
85
|
nodo.core.close(() => { process.exit(0) });
|
85
86
|
};
|
@@ -104,16 +105,6 @@ module Nodo
|
|
104
105
|
})()
|
105
106
|
JS
|
106
107
|
end
|
107
|
-
|
108
|
-
protected
|
109
|
-
|
110
|
-
def finalize(pid, tmpdir)
|
111
|
-
proc do
|
112
|
-
Process.kill(:SIGTERM, pid)
|
113
|
-
Process.wait(pid)
|
114
|
-
FileUtils.remove_entry(tmpdir) if File.directory?(tmpdir)
|
115
|
-
end
|
116
|
-
end
|
117
108
|
|
118
109
|
private
|
119
110
|
|
@@ -155,23 +146,31 @@ module Nodo
|
|
155
146
|
return if self.class.class_defined?
|
156
147
|
call_js_method(DEFINE_METHOD, self.class.generate_class_code)
|
157
148
|
self.class.class_defined = true
|
158
|
-
# rescue => e
|
159
|
-
# raise Error, e.message
|
160
149
|
end
|
161
|
-
|
150
|
+
|
162
151
|
def spawn_process
|
163
152
|
@@tmpdir = Pathname.new(Dir.mktmpdir('nodo'))
|
164
153
|
env = Nodo.env.merge('NODE_PATH' => Nodo.modules_root.to_s)
|
165
|
-
@@node_pid = Process.spawn(env, Nodo.binary, '-e', self.class.generate_core_code, '--', socket_path.to_s)
|
166
|
-
|
154
|
+
@@node_pid = Process.spawn(env, Nodo.binary, '-e', self.class.generate_core_code, '--', socket_path.to_s, err: :out)
|
155
|
+
at_exit do
|
156
|
+
Process.kill(:SIGTERM, node_pid) rescue Errno::ECHILD
|
157
|
+
Process.wait(node_pid) rescue Errno::ECHILD
|
158
|
+
FileUtils.remove_entry(tmpdir) if File.directory?(tmpdir)
|
159
|
+
end
|
167
160
|
end
|
168
161
|
|
169
162
|
def wait_for_socket
|
170
163
|
start = Time.now
|
171
|
-
|
172
|
-
|
173
|
-
|
164
|
+
socket = nil
|
165
|
+
while Time.now - start < TIMEOUT
|
166
|
+
begin
|
167
|
+
break if socket = UNIXSocket.new(socket_path)
|
168
|
+
rescue Errno::ENOENT, Errno::ECONNREFUSED, Errno::ENOTDIR
|
169
|
+
sleep 0.2
|
170
|
+
end
|
174
171
|
end
|
172
|
+
socket.close if socket
|
173
|
+
raise TimeoutError, "could not connect to socket #{socket_path}" unless socket
|
175
174
|
end
|
176
175
|
|
177
176
|
def call_js_method(method, args)
|
@@ -205,5 +204,14 @@ module Nodo
|
|
205
204
|
JSON.parse(response.body.force_encoding('UTF-8'))
|
206
205
|
end
|
207
206
|
|
207
|
+
def with_tempfile(name)
|
208
|
+
ext = File.extname(name)
|
209
|
+
result = nil
|
210
|
+
Tempfile.create([File.basename(name, ext), ext], tmpdir) do |file|
|
211
|
+
result = yield(file)
|
212
|
+
end
|
213
|
+
result
|
214
|
+
end
|
215
|
+
|
208
216
|
end
|
209
217
|
end
|
data/lib/nodo/version.rb
CHANGED
data/lib/nodo.rb
CHANGED
@@ -2,6 +2,8 @@ require 'pathname'
|
|
2
2
|
require 'json'
|
3
3
|
require 'fileutils'
|
4
4
|
require 'tmpdir'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'socket'
|
5
7
|
|
6
8
|
module Nodo
|
7
9
|
class << self
|
@@ -21,4 +23,4 @@ require_relative 'nodo/constant'
|
|
21
23
|
require_relative 'nodo/client'
|
22
24
|
require_relative 'nodo/core'
|
23
25
|
|
24
|
-
require_relative 'nodo/railtie' if defined?(Rails)
|
26
|
+
require_relative 'nodo/railtie' if defined?(Rails::Railtie)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nodo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
105
105
|
- !ruby/object:Gem::Version
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
|
-
rubygems_version: 3.
|
108
|
+
rubygems_version: 3.2.22
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Call Node.js from Ruby
|