Add a base_url property to JS::RequreRemote to specify the base URL for resolving relative paths. #506
      
        
          +40
        
        
          −0
        
        
          
        
      
    
  
  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.
  
    
  
    
Before
Currently,
JS::RequireRemotetreats the URL of the HTML file that calls ruby.wasm as the base URL for resolving relative paths. For this reason, you will have to write an uncomfortable require_relative if you place the Ruby script that serves as the entry point in a directory different from the HTML file.For example, if the entry point for a Ruby script is placed in the
libdirectory as follows:If you want to read the
jsrb.rbfile in the samelibdirectory, include thelibdirectory in therequire_relativeargument, likerequire_relative 'lib/jsrb'. Or, specify an absolute path, such as/lib/jsrb.After
If you set
libin the base_url property as follows, you can writerequire_relative 'jsrb'as a relative path fromlib/init.rb.Why not automatically resolve the base URL?
I do not know if
JS::RequireRemoteis used when a ruby script is loaded with the script tag. It is not appropriate to change theJS::RequireRemotesetting at this time.Also, when multiple ruby scripts are loaded in a script tag, I am not sure which ruby script path should be used as the base URL.