Skip to content

Commit eddd567

Browse files
Create vendor gem cache before computing cache key for npm package
1 parent 449c3d6 commit eddd567

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

rakelib/packaging.rake

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def npm_pkg_build_command(pkg)
2525
end
2626

2727
def npm_pkg_rubies_cache_key(pkg)
28+
vendor_gem_cache(pkg)
29+
2830
build_command = npm_pkg_build_command(pkg)
2931
return nil unless build_command
3032
require "open3"
@@ -39,6 +41,17 @@ def npm_pkg_rubies_cache_key(pkg)
3941
JSON.parse(stdout)["hexdigest"]
4042
end
4143

44+
def vendor_gem_cache(pkg)
45+
return unless pkg[:gemfile]
46+
pkg_dir = File.dirname(pkg[:gemfile])
47+
pkg_dir = File.expand_path(pkg_dir)
48+
vendor_cache_dir = File.join(pkg_dir, "vendor", "cache")
49+
mkdir_p vendor_cache_dir
50+
require_relative "../packages/gems/js/lib/js/version"
51+
sh "gem", "-C", "packages/gems/js", "build", "-o",
52+
File.join(vendor_cache_dir, "js-local.gem")
53+
end
54+
4255
namespace :npm do
4356
NPM_PACKAGES.each do |pkg|
4457
base_dir = Dir.pwd
@@ -51,6 +64,8 @@ namespace :npm do
5164
# Skip if the package does not require building ruby
5265
next unless build_command
5366

67+
vendor_gem_cache(pkg)
68+
5469
env = {
5570
# Share ./build and ./rubies in the same workspace
5671
"RUBY_WASM_ROOT" => base_dir
@@ -67,11 +82,6 @@ namespace :npm do
6782
mkdir_p dist_dir
6883
if pkg[:target].start_with?("wasm32-unknown-wasi")
6984
Dir.chdir(cwd || base_dir) do
70-
vendor_cache_dir = File.join(pkg_dir, "vendor", "cache")
71-
mkdir_p vendor_cache_dir
72-
require_relative "../packages/gems/js/lib/js/version"
73-
sh "gem", "-C", File.join(base_dir, "packages/gems/js"), "build", "-o",
74-
File.join(pkg_dir, "vendor", "cache", "js-local.gem")
7585

7686
sh env,
7787
*build_command,

0 commit comments

Comments
 (0)