oxtree 0.1.0

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.
data/exe/oxtree ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../lib/oxtree"
5
+
6
+ begin
7
+ Oxtree.exec(ARGV)
8
+ rescue Oxtree::ExecutableNotFound => e
9
+ warn("ERROR: #{e.message}")
10
+ exit 2
11
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Oxtree
4
+ VERSION = "0.1.0"
5
+
6
+ # The releases whose formatting oxtree reproduces byte for byte.
7
+ SYNTAX_TREE_VERSION = "6.3.0"
8
+ SYNTAX_TREE_ERB_VERSION = "0.12.0"
9
+ end
data/lib/oxtree.rb ADDED
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "oxtree/version"
4
+
5
+ # Locates and runs the native `oxtree` binary. Platform gems ship it under
6
+ # `exe/<platform>/oxtree` (the layout tailwindcss-ruby uses); the plain `ruby`
7
+ # platform gem has no binary and explains why at run time.
8
+ module Oxtree
9
+ GEM_NAME = "oxtree"
10
+ EXE_DIR = File.expand_path("../exe", __dir__)
11
+ REPO_ROOT = File.expand_path("../../..", __dir__)
12
+
13
+ class ExecutableNotFound < StandardError; end
14
+
15
+ class << self
16
+ def executable
17
+ return ENV["OXTREE_BINARY"] if ENV["OXTREE_BINARY"] && !ENV["OXTREE_BINARY"].empty?
18
+
19
+ packaged_executable || development_executable || raise(ExecutableNotFound, not_found_message)
20
+ end
21
+
22
+ # Every argument goes straight to the binary.
23
+ def exec(argv)
24
+ Kernel.exec(executable, *argv)
25
+ end
26
+
27
+ private
28
+
29
+ def packaged_executable
30
+ Dir.glob(File.join(EXE_DIR, "*", "oxtree")).find do |path|
31
+ platform = Gem::Platform.new(File.basename(File.dirname(path)))
32
+ Gem::Platform.match_gem?(platform, GEM_NAME)
33
+ end
34
+ end
35
+
36
+ # When the gem is used straight from a checkout (`gem "oxtree", path: ...`),
37
+ # fall back to the Cargo build output.
38
+ def development_executable
39
+ %w[release debug].map { |profile| File.join(REPO_ROOT, "target", profile, "oxtree") }
40
+ .find { |path| File.executable?(path) }
41
+ end
42
+
43
+ def not_found_message
44
+ <<~MSG
45
+ oxtree does not ship a prebuilt binary for #{Gem::Platform.local} (#{RUBY_PLATFORM}).
46
+ Supported platforms: #{Dir.children(EXE_DIR).select { |d| File.directory?(File.join(EXE_DIR, d)) }.join(", ").then { |s| s.empty? ? "none in this gem (see https://github.com/pocketflows/oxruby#releasing for those with prebuilt gems)" : s }}.
47
+ Set OXTREE_BINARY to the path of an oxtree binary built with `cargo build --release -p oxtree`.
48
+ MSG
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oxtree
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Teddy Liu
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ oxtree formats Ruby and ERB exactly as syntax_tree 6.3.0
14
+ and w_syntax_tree-erb 0.12.0 do, but runs as a native
15
+ binary.
16
+ email:
17
+ - theodoretliu@gmail.com
18
+ executables:
19
+ - oxtree
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - LICENSE.txt
24
+ - README.md
25
+ - THIRD_PARTY_NOTICES.md
26
+ - exe/oxtree
27
+ - lib/oxtree.rb
28
+ - lib/oxtree/version.rb
29
+ homepage: https://github.com/pocketflows/oxruby
30
+ licenses:
31
+ - MIT
32
+ metadata:
33
+ homepage_uri: https://github.com/pocketflows/oxruby
34
+ source_code_uri: https://github.com/pocketflows/oxruby
35
+ rubygems_mfa_required: 'true'
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '3.1'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ requirements: []
50
+ rubygems_version: 4.0.3
51
+ specification_version: 4
52
+ summary: A drop-in replacement for syntax_tree, rewritten in Rust on the Prism parser
53
+ test_files: []