Skip to content

Commit 031f3ee

Browse files
committed
fixes
1 parent 2d6c4a4 commit 031f3ee

File tree

9 files changed

+178
-84
lines changed

9 files changed

+178
-84
lines changed

pkgs/code_assets/lib/src/code_assets/validation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Future<ValidationErrors> validateCodeAssetLinkOutput(
106106
input,
107107
input.config.code,
108108
output.assets.encodedAssets,
109-
output.assets.encodedAssetsForLink,
109+
output.assets.encodedAssetsForLink.values,
110110
output,
111111
false,
112112
);

pkgs/hooks/doc/schema/shared/shared_definitions.schema.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@
8787
"BuildOutput": {
8888
"type": "object",
8989
"properties": {
90+
"assets_for_build": {
91+
"type": "array",
92+
"items": {
93+
"$ref": "#/definitions/Asset"
94+
}
95+
},
9096
"assets_for_linking": {
9197
"type": "object",
9298
"additionalProperties": {
@@ -200,12 +206,6 @@
200206
"$ref": "#/definitions/Asset"
201207
}
202208
},
203-
"assets_for_hook": {
204-
"type": "array",
205-
"items": {
206-
"$ref": "#/definitions/Asset"
207-
}
208-
},
209209
"dependencies": {
210210
"type": "array",
211211
"items": {
@@ -270,6 +270,18 @@
270270
]
271271
},
272272
"LinkOutput": {
273+
"type": "object",
274+
"properties": {
275+
"assets_for_link": {
276+
"type": "object",
277+
"additionalProperties": {
278+
"type": "array",
279+
"items": {
280+
"$ref": "#/definitions/Asset"
281+
}
282+
}
283+
}
284+
},
273285
"allOf": [
274286
{
275287
"$ref": "#/definitions/HookOutput"

pkgs/hooks/lib/hooks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export 'src/config.dart'
5555
LinkOutputMaybeFailure,
5656
PackageMetadata,
5757
ToAppBundle,
58-
ToHooks,
58+
ToBuildHooks,
5959
ToLinkHook;
6060
export 'src/encoded_asset.dart' show EncodedAsset;
6161
export 'src/extension.dart';

pkgs/hooks/lib/src/config.dart

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ final class BuildInput extends HookInput {
214214
@override
215215
BuildConfig get config => BuildConfig._(this);
216216

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].
218218
BuildInputAssets get assets => BuildInputAssets._(this);
219219

220220
/// The metadata emitted by dependent build hooks.
@@ -472,9 +472,6 @@ sealed class HookOutput {
472472

473473
HookOutput._(Map<String, Object?> json);
474474

475-
List<EncodedAsset> get _encodedAssetsForHook =>
476-
EncodedAssetSyntax._fromSyntax(_syntax.assetsForHook ?? []);
477-
478475
@override
479476
String toString() => const JsonEncoder.withIndent(' ').convert(json);
480477
}
@@ -487,7 +484,6 @@ sealed class HookOutputBuilder {
487484
dependencies: null,
488485
status: OutputStatusSyntax.success,
489486
failureDetails: null,
490-
assetsForHook: [],
491487
);
492488

493489
/// The JSON representation of this hook output builder.
@@ -544,6 +540,9 @@ final class BuildOutput extends HookOutput implements BuildOutputMaybeFailure {
544540
key: EncodedAssetSyntax._fromSyntax(value),
545541
};
546542

543+
List<EncodedAsset> get _encodedAssetsForBuild =>
544+
EncodedAssetSyntax._fromSyntax(_syntax.assetsForBuild ?? []);
545+
547546
@override
548547
final BuildOutputSyntax _syntax;
549548

@@ -573,9 +572,10 @@ final class BuildOutputAssets {
573572
Map<String, List<EncodedAsset>> get encodedAssetsForLinking =>
574573
_output._encodedAssetsForLinking;
575574

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;
579579
}
580580

581581
/// The builder for [BuildOutput].
@@ -618,7 +618,7 @@ final class BuildOutputMetadataBuilder {
618618
void operator []=(String key, Object value) {
619619
_output.assets.addEncodedAsset(
620620
MetadataAsset(key: key, value: value).encode(),
621-
routing: const ToHooks(),
621+
routing: const ToBuildHooks(),
622622
);
623623
}
624624

@@ -633,7 +633,7 @@ final class BuildOutputMetadataBuilder {
633633
/// The destination for assets in the [BuildOutput].
634634
///
635635
/// Currently supported routings:
636-
/// * [ToHooks]: From build hook to all dependent builds hooks.
636+
/// * [ToBuildHooks]: From build hook to all dependent builds hooks.
637637
/// * [ToLinkHook]: From build hook to a specific link hook.
638638
/// * [ToAppBundle]: From build or link hook to the application Bundle.
639639
sealed class AssetRouting {
@@ -643,7 +643,7 @@ sealed class AssetRouting {
643643
/// The destination for assets in the [LinkOutput].
644644
///
645645
/// Currently supported routings:
646-
/// * [ToHooks]: From build hook to all dependent builds hooks.
646+
/// * [ToBuildHooks]: From build hook to all dependent builds hooks.
647647
/// * [ToLinkHook]: From build hook to a specific link hook.
648648
/// * [ToAppBundle]: From build or link hook to the application Bundle.
649649
sealed class LinkAssetRouting {
@@ -671,9 +671,9 @@ final class ToAppBundle implements AssetRouting, LinkAssetRouting {
671671
/// The receiver will know about sender package (it must be a direct
672672
/// dependency), the sender does not know about the receiver. Hence this routing
673673
/// 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();
677677
}
678678

679679
/// Assets with this [AssetRouting] in the [BuildOutput] will be sent to the
@@ -687,7 +687,7 @@ final class ToHooks implements AssetRouting, LinkAssetRouting {
687687
/// The receiver will not know about the sender package. The sender knows about
688688
/// the receiver package. Hence, the receiver must be specified and there is
689689
/// exactly one receiver.
690-
final class ToLinkHook implements AssetRouting {
690+
final class ToLinkHook implements AssetRouting, LinkAssetRouting {
691691
/// The name of the package that contains the `hook/link.dart` to which assets
692692
/// should be sent.
693693
final String packageName;
@@ -726,10 +726,10 @@ final class BuildOutputAssetsBuilder {
726726
final assets = _syntax.assets ?? [];
727727
assets.add(AssetSyntax.fromJson(asset.toJson()));
728728
_syntax.assets = assets;
729-
case ToHooks():
730-
final assets = _syntax.assetsForHook ?? [];
729+
case ToBuildHooks():
730+
final assets = _syntax.assetsForBuild ?? [];
731731
assets.add(AssetSyntax.fromJson(asset.toJson()));
732-
_syntax.assetsForHook = assets;
732+
_syntax.assetsForBuild = assets;
733733
case ToLinkHook():
734734
final packageName = routing.packageName;
735735
final assetsForLinking = _syntax.assetsForLinking ?? {};
@@ -767,12 +767,12 @@ final class BuildOutputAssetsBuilder {
767767
list.add(AssetSyntax.fromJson(asset.toJson()));
768768
}
769769
_syntax.assets = list;
770-
case ToHooks():
771-
final list = _syntax.assetsForHook ?? [];
770+
case ToBuildHooks():
771+
final list = _syntax.assetsForBuild ?? [];
772772
for (final asset in assets) {
773773
list.add(AssetSyntax.fromJson(asset.toJson()));
774774
}
775-
_syntax.assetsForHook = list;
775+
_syntax.assetsForBuild = list;
776776
case ToLinkHook():
777777
final linkInPackage = routing.packageName;
778778
final assetsForLinking = _syntax.assetsForLinking ?? {};
@@ -792,6 +792,16 @@ final class BuildOutputAssetsBuilder {
792792
///
793793
/// See [LinkOutputFailure] for failure.
794794
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+
795805
/// Creates a [LinkOutput] from the given [json].
796806
LinkOutput(super.json) : _syntax = LinkOutputSyntax.fromJson(json), super._();
797807

@@ -813,7 +823,8 @@ final class LinkOutputAssets {
813823

814824
/// The assets produced by this build which should be available to subsequent
815825
/// link hooks.
816-
List<EncodedAsset> get encodedAssetsForLink => _output._encodedAssetsForHook;
826+
Map<String, List<EncodedAsset>> get encodedAssetsForLink =>
827+
_output._encodedAssetsForLinking;
817828
}
818829

819830
/// The builder for [LinkOutput].
@@ -866,10 +877,14 @@ final class LinkOutputAssetsBuilder {
866877
final assets = _syntax.assets ?? [];
867878
assets.add(AssetSyntax.fromJson(asset.toJson()));
868879
_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;
873888
}
874889
}
875890

@@ -897,12 +912,14 @@ final class LinkOutputAssetsBuilder {
897912
list.add(AssetSyntax.fromJson(asset.toJson()));
898913
}
899914
_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] ??= [];
902919
for (final asset in assets) {
903920
list.add(AssetSyntax.fromJson(asset.toJson()));
904921
}
905-
_syntax.assetsForHook = list;
922+
_syntax.assetsForLink = assetsForLinking;
906923
}
907924
}
908925

0 commit comments

Comments
 (0)