Skip to content

Commit

Permalink
Merge pull request #926 from ayushn21/v2-upgrade-fixes
Browse files Browse the repository at this point in the history
Minor fixes for migrating webpack to esbuild during a v2 upgrade
  • Loading branch information
ayushn21 authored Oct 17, 2024
2 parents 47a891a + ccab809 commit 820b734
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
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

0 comments on commit 820b734

Please sign in to comment.