Skip to content

Commit

Permalink
Add support for single digit version strings, closes shakacode#489
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Davies committed Aug 1, 2016
1 parent b4cdfd2 commit d694df8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/react_on_rails/version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/react_on_rails/version_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d694df8

Please sign in to comment.