Skip to content

Commit 5eadfaf

Browse files
authored
[hooks] Stop leaking MetadataAsset (#2357)
1 parent 33c0251 commit 5eadfaf

File tree

7 files changed

+30
-20
lines changed

7 files changed

+30
-20
lines changed

pkgs/code_assets/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ environment:
2121

2222
dependencies:
2323
collection: ^1.19.1
24-
hooks: ^0.19.4
24+
hooks: ^0.19.5
2525

2626
dev_dependencies:
2727
custom_lint: ^0.7.5

pkgs/data_assets/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ environment:
1717
sdk: '>=3.9.0-21.0.dev <4.0.0'
1818

1919
dependencies:
20-
hooks: ^0.19.4
20+
hooks: ^0.19.5
2121

2222
dev_dependencies:
2323
custom_lint: ^0.7.5

pkgs/hooks/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.19.5
2+
3+
* Stop leaking unexported symbols.
4+
15
## 0.19.4
26

37
* Add doc comments to all public members.

pkgs/hooks/lib/src/config.dart

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ final class BuildInputMetadata {
228228
BuildInputMetadata._(this._input);
229229

230230
/// The metadata emitted by the build hook of package [packageName].
231-
PackageMetadata operator [](String packageName) => PackageMetadata(
231+
PackageMetadata operator [](String packageName) => PackageMetadata._(
232232
(_input.assets.encodedAssets[packageName] ?? [])
233233
.where((e) => e.isMetadataAsset)
234234
.map((e) => e.asMetadataAsset)
@@ -238,8 +238,7 @@ final class BuildInputMetadata {
238238

239239
/// The metadata from a specific package, available in [BuildInput.metadata].
240240
final class PackageMetadata {
241-
/// Creates a [PackageMetadata] from the given metadata.
242-
PackageMetadata(this._metadata);
241+
PackageMetadata._(this._metadata);
243242

244243
final List<MetadataAsset> _metadata;
245244

@@ -258,7 +257,7 @@ final class BuildInputAssets {
258257
Map<String, List<EncodedAsset>> get encodedAssets => {
259258
for (final MapEntry(:key, :value)
260259
in (_input._syntaxBuildInput.assets ?? {}).entries)
261-
key: _parseAssets(value),
260+
key: EncodedAssetSyntax._fromSyntax(value),
262261
};
263262

264263
/// The encoded assets from the direct dependency [packageName].
@@ -334,7 +333,7 @@ final class BuildConfigBuilder extends HookConfigBuilder {
334333
final class LinkInput extends HookInput {
335334
List<EncodedAsset> get _encodedAssets {
336335
final assets = _syntaxLinkInput.assets;
337-
return _parseAssets(assets);
336+
return EncodedAssetSyntax._fromSyntax(assets);
338337
}
339338

340339
/// The file containing recorded usages, if any.
@@ -407,12 +406,18 @@ final class LinkConfigBuilder extends HookConfigBuilder {
407406
LinkConfigBuilder._(super.builder) : super._();
408407
}
409408

410-
List<EncodedAsset> _parseAssets(List<AssetSyntax>? assets) => assets == null
411-
? []
412-
: [
413-
for (final asset in assets)
414-
EncodedAsset.fromJson(asset.json, asset.path),
415-
];
409+
/// Extension methods for [EncodedAsset] to convert to and from the syntax
410+
/// model.
411+
extension EncodedAssetSyntax on List<EncodedAsset> {
412+
static List<EncodedAsset> _fromSyntax(List<AssetSyntax>? assets) {
413+
if (assets == null) {
414+
return [];
415+
}
416+
return [
417+
for (final asset in assets) EncodedAsset.fromJson(asset.json, asset.path),
418+
];
419+
}
420+
}
416421

417422
/// The output from a `hook/build.dart` or `hook/link.dart`.
418423
///
@@ -442,7 +447,8 @@ sealed class HookOutput {
442447
List<Uri> get dependencies => _syntax.dependencies ?? [];
443448

444449
/// The assets produced by this build.
445-
List<EncodedAsset> get _encodedAssets => _parseAssets(_syntax.assets);
450+
List<EncodedAsset> get _encodedAssets =>
451+
EncodedAssetSyntax._fromSyntax(_syntax.assets);
446452

447453
HookOutputSyntax get _syntax;
448454

@@ -513,11 +519,11 @@ final class BuildOutput extends HookOutput implements BuildOutputMaybeFailure {
513519
Map<String, List<EncodedAsset>> get _encodedAssetsForLinking => {
514520
for (final MapEntry(:key, :value)
515521
in (_syntax.assetsForLinking ?? {}).entries)
516-
key: _parseAssets(value),
522+
key: EncodedAssetSyntax._fromSyntax(value),
517523
};
518524

519525
List<EncodedAsset> get _encodedAssetsForBuild =>
520-
_parseAssets(_syntax.assetsForBuild ?? []);
526+
EncodedAssetSyntax._fromSyntax(_syntax.assetsForBuild ?? []);
521527

522528
@override
523529
final BuildOutputSyntax _syntax;

pkgs/hooks/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: >-
33
A library that contains a Dart API for the JSON-based protocol for
44
`hook/build.dart` and `hook/link.dart`.
55
6-
version: 0.19.4
6+
version: 0.19.5
77

88
repository: https://github.com/dart-lang/native/tree/main/pkgs/hooks
99

@@ -29,7 +29,7 @@ dependencies:
2929

3030
dev_dependencies:
3131
args: ^2.6.0
32-
code_assets: any # Used for running tests with real asset types.
32+
code_assets: ^0.19.4 # Used for running tests with real asset types.
3333
custom_lint: ^0.7.5
3434
dart_flutter_team_lints: ^3.5.1
3535
data_assets: any # Used for running tests with real asset types.

pkgs/hooks_runner/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ dependencies:
1717
crypto: ^3.0.6
1818
file: ^7.0.1
1919
graphs: ^2.3.2
20-
hooks: ^0.19.4
20+
hooks: ^0.19.5
2121
logging: ^1.3.0
2222
meta: ^1.16.0
2323
package_config: ^2.1.0

pkgs/native_toolchain_c/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ environment:
1919
dependencies:
2020
code_assets: ^0.19.4
2121
glob: ^2.1.1
22-
hooks: ^0.19.4
22+
hooks: ^0.19.5
2323
logging: ^1.3.0
2424
meta: ^1.16.0
2525
pub_semver: ^2.2.0

0 commit comments

Comments
 (0)