diff --git a/Changes b/Changes index 8e0056392..c99bab4d0 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,8 @@ Revision history for {{$dist->name}} {{$NEXT}} + - [MetaJSON] is now in [@Basic], with special handling to handle the + possibility the plugin is loaded twice 6.011 2018-02-11 12:57:02-05:00 America/New_York - stashes can now be added in [%Stash] form from a bundle (thanks, diff --git a/lib/Dist/Zilla/Plugin/MetaJSON.pm b/lib/Dist/Zilla/Plugin/MetaJSON.pm index 6b2223dfe..488f7faa2 100644 --- a/lib/Dist/Zilla/Plugin/MetaJSON.pm +++ b/lib/Dist/Zilla/Plugin/MetaJSON.pm @@ -5,6 +5,7 @@ use Moose; with 'Dist::Zilla::Role::FileGatherer'; use Moose::Util::TypeConstraints; +use List::Util 'first'; use namespace::autoclean; =head1 DESCRIPTION @@ -54,6 +55,12 @@ sub gather_files { my $zilla = $self->zilla; + # gracefully handle there being more than one of us (e.g. one via [@Basic]) + if ((first { $_->isa(__PACKAGE__) } @{ $self->zilla->plugins }) != $self) { + $self->log('doing nothing: another [MetaJSON] already ran...'); + return; + } + require JSON::MaybeXS; require Dist::Zilla::File::FromCode; require CPAN::Meta::Converter; diff --git a/lib/Dist/Zilla/PluginBundle/Basic.pm b/lib/Dist/Zilla/PluginBundle/Basic.pm index 096d4d8eb..293ebafb6 100644 --- a/lib/Dist/Zilla/PluginBundle/Basic.pm +++ b/lib/Dist/Zilla/PluginBundle/Basic.pm @@ -14,6 +14,7 @@ sub configure { PruneCruft ManifestSkip MetaYAML + MetaJSON License Readme ExtraTests @@ -45,6 +46,7 @@ It includes the following plugins with their default configuration: * L * L * L +* L * L * L * L diff --git a/t/plugins/metajson.t b/t/plugins/metajson.t new file mode 100644 index 000000000..dbd94c34a --- /dev/null +++ b/t/plugins/metajson.t @@ -0,0 +1,37 @@ +use strict; +use warnings; + +use Test::More 0.88; +use if $ENV{AUTHOR_TESTING}, 'Test::Warnings'; +use Test::DZil; +use Test::Fatal; +use Path::Tiny; + +{ + my $tzil = Builder->from_config( + { dist_root => 'does-not-exist' }, + { + add_files => { + 'source/dist.ini' => simple_ini( + '@Basic', + 'MetaJSON', + ), + }, + }, + ); + + $tzil->chrome->logger->set_debug(1); + is( + exception { $tzil->build }, + undef, + 'build proceeds normally', + ); + + my $build_dir = path($tzil->tempdir)->child('build'); + ok(-e $build_dir->child('META.json'), 'META.json was created successfully'); + + diag 'got log messages: ', explain $tzil->log_messages + if not Test::Builder->new->is_passing; +} + +done_testing;