Skip to content

Commit

Permalink
feat!: enable ensure_consistent_versioning by default
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Mar 9, 2024
1 parent 8585bf8 commit 70410e6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/install/config/shakapacker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 8 additions & 30 deletions lib/shakapacker/version_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/dummy/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4060,7 +4060,7 @@ [email protected]:
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"
Expand Down
8 changes: 4 additions & 4 deletions spec/shakapacker/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/shakapacker/version_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 70410e6

Please sign in to comment.