I have created a custom extension that I am using in my Middleman site (ver 4.2.1). The extension works, however upon debugging, I have noticed that my initialize()
and after_configuration()
methods are being executed twice. The before_build()
method is only executed once though as expected.
To make sure it wasn’t my extension, I created and empty extension via middleman extension my-extension
and had the same issue.
The first time the initialize()
method is executed is after after running middleman build
and before the webpack external pipeline does its thing. Stack trace below:
Showing all accessible frames in stack (15 in total):
--
=> #0 initialize <Middleman::MyExtension::Extension#initialize(app, options_hash=?, &block)>
#1 [block] block in run <Byebug::PryProcessor#run(&_block)>
#2 [method] run <Byebug::PryProcessor#run(&_block)>
#3 [method] resume_pry <Byebug::PryProcessor#resume_pry()>
#4 [method] at_line <Byebug::PryProcessor#at_line()>
#5 [method] at_line <Byebug::Context#at_line()>
#6 [method] initialize <Middleman::MyExtension::Extension#initialize(app, options_hash=?, &block)>
#7 [method] activate <Middleman::ExtensionManager#activate(ext_name, options=?, &block)>
#8 [method] activate <Middleman::ConfigContext#activate(*args, &block)>
#9 [eval] evaluate_configuration! <self.evaluate_configuration!(UNKNOWN) (undefined method)>
#10 [method] evaluate_configuration! <Middleman::Application#evaluate_configuration!()>
#11 [method] initialize <Middleman::Application#initialize(&block)>
#12 [top] <top (required)>
#13 [eval] <main>
#14 [main] <main>
The second time the initialize()
method is executed is after webpack finishes doing its thing and before the rest of the site is built. Strack trace below:
Showing all accessible frames in stack (30 in total):
--
=> #0 initialize <Middleman::MyExtension::Extension#initialize(app, options_hash=?, &block)>
#1 [block] block in run <Byebug::PryProcessor#run(&_block)>
#2 [method] run <Byebug::PryProcessor#run(&_block)>
#3 [method] resume_pry <Byebug::PryProcessor#resume_pry()>
#4 [method] at_line <Byebug::PryProcessor#at_line()>
#5 [method] at_line <Byebug::Context#at_line()>
#6 [method] initialize <Middleman::MeExtension::Extension#initialize(app, options_hash=?, &block)>
#7 [method] activate <Middleman::ExtensionManager#activate(ext_name, options=?, &block)>
#8 [method] activate <Middleman::ConfigContext#activate(*args, &block)>
#9 [eval] evaluate_configuration! <self.evaluate_configuration!(UNKNOWN) (undefined method)>
#10 [method] evaluate_configuration! <Middleman::Application#evaluate_configuration!()>
#11 [method] initialize <Middleman::Application#initialize(&block)>
#12 [block] block in build <Middleman::Cli::Build#build()>
#13 [method] instrument <ActiveSupport::Notifications.instrument(name, payload=?)>
#14 [method] instrument <Middleman::Util.instrument(name, payload=?, &block)>
#15 [method] build <Middleman::Cli::Build#build()>
#16 [method] run <Thor::Command#run(instance, args=?)>
#17 [method] invoke_command <Thor::Invocation#invoke_command(command, *args)>
#18 [block] block in invoke_all <Thor::Invocation#invoke_all()>
#19 [method] invoke_all <Thor::Invocation#invoke_all()>
#20 [method] dispatch <Thor::Group.dispatch(command, given_args, given_opts, config)>
#21 [method] invoke <Thor::Invocation#invoke(name=?, *args)>
#22 [block] block in register <Middleman::Cli::Base#build(*args)>
#23 [method] run <Thor::Command#run(instance, args=?)>
#24 [method] invoke_command <Thor::Invocation#invoke_command(command, *args)>
#25 [method] dispatch <Thor.dispatch(meth, given_args, given_opts, config)>
#26 [method] start <Thor::Base::ClassMethods#start(given_args=?, config=?)>
#27 [top] <top (required)>
#28 [eval] <main>
#29 [main] <main>
I am not sure why it is called twice and which of the two times the initialize()
and after_configuration()
methods are ran is the correct one.
Thanks!