class Webpacker::VersionChecker::NodePackageVersion

Attributes

package_json[R]

Public Class Methods

build() click to toggle source
# File lib/webpacker/version_checker.rb, line 93
def self.build
  new(package_json_path)
end
new(package_json) click to toggle source
# File lib/webpacker/version_checker.rb, line 101
def initialize(package_json)
  @package_json = package_json
end
package_json_path() click to toggle source
# File lib/webpacker/version_checker.rb, line 97
def self.package_json_path
  Rails.root.join("package.json")
end

Public Instance Methods

major_minor_patch() click to toggle source
# File lib/webpacker/version_checker.rb, line 118
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
raw() click to toggle source
# File lib/webpacker/version_checker.rb, line 105
def raw
  parsed_package_contents = JSON.parse(package_json_contents)
  parsed_package_contents.dig("dependencies", "shakapacker").to_s
end
semver_wildcard?() click to toggle source
# File lib/webpacker/version_checker.rb, line 110
def semver_wildcard?
  raw.match(/[~^]/).present?
end
skip_processing?() click to toggle source
# File lib/webpacker/version_checker.rb, line 114
def skip_processing?
  !package_specified? || relative_path? || git_url? || github_url?
end

Private Instance Methods

git_url?() click to toggle source
# File lib/webpacker/version_checker.rb, line 139
def git_url?
  raw.match(%r{^git}).present?
end
github_url?() click to toggle source
# File lib/webpacker/version_checker.rb, line 143
def github_url?
  raw.match(%r{^([\w-]+\/[\w-]+)}).present?
end
package_json_contents() click to toggle source
# File lib/webpacker/version_checker.rb, line 147
def package_json_contents
  @package_json_contents ||= File.read(package_json)
end
package_specified?() click to toggle source
# File lib/webpacker/version_checker.rb, line 131
def package_specified?
  raw.present?
end
relative_path?() click to toggle source
# File lib/webpacker/version_checker.rb, line 135
def relative_path?
  raw.match(%r{(\.\.|\Afile:///)}).present?
end