• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uclibs / application_portfolio / 28464678013

30 Jun 2026 05:48PM UTC coverage: 74.299% (+0.2%) from 74.111%
28464678013

Pull #457

circleci

Janell-Huyck
Ensure yarn is available when Rake runs javascript:install.

Activate Corepack from the nvm Node bin so jsbundling-rails can shell out
to bare yarn in CI and during assets:precompile specs.

Co-authored-by: Cursor <cursoragent@cursor.com>
Pull Request #457: Upgrade stack to Ruby 4.0.5 and Node 26.4.0.

333 of 494 branches covered (67.41%)

Branch coverage included in aggregate %.

21 of 23 new or added lines in 1 file covered. (91.3%)

1 existing line in 1 file now uncovered.

965 of 1253 relevant lines covered (77.02%)

23.59 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.51
/lib/javascript_build_env.rb
1
# frozen_string_literal: true
2

3
require 'json'
2✔
4

5
# jsbundling-rails and bin/yarn shell out to yarn; prepend the Node version from
6
# .nvmrc when nvm is installed so builds work even if an older node or yarn
7
# binary appears earlier on PATH. Activates Yarn via Corepack from that Node's
8
# bin directory (bare `yarn` is unavailable until corepack enable runs there).
9
module JavascriptBuildEnv
2✔
10
  module_function
2✔
11

12
  def apply!(root = default_root)
2✔
13
    node_bin = node_bin_directory(root)
8✔
14
    return unless node_bin
8✔
15

16
    ENV['PATH'] = "#{node_bin}:#{ENV['PATH']}" unless path_prefixed_with?(node_bin)
4!
17
    activate_yarn!(root, node_bin)
4✔
18
  end
19

20
  def node_bin_directory(root = default_root)
2✔
21
    nvm_node_bin(root)
8✔
22
  end
23

24
  def nvm_node_bin(root = default_root)
2✔
25
    nvmrc = root.join('.nvmrc')
14✔
26
    return unless nvmrc.exist?
14✔
27

28
    version = nvmrc.read.strip.delete_prefix('v')
12✔
29
    nvm_dir = ENV.fetch('NVM_DIR') { File.expand_path('~/.nvm') }
12✔
30
    node_bin = File.join(nvm_dir, 'versions', 'node', "v#{version}", 'bin')
12✔
31

32
    node_bin if File.directory?(node_bin)
12✔
33
  end
34

35
  def activate_yarn!(root, node_bin)
2✔
36
    package_manager = package_manager_for(root)
4✔
37
    return unless package_manager
4✔
38

39
    corepack = File.join(node_bin, 'corepack')
2✔
40
    return unless File.executable?(corepack)
2!
41

42
    # Invoke Corepack from node_bin so shims land in a user-writable directory,
43
    # not /usr/local when a system Node appears earlier on PATH (CircleCI cimg).
44
    system(corepack, 'enable', out: File::NULL, err: File::NULL)
2✔
45
    system(corepack, 'prepare', package_manager, '--activate', out: File::NULL, err: File::NULL)
2✔
46
  end
47

48
  def package_manager_for(root)
2✔
49
    package_json = root.join('package.json')
4✔
50
    return unless package_json.exist?
4✔
51

52
    JSON.parse(package_json.read).fetch('packageManager', nil).presence
2✔
53
  rescue JSON::ParserError
NEW
54
    nil
×
55
  end
56

57
  def path_prefixed_with?(node_bin)
2✔
58
    ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).first == node_bin
4✔
59
  end
60

61
  def default_root
2✔
62
    if defined?(Rails) && Rails.application&.initialized?
4!
63
      Rails.root
4✔
64
    else
×
NEW
65
      Pathname.new(File.expand_path('..', __dir__))
×
66
    end
67
  end
68
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc