Class: Shakapacker::VersionChecker::NodePackageVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/shakapacker/version_checker.rb

Overview

TODO: this might as well use package_json

Constant Summary collapse

LOCAL_PATH_REGEX =

Matches local paths package managers emit: “./…”, “../..”, bare “..”, or “file:…”. Bare “..foo” (two dots, no slash, non-empty suffix) and bare “.” are intentionally not matched — package managers don’t emit those forms for shakapacker installs.

%r{\A(\./|\.\.(/|\z)|file:)}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_json, yarn_lock, package_lock, pnpm_lock) ⇒ NodePackageVersion

Returns a new instance of NodePackageVersion.



97
98
99
100
101
102
# File 'lib/shakapacker/version_checker.rb', line 97

def initialize(package_json, yarn_lock, package_lock, pnpm_lock)
  @package_json = package_json
  @yarn_lock = yarn_lock
  @package_lock = package_lock
  @pnpm_lock = pnpm_lock
end

Instance Attribute Details

#package_jsonObject (readonly)

Returns the value of attribute package_json.



75
76
77
# File 'lib/shakapacker/version_checker.rb', line 75

def package_json
  @package_json
end

Class Method Details

.buildObject



77
78
79
# File 'lib/shakapacker/version_checker.rb', line 77

def self.build
  new(package_json_path, yarn_lock_path, package_lock_path, pnpm_lock_path)
end

.package_json_pathObject



81
82
83
# File 'lib/shakapacker/version_checker.rb', line 81

def self.package_json_path
  Rails.root.join("package.json")
end

.package_lock_pathObject



89
90
91
# File 'lib/shakapacker/version_checker.rb', line 89

def self.package_lock_path
  Rails.root.join("package-lock.json")
end

.pnpm_lock_pathObject



93
94
95
# File 'lib/shakapacker/version_checker.rb', line 93

def self.pnpm_lock_path
  Rails.root.join("pnpm-lock.yaml")
end

.yarn_lock_pathObject



85
86
87
# File 'lib/shakapacker/version_checker.rb', line 85

def self.yarn_lock_path
  Rails.root.join("yarn.lock")
end

Instance Method Details

#major_minor_patchObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/shakapacker/version_checker.rb', line 116

def major_minor_patch
  return if skip_processing?

  match = raw.match(MAJOR_MINOR_PATCH_VERSION_REGEX)
  unless match
    raise "Cannot parse version number '#{raw}' (wildcard versions are not supported)"
  end

  [match[1], match[2], match[3]]
end

#rawObject



104
105
106
# File 'lib/shakapacker/version_checker.rb', line 104

def raw
  @raw ||= find_version
end

#semver_wildcard?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/shakapacker/version_checker.rb', line 108

def semver_wildcard?
  raw.match(/[~^]/).present?
end

#skip_processing?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/shakapacker/version_checker.rb', line 112

def skip_processing?
  !package_specified? || relative_path? || git_url? || github_url?
end