hmdne / opal-optimizer

Postprocesses Opal output for size and performance optimizations
MIT License
3 stars 0 forks source link

cant deduce opal #1

Closed rubydesign closed 1 year ago

rubydesign commented 1 year ago

ArgumentError: Couldn't deduce Opal version based on this content

3.0.0/bundler/gems/opal-optimizer-8b48ab17fb97/lib/opal/optimizer.rb:40:in initialize' 3.0.0/bundler/gems/opal-optimizer-8b48ab17fb97/lib/opal/optimizer/sprockets.rb:9:innew' 3.0.0/bundler/gems/opal-optimizer-8b48ab17fb97/lib/opal/optimizer/sprockets.rb:9:in call' 3.0.0/gems/sprockets-4.2.0/lib/sprockets/processor_utils.rb:84:incall_processor'

rails 7.0.4.2 sprockets 4.2 ruby 3.0.4

hmdne commented 1 year ago

It is much likely this error stems from building a non-Opal application. Let me issue a couple of amendments for it to ignore non-Opal JavaScripts

hmdne commented 1 year ago

You can try the master branch now if it has fixed your issue

rubydesign commented 1 year ago

I'll try, but yes, i do have non opal js

rubydesign commented 1 year ago

I think it got further

NoMethodError: undefined method `value' for nil:NilClass

3.0.0/bundler/gems/opal-optimizer-a6daa112a401/lib/opal/optimizer.rb:20:in `initialize'

3.0.0/bundler/gems/opal-optimizer-a6daa112a401/lib/opal/optimizer/sprockets.rb:9:in `new'

bundler/gems/opal-optimizer-a6daa112a401/lib/opal/optimizer/sprockets.rb:9:in `call'

hmdne commented 1 year ago

I have improved the logic, you can try again now

rubydesign commented 1 year ago

ok, no more fails.

The reduction i see is about 30% . I think it could possibly be much more. As i really only have 200 lines myself. But as a freeby i'll happily take it and won't complain :-)

rubydesign commented 1 year ago

I just checked the asset file size, but now i see that it does not work. My fault

I use dynamic sends like send "match_#{somevar}" and in a way it's a good thing that the optimiser cleans those match* methods out

If you want to fix this too i could try. tomorrow. If not also fine, should probably use inheritance instead

hmdne commented 1 year ago

Exactly - that is the kind of incompatibility that opal-optimizer introduces about which you must be aware. Opal-Optimizer works in such a way, that it collects all method calls and removes methods that are not called. Due to Ruby highly dynamic nature, we can't go too far in terms of optimizations.

For an equivalent function planned for Opal 2.0, we may introduce some kind of a DSL, perhaps a magic comment, that will allow you to make things work a little bit differently.