Skip to content
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

Changes since the last non-beta release.

### Added

- **Added `SKIP=true` installer mode to preserve existing files**. [PR #893](https://github.com/shakacode/shakapacker/pull/893) by [justin808](https://github.com/justin808). Running `rails shakapacker:install SKIP=true` now skips conflicting files instead of overwriting them. This is useful for CI/CD pipelines and automated setups where you want to install only missing files without touching existing configuration.

### Changed

- **BREAKING: sass-loader now defaults to modern Sass API**. [PR #879](https://github.com/shakacode/shakapacker/pull/879) by [justin808](https://github.com/justin808). The sass-loader configuration now uses `api: "modern"` instead of the deprecated legacy API. This improves compatibility with plugins like sass-resources-loader that require the modern API. If you experience issues after upgrading, you can revert to the legacy API by customizing your webpack config:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Then run the following to install Shakapacker:
bundle exec rake shakapacker:install
```

Before initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files or use the `FORCE=true` environment variable before the installation command to force the override without any prompt.
Before initiating the installation process, ensure you have committed all the changes. While installing Shakapacker, there might be some conflict between the existing file content and what Shakapacker tries to copy. You can either approve all the prompts for overriding these files, use `FORCE=true` to overwrite without prompting, or use `SKIP=true` to preserve existing files and only create missing ones. If both are set, `FORCE=true` takes precedence.

Shakapacker uses the [`package_json`](https://github.com/shakacode/package_json) gem to handle updating the `package.json` and interacting with the underlying package manager of choice for managing dependencies and running commands; the package manager is managed using the [`packageManager`](https://nodejs.org/api/packages.html#packagemanager) property in the `package.json`, otherwise falling back to the value of `PACKAGE_JSON_FALLBACK_MANAGER` if set or otherwise `npm`.

Expand Down
10 changes: 8 additions & 2 deletions lib/install/binstubs.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
force_option = ENV["FORCE"] ? { force: true } : {}
conflict_option = if ENV["FORCE"]
{ force: true }
elsif ENV["SKIP"]
{ skip: true }
else
{}
end

say "Copying binstubs"
directory "#{__dir__}/bin", "bin", force_option
directory "#{__dir__}/bin", "bin", conflict_option

chmod "bin", 0755 & ~File.umask, verbose: false
12 changes: 9 additions & 3 deletions lib/install/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@

# Install Shakapacker

force_option = ENV["FORCE"] ? { force: true } : {}
conflict_option = if ENV["FORCE"]
{ force: true }
elsif ENV["SKIP"]
{ skip: true }
else
{}
end
Comment on lines +10 to +16
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

ENV["SKIP"] is truthy for any value, including "false" or "0".

ENV["SKIP"] returns a non-nil string for any set value, so SKIP=false bundle exec rake shakapacker:install would still activate skip mode. Consider checking for explicit truthy values to match the documented SKIP=true usage. The same applies to ENV["FORCE"], though that's pre-existing behavior.

Proposed fix
-conflict_option = if ENV["FORCE"]
+conflict_option = if ENV["FORCE"] == "true"
   { force: true }
-elsif ENV["SKIP"]
+elsif ENV["SKIP"] == "true"
   { skip: true }
 else
   {}
 end
🤖 Prompt for AI Agents
In `@lib/install/template.rb` around lines 10 - 16, The code currently treats any
set ENV["SKIP"] or ENV["FORCE"] as truthy (so "false" or "0" still activates),
so update the conflict_option logic to test for explicit truthy strings (e.g.
check ENV["SKIP"] && %w[true 1 yes].include?(ENV["SKIP"].to_s.downcase)) and do
the same for ENV["FORCE"] (or extract a small helper like truthy_env?(name)) so
only intended values like "true"/"1"/"yes" enable skip/force in the
conflict_option branch.


# Initialize variables for use throughout the template
# Using instance variable to avoid method definition issues in Rails templates
Expand All @@ -31,7 +37,7 @@
end

# Copy config file
copy_file "#{install_dir}/config/shakapacker.yml", "config/shakapacker.yml", force_option
copy_file "#{install_dir}/config/shakapacker.yml", "config/shakapacker.yml", conflict_option

# Update config if USE_BABEL_PACKAGES is set to ensure babel is used at runtime
if @transpiler_to_install == "babel" && !ENV["JAVASCRIPT_TRANSPILER"]
Expand All @@ -53,7 +59,7 @@
dest_config = "config/#{assets_bundler}/#{config_file}"

empty_directory "config/#{assets_bundler}"
copy_file source_config, dest_config, force_option
copy_file source_config, dest_config, conflict_option

if @use_typescript
say " ✨ Using TypeScript config for enhanced type safety", :green
Expand Down