Skip to content

Commit c443294

Browse files
committed
Improve the logic to handle exact, caret, tilde version
1 parent 9fc7bac commit c443294

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/inertia_rails/generators/helper.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ module InertiaRails
44
module Generators
55
module Helper
66
class << self
7-
def guess_the_default_framework(package_json_path = Rails.root.join("package.json"))
8-
package = File.read(package_json_path)
9-
case package
10-
when %r{@inertiajs/react}
7+
def guess_the_default_framework(package_json_path = Rails.root.join('package.json'))
8+
package_json = JSON.parse(package_json_path.read)
9+
dependencies = package_json['dependencies'] || {}
10+
11+
if dependencies['@inertiajs/react']
1112
'react'
12-
when %r{@inertiajs/svelte}
13-
package.match?(/"svelte": "\^5/) ? 'svelte' : 'svelte4'
14-
when %r{@inertiajs/vue3}
13+
elsif dependencies['@inertiajs/svelte']
14+
version = dependencies['svelte'].gsub(/[\^~]/, '') # Remove ^ or ~ from version
15+
version.start_with?('5') ? 'svelte' : 'svelte4'
16+
elsif dependencies['@inertiajs/vue3']
1517
'vue'
1618
else
1719
Thor::Shell::Basic.new.say_error 'Could not determine the Inertia.js framework you are using.'

0 commit comments

Comments
 (0)