opal-vite-rails 0.3.16 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4324653e587faaeb544294659054bd01b0815ac4056950d8ee8de78c62fd8778
4
- data.tar.gz: 00333bbe532cced98a84165a037bbd7df9247ed4cf06c568b0dce4e98cc79b5c
3
+ metadata.gz: f636fba332d720cdabb3fe9be702ba4ff112c9f84492fb14a9afc1bbbae2f2d2
4
+ data.tar.gz: 35706c079ab295a7fa5b8ffd4abd5d47674660b9b0f052e35baff6257f6375d0
5
5
  SHA512:
6
- metadata.gz: 0a7a1739693c6aa93583d2bb0dc48c6dacf18ba215bd0b371d69ee9df396a5774838d9b234918b719d0b07b561c531f925cfe61079a93b9735bc2d4e4f38332e
7
- data.tar.gz: 6d36e9693f19c772a3f91609a63104bbcbc6cab6bf267b3f542fc3142e218b21836d29200278bfeaac250f1bfe3d8f31fbf86e9b73b68f5ad5567a3a56599466
6
+ metadata.gz: 2a95c18d071d903977c48b8424365c51e57b91c2f1cf06bbeae1fa0a50f0afbe6836ed3162832f8215b78a7d46f4b73863e4a7d1fc1f7cea374a6cb1744a4c4a
7
+ data.tar.gz: b74c9c06b426f92fadef4beabaac4be18e29eb1d0788439a3f8c35ccb4451887e29a54eaeaded29625bbb9770070cab30608c2d2f44298c60fccdf621a4b7826
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 opal-vite contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -13,7 +13,7 @@ Seamless integration of [Opal](https://opalrb.com/) (Ruby to JavaScript compiler
13
13
  ## Requirements
14
14
 
15
15
  - Ruby >= 3.0
16
- - Rails >= 7.0
16
+ - Rails >= 7.0, < 9
17
17
  - Node.js >= 18.0
18
18
  - Opal >= 1.8
19
19
 
@@ -207,7 +207,8 @@ You usually don't need to run it yourself: vite_rails already runs the Vite buil
207
207
  # Compile Opal assets for production
208
208
  rake opal_vite:compile
209
209
 
210
- # Clean compiled assets
210
+ # Remove the Vite build output of the current RAILS_ENV
211
+ # (public/vite-dev in development; public/vite only with RAILS_ENV=production)
211
212
  rake opal_vite:clean
212
213
 
213
214
  # Show configuration info
@@ -36,6 +36,11 @@ module Opal
36
36
  end
37
37
  end
38
38
 
39
+ initializer "opal_vite.deprecator" do |app|
40
+ # Rails.application.deprecators exists since Rails 7.1
41
+ app.deprecators[:opal_vite_rails] = Opal::Vite::Rails.deprecator if app.respond_to?(:deprecators)
42
+ end
43
+
39
44
  initializer "opal_vite.view_helpers" do
40
45
  ActiveSupport.on_load(:action_view) do
41
46
  include Opal::Vite::Rails::Helper
@@ -51,7 +51,7 @@ module Opal
51
51
  end
52
52
 
53
53
  def create_package_json_entry
54
- if File.exist?("package.json")
54
+ if File.exist?(File.join(destination_root, "package.json"))
55
55
  say "Adding vite-plugin-opal to package.json...", :green
56
56
  say "Run: npm install vite-plugin-opal", :yellow
57
57
  end
@@ -12,7 +12,10 @@ module Opal
12
12
  # modulepreload links), and vite_ruby already switches between the dev
13
13
  # server and the build manifest.
14
14
  def opal_javascript_tag(name, **options)
15
- vite_javascript_tag("#{name}.js", **options)
15
+ name = name.to_s
16
+ # "application" and "application.js" are the same entrypoint
17
+ name = "#{name}.js" if File.extname(name).empty?
18
+ vite_javascript_tag(name, **options)
16
19
  end
17
20
 
18
21
  # Generate multiple script tags for Opal JavaScript files
@@ -39,12 +42,7 @@ module Opal
39
42
  # Hash's inspect string instead of a URL. #path_for returns the resolved
40
43
  # asset URL string.
41
44
  def opal_asset_path(name)
42
- if defined?(ViteRuby)
43
- ViteRuby.instance.manifest.path_for(name)
44
- else
45
- # Fallback to standard asset path
46
- "/#{Opal::Vite::Rails.config.public_output_path}/#{name}"
47
- end
45
+ ViteRuby.instance.manifest.path_for(name)
48
46
  end
49
47
 
50
48
  # Deprecated: outputs nothing.
@@ -54,7 +52,7 @@ module Opal
54
52
  # chunks, so there is no separate runtime file to load. A standalone
55
53
  # tag would load a second copy of the runtime in development.
56
54
  def opal_runtime_tag(**_options)
57
- ActiveSupport::Deprecation.new("0.4", "opal-vite-rails").warn(
55
+ Opal::Vite::Rails.deprecator.warn(
58
56
  "opal_runtime_tag is no longer needed and outputs nothing; remove it from your views."
59
57
  )
60
58
  "".html_safe
@@ -1,7 +1,7 @@
1
1
  module Opal
2
2
  module Vite
3
3
  module Rails
4
- VERSION = "0.3.16"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
@@ -6,7 +6,6 @@ require "vite_rails"
6
6
  require_relative "opal/vite/rails/version"
7
7
  require_relative "opal/vite/rails/engine"
8
8
  require_relative "opal/vite/rails/helper"
9
- require_relative "opal/vite/rails/manifest"
10
9
 
11
10
  module Opal
12
11
  module Vite
@@ -19,6 +18,12 @@ module Opal
19
18
  def configure
20
19
  yield(config) if block_given?
21
20
  end
21
+
22
+ # Registered in Rails.application.deprecators by the engine, so that
23
+ # config.active_support.report_deprecations and friends apply to it.
24
+ def deprecator
25
+ @deprecator ||= ActiveSupport::Deprecation.new("0.4", "opal-vite-rails")
26
+ end
22
27
  end
23
28
 
24
29
  @config = OpenStruct.new(
@@ -12,16 +12,28 @@ namespace :opal_vite do
12
12
  puts "✅ Opal assets compiled successfully!"
13
13
  end
14
14
 
15
- desc "Clean compiled Opal assets"
15
+ desc "Clean compiled Opal assets (the Vite build output of the current RAILS_ENV)"
16
16
  task clean: :environment do
17
17
  puts "Cleaning Opal assets..."
18
18
 
19
- vite_dir = Rails.public_path.join("vite")
19
+ # The directory vite_ruby builds into for this environment (config/vite.json
20
+ # publicOutputDir), e.g. public/vite-dev in development and public/vite in
21
+ # production. A build you commit (public/vite) is only removed when this
22
+ # runs with RAILS_ENV=production.
23
+ vite = ViteRuby.config
24
+ vite_dir = vite.build_output_dir.expand_path
25
+ # Only ever delete a subdirectory of the public dir, so a misconfigured
26
+ # publicOutputDir ("", ".", "..") cannot wipe public/ or the app itself.
27
+ public_dir = vite.root.join(vite.public_dir).expand_path
28
+ unless vite_dir.to_s.start_with?("#{public_dir}#{File::SEPARATOR}")
29
+ abort "❌ Refusing to delete #{vite_dir}: it is not inside #{public_dir}"
30
+ end
31
+
20
32
  if vite_dir.exist?
21
33
  FileUtils.rm_rf(vite_dir)
22
34
  puts "✅ Cleaned #{vite_dir}"
23
35
  else
24
- puts "No compiled assets found"
36
+ puts "No compiled assets found in #{vite_dir}"
25
37
  end
26
38
  end
27
39
 
@@ -33,15 +45,14 @@ namespace :opal_vite do
33
45
 
34
46
  puts "\nOpal-Vite version: #{Opal::Vite::VERSION}"
35
47
  puts "Rails root: #{Rails.root}"
36
- puts "Vite manifest: #{Rails.public_path.join('vite', 'manifest.json')}"
37
- puts "Opal source directory: #{Rails.root.join('app', 'opal')}"
38
48
 
39
- if defined?(ViteRuby)
40
- puts "\nViteRuby: Installed ✅"
41
- puts "Vite dev server: #{ViteRuby.config.host}:#{ViteRuby.config.port}"
42
- else
43
- puts "\nViteRuby: Not installed ⚠️"
44
- end
49
+ vite = ViteRuby.config
50
+ manifest = vite.manifest_paths.first
51
+ puts "Vite build output: #{vite.build_output_dir}"
52
+ puts "Vite manifest: #{manifest || vite.known_manifest_paths.first} (#{manifest ? 'found' : 'not built yet'})"
53
+ puts "Opal source directory: #{Rails.root.join(Opal::Vite::Rails.config.source_path)}"
54
+ puts "Vite source directory: #{vite.root.join(vite.source_code_dir)}"
55
+ puts "Vite dev server: #{vite.host}:#{vite.port}"
45
56
 
46
57
  puts "\n" + "="*60
47
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opal-vite-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.16
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - stofu1234
@@ -50,6 +50,9 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 6.0.0
53
+ - - "<"
54
+ - !ruby/object:Gem::Version
55
+ version: '9'
53
56
  type: :runtime
54
57
  prerelease: false
55
58
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,6 +60,9 @@ dependencies:
57
60
  - - ">="
58
61
  - !ruby/object:Gem::Version
59
62
  version: 6.0.0
63
+ - - "<"
64
+ - !ruby/object:Gem::Version
65
+ version: '9'
60
66
  - !ruby/object:Gem::Dependency
61
67
  name: actionview
62
68
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +70,9 @@ dependencies:
64
70
  - - ">="
65
71
  - !ruby/object:Gem::Version
66
72
  version: 6.0.0
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: '9'
67
76
  type: :runtime
68
77
  prerelease: false
69
78
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,6 +80,9 @@ dependencies:
71
80
  - - ">="
72
81
  - !ruby/object:Gem::Version
73
82
  version: 6.0.0
83
+ - - "<"
84
+ - !ruby/object:Gem::Version
85
+ version: '9'
74
86
  - !ruby/object:Gem::Dependency
75
87
  name: vite_rails
76
88
  requirement: !ruby/object:Gem::Requirement
@@ -135,12 +147,12 @@ executables: []
135
147
  extensions: []
136
148
  extra_rdoc_files: []
137
149
  files:
150
+ - LICENSE
138
151
  - README.md
139
152
  - lib/opal-vite-rails.rb
140
153
  - lib/opal/vite/rails/engine.rb
141
154
  - lib/opal/vite/rails/generators/install_generator.rb
142
155
  - lib/opal/vite/rails/helper.rb
143
- - lib/opal/vite/rails/manifest.rb
144
156
  - lib/opal/vite/rails/version.rb
145
157
  - lib/tasks/opal_vite.rake
146
158
  - templates/application.rb.tt
@@ -1,64 +0,0 @@
1
- require "json"
2
-
3
- module Opal
4
- module Vite
5
- module Rails
6
- class Manifest
7
- def initialize(manifest_path = nil)
8
- @manifest_path = manifest_path || default_manifest_path
9
- @data = load_manifest
10
- end
11
-
12
- def lookup(name)
13
- # Try exact match first
14
- entry = @data[name]
15
- return entry if entry
16
-
17
- # Try with .rb extension
18
- entry = @data["#{name}.rb"]
19
- return entry if entry
20
-
21
- # Try without extension
22
- name_without_ext = name.sub(/\.(rb|js)$/, '')
23
- entry = @data[name_without_ext]
24
- return entry if entry
25
-
26
- # Not found
27
- nil
28
- end
29
-
30
- def [](name)
31
- entry = lookup(name)
32
- entry && entry['file']
33
- end
34
-
35
- def reload!
36
- @data = load_manifest
37
- end
38
-
39
- private
40
-
41
- def default_manifest_path
42
- if defined?(::ViteRuby) && ::ViteRuby.instance.config.respond_to?(:manifest_paths)
43
- vite_config = ::ViteRuby.instance.config
44
- vite_config.manifest_paths.first ||
45
- vite_config.build_output_dir.join('.vite', 'manifest.json')
46
- elsif defined?(::Rails)
47
- ::Rails.public_path.join('vite', 'manifest.json')
48
- else
49
- 'public/vite/manifest.json'
50
- end
51
- end
52
-
53
- def load_manifest
54
- return {} unless File.exist?(@manifest_path)
55
-
56
- JSON.parse(File.read(@manifest_path))
57
- rescue JSON::ParserError => e
58
- warn "Failed to parse Vite manifest at #{@manifest_path}: #{e.message}"
59
- {}
60
- end
61
- end
62
- end
63
- end
64
- end