execjs-pcruntime 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +27 -0
- data/.gitignore +1 -0
- data/Gemfile +1 -3
- data/README.md +15 -2
- data/execjs-pcruntime.gemspec +3 -1
- data/lib/execjs/pcruntime/context_process_runtime.rb +17 -29
- data/lib/execjs/pcruntime/runner.js +2 -0
- data/lib/execjs/pcruntime/runtimes.rb +1 -2
- data/lib/execjs/pcruntime/version.rb +1 -1
- data/lib/execjs/pcruntime.rb +1 -1
- metadata +20 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba11ad7f3ad06a577368aff2e27006d95f16fe0c9f3c1ae371d8c413797b418e
|
4
|
+
data.tar.gz: 654d4ddc8bfd649ff17fa59d74fa1512db3d0150a9dd759b3d2dfebf7644c767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 109ce5c2898e87f21fe75c06cc818b7ecc45cd316466ef82bb5fd3fd4c305f00434d284a038d1947626ea13d19a8e3f76037da7b6604f1680c546ee0d4a1c1f4
|
7
|
+
data.tar.gz: '020513096f47aae6fd42c2e73a9b80ba378ad7ff01f1e7acdce2042f6ad37396fa40b0755dae17e7bb5f87e9c4bde881df825648e61c4603e406d8f0ec2e00b5'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ main ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ['3.2', '3.1', '3.0']
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v3
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
- name: Install dependencies
|
25
|
+
run: bundle install
|
26
|
+
- name: Run tests
|
27
|
+
run: bundle exec rake
|
data/Gemfile
CHANGED
@@ -7,8 +7,6 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
7
7
|
# Specify your gem's dependencies in execjs-pcruntime.gemspec
|
8
8
|
gemspec
|
9
9
|
|
10
|
-
gem 'execjs', '~> 2.0'
|
11
|
-
|
12
10
|
group :development do
|
13
11
|
gem 'rubocop', require: false
|
14
12
|
gem 'rubocop-minitest', require: false
|
@@ -18,5 +16,5 @@ end
|
|
18
16
|
|
19
17
|
group :test do
|
20
18
|
gem 'minitest', '~> 5.0'
|
21
|
-
gem 'rake', '~>
|
19
|
+
gem 'rake', '~> 12.0'
|
22
20
|
end
|
data/README.md
CHANGED
@@ -4,6 +4,11 @@ Accelerated ExecJS Runtime by launching Node.js Processes per Context, not per e
|
|
4
4
|
|
5
5
|
inspired by [execjs-fastnode](https://github.com/jhawthorn/execjs-fastnode)
|
6
6
|
|
7
|
+
## Requirements
|
8
|
+
|
9
|
+
- Ruby >= 3.0.0
|
10
|
+
- execjs ~> 2.0
|
11
|
+
|
7
12
|
## Installation
|
8
13
|
|
9
14
|
Add this line to your application's Gemfile:
|
@@ -13,8 +18,8 @@ gem 'execjs-pcruntime'
|
|
13
18
|
```
|
14
19
|
|
15
20
|
And then execute:
|
16
|
-
```
|
17
|
-
|
21
|
+
```shell
|
22
|
+
bundle
|
18
23
|
```
|
19
24
|
|
20
25
|
## Usage
|
@@ -28,6 +33,14 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
|
28
33
|
|
29
34
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
35
|
|
36
|
+
### Test
|
37
|
+
|
38
|
+
To run a unit test, run the following command.
|
39
|
+
|
40
|
+
```shell
|
41
|
+
bundle exec rake
|
42
|
+
```
|
43
|
+
|
31
44
|
## Contributing
|
32
45
|
|
33
46
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/execjs-pcruntime. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
data/execjs-pcruntime.gemspec
CHANGED
@@ -8,11 +8,13 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = 'execjs-pcruntime'
|
9
9
|
spec.version = Execjs::PCRuntime::VERSION
|
10
10
|
spec.authors = ['White-Green']
|
11
|
-
spec.required_ruby_version = '
|
11
|
+
spec.required_ruby_version = '>=3.0.0'
|
12
12
|
spec.summary = 'Fast ExecJS Runtime using Process as a Context.'
|
13
13
|
spec.homepage = 'https://rubygems.org/gems/execjs-pcruntime'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
16
|
+
spec.add_dependency 'execjs', '~> 2.0'
|
17
|
+
|
16
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
19
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
20
|
if spec.respond_to?(:metadata)
|
@@ -8,15 +8,15 @@ require 'net/http'
|
|
8
8
|
|
9
9
|
module ExecJS
|
10
10
|
module PCRuntime
|
11
|
-
#
|
11
|
+
# implementation of ExecJS::Runtime
|
12
12
|
class ContextProcessRuntime < Runtime
|
13
|
-
#
|
13
|
+
# implementation of ExecJS::Runtime::Context
|
14
14
|
class Context < Runtime::Context
|
15
15
|
# @param [String] runtime Instance of ContextProcessRuntime
|
16
16
|
# @param [String] source JavaScript source code that Runtime load at startup
|
17
17
|
# @param [any] options
|
18
18
|
def initialize(runtime, source = '', options = {})
|
19
|
-
super
|
19
|
+
super
|
20
20
|
|
21
21
|
# @type [JSRuntimeHandle]
|
22
22
|
@runtime = runtime.create_runtime_handle
|
@@ -25,7 +25,7 @@ module ExecJS
|
|
25
25
|
@runtime.evaluate(source.encode('UTF-8'))
|
26
26
|
end
|
27
27
|
|
28
|
-
#
|
28
|
+
# implementation of ExecJS::Runtime::Context#eval
|
29
29
|
# @param [String] source
|
30
30
|
# @param [any] _options
|
31
31
|
def eval(source, _options = {})
|
@@ -34,14 +34,14 @@ module ExecJS
|
|
34
34
|
@runtime.evaluate("(#{source.encode('UTF-8')})")
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
37
|
+
# implementation of ExecJS::Runtime::Context#exec
|
38
38
|
# @param [String] source
|
39
39
|
# @param [any] _options
|
40
40
|
def exec(source, _options = {})
|
41
41
|
@runtime.evaluate("(()=>{#{source.encode('UTF-8')}})()")
|
42
42
|
end
|
43
43
|
|
44
|
-
#
|
44
|
+
# implementation of ExecJS::Runtime:Context#call
|
45
45
|
# @param [String] identifier
|
46
46
|
# @param [Array<_ToJson>] args
|
47
47
|
def call(identifier, *args)
|
@@ -54,12 +54,12 @@ module ExecJS
|
|
54
54
|
class JSRuntimeHandle
|
55
55
|
# @param [Array<String>] binary Launch command for the node(or similar JavaScript Runtime) binary,
|
56
56
|
# such as ['node'], ['deno', 'run'].
|
57
|
-
# @param [String]
|
58
|
-
def initialize(binary,
|
57
|
+
# @param [String] initial_source_path Path of .js Runtime loads at startup.
|
58
|
+
def initialize(binary, initial_source_path)
|
59
59
|
Dir::Tmpname.create 'execjs_pcruntime' do |path|
|
60
60
|
# Dir::Tmpname.create rescues Errno::EEXIST and retry block
|
61
61
|
# So, raise it if failed to create Process.
|
62
|
-
@runtime_pid = create_process(path, *binary,
|
62
|
+
@runtime_pid = create_process(path, *binary, initial_source_path) || raise(Errno::EEXIST)
|
63
63
|
@socket_path = path
|
64
64
|
end
|
65
65
|
ObjectSpace.define_finalizer(self, self.class.finalizer(@runtime_pid))
|
@@ -176,6 +176,7 @@ module ExecJS
|
|
176
176
|
result = response.body
|
177
177
|
::JSON.parse(response.body, create_additions: false) if /\S/.match?(result)
|
178
178
|
else
|
179
|
+
# expects ErrorMessage\0StackTrace =~ response.body
|
179
180
|
message, stack = response.body.split "\0"
|
180
181
|
error_class = /SyntaxError:/.match?(message) ? RuntimeError : ProgramError
|
181
182
|
error = error_class.new(message)
|
@@ -200,9 +201,8 @@ module ExecJS
|
|
200
201
|
@deprecated = deprecated
|
201
202
|
end
|
202
203
|
|
203
|
-
#
|
204
|
+
# implementation of ExecJS::Runtime#available?
|
204
205
|
def available?
|
205
|
-
require 'json'
|
206
206
|
binary ? true : false
|
207
207
|
end
|
208
208
|
|
@@ -231,7 +231,7 @@ module ExecJS
|
|
231
231
|
# e.g. ["/the/absolute/path/to/deno", "run"]
|
232
232
|
def which(commands)
|
233
233
|
commands.each do |command|
|
234
|
-
command, *args =
|
234
|
+
command, *args = Shellwords.split command
|
235
235
|
command = search_executable_path command
|
236
236
|
return [command] + args unless command.nil?
|
237
237
|
end
|
@@ -240,29 +240,17 @@ module ExecJS
|
|
240
240
|
# Search for absolute path of the executable file from the command.
|
241
241
|
# @param [String] command
|
242
242
|
# @return [String, nil] the absolute path of the command, or nil if not found
|
243
|
-
# It seems that further method splitting might actually make it harder to read, so suppressing
|
244
|
-
# rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
245
243
|
def search_executable_path(command)
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
244
|
+
extensions = ExecJS.windows? ? ENV['PATHEXT'].split(File::PATH_SEPARATOR) + [''] : ['']
|
245
|
+
path = ENV['PATH'].split(File::PATH_SEPARATOR) + ['']
|
246
|
+
path.each do |base_path|
|
247
|
+
extensions.each do |extension|
|
250
248
|
executable_path = base_path == '' ? command + extension : File.join(base_path, command + extension)
|
251
|
-
return executable_path if File.executable?(executable_path)
|
249
|
+
return executable_path if File.executable?(executable_path)
|
252
250
|
end
|
253
251
|
end
|
254
252
|
nil
|
255
253
|
end
|
256
|
-
# rubocop:enable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
257
|
-
|
258
|
-
# Split command string
|
259
|
-
# split_command_string "deno run" # ["deno", "run"]
|
260
|
-
# @param [String] command command string
|
261
|
-
# @return [Array<String>] array split from the command string
|
262
|
-
def split_command_string(command)
|
263
|
-
regex = /([^\s"']+)|"([^"]+)"|'([^']+)'(?:\s+|\s*\Z)/
|
264
|
-
command.scan(regex).flatten.compact
|
265
|
-
end
|
266
254
|
end
|
267
255
|
end
|
268
256
|
end
|
@@ -21,6 +21,8 @@ const server = http.createServer(function (req, res) {
|
|
21
21
|
} catch (e) {
|
22
22
|
res.statusCode = 500;
|
23
23
|
res.setHeader('Content-Type', 'text/plain');
|
24
|
+
// to split by \0 on Ruby side
|
25
|
+
// see context_process_runtime.rb:179
|
24
26
|
res.end(e.toString() + "\0" + (e.stack || ""));
|
25
27
|
}
|
26
28
|
});
|
data/lib/execjs/pcruntime.rb
CHANGED
metadata
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: execjs-pcruntime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- White-Green
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
12
|
-
dependencies:
|
11
|
+
date: 2023-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: execjs
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
13
27
|
description:
|
14
28
|
email:
|
15
29
|
executables: []
|
16
30
|
extensions: []
|
17
31
|
extra_rdoc_files: []
|
18
32
|
files:
|
33
|
+
- ".github/workflows/test.yml"
|
19
34
|
- ".gitignore"
|
20
35
|
- ".rubocop.yml"
|
21
36
|
- CODE_OF_CONDUCT.md
|
@@ -44,7 +59,7 @@ require_paths:
|
|
44
59
|
- lib
|
45
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
61
|
requirements:
|
47
|
-
- - "
|
62
|
+
- - ">="
|
48
63
|
- !ruby/object:Gem::Version
|
49
64
|
version: 3.0.0
|
50
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
@@ -53,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
68
|
- !ruby/object:Gem::Version
|
54
69
|
version: '0'
|
55
70
|
requirements: []
|
56
|
-
rubygems_version: 3.
|
71
|
+
rubygems_version: 3.2.33
|
57
72
|
signing_key:
|
58
73
|
specification_version: 4
|
59
74
|
summary: Fast ExecJS Runtime using Process as a Context.
|