lib/vite_ruby/cli/install.rb in vite_ruby-3.6.2 vs lib/vite_ruby/cli/install.rb in vite_ruby-3.7.0

- old
+ new

@@ -4,11 +4,15 @@ require 'json' class ViteRuby::CLI::Install < Dry::CLI::Command desc 'Performs the initial configuration setup to get started with Vite Ruby.' - def call(**) + option(:package_manager, values: %w[npm pnpm yarn bun], aliases: %w[package-manager with], desc: 'The package manager to use when installing JS dependencies.') + + def call(package_manager: nil, **) + ENV['VITE_RUBY_PACKAGE_MANAGER'] ||= package_manager if package_manager + $stdout.sync = true say 'Creating binstub' ViteRuby.commands.install_binstubs @@ -91,12 +95,11 @@ if (JSON.parse(package_json.read)['type'] != 'module' rescue nil) FileUtils.mv root.join('vite.config.ts'), root.join('vite.config.mts'), force: true, verbose: true end - deps = js_dependencies.join(' ') - run_with_capture("#{ npm_install } -D #{ deps }", stdin_data: "\n") + install_js_packages js_dependencies.join(' ') end # Internal: Adds compilation output dirs to git ignore. def install_gitignore return unless (gitignore_file = root.join('.gitignore')).exist? @@ -126,15 +129,11 @@ _, stderr, status = ViteRuby::IO.capture(*args, **options) say(stderr) unless status.success? || stderr.empty? end end - # Internal: Support all popular package managers. - def npm_install - return 'yarn add' if root.join('yarn.lock').exist? - return 'pnpm install' if root.join('pnpm-lock.yaml').exist? - - 'npm install' + def install_js_packages(deps) + run_with_capture("#{ config.package_manager } add -D #{ deps }", stdin_data: "\n") end # Internal: Avoid printing warning about missing vite.json, we will create one. def silent_warnings old_stderr = $stderr