Class: ReactOnRails::VersionChecker::NodePackageVersion
- Inherits:
-
Object
- Object
- ReactOnRails::VersionChecker::NodePackageVersion
- Defined in:
- lib/react_on_rails/version_checker.rb
Instance Attribute Summary collapse
-
#package_json ⇒ Object
readonly
Returns the value of attribute package_json.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(package_json) ⇒ NodePackageVersion
constructor
A new instance of NodePackageVersion.
- #local_path_or_url? ⇒ Boolean
- #major_minor_patch ⇒ Object
- #raw ⇒ Object
- #semver_wildcard? ⇒ Boolean
Constructor Details
#initialize(package_json) ⇒ NodePackageVersion
Returns a new instance of NodePackageVersion.
79 80 81 |
# File 'lib/react_on_rails/version_checker.rb', line 79 def initialize(package_json) @package_json = package_json end |
Instance Attribute Details
#package_json ⇒ Object (readonly)
Returns the value of attribute package_json.
69 70 71 |
# File 'lib/react_on_rails/version_checker.rb', line 69 def package_json @package_json end |
Class Method Details
.build ⇒ Object
71 72 73 |
# File 'lib/react_on_rails/version_checker.rb', line 71 def self.build new(package_json_path) end |
.package_json_path ⇒ Object
75 76 77 |
# 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 |
Instance Method Details
#local_path_or_url? ⇒ Boolean
106 107 108 109 110 111 |
# 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 |
#major_minor_patch ⇒ Object
113 114 115 116 117 118 119 120 121 122 |
# 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 |
#raw ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# 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 |
#semver_wildcard? ⇒ Boolean
99 100 101 102 103 104 |
# 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 |