From 5cf2fd3aec5ef6bc908c988f411319c7eb99ce9e Mon Sep 17 00:00:00 2001 From: Ayush Newatia Date: Thu, 17 Oct 2024 13:09:20 +0100 Subject: [PATCH 1/4] Fallback to NPM when package.json exists without a lockfile --- bridgetown-core/lib/bridgetown-core/plugin_manager.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/plugin_manager.rb b/bridgetown-core/lib/bridgetown-core/plugin_manager.rb index 3ccd215da..0684a9747 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 From 9b368c585d5c4b0dc4cdd58a923b0d44bf5635ca Mon Sep 17 00:00:00 2001 From: Ayush Newatia Date: Thu, 17 Oct 2024 13:09:39 +0100 Subject: [PATCH 2/4] Add command to remove an NPM package --- .../lib/bridgetown-core/commands/concerns/actions.rb | 4 ++++ .../bridgetown-core/commands/esbuild/migrate-from-webpack.rb | 2 +- bridgetown-core/lib/bridgetown-core/plugin_manager.rb | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) 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/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 0684a9747..ace91abf3 100644 --- a/bridgetown-core/lib/bridgetown-core/plugin_manager.rb +++ b/bridgetown-core/lib/bridgetown-core/plugin_manager.rb @@ -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. From c45020a9f29ba631784d4d04a6b33650a5353b8e Mon Sep 17 00:00:00 2001 From: Ayush Newatia Date: Thu, 17 Oct 2024 13:09:54 +0100 Subject: [PATCH 3/4] Include bridgetown actions in the Esbuild command --- bridgetown-core/lib/bridgetown-core/commands/esbuild.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From ccab809741b3b0de4cb70731ab70ab95ded09421 Mon Sep 17 00:00:00 2001 From: Ayush Newatia Date: Thu, 17 Oct 2024 13:24:27 +0100 Subject: [PATCH 4/4] Disable Rubocop mixing grouping rule --- bridgetown-core/.rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) 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