awood / hawkins

A Jekyll plugin that incorporates LiveReload
MIT License
57 stars 4 forks source link

Doesn't work with Jekyll 3.0 only 3.1+ #2

Closed RobertDeRose closed 8 years ago

RobertDeRose commented 8 years ago

Github-pages is still using Jekyll 3.0 (3.0.5), your code is highly dependent on the codebase of 3.1.

You should change your gemspec to reflect that it needs ~> 3.1.0

awood commented 8 years ago

@RobertDeRose I'll go ahead and do that, but did you have a stacktrace or anything for running against Jekyll 3.0.X? I'd like to make it compatible with Jekyll 3+.

awood commented 8 years ago

The error I'm seeing with Jekyll 3.0.5 is.

% jekyll --version
/home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:80:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'hawkins'. (Bundler::GemRequireError)
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `each'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:72:in `block in require'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `each'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler/runtime.rb:61:in `require'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@global/gems/bundler-1.11.2/lib/bundler.rb:99:in `require'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@candlepinproject.org/gems/jekyll-3.0.5/lib/jekyll/plugin_manager.rb:39:in `require_from_bundler'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@candlepinproject.org/gems/jekyll-3.0.5/bin/jekyll:13:in `<top (required)>'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@candlepinproject.org/bin/jekyll:23:in `load'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@candlepinproject.org/bin/jekyll:23:in `<main>'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@candlepinproject.org/bin/ruby_executable_hooks:15:in `eval'
    from /home/awood/.rvm/gems/ruby-2.0.0-p643@candlepinproject.org/bin/ruby_executable_hooks:15:in `<main>'

Looks like the relevant difference between 3.0.5 and 3.1.X is in https://github.com/jekyll/jekyll/commit/4fe9eecf053eb5d6047011372d8a195e88fb8614

RobertDeRose commented 8 years ago

@awood The issue I was having was from here: https://github.com/jekyll/jekyll/blob/master/lib/jekyll/commands/serve.rb#L5

COMMAND_OPTIONS does not exist in the 3.0.5 branch

Also, the https://github.com/jekyll/jekyll/blob/master/lib/jekyll/commands/serve/servlet.rb doesn't exist in 3.0.5

I made these changes to get around the COMMAND_OPTIONS

 module Hawkins
   module Commands
@@ -11,13 +12,17 @@ module Hawkins
           "min_delay" => ["--min-delay [SECONDS]", "Minimum reload delay"],
           "max_delay" => ["--max-delay [SECONDS]", "Maximum reload delay"],
           "reload_port" => ["--reload-port [PORT]", Integer, "Port for LiveReload to listen on"],
-        }.merge(Jekyll::Commands::Serve.singleton_class::COMMAND_OPTIONS).freeze
+        }

         LIVERELOAD_PORT = 35729

         #

         def init_with_program(prog)
+          options = {}
+          prog.commands[:serve].options.each { |e| options[e.config_key] = [ e.short, e.long, e.description, e.return_type ] }
+          options = COMMAND_OPTIONS.merge(options).freeze
+
           prog.command(:liveserve) do |cmd|
             cmd.description "Serve your site locally with LiveReload"
             cmd.syntax "liveserve [options]"
@@ -25,7 +30,7 @@ module Hawkins
             cmd.alias :l

             add_build_options(cmd)
-            COMMAND_OPTIONS.each do |key, val|
+            options.each do |key, val|
               cmd.option(key, *val)
             end

But I didn't have the time to work around the servlet not existing issue.

Here is the backtrace with Jekyll 3.1.3 without my workaround

Gem Load Error is: uninitialized constant #<Class:Jekyll::Commands::Serve>::COMMAND_OPTIONS
Backtrace for gem load error is:
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins/liveserve.rb:14:in `singleton class'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins/liveserve.rb:6:in `<class:LiveServe>'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins/liveserve.rb:5:in `<module:Commands>'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins/liveserve.rb:4:in `<module:Hawkins>'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins/liveserve.rb:3:in `<top (required)>'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins.rb:9:in `require'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins.rb:9:in `<module:Hawkins>'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bundler/gems/hawkins-9142e5814bd2/lib/hawkins.rb:3:in `<top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:86:in `require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:86:in `block (2 levels) in require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:81:in `each'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:81:in `block in require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:70:in `each'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:70:in `require'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler.rb:102:in `require'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/gems/jekyll-3.0.5/lib/jekyll/plugin_manager.rb:39:in `require_from_bundler'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/gems/jekyll-3.0.5/bin/jekyll:13:in `<top (required)>'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bin/jekyll:23:in `load'
/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bin/jekyll:23:in `<top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli/exec.rb:24:in `run'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli.rb:304:in `exec'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/cli.rb:11:in `start'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/exe/bundle:27:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/exe/bundle:19:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Bundler Error Backtrace:

  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:89:in `rescue in block (2 levels) in require'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:85:in `block (2 levels) in require'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:81:in `each'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:81:in `block in require'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:70:in `each'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler/runtime.rb:70:in `require'
  /usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.12.1/lib/bundler.rb:102:in `require'
  /Users/rderose/workspace/developers/vendor/ruby/2.3.0/gems/jekyll-3.0.5/lib/jekyll/plugin_manager.rb:39:in `require_from_bundler'
  /Users/rderose/workspace/developers/vendor/ruby/2.3.0/gems/jekyll-3.0.5/bin/jekyll:13:in `<top (required)>'
  /Users/rderose/workspace/developers/vendor/ruby/2.3.0/bin/jekyll:23:in `load'
  /Users/rderose/workspace/developers/vendor/ruby/2.3.0/bin/jekyll:23:in `<top (required)>'

Here is the backtrace after my workaround.

$ bundle exec jekyll l                                                                                                                                  1 Configuration file: /Users/rderose/workspace/developers/_config.yml
 LiveReload Server: 127.0.0.1:35729
Configuration file: /Users/rderose/workspace/developers/_config.yml
            Source: /Users/rderose/workspace/developers
       Destination: /Users/rderose/workspace/developers/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
        LiveReload: Browser connected
                    done in 2.089 seconds.
 Auto-regeneration: enabled for '/Users/rderose/workspace/developers'
bundler: failed to load command: jekyll (/Users/rderose/workspace/developers/vendor/ruby/2.3.0/bin/jekyll)
LoadError: cannot load such file -- jekyll/commands/serve/servlet
awood commented 8 years ago

Ah, darn. Without that servlet class, it's pretty tough to invoke Hawkins' code that injects the LiveReload javascript into the top of a page. It might be possible, but until I get some time to really dig into it, I'm going to leave Hawkins as requiring <~ 3.1. Thanks for the debug output.

RobertDeRose commented 8 years ago

@awood no problem.