diff --git a/bridgetown-core/.rubocop.yml b/bridgetown-core/.rubocop.yml index 0e586bd0a..814a251e6 100644 --- a/bridgetown-core/.rubocop.yml +++ b/bridgetown-core/.rubocop.yml @@ -43,3 +43,6 @@ Style/OpenStructUse: Style/StringConcatenation: Exclude: - test/test_apply_command.rb + +Style/MixinGrouping: + Enabled: false \ No newline at end of file diff --git a/bridgetown-core/lib/bridgetown-core/commands/concerns/actions.rb b/bridgetown-core/lib/bridgetown-core/commands/concerns/actions.rb index 28e161f70..7f2e5abe1 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/concerns/actions.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/concerns/actions.rb @@ -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 diff --git a/bridgetown-core/lib/bridgetown-core/commands/esbuild.rb b/bridgetown-core/lib/bridgetown-core/commands/esbuild.rb index f47b01e57..345a6b7a6 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/esbuild.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/esbuild.rb @@ -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 diff --git a/bridgetown-core/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb b/bridgetown-core/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb index c12383095..554072753 100644 --- a/bridgetown-core/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +++ b/bridgetown-core/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb @@ -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 diff --git a/bridgetown-core/lib/bridgetown-core/plugin_manager.rb b/bridgetown-core/lib/bridgetown-core/plugin_manager.rb index 3ccd215da..ace91abf3 100644 --- a/bridgetown-core/lib/bridgetown-core/plugin_manager.rb +++ b/bridgetown-core/lib/bridgetown-core/plugin_manager.rb @@ -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 @@ -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.