Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2275ef1

Browse files
committed
Vendor prettier_print into wasm package
1 parent 4dc5dbe commit 2275ef1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Rakefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
file "wasi-vfs" do
4-
version = "0.1.1"
4+
version = "0.2.0"
55
filename =
66
if ENV["CI"]
77
"wasi-vfs-cli-x86_64-unknown-linux-gnu.zip"
@@ -19,7 +19,7 @@ file "head-wasm32-unknown-wasi-full-js" do
1919
version = JSON.parse(File.read("package.json"))["dependencies"]["ruby-head-wasm-wasi"][1..]
2020
filename = "ruby-head-wasm32-unknown-wasi-full-js.tar.gz"
2121

22-
`curl -LO https://github.com/ruby/ruby.wasm/releases/download/ruby-head-wasm-wasi-#{version}/#{filename}`
22+
`curl -LO https://github.com/ruby/ruby.wasm/releases/download/ruby-head-wasm-wasi-#{version}/ruby-head-wasm32-unknown-wasi-full-js.tar.gz`
2323
`tar xfz #{filename}`
2424
rm filename
2525
end
@@ -30,7 +30,9 @@ end
3030

3131
file "src/app.wasm" => ["Gemfile.lock", "wasi-vfs", "ruby.wasm"] do
3232
require "bundler/setup"
33-
cp_r $:.find { _1.include?("syntax_tree") }, "lib"
33+
34+
cp_r $:.find { _1.include?("syntax_tree") }, "."
35+
cp_r $:.find { _1.include?("prettier_print") }, "."
3436

3537
`./wasi-vfs pack ruby.wasm --mapdir /lib::./lib --mapdir /usr::./head-wasm32-unknown-wasi-full-js/usr -o src/app.wasm`
3638
rm_rf "lib"

src/createRuby.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ export default async function createRuby() {
6666
// files to make it work. I'm not sure why I need to explicitly require
6767
// did_you_mean here, but it doesn't work without it.
6868
ruby.eval(`
69+
require "rubygems"
6970
require "did_you_mean"
7071
require "json"
7172
$:.unshift("/lib")
7273
require_relative "/lib/syntax_tree"
74+
require_relative "/lib/prettier_print"
7375
`);
7476

7577
return {
@@ -93,10 +95,8 @@ export default async function createRuby() {
9395
prettyPrint(source: string) {
9496
const jsonSource = JSON.stringify(JSON.stringify(source));
9597
const rubySource = `
96-
PP.format([], 80) do |q|
97-
source = JSON.parse(${jsonSource})
98-
SyntaxTree.parse(source).pretty_print(q)
99-
end.join
98+
source = JSON.parse(${jsonSource})
99+
SyntaxTree.parse(source).pretty_inspect
100100
`;
101101

102102
return ruby.eval(rubySource).toString();

0 commit comments

Comments
 (0)