Expose WASI preopens through DefaultRubyVM - #658
Merged
kateinoigakukun merged 1 commit intoAug 15, 2026
Conversation
ledsun
marked this pull request as ready for review
August 15, 2026 14:47
kateinoigakukun
approved these changes
Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
As we develop the JavaScript APIs for running Ruby, Node.js is a convenient environment for quickly verifying behavior. However,
DefaultRubyVMdid not expose the WASIpreopensoption, so loading an application made up of multiple local Ruby files was unnecessarily difficult.The goal of this PR is to make local Ruby application code easy to load in Node.js while keeping the normal Ruby loading behavior.
Why WASI preopens
One possible approach is a loader similar to
RequireRemote: read source code through JavaScript and evaluate it in Ruby. For local files in Node.js, WASI preopens provide a better fit:requireandrequire_relativeimplementations.$LOADED_FEATURES, duplicate requires, and load errors.RequireRemoteremains useful in browser environments where source files must be fetched over a URL. This PR uses the WASI filesystem capability already available in Node.js for the local-file case.Changes
preopensthroughDefaultRubyVMrequireandrequire_relative__FILE__and$LOADED_FEATURES, duplicate-require behavior, and that the original host path is not visible to RubyExample
Verification
bundle exec rake npm:ruby-wasm-wasi:buildenv RUBY_NPM_PACKAGE_ROOT=packages/npm-packages/ruby-head-wasm-wasi npm run test:vitest --workspace=@ruby/wasm-wasi -- --run(44 tests)node packages/npm-packages/ruby-wasm-wasi/example/preopens.node.jsgit diff --check origin/main...HEAD