Skip to content

asset manifest parsing code is duplicated for parsing the deferred components manifest #136092

@andrewkolos

Description

@andrewkolos

When it comes to validating and parsing asset manifests for both the "regular" asset manifest and the asset manifests of deferred components, there is nearly-duplicate code.

Code example

Code from parsing the regular asset manifest:

late final List<Uri> assets = _computeAssets();
List<Uri> _computeAssets() {
final List<Object?>? assets = _flutterDescriptor['assets'] as List<Object?>?;
if (assets == null) {
return const <Uri>[];
}
final List<Uri> results = <Uri>[];
for (final Object? asset in assets) {
if (asset is! String || asset == '') {
_logger.printError('Asset manifest contains a null or empty uri.');
continue;
}
try {
results.add(Uri(pathSegments: asset.split('/')));
} on FormatException {
_logger.printError('Asset manifest contains invalid uri: $asset.');
}
}
return results;
}

Code from parsing deferred component manifests:

final List<Object?>? assets = component['assets'] as List<Object?>?;
if (assets == null) {
assetsUri = const <Uri>[];
} else {
for (final Object? asset in assets) {
if (asset is! String || asset == '') {
_logger.printError('Deferred component asset manifest contains a null or empty uri.');
continue;
}
try {
assetsUri.add(Uri.parse(asset));
} on FormatException {
_logger.printError('Asset manifest contains invalid uri: $asset.');
}
}
}

For context, #132985 wishes to augment the grammar for the assets sections of pubspec.yaml. This duplicate logic has made this change more difficult to implement1.

Footnotes

  1. Fun fact: the dart SDK also contains logic for validating asset declarations 🙃 .

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.team-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions