diff --git a/CHANGELOG.md b/CHANGELOG.md index 59969ce00..0f73c2494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ Changes since the last non-beta release. - Drop support for Node v12 [PR 431](https://github.com/shakacode/shakapacker/pull/431) by [G-Rath](https://github.com/g-rath). +- Enable `ensure_consistent_versioning` by default [PR 447](https://github.com/shakacode/shakapacker/pull/447) by [G-Rath](https://github.com/g-rath). + ### Added - Emit warnings instead of errors when compilation is success but stderr is not empty. [PR 416](https://github.com/shakacode/shakapacker/pull/416) by [n-rodriguez](https://github.com/n-rodriguez). - Allow `webpack-dev-server` v5. [PR 418](https://github.com/shakacode/shakapacker/pull/418) by [G-Rath](https://github.com/g-rath) diff --git a/lib/install/config/shakapacker.yml b/lib/install/config/shakapacker.yml index 6a4df72e3..043b47afa 100644 --- a/lib/install/config/shakapacker.yml +++ b/lib/install/config/shakapacker.yml @@ -39,8 +39,8 @@ default: &default # Select loader to use, available options are 'babel' (default), 'swc' or 'esbuild' webpack_loader: 'babel' - # Set to true to enable check for matching versions of shakapacker gem and NPM package - will raise an error if there is a mismatch or wildcard versioning is used - ensure_consistent_versioning: false + # Raises an error if there is a mismatch in the shakapacker gem and npm package being used + ensure_consistent_versioning: true # Select whether the compiler will use SHA digest ('digest' option) or most most recent modified timestamp ('mtime') to determine freshness compiler_strategy: digest diff --git a/lib/shakapacker/version_checker.rb b/lib/shakapacker/version_checker.rb index 1ea4730d3..d5c10260f 100644 --- a/lib/shakapacker/version_checker.rb +++ b/lib/shakapacker/version_checker.rb @@ -17,41 +17,19 @@ def initialize(node_package_version) def raise_if_gem_and_node_package_versions_differ # Skip check if package is not in package.json or listed from relative path, git repo or github URL - return if node_package_version.skip_processing? + # or if consistent version checking is not enabled + return if node_package_version.skip_processing? || !Shakapacker.config.ensure_consistent_versioning? node_major_minor_patch = node_package_version.major_minor_patch gem_major_minor_patch = gem_major_minor_patch_version - versions_match = node_major_minor_patch[0] == gem_major_minor_patch[0] && - node_major_minor_patch[1] == gem_major_minor_patch[1] && - node_major_minor_patch[2] == gem_major_minor_patch[2] - uses_wildcard = node_package_version.semver_wildcard? + raise_differing_versions_warning unless ( + node_major_minor_patch[0] == gem_major_minor_patch[0] && + node_major_minor_patch[1] == gem_major_minor_patch[1] && + node_major_minor_patch[2] == gem_major_minor_patch[2] + ) - if !Shakapacker.config.ensure_consistent_versioning? && (uses_wildcard || !versions_match) - check_failed = if uses_wildcard - "Semver wildcard without a lockfile detected" - else - "Version mismatch detected" - end - - warn <<-MSG.strip_heredoc - Shakapacker::VersionChecker - #{check_failed} - - You are currently not checking for consistent versions of shakapacker gem and npm package. A version mismatch or usage of semantic versioning wildcard (~ or ^) without a lockfile has been detected. - - Version mismatch can lead to incorrect behavior and bugs. You should ensure that both the gem and npm package dependencies are locked to the same version. - - You can enable the version check by setting `ensure_consistent_versioning: true` in your `shakapacker.yml` file. - - Checking for gem and npm package versions mismatch or wildcard will be enabled by default in the next major version of shakapacker. - MSG - - return - end - - raise_differing_versions_warning unless versions_match - - raise_node_semver_version_warning if uses_wildcard + raise_node_semver_version_warning if node_package_version.semver_wildcard? end private diff --git a/spec/dummy/yarn.lock b/spec/dummy/yarn.lock index c21d5c6b4..a7ccb68d8 100644 --- a/spec/dummy/yarn.lock +++ b/spec/dummy/yarn.lock @@ -4060,7 +4060,7 @@ setprototypeof@1.2.0: integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw== "shakapacker@file:.yalc/shakapacker": - version "7.0.0-rc.0" + version "7.2.2" dependencies: glob "^7.2.0" js-yaml "^4.1.0" diff --git a/spec/shakapacker/configuration_spec.rb b/spec/shakapacker/configuration_spec.rb index b646aebb2..c562ed58b 100644 --- a/spec/shakapacker/configuration_spec.rb +++ b/spec/shakapacker/configuration_spec.rb @@ -113,8 +113,8 @@ end describe "#ensure_consistent_versioning?" do - it "returns false in production environment" do - expect(config.ensure_consistent_versioning?).to be false + it "returns true in production environment" do + expect(config.ensure_consistent_versioning?).to be true end it "returns true in development environment" do @@ -123,9 +123,9 @@ end end - it "returns false in test environment" do + it "returns true in test environment" do with_rails_env("test") do - expect(Shakapacker.config.ensure_consistent_versioning?).to be false + expect(Shakapacker.config.ensure_consistent_versioning?).to be true end end end diff --git a/spec/shakapacker/version_checker_spec.rb b/spec/shakapacker/version_checker_spec.rb index fe0bd83dc..9f8e44dd7 100644 --- a/spec/shakapacker/version_checker_spec.rb +++ b/spec/shakapacker/version_checker_spec.rb @@ -29,19 +29,19 @@ def check_version(node_package_version, stub_gem_version = Shakapacker::VERSION, version_checker.raise_if_gem_and_node_package_versions_differ end - it "prints error in stderr if consistency check is disabled and version mismatch" do + it "does nothing if consistency check is disabled and version mismatch" do node_package_version = NodePackageVersionDouble.new(raw: "6.1.0", major_minor_patch: ["6", "1", "0"]) expect { check_version(node_package_version, "6.0.0", false) } - .to output(/Shakapacker::VersionChecker - Version mismatch/) + .not_to output .to_stderr end - it "prints error in stderr if consistency check is disabled and we have semver" do + it "does nothing if consistency check is disabled and we have semver" do node_package_version = NodePackageVersionDouble.new(raw: "^6.1.0", major_minor_patch: ["6", "1", "0"], semver_wildcard: true) expect { check_version(node_package_version, "6.0.0", false) } - .to output(/Shakapacker::VersionChecker - Semver wildcard without a lockfile detected/) + .not_to output .to_stderr end