Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: enable ensure_consistent_versioning by default #447

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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 @@ setprototypeof@1.2.0:
integrity sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==

"shakapacker@file:.yalc/shakapacker":
version "7.0.0-rc.0"
version "7.2.2"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is annoying - pretty sure this'll need to be updated for CI whenever a new version is released, and is because Yarn doesn't update its lockfile when running in CI.

Will have a think on how we could handle this more gracefully

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this one matter past error being thrown on mismatch? If that's the only worry here then I'd probably just disable version check in https://github.com/shakacode/shakapacker/blob/next/spec/dummy/config/shakapacker.yml and move on 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that and I'm not fussed but arguably it is nicer to have it enabled since it's ensuring the out of box config works nicely.

Currently I'd say it should be fine to even land as-is because this'll only matter when a new version comes out which already requires bumping the version number elsewhere and takes a minute so should be fine to live with for now 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, should be easy enough to get and hookup this update in any other bumps and release flows. We'll see it when it fails 😅

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
Loading