nodo 1.6.3 → 1.6.5
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 +55 -30
- data/lib/nodo/core.rb +1 -1
- data/lib/nodo/nodo.js +7 -3
- data/lib/nodo/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85e8ece889660e457a3473919da402124d9688011c3dbe5f69015e9f5e258465
|
4
|
+
data.tar.gz: 32ed8d2c1905c22cc68cf2734272f0d743890be066add8ce8de1a72132c6c3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c6a6af11b36730dae8bc00d31a17a96f0fbe0fe3a5ddc3da5df636efcdc648a6890e37aee63c7f0b67fc000ce354247eaa61cde12557eb9a3126b6cd0d9a291
|
7
|
+
data.tar.gz: b12074e9a1312694fcb46246eb2d66d418054b3f518be6dc5b2469a908b8b7e35d55d4a30b77144005b2b898c193ed062473ee4916239022c9d32361a5e324c4
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](
|
1
|
+
[](https://badge.fury.io/rb/nodo)
|
2
2
|
[](https://github.com/mtgrosser/nodo/actions/workflows/build.yml)
|
3
3
|
|
4
4
|
# Nōdo – call Node.js from Ruby
|
@@ -54,6 +54,26 @@ foo.say_hi('Nodo')
|
|
54
54
|
=> "Hello Nodo!"
|
55
55
|
```
|
56
56
|
|
57
|
+
JS code can also be supplied using the `code:` keyword argument:
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
function :hello, code: "() => 'world'"
|
61
|
+
```
|
62
|
+
|
63
|
+
### Async functions
|
64
|
+
|
65
|
+
`Nodo` supports calling `async` functions from Ruby.
|
66
|
+
The Ruby call will happen synchronously, i.e. it will block until the JS
|
67
|
+
function resolves:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
class SyncFoo < Nodo::Core
|
71
|
+
function :do_something, <<~JS
|
72
|
+
async () => { return await asyncFunc(); }
|
73
|
+
JS
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
57
77
|
### Using npm modules
|
58
78
|
|
59
79
|
Install your modules to `node_modules`:
|
@@ -79,7 +99,6 @@ bar = Bar.new
|
|
79
99
|
bar.v4 => "b305f5c4-db9a-4504-b0c3-4e097a5ec8b9"
|
80
100
|
```
|
81
101
|
|
82
|
-
|
83
102
|
### Aliasing requires
|
84
103
|
|
85
104
|
If the library name cannot be used as name of the constant, the `const` name
|
@@ -91,24 +110,22 @@ class FooBar < Nodo::Core
|
|
91
110
|
end
|
92
111
|
```
|
93
112
|
|
94
|
-
###
|
113
|
+
### Dynamic ESM imports
|
95
114
|
|
96
|
-
|
115
|
+
ES modules can be imported dynamically using `nodo.import()`:
|
97
116
|
|
98
117
|
```ruby
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
Nodo.modules_root = 'path/to/node_modules'
|
118
|
+
class DynamicFoo < Nodo::Core
|
119
|
+
function :v4, <<~JS
|
120
|
+
async () => {
|
121
|
+
const uuid = await nodo.import('uuid');
|
122
|
+
return await uuid.v4()
|
123
|
+
}
|
124
|
+
JS
|
125
|
+
end
|
109
126
|
```
|
110
127
|
|
111
|
-
|
128
|
+
Note that the availability of dynamic imports depends on your Node version.
|
112
129
|
|
113
130
|
### Defining JS constants
|
114
131
|
|
@@ -171,20 +188,6 @@ SubFoo.new.bar => "callingsuperclass"
|
|
171
188
|
SubSubFoo.new.bar => "callingsubsubclass"
|
172
189
|
```
|
173
190
|
|
174
|
-
### Async functions
|
175
|
-
|
176
|
-
`Nodo` supports calling `async` functions from Ruby.
|
177
|
-
The Ruby call will happen synchronously, i.e. it will block until the JS
|
178
|
-
function resolves:
|
179
|
-
|
180
|
-
```ruby
|
181
|
-
class SyncFoo < Nodo::Core
|
182
|
-
function :do_something, <<~JS
|
183
|
-
async () => { return await asyncFunc(); }
|
184
|
-
JS
|
185
|
-
end
|
186
|
-
```
|
187
|
-
|
188
191
|
### Deferred function definition
|
189
192
|
|
190
193
|
By default, the function code string literal is created when the class
|
@@ -241,6 +244,17 @@ Foo.new.sleep(2)
|
|
241
244
|
=> Nodo::TimeoutError raised
|
242
245
|
```
|
243
246
|
|
247
|
+
### Setting NODE_PATH
|
248
|
+
|
249
|
+
By default, `./node_modules` is used as the `NODE_PATH`.
|
250
|
+
|
251
|
+
To set a custom path:
|
252
|
+
```ruby
|
253
|
+
Nodo.modules_root = 'path/to/node_modules'
|
254
|
+
```
|
255
|
+
|
256
|
+
Also see: [Clean your Rails root](#Clean-your-Rails-root)
|
257
|
+
|
244
258
|
### Logging
|
245
259
|
|
246
260
|
By default, JS errors will be logged to `STDOUT`.
|
@@ -253,7 +267,6 @@ Nodo.logger = Logger.new('nodo.log')
|
|
253
267
|
|
254
268
|
In Rails applications, `Rails.logger` will automatically be set.
|
255
269
|
|
256
|
-
|
257
270
|
### Debugging
|
258
271
|
|
259
272
|
To get verbose debug output, set
|
@@ -339,3 +352,15 @@ With this new default, all `yarn` operations should be done after `cd`ing to `ve
|
|
339
352
|
|
340
353
|
This repo provides an [adapted version](https://github.com/mtgrosser/nodo/blob/master/install/yarn.rake)
|
341
354
|
of the `yarn:install` rake task which will automatically take care of the vendored module location.
|
355
|
+
|
356
|
+
|
357
|
+
## Working with web mocking frameworks like WebMock
|
358
|
+
|
359
|
+
Nodo uses HTTP via UNIX sockets to connect to its Node process. This may lead to
|
360
|
+
conflicts during tests when using `WebMock` or other tools which interfere with
|
361
|
+
`Net::HTTP`. In order to work with WebMock, you need to enable its `allow_localhost`
|
362
|
+
option:
|
363
|
+
|
364
|
+
```ruby
|
365
|
+
WebMock.disable_net_connect!(allow_localhost: true)
|
366
|
+
```
|
data/lib/nodo/core.rb
CHANGED
@@ -221,7 +221,7 @@ module Nodo
|
|
221
221
|
socket = nil
|
222
222
|
while Time.now - start < LAUNCH_TIMEOUT
|
223
223
|
begin
|
224
|
-
break if socket = UNIXSocket.new(socket_path)
|
224
|
+
break if socket = UNIXSocket.new(socket_path.to_s)
|
225
225
|
rescue Errno::ENOENT, Errno::ECONNREFUSED, Errno::ENOTDIR
|
226
226
|
Kernel.sleep(0.2)
|
227
227
|
end
|
data/lib/nodo/nodo.js
CHANGED
@@ -9,7 +9,7 @@ module.exports = (function() {
|
|
9
9
|
const path = require('path');
|
10
10
|
const fs = require('fs');
|
11
11
|
const performance = require('perf_hooks').performance;
|
12
|
-
|
12
|
+
|
13
13
|
let server, closing;
|
14
14
|
const classes = {};
|
15
15
|
const contexts = {};
|
@@ -48,7 +48,11 @@ module.exports = (function() {
|
|
48
48
|
console.log(`[Nodo] ${message}`);
|
49
49
|
}
|
50
50
|
}
|
51
|
-
|
51
|
+
|
52
|
+
async function import_module(specifier) {
|
53
|
+
return await import(specifier);
|
54
|
+
}
|
55
|
+
|
52
56
|
const core = {
|
53
57
|
run: (socket) => {
|
54
58
|
debug('Starting up...');
|
@@ -135,5 +139,5 @@ module.exports = (function() {
|
|
135
139
|
}
|
136
140
|
};
|
137
141
|
|
138
|
-
return { core: core, debug: debug };
|
142
|
+
return { core: core, debug: debug, import: import_module };
|
139
143
|
})();
|
data/lib/nodo/version.rb
CHANGED
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.6.
|
4
|
+
version: 1.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthias Grosser
|
@@ -11,56 +11,56 @@ cert_chain: []
|
|
11
11
|
date: 2021-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
18
|
version: '0'
|
20
|
-
|
19
|
+
name: bundler
|
21
20
|
prerelease: false
|
21
|
+
type: :development
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
30
29
|
requirements:
|
31
30
|
- - ">="
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0'
|
34
|
-
|
33
|
+
name: rake
|
35
34
|
prerelease: false
|
35
|
+
type: :development
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: byebug
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
44
43
|
requirements:
|
45
44
|
- - ">="
|
46
45
|
- !ruby/object:Gem::Version
|
47
46
|
version: '0'
|
48
|
-
|
47
|
+
name: byebug
|
49
48
|
prerelease: false
|
49
|
+
type: :development
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: minitest
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
58
|
- - ">="
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: '0'
|
62
|
-
|
61
|
+
name: minitest
|
63
62
|
prerelease: false
|
63
|
+
type: :development
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
@@ -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.3.25
|
109
109
|
signing_key:
|
110
110
|
specification_version: 4
|
111
111
|
summary: Call Node.js from Ruby
|