class ReactOnRails::VersionChecker::NodePackageVersion
Attributes
Public Class Methods
Source
# File lib/react_on_rails/version_checker.rb, line 71 def self.build new(package_json_path) end
Source
# File lib/react_on_rails/version_checker.rb, line 79 def initialize(package_json) @package_json = package_json end
Source
# File lib/react_on_rails/version_checker.rb, line 75 def self.package_json_path Rails.root.join(ReactOnRails.configuration.node_modules_location, "package.json") end
Public Instance Methods
Source
# File lib/react_on_rails/version_checker.rb, line 106 def local_path_or_url? # See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies # All path and protocol "version ranges" include / somewhere, # but we want to make an exception for npm:@scope/pkg@version. !raw.nil? && raw.include?("/") && !raw.start_with?("npm:") end
Source
# File lib/react_on_rails/version_checker.rb, line 113 def major_minor_patch return if local_path_or_url? match = raw.match(MAJOR_MINOR_PATCH_VERSION_REGEX) unless match raise ReactOnRails::Error, "Cannot parse version number '#{raw}' (only exact versions are supported)" end [match[1], match[2], match[3]] end
Source
# File lib/react_on_rails/version_checker.rb, line 83 def raw return @raw if defined?(@raw) if File.exist?(package_json) parsed_package_contents = JSON.parse(package_json_contents) if parsed_package_contents.key?("dependencies") && parsed_package_contents["dependencies"].key?("react-on-rails") return @raw = parsed_package_contents["dependencies"]["react-on-rails"] end end msg = "No 'react-on-rails' entry in the dependencies of #{NodePackageVersion.package_json_path}, " \ "which is the expected location according to ReactOnRails.configuration.node_modules_location" Rails.logger.warn(msg) @raw = nil end
Source
# File lib/react_on_rails/version_checker.rb, line 99 def semver_wildcard? # See https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies # We want to disallow all expressions other than exact versions # and the ones allowed by local_path_or_url? raw.blank? || raw.match(/[~^><|*-]/).present? end
Private Instance Methods
Source
# File lib/react_on_rails/version_checker.rb, line 126 def package_json_contents @package_json_contents ||= File.read(package_json) end