@@ -48,6 +48,7 @@ def vendor_gem_cache(pkg)
4848 require_relative "../packages/gems/js/lib/js/version"
4949 sh "gem" , "-C" , "packages/gems/js" , "build" , "-o" ,
5050 File . join ( vendor_cache_dir , "js-#{ JS ::VERSION } .gem" )
51+ JS ::VERSION
5152end
5253
5354namespace :npm do
@@ -62,7 +63,7 @@ namespace :npm do
6263 # Skip if the package does not require building ruby
6364 next unless build_command
6465
65- vendor_gem_cache ( pkg )
66+ js_gem_version = vendor_gem_cache ( pkg )
6667
6768 env = {
6869 # Share ./build and ./rubies in the same workspace
@@ -80,12 +81,15 @@ namespace :npm do
8081 mkdir_p dist_dir
8182 if pkg [ :target ] . start_with? ( "wasm32-unknown-wasi" )
8283 Dir . chdir ( cwd || base_dir ) do
84+ # Uninstall js gem to re-install just-built js gem
85+ sh "gem" , "uninstall" , "js" , "-v" , js_gem_version , "--force"
86+ # Install gems including js gem
8387 sh "bundle" , "install"
8488
8589 sh env ,
8690 "bundle" , "exec" ,
8791 *build_command ,
88- "--no-stdlib" ,
92+ "--no-stdlib" , "--remake" ,
8993 "-o" ,
9094 File . join ( dist_dir , "ruby.wasm" )
9195 sh env ,
@@ -97,6 +101,9 @@ namespace :npm do
97101 component_path = File . join ( pkg_dir , "tmp" , "ruby.component.wasm" )
98102 FileUtils . mkdir_p ( File . dirname ( component_path ) )
99103
104+ # Remove js gem from the ./bundle directory to force Bundler to re-install it
105+ rm_rf FileList [ File . join ( pkg_dir , "bundle" , "**" , "js-#{ js_gem_version } " ) ]
106+
100107 sh env . merge ( "RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING" => "1" ) ,
101108 *build_command , "-o" , component_path
102109 sh "npx" , "jco" , "transpile" ,
0 commit comments