Skip to content
This repository was archived by the owner on Nov 20, 2023. It is now read-only.

Commit 24ed255

Browse files
committed
More documentation in the rakefile
1 parent aea49ff commit 24ed255

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Rakefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,23 @@ file "src/app.wasm" => ["Gemfile.lock", "wasi-vfs", "ruby.wasm"] do
4343
# require "syntax_tree/rbs"
4444
loaded_after = $LOADED_FEATURES - loaded_before
4545

46+
# Here we're going to find all of the gems that were loaded by requiring each
47+
# of the gems that we wanted. We do this because dependencies can require
48+
# their own dependencies recursively. Once everything is required, we can walk
49+
# through the loaded gems and find the ones we need.
4650
filepaths = loaded_after.group_by { |filepath| filepath[%r{/gems/(.+?)-\d}, 1] }
4751
gem_names = filepaths.keys.tap { |names| names.delete(nil) }.sort
4852
puts "Gems loaded: #{gem_names.join(", ")}"
4953

54+
# Walk through each gem and copy all of their contents into the same lib
55+
# directory. This is nice because it allows us to only have to put one
56+
# directory onto the load path. It works because we're sure that all of the
57+
# gems are structured such that there isn't any overlap in the filepaths.
5058
mkdir "lib"
5159
gem_names.each do |gem_name|
60+
# Now that we know which gem we're attempting to load, we can find the lib
61+
# directory for that gem by looking through the load path that bundler
62+
# kindly set up for us.
5263
libdir = $:.find { _1.match?(%r{/#{gem_name}-\d}) }
5364

5465
Dir["#{libdir}/**/*"].sort.each do |filepath|

0 commit comments

Comments
 (0)