opal / opal-sprockets

Sprockets support for Opal (used to be embedded into Opal from v0.6 up to v0.10)
29 stars 17 forks source link

Get many warning "loading in progress, circular require considered harmful" when run test. #27

Open zw963 opened 3 years ago

zw963 commented 3 years ago

Following is output messages when i run rake to run my test, but the test is passing.

home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/cliver-0.3.2/lib/core_ext/file.rb:15: warning: method redefined; discarding old absolute_path?
/home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34: warning: /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34: warning: loading in progress, circular require considered harmful - /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal/sprockets.rb
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in  `<main>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:6:in  `select'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in  `block in <main>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rake-13.0.6/lib/rake/rake_test_loader.rb:21:in  `require'
        from /home/zw963/Stocks/marketbet_crawler/test/services/latest_institutions_test.rb:1:in  `<top (required)>'
        from /home/zw963/Stocks/marketbet_crawler/test/services/latest_institutions_test.rb:1:in  `require'
        from /home/zw963/Stocks/marketbet_crawler/test/test_helper.rb:13:in  `<top (required)>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rack-2.2.3/lib/rack/builder.rb:66:in  `parse_file'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rack-2.2.3/lib/rack/builder.rb:105:in  `load_file'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rack-2.2.3/lib/rack/builder.rb:116:in  `new_from_string'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rack-2.2.3/lib/rack/builder.rb:116:in  `eval'
        from config.ru:1:in  `block in <main>'
        from config.ru:1:in  `require_relative'
        from /home/zw963/Stocks/marketbet_crawler/config/environment.rb:3:in  `<top (required)>'
        from /home/zw963/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler.rb:174:in  `require'
        from /home/zw963/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:50:in  `require'
        from /home/zw963/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:50:in  `each'
        from /home/zw963/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:61:in  `block in require'
        from /home/zw963/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:61:in  `each'
        from /home/zw963/.rvm/rubies/ruby-3.0.2/lib/ruby/3.0.0/bundler/runtime.rb:66:in  `block (2 levels) in require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal-sprockets.rb:1:in  `<top (required)>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal/sprockets.rb:4:in  `<top (required)>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal/sprockets.rb:5:in  `<module:Opal>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal/sprockets.rb:11:in  `<module:Sprockets>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal/sprockets/environment.rb:2:in  `<top (required)>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/opal-sprockets-1.0.1/lib/opal/sprockets/processor.rb:6:in  `<top (required)>'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'
        from /home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in  `require'

/home/zw963/Stocks/marketbet_crawler/config/application.rb:9: warning: method redefined; discarding old call
/home/zw963/.rvm/gems/ruby-3.0.2@marketbet_crawler/gems/rack-2.2.3/lib/rack/lint.rb:37: warning: previous definition of call was here

You can check my source code here

https://github.com/zw963/marketbet_crawler/tree/test_opal_sprockets

for run test, you must set following ENVS:

export TEST_DATABASE_URL="sqlite://db/files/marketbet_crawler_test.db"
export APP_SESSION_SECRET="909f017cc94c96f8a1aff843d95920485376f4c997143cc3c39ca945c883ec88e310a2177a69b8b714d22af1b5fd7864833568b6bf93fc3bc811bcf6e112"

Thank you.

fxn commented 3 years ago

This was reported in the Zeitwerk issue tracker too, so I looked into it.

You see "zeitwerk" in the logs because all require calls pass through this thin wrapper if the library is loaded.

It is a regular circular require warning (this project does not use Zeitwerk). I see for example that lib/opal/sprockets.rb loads lib/opal/sprockets/processor.rb (here), and while that is happening, lib/opal/sprockets/processor.rb tries to load lib/opal/sprockets.rb (here).

One way to address that would be to forbid client code from loading the processor directly, you have to load opal/sprockets no matter what (that way, the processor can assume the namespace is defined). If that is not possible... well, you need to figure that out.