guard / guard-nanoc

A Guard for nanoc
39 stars 9 forks source link

Warnings about constant redefinition when used with Nanoc v4.9.3 #37

Open moll opened 6 years ago

moll commented 6 years ago

Hey,

I'm not sure whether this is Nanoc's or the Guard plugin's fault, but the latest versions give the following warnings when starting nanoc live:

/home/user/.gem/ruby/2.5.0/gems/nanoc-4.9.3/lib/nanoc/cli/commands/view.rb:18: warning: already initialized constant Nanoc::CLI::Commands::View::DEFAULT_HANDLER_NAME
/home/user/.gem/ruby/2.5.0/gems/nanoc-4.9.3/lib/nanoc/cli/commands/view.rb:18: warning: previous definition of DEFAULT_HANDLER_NAME was here
/home/user/.gem/ruby/2.5.0/gems/nanoc-4.9.3/lib/nanoc/cli/commands/show-plugins.rb:75: warning: already initialized constant Nanoc::CLI::Commands::ShowPlugins::PLUGIN_CLASS_ORDER
/home/user/.gem/ruby/2.5.0/gems/nanoc-4.9.3/lib/nanoc/cli/commands/show-plugins.rb:75: warning: previous definition of PLUGIN_CLASS_ORDER was here
/home/user/.gem/ruby/2.5.0/gems/nanoc-4.9.3/lib/nanoc/cli/commands/show-plugins.rb:81: warning: already initialized constant Nanoc::CLI::Commands::ShowPlugins::PLUGIN_CLASSES
/home/user/.gem/ruby/2.5.0/gems/nanoc-4.9.3/lib/nanoc/cli/commands/show-plugins.rb:81: warning: previous definition of PLUGIN_CLASSES was here

Functionality seems to work though.

denisdefreyne commented 6 years ago

This indeed harmless, even though it doesn’t look like it.

I think this might not be easily resolvable in a generic way, because bundle exec nanoc live loads Nanoc and guard, and loading guard makes it load Nanoc again.

One way around it would be to define constants as

FOO = 123 unless defined?(FOO)

… but that is a bit icky.

denisdefreyne commented 6 years ago

FYI: there is the (experimental) nanoc-live project, which adds a nanoc live command without needing Guard or a Guardfile. It’s still experimental (not super-well tested and does not have notifications, for example) but you’re welcome to try it out!

References:

gpakosz commented 3 years ago

Hitting these as well, see https://gitter.im/nanoc/nanoc?at=617fca50fb8ca0572bf78ffc

The thing with nanoc-live is that it doesn't integrate with LiveReload as far as I know. Which means a setup using guard-nanoc + guard-livereload is still a superior solution

denisdefreyne commented 3 years ago

I recommend switching to nanoc-live (https://github.com/nanoc/nanoc/tree/main/nanoc-live). It comes with livereload support built-in. To switch to nanoc-live:

  1. Add nanoc-live to your Gemfile: bundle add nanoc-live
  2. Remove guard-nanoc from your Gemfile, and run bundle install

Now, you can use the command nanoc live which will work out of the box.

(You can now also delete your Guardfile if you’re not using it for anything else.)

gpakosz commented 3 years ago

I overlooked nanoc-live comes with LiveReload support