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

uclibs / application_portfolio / 28464964216

30 Jun 2026 05:53PM UTC coverage: 74.394% (+0.3%) from 74.111%
28464964216

Pull #457

circleci

Janell-Huyck
Run Corepack via corepack.js when bin/corepack is missing.

CircleCI nvm Node installs omit the corepack shim; invoke corepack.js
with --install-directory ~/bin so yarn is on PATH for Rake and CI.

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

341 of 506 branches covered (67.39%)

Branch coverage included in aggregate %.

32 of 34 new or added lines in 1 file covered. (94.12%)

2 existing lines in 2 files now uncovered.

978 of 1267 relevant lines covered (77.19%)

23.4 hits per line

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

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

3
require 'json'
2✔
4
require 'fileutils'
2✔
5

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

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

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

21
  def node_bin_directory(root = default_root)
2✔
22
    nvm_node_bin(root)
10✔
23
  end
24

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

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

33
    node_bin if File.directory?(node_bin)
14✔
34
  end
35

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

40
    runner, *runner_args = corepack_command(node_bin)
4✔
41
    return unless runner
4!
42

43
    install_dir = File.expand_path('~/bin')
4✔
44
    FileUtils.mkdir_p(install_dir)
4✔
45
    ENV['PATH'] = "#{install_dir}:#{ENV['PATH']}" unless path_includes?(install_dir)
4!
46

47
    enable_args = runner_args + ['enable', '--install-directory', install_dir]
4✔
48
    prepare_args = runner_args + ['prepare', package_manager, '--activate']
4✔
49
    system(runner, *enable_args, out: File::NULL, err: File::NULL)
4✔
50
    system(runner, *prepare_args, out: File::NULL, err: File::NULL)
4✔
51
  end
52

53
  def corepack_command(node_bin)
2✔
54
    corepack_bin = File.join(node_bin, 'corepack')
4✔
55
    return [corepack_bin] if File.executable?(corepack_bin)
4✔
56

57
    corepack_js = File.expand_path(File.join(node_bin, '..', 'lib', 'node_modules', 'corepack', 'dist', 'corepack.js'))
2✔
58
    return ['node', corepack_js] if File.file?(corepack_js)
2!
59

NEW
60
    nil
×
61
  end
62

63
  def package_manager_for(root)
2✔
64
    package_json = root.join('package.json')
6✔
65
    return unless package_json.exist?
6✔
66

67
    JSON.parse(package_json.read).fetch('packageManager', nil).presence
4✔
68
  rescue JSON::ParserError
NEW
69
    nil
×
70
  end
71

72
  def path_prefixed_with?(node_bin)
2✔
73
    ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).first == node_bin
6✔
74
  end
75

76
  def path_includes?(directory)
2✔
77
    ENV.fetch('PATH', '').split(File::PATH_SEPARATOR).include?(directory)
4✔
78
  end
79

80
  def default_root
2✔
81
    if defined?(Rails) && Rails.application&.initialized?
4!
82
      Rails.root
4✔
83
    else
×
UNCOV
84
      Pathname.new(File.expand_path('..', __dir__))
×
85
    end
86
  end
87
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