lib/vite_ruby/config.rb in vite_ruby-3.6.2 vs lib/vite_ruby/config.rb in vite_ruby-3.7.0

- old
+ new

@@ -94,21 +94,31 @@ # Internal: Coerces all the configuration values, in case they were passed # as environment variables which are always strings. def coerce_values(config) config['mode'] = config['mode'].to_s config['port'] = config['port'].to_i - config['root'] = Pathname.new(config['root']) - config['build_cache_dir'] = config['root'].join(config['build_cache_dir']) - config['ssr_output_dir'] = config['root'].join(config['ssr_output_dir']) + config['root'] = root = Pathname.new(config['root']) + config['build_cache_dir'] = root.join(config['build_cache_dir']) + config['ssr_output_dir'] = root.join(config['ssr_output_dir']) coerce_booleans(config, 'auto_build', 'hide_build_console_output', 'https', 'skip_compatibility_check', 'skip_proxy') + config['package_manager'] ||= detect_package_manager(root) end # Internal: Coerces configuration options to boolean. def coerce_booleans(config, *names) names.each { |name| config[name] = [true, 'true'].include?(config[name]) } end + def detect_package_manager(root) + return 'npm' if root.join('package-lock.json').exist? + return 'pnpm' if root.join('pnpm-lock.yaml').exist? + return 'bun' if root.join('bun.lockb').exist? + return 'yarn' if root.join('yarn.lock').exist? + + 'npm' + end + def initialize(attrs) @config = attrs.tap { |config| coerce_values(config) }.freeze ViteRuby::CompatibilityCheck.verify_plugin_version(root) unless skip_compatibility_check end @@ -187,18 +197,19 @@ # Internal: Configuration options that can be provided as env vars. CONFIGURABLE_WITH_ENV = (DEFAULT_CONFIG.keys + %w[mode root] - NOT_CONFIGURABLE_WITH_ENV).freeze # Internal: If any of these files is modified the build won't be skipped. DEFAULT_WATCHED_PATHS = %w[ + bun.lockb package-lock.json package.json pnpm-lock.yaml postcss.config.js tailwind.config.js vite.config.js vite.config.mjs - vite.config.ts vite.config.mts + vite.config.ts windi.config.ts yarn.lock ].freeze public