From d694df87bca9df3271b7c7fdcb7c0d956638d234 Mon Sep 17 00:00:00 2001 From: Sam Davies Date: Wed, 27 Jul 2016 10:52:49 +0100 Subject: [PATCH] Add support for single digit version strings, closes #489 --- CHANGELOG.md | 10 ++++++---- lib/react_on_rails/version_checker.rb | 5 +++-- spec/react_on_rails/version_checker_spec.rb | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8667d6d1c..da9aa4a99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com] ## [Unreleased] +- React on Rails now correctly parses single-digit version strings from package.json [#491](https://github.com/shakacode/react_on_rails/pull/491) + ## [6.0.5] ##### Added - Added better error messages to avoid issues with shared redux stores [#470](https://github.com/shakacode/react_on_rails/pull/470). @@ -27,19 +29,19 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com] ## [6.0.0] ##### Breaking Changes -- Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own assets.rake file that does the precompilation. +- Added automatic compilation of assets at precompile is now done by ReactOnRails. Thus, you don't need to provide your own assets.rake file that does the precompilation. [#398](https://github.com/shakacode/react_on_rails/pull/398) by [robwise](https://github.com/robwise), [jbhatab](https://github.com/jbhatab), and [justin808](https://github.com/justin808). - **Migration to v6** - Do not run the generator again if you've already run it. - See [shakacode/react-webpack-rails-tutorial/pull/287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287) for an example of upgrading from v5. - + - To configure the asset compliation you can either 1. Specify a `config/react_on_rails` setting for `npm_build_production_command` to be nil to turn this feature off. 2. Specify the script command you want to run to build your production assets, and remove your assets.rake file. - If you are using the ReactOnRails test helper, then you will need to add the 'config.npm_build_test_command' to your config to tell react_on_rails what command to run when you run rspec. - + - See [shakacode/react-webpack-rails-tutorial #287](https://github.com/shakacode/react-webpack-rails-tutorial/pull/287/files) for an upgrade example. The PR has a few comments on the upgrade. Here is the addition to the generated config file: @@ -92,7 +94,7 @@ Here is the addition to the generated config file: - [Security] Address failure to sanitize console messages when server rendering and displaying in the browser console. See [#366](https://github.com/shakacode/react_on_rails/pull/366) and [#370](https://github.com/shakacode/react_on_rails/pull/370) by [justin808](https://github.com/justin808) ##### Added -- railsContext includes the port number and a boolean if the code is being run on the server or client. +- railsContext includes the port number and a boolean if the code is being run on the server or client. ## [5.1.0] - 2016-04-03 ##### Added diff --git a/lib/react_on_rails/version_checker.rb b/lib/react_on_rails/version_checker.rb index 5ba50d94d..6e24189ee 100644 --- a/lib/react_on_rails/version_checker.rb +++ b/lib/react_on_rails/version_checker.rb @@ -3,6 +3,7 @@ module ReactOnRails # against each otherat runtime. class VersionChecker attr_reader :node_package_version, :logger + MAJOR_VERSION_REGEX = /(\d+)\.?/ def self.build new(NodePackageVersion.build, Rails.logger) @@ -38,7 +39,7 @@ def gem_version end def gem_major_version - gem_version.match(/(\d+)\./)[1] + gem_version.match(MAJOR_VERSION_REGEX)[1] end class NodePackageVersion @@ -66,7 +67,7 @@ def relative_path? def major return if relative_path? - raw.match(/(\d+)\./)[1] + raw.match(MAJOR_VERSION_REGEX)[1] end private diff --git a/spec/react_on_rails/version_checker_spec.rb b/spec/react_on_rails/version_checker_spec.rb index 37fa09234..fc1462c4b 100644 --- a/spec/react_on_rails/version_checker_spec.rb +++ b/spec/react_on_rails/version_checker_spec.rb @@ -47,6 +47,24 @@ module ReactOnRails expect(logger.message).to be_nil end end + + context "when package json uses a one-digit version string" do + let(:node_package_version) do + double_package_version(raw: "^6", major: "6") + end + + it "does not log a warning" do + stub_gem_version("6") + check_version(node_package_version, logger) + expect(logger.message).to be_nil + end + + it "logs a warning" do + stub_gem_version("5") + check_version(node_package_version, logger) + expect(logger.message).to be_present + end + end end def double_package_version(raw: nil, major: nil, relative_path: false)