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 bef9fab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 32 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

0 comments on commit bef9fab

Please sign in to comment.