node-runner 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ead50dfa95fa818eb046575996e0047ee234dedf0f0813c5cf6ee4f684677b47
4
- data.tar.gz: fcd76591a0acd31bb3930e2fa73c743c71290c075046c297417c75382e2efe1b
3
+ metadata.gz: 3c6222ef23c1975d9325fbf60b6bbbd63a6ffad0c13c5249e8c1b4734f09dab9
4
+ data.tar.gz: abbd491dd0894a0a2a13d8d56138ddca1c8f168b969c3dea8e31ec96bce6ab5a
5
5
  SHA512:
6
- metadata.gz: aa16d705dc422f545ee607c91cc2868d2c2cb5a301a722c2a9964cea5cca80d6051d4b72726af45a04d0c16c6b91e855ff25b01c4b68c84a06740eaa2050ce61
7
- data.tar.gz: bee406b3703184445d677359429a8d68f75ba382cff78eb94484575d82a0f83d96d99a96d05c57d98becbfff73f1d43a72d3ba32a2735592897f43c720e48121
6
+ metadata.gz: 8c4932b21e6a843e53abb1943de4062e685f8e45b12c2bcdda63765235262f2a83c31179961fd0a59ba53031393a307b0711cd39eae122e6618b4399a096a258
7
+ data.tar.gz: de4c98cdd6b6be6b07e6c8c8a0e18fc8a2555a505d5dc102be72bf88830a8877c39b71be3faea208cc20b1e1e3bff79155ec6854ce1d6f5bbb68410f59cd1d41
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # master
2
+
3
+ # 1.0.1 / 2020-05-09
4
+
5
+ Set the NODE_ENV so local modules can be found.
6
+
7
+ # 1.0.0 / 2020-04-29
8
+
9
+ Initial release of NodeRunner.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A simple way to execute Javascript in a Ruby context via Node. (Loosely based on the Node Runtime module from [ExecJS](https://github.com/rails/execjs).)
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/node-runner)](https://badge.fury.io/rb/node-runner)
5
+ [![Gem Version](https://badge.fury.io/rb/node-runner.svg)](https://badge.fury.io/rb/node-runner)
6
6
 
7
7
  ## Installation
8
8
 
@@ -18,6 +18,8 @@ Simply create a new `NodeRunner` object and pass in the Javascript code you wish
18
18
  execute:
19
19
 
20
20
  ```ruby
21
+ require "node-runner"
22
+
21
23
  runner = NodeRunner.new(
22
24
  <<~NODE
23
25
  const hello = (response) => {
@@ -73,6 +75,14 @@ NodeRunner.new "…", executor: NodeRunner::Executor.new(command: "/path/to/cust
73
75
 
74
76
  `command` can be an array as well, if you want to attempt multiple paths until one is found. Inspect the `node-runner.rb` source code for more information on the available options.
75
77
 
78
+ ## Caveats
79
+
80
+ A single run of a script is quite fast, nearly as fast as running a script directly with the
81
+ `node` CLI…because that's essentially what is happening here. However, the performance characteristics using
82
+ this in a high-traffic request/response cycle (say, from a Rails app) is unknown. Likely the best context to use
83
+ Node Runner would be via a background job, or during a build process like when using a static site generator.
84
+ (Like our parent project [Bridgetown](https://github.com/bridgetownrb/bridgetown)!)
85
+
76
86
  ## Testing
77
87
 
78
88
  * Run `bundle exec rake` to run the test suite.
data/lib/node-runner.rb CHANGED
@@ -84,10 +84,11 @@ class NodeRunner::Executor
84
84
  attr_reader :name
85
85
 
86
86
  def initialize(options = {})
87
- @command = options[:command] || ['node']
88
- @runner_path = options[:runner_path] || File.join(File.expand_path(__dir__), '/node_runner.js')
89
- @encoding = options[:encoding] || "UTF-8"
90
- @binary = nil
87
+ @command = options[:command] || ['node']
88
+ @modules_path = options[:modules_path] || File.join(Dir.pwd, "node_modules")
89
+ @runner_path = options[:runner_path] || File.join(File.expand_path(__dir__), '/node_runner.js')
90
+ @encoding = options[:encoding] || "UTF-8"
91
+ @binary = nil
91
92
 
92
93
  @popen_options = {}
93
94
  @popen_options[:external_encoding] = @encoding if @encoding
@@ -99,6 +100,7 @@ class NodeRunner::Executor
99
100
  end
100
101
 
101
102
  def exec(filename)
103
+ ENV["NODE_PATH"] = @modules_path
102
104
  stdout, stderr, status = Open3.capture3("#{binary} #{filename}")
103
105
  if status.success?
104
106
  stdout
data/lib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  class NodeRunner
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: node-runner
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-30 00:00:00.000000000 Z
11
+ date: 2020-05-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: maintainers@bridgetownrb.com
@@ -17,6 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - ".gitignore"
20
+ - CHANGELOG.md
20
21
  - Gemfile
21
22
  - LICENSE.txt
22
23
  - README.md