@@ -214,7 +214,7 @@ final class BuildInput extends HookInput {
214
214
@override
215
215
BuildConfig get config => BuildConfig ._(this );
216
216
217
- /// The assets emitted by `hook/build.dart` of direct dependencies with [ToHooks ] .
217
+ /// The assets emitted by `hook/build.dart` of direct dependencies with [ToBuildHooks ] .
218
218
BuildInputAssets get assets => BuildInputAssets ._(this );
219
219
220
220
/// The metadata emitted by dependent build hooks.
@@ -472,9 +472,6 @@ sealed class HookOutput {
472
472
473
473
HookOutput ._(Map <String , Object ?> json);
474
474
475
- List <EncodedAsset > get _encodedAssetsForHook =>
476
- EncodedAssetSyntax ._fromSyntax (_syntax.assetsForHook ?? []);
477
-
478
475
@override
479
476
String toString () => const JsonEncoder .withIndent (' ' ).convert (json);
480
477
}
@@ -487,7 +484,6 @@ sealed class HookOutputBuilder {
487
484
dependencies: null ,
488
485
status: OutputStatusSyntax .success,
489
486
failureDetails: null ,
490
- assetsForHook: [],
491
487
);
492
488
493
489
/// The JSON representation of this hook output builder.
@@ -544,6 +540,9 @@ final class BuildOutput extends HookOutput implements BuildOutputMaybeFailure {
544
540
key: EncodedAssetSyntax ._fromSyntax (value),
545
541
};
546
542
543
+ List <EncodedAsset > get _encodedAssetsForBuild =>
544
+ EncodedAssetSyntax ._fromSyntax (_syntax.assetsForBuild ?? []);
545
+
547
546
@override
548
547
final BuildOutputSyntax _syntax;
549
548
@@ -573,9 +572,10 @@ final class BuildOutputAssets {
573
572
Map <String , List <EncodedAsset >> get encodedAssetsForLinking =>
574
573
_output._encodedAssetsForLinking;
575
574
576
- /// The assets produced by this link which should be available to subsequent
577
- /// link hooks.
578
- List <EncodedAsset > get encodedAssetsForBuild => _output._encodedAssetsForHook;
575
+ /// The assets produced by this build which should be available to subsequent
576
+ /// build hooks.
577
+ List <EncodedAsset > get encodedAssetsForBuild =>
578
+ _output._encodedAssetsForBuild;
579
579
}
580
580
581
581
/// The builder for [BuildOutput] .
@@ -618,7 +618,7 @@ final class BuildOutputMetadataBuilder {
618
618
void operator []= (String key, Object value) {
619
619
_output.assets.addEncodedAsset (
620
620
MetadataAsset (key: key, value: value).encode (),
621
- routing: const ToHooks (),
621
+ routing: const ToBuildHooks (),
622
622
);
623
623
}
624
624
@@ -633,7 +633,7 @@ final class BuildOutputMetadataBuilder {
633
633
/// The destination for assets in the [BuildOutput] .
634
634
///
635
635
/// Currently supported routings:
636
- /// * [ToHooks ] : From build hook to all dependent builds hooks.
636
+ /// * [ToBuildHooks ] : From build hook to all dependent builds hooks.
637
637
/// * [ToLinkHook] : From build hook to a specific link hook.
638
638
/// * [ToAppBundle] : From build or link hook to the application Bundle.
639
639
sealed class AssetRouting {
@@ -643,7 +643,7 @@ sealed class AssetRouting {
643
643
/// The destination for assets in the [LinkOutput] .
644
644
///
645
645
/// Currently supported routings:
646
- /// * [ToHooks ] : From build hook to all dependent builds hooks.
646
+ /// * [ToBuildHooks ] : From build hook to all dependent builds hooks.
647
647
/// * [ToLinkHook] : From build hook to a specific link hook.
648
648
/// * [ToAppBundle] : From build or link hook to the application Bundle.
649
649
sealed class LinkAssetRouting {
@@ -671,9 +671,9 @@ final class ToAppBundle implements AssetRouting, LinkAssetRouting {
671
671
/// The receiver will know about sender package (it must be a direct
672
672
/// dependency), the sender does not know about the receiver. Hence this routing
673
673
/// is a broadcast with 0-N receivers.
674
- final class ToHooks implements AssetRouting , LinkAssetRouting {
675
- /// Creates a [ToHooks ] .
676
- const ToHooks ();
674
+ final class ToBuildHooks implements AssetRouting {
675
+ /// Creates a [ToBuildHooks ] .
676
+ const ToBuildHooks ();
677
677
}
678
678
679
679
/// Assets with this [AssetRouting] in the [BuildOutput] will be sent to the
@@ -687,7 +687,7 @@ final class ToHooks implements AssetRouting, LinkAssetRouting {
687
687
/// The receiver will not know about the sender package. The sender knows about
688
688
/// the receiver package. Hence, the receiver must be specified and there is
689
689
/// exactly one receiver.
690
- final class ToLinkHook implements AssetRouting {
690
+ final class ToLinkHook implements AssetRouting , LinkAssetRouting {
691
691
/// The name of the package that contains the `hook/link.dart` to which assets
692
692
/// should be sent.
693
693
final String packageName;
@@ -726,10 +726,10 @@ final class BuildOutputAssetsBuilder {
726
726
final assets = _syntax.assets ?? [];
727
727
assets.add (AssetSyntax .fromJson (asset.toJson ()));
728
728
_syntax.assets = assets;
729
- case ToHooks ():
730
- final assets = _syntax.assetsForHook ?? [];
729
+ case ToBuildHooks ():
730
+ final assets = _syntax.assetsForBuild ?? [];
731
731
assets.add (AssetSyntax .fromJson (asset.toJson ()));
732
- _syntax.assetsForHook = assets;
732
+ _syntax.assetsForBuild = assets;
733
733
case ToLinkHook ():
734
734
final packageName = routing.packageName;
735
735
final assetsForLinking = _syntax.assetsForLinking ?? {};
@@ -767,12 +767,12 @@ final class BuildOutputAssetsBuilder {
767
767
list.add (AssetSyntax .fromJson (asset.toJson ()));
768
768
}
769
769
_syntax.assets = list;
770
- case ToHooks ():
771
- final list = _syntax.assetsForHook ?? [];
770
+ case ToBuildHooks ():
771
+ final list = _syntax.assetsForBuild ?? [];
772
772
for (final asset in assets) {
773
773
list.add (AssetSyntax .fromJson (asset.toJson ()));
774
774
}
775
- _syntax.assetsForHook = list;
775
+ _syntax.assetsForBuild = list;
776
776
case ToLinkHook ():
777
777
final linkInPackage = routing.packageName;
778
778
final assetsForLinking = _syntax.assetsForLinking ?? {};
@@ -792,6 +792,16 @@ final class BuildOutputAssetsBuilder {
792
792
///
793
793
/// See [LinkOutputFailure] for failure.
794
794
final class LinkOutput extends HookOutput implements LinkOutputMaybeFailure {
795
+ /// The assets produced by this link which are sent to linkers upstream.
796
+ ///
797
+ /// Every key in the map is a package name. These assets in the values are not
798
+ /// bundled with the application, but are sent to the link hook of the package
799
+ /// specified in the key, which can decide what to do with them.
800
+ Map <String , List <EncodedAsset >> get _encodedAssetsForLinking => {
801
+ for (final MapEntry (: key, : value) in (_syntax.assetsForLink ?? {}).entries)
802
+ key: EncodedAssetSyntax ._fromSyntax (value),
803
+ };
804
+
795
805
/// Creates a [LinkOutput] from the given [json] .
796
806
LinkOutput (super .json) : _syntax = LinkOutputSyntax .fromJson (json), super ._();
797
807
@@ -813,7 +823,8 @@ final class LinkOutputAssets {
813
823
814
824
/// The assets produced by this build which should be available to subsequent
815
825
/// link hooks.
816
- List <EncodedAsset > get encodedAssetsForLink => _output._encodedAssetsForHook;
826
+ Map <String , List <EncodedAsset >> get encodedAssetsForLink =>
827
+ _output._encodedAssetsForLinking;
817
828
}
818
829
819
830
/// The builder for [LinkOutput] .
@@ -866,10 +877,14 @@ final class LinkOutputAssetsBuilder {
866
877
final assets = _syntax.assets ?? [];
867
878
assets.add (AssetSyntax .fromJson (asset.toJson ()));
868
879
_syntax.assets = assets;
869
- case ToHooks ():
870
- final assets = _syntax.assetsForHook ?? [];
871
- assets.add (AssetSyntax .fromJson (asset.toJson ()));
872
- _syntax.assetsForHook = assets;
880
+ case ToLinkHook ():
881
+ final packageName = routing.packageName;
882
+ final assetsForLinking = _syntax.assetsForLink ?? {};
883
+ assetsForLinking[packageName] ?? = [];
884
+ assetsForLinking[packageName]! .add (
885
+ AssetSyntax .fromJson (asset.toJson ()),
886
+ );
887
+ _syntax.assetsForLink = assetsForLinking;
873
888
}
874
889
}
875
890
@@ -897,12 +912,14 @@ final class LinkOutputAssetsBuilder {
897
912
list.add (AssetSyntax .fromJson (asset.toJson ()));
898
913
}
899
914
_syntax.assets = list;
900
- case ToHooks ():
901
- final list = _syntax.assetsForHook ?? [];
915
+ case ToLinkHook ():
916
+ final linkInPackage = routing.packageName;
917
+ final assetsForLinking = _syntax.assetsForLink ?? {};
918
+ final list = assetsForLinking[linkInPackage] ?? = [];
902
919
for (final asset in assets) {
903
920
list.add (AssetSyntax .fromJson (asset.toJson ()));
904
921
}
905
- _syntax.assetsForHook = list ;
922
+ _syntax.assetsForLink = assetsForLinking ;
906
923
}
907
924
}
908
925
0 commit comments