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

Minor fixes for migrating webpack to esbuild during a v2 upgrade #926

Merged
merged 4 commits into from
Oct 17, 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
3 changes: 3 additions & 0 deletions bridgetown-core/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@ Style/OpenStructUse:
Style/StringConcatenation:
Exclude:
- test/test_apply_command.rb

Style/MixinGrouping:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ def add_npm_package(package_details)
run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_install_command} #{package_details}" # rubocop:disable Layout
end

def remove_npm_package(package_details)
run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_uninstall_command} #{package_details}" # rubocop:disable Layout
end

def apply_from_url(url)
apply transform_automation_url(url.dup)
end
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/commands/esbuild.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Bridgetown
module Commands
class Esbuild < Thor::Group
include Thor::Actions
include Thor::Actions, Bridgetown::Commands::Actions
extend Summarizable

Registrations.register do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
confirm = ask "\nThe following packages will be removed: \n\n#{packages_to_remove.join("\n")}\n\nWould you like to continue? [Yn]"
return unless confirm.casecmp?("Y")

run "yarn remove #{packages_to_remove.join(" ")}"
remove_npm_package packages_to_remove.join(" ")
end
end

Expand Down
10 changes: 7 additions & 3 deletions bridgetown-core/lib/bridgetown-core/plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ def self.require_gem(name)
end

def self.package_manager
@package_manager ||= if File.exist?("package-lock.json")
"npm"
elsif File.exist?("yarn.lock")
@package_manager ||= if File.exist?("yarn.lock")
"yarn"
elsif File.exist?("pnpm-lock.yaml")
"pnpm"
elsif File.exist?("package.json")
"npm"
else
""
end
Expand All @@ -96,6 +96,10 @@ def self.package_manager_install_command
package_manager == "npm" ? "install" : "add"
end

def self.package_manager_uninstall_command
package_manager == "npm" ? "uninstall" : "remove"
end

# rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity

# Iterates through loaded gems and finds npm-add gemspec metadata.
Expand Down