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

Add support to SyntaxTree 6 and Mermaid.js #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Vendor prettier_print into wasm package
  • Loading branch information
wenderjean committed Feb 10, 2023
commit 2275ef1ef53b32567837db2149e48c0c5c538b5a
8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

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

`curl -LO https://github.com/ruby/ruby.wasm/releases/download/ruby-head-wasm-wasi-#{version}/#{filename}`
`curl -LO https://github.com/ruby/ruby.wasm/releases/download/ruby-head-wasm-wasi-#{version}/ruby-head-wasm32-unknown-wasi-full-js.tar.gz`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is equivalent and can be reverted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, It was just a missing test.

`tar xfz #{filename}`
rm filename
end
Expand All @@ -30,7 +30,9 @@ end

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

cp_r $:.find { _1.include?("syntax_tree") }, "."
cp_r $:.find { _1.include?("prettier_print") }, "."

`./wasi-vfs pack ruby.wasm --mapdir /lib::./lib --mapdir /usr::./head-wasm32-unknown-wasi-full-js/usr -o src/app.wasm`
rm_rf "lib"
Expand Down
8 changes: 4 additions & 4 deletions src/createRuby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ export default async function createRuby() {
// files to make it work. I'm not sure why I need to explicitly require
// did_you_mean here, but it doesn't work without it.
ruby.eval(`
require "rubygems"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this require and the pp one necessary? I hope they aren't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, they are. Without them, we get unutilized Gem lib/syntax_tree/formatter.rb:10 and unutilized PP in the browser.

require "did_you_mean"
require "json"
$:.unshift("/lib")
require_relative "/lib/syntax_tree"
require_relative "/lib/prettier_print"
`);

return {
Expand All @@ -93,10 +95,8 @@ export default async function createRuby() {
prettyPrint(source: string) {
const jsonSource = JSON.stringify(JSON.stringify(source));
const rubySource = `
PP.format([], 80) do |q|
source = JSON.parse(${jsonSource})
SyntaxTree.parse(source).pretty_print(q)
end.join
source = JSON.parse(${jsonSource})
SyntaxTree.parse(source).pretty_inspect
`;

return ruby.eval(rubySource).toString();
Expand Down