diff --git a/packages/mason/lib/src/generator.dart b/packages/mason/lib/src/generator.dart index 35e9fbe5f..2a3d767fe 100644 --- a/packages/mason/lib/src/generator.dart +++ b/packages/mason/lib/src/generator.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io' show Directory, File, FileMode, FileSystemEntity, Process; import 'dart:isolate'; +import 'dart:typed_data'; import 'package:checked_yaml/checked_yaml.dart'; import 'package:collection/collection.dart'; @@ -202,7 +203,7 @@ abstract class Generator implements Comparable { /// Map of partial files which will be used as includes. /// /// Contains a Map of partial file path to partial file content. - final Map> partials = {}; + final Map partials = {}; /// Add a new template file. void addTemplateFile(TemplateFile? file) { @@ -238,7 +239,7 @@ abstract class Generator implements Comparable { final resultFiles = await _runSubstitutionAsync( file, Map.of(vars), - Map>.of(partials), + Map.of(partials), ); final root = RegExp(r'\w:\\|\w:\/'); final separator = RegExp(r'\/|\\'); @@ -339,7 +340,7 @@ class DirectoryGeneratorTarget extends GeneratorTarget { @override Future createFile( String path, - List contents, { + Uint8List contents, { Logger? logger, OverwriteRule? overwriteRule, }) async { @@ -424,7 +425,7 @@ abstract class GeneratorTarget { /// Create a file at the given path with the given contents. Future createFile( String path, - List contents, { + Uint8List contents, { Logger? logger, OverwriteRule? overwriteRule, }); @@ -447,12 +448,12 @@ class TemplateFile { final String path; /// The template file content. - final List content; + final Uint8List content; /// Performs a substitution on the [path] based on the incoming [parameters]. Set runSubstitution( Map parameters, - Map> partials, + Map partials, ) { var filePath = path.replaceAll(r'\', '/'); if (_loopRegExp().hasMatch(filePath)) { @@ -506,9 +507,9 @@ class TemplateFile { } } - List _createContent( + Uint8List _createContent( Map vars, - Map> partials, + Map partials, ) { try { final decoded = utf8.decode(content); @@ -533,7 +534,7 @@ class FileContents { final String path; /// The contents of the file. - final List content; + final Uint8List content; @override bool operator ==(Object other) { @@ -584,7 +585,7 @@ class _Permutations { Future> _runSubstitutionAsync( TemplateFile file, Map vars, - Map> partials, + Map partials, ) async { return Isolate.run(() => file.runSubstitution(vars, partials)); } diff --git a/packages/mason/lib/src/hooks.dart b/packages/mason/lib/src/hooks.dart index 4d64d9ad8..dd89f4294 100644 --- a/packages/mason/lib/src/hooks.dart +++ b/packages/mason/lib/src/hooks.dart @@ -97,7 +97,7 @@ class GeneratorHooks { static Future fromBrickYaml(BrickYaml brick) async { HookFile? preGenHook; HookFile? postGenHook; - List? pubspec; + Uint8List? pubspec; final accumulator = AccumulatorSink(); final sink = sha1.startChunkedConversion(accumulator); @@ -151,7 +151,7 @@ class GeneratorHooks { final HookFile? postGenHook; /// Contents of the hooks `pubspec.yaml` if exists. - final List? pubspec; + final Uint8List? pubspec; /// The hash of the hooks directory and its contents. final String checksum; @@ -403,7 +403,7 @@ class HookFile { final String path; /// The template file content. - final List content; + final Uint8List content; } /// A reference to core mason APIs to be used within hooks. diff --git a/packages/mason/lib/src/mason_bundle.dart b/packages/mason/lib/src/mason_bundle.dart index 5ef350ef8..4be4b4074 100644 --- a/packages/mason/lib/src/mason_bundle.dart +++ b/packages/mason/lib/src/mason_bundle.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:isolate'; +import 'dart:typed_data'; import 'package:archive/archive.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -58,7 +59,7 @@ class MasonBundle { _$MasonBundleFromJson(json); /// Converts a universal bundle into a [MasonBundle] instance. - static Future fromUniversalBundle(List bytes) async { + static Future fromUniversalBundle(Uint8List bytes) async { final bundleJson = await Isolate.run( () => json.decode( utf8.decode(BZip2Decoder().decodeBytes(bytes)), @@ -121,11 +122,13 @@ class MasonBundle { Map toJson() => _$MasonBundleToJson(this); /// Converts a [MasonBundle] into universal bundle bytes. - Future> toUniversalBundle() { + Future toUniversalBundle() { return Isolate.run(() => _encodeBundle(this)); } - Future> _encodeBundle(MasonBundle bundle) async { - return BZip2Encoder().encode(utf8.encode(json.encode(bundle.toJson()))); + Future _encodeBundle(MasonBundle bundle) async { + return BZip2Encoder().encodeBytes( + utf8.encode(json.encode(bundle.toJson())), + ); } } diff --git a/packages/mason/lib/src/render.dart b/packages/mason/lib/src/render.dart index 9ef43d5c6..f2f929800 100644 --- a/packages/mason/lib/src/render.dart +++ b/packages/mason/lib/src/render.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:typed_data'; import 'package:mason/mason.dart'; import 'package:mustache_template/mustache_template.dart'; @@ -97,7 +98,7 @@ extension RenderTemplate on String { /// {@macro render_template} String render( Map vars, [ - Map>? partials = const {}, + Map? partials = const {}, ]) { final template = Template( _sanitizeInput(transpiled()), @@ -159,7 +160,7 @@ extension on String { /// A resolver function which given a partial name. /// attempts to return a new [Template]. /// {@endtemplate} -extension ResolvePartial on Map> { +extension ResolvePartial on Map { /// {@macro resolve_partial} Template? resolve(String name) { final content = this['{{~ $name }}']; diff --git a/packages/mason/test/src/generator_test.dart b/packages/mason/test/src/generator_test.dart index c7c396151..de5e11316 100644 --- a/packages/mason/test/src/generator_test.dart +++ b/packages/mason/test/src/generator_test.dart @@ -1,5 +1,6 @@ // ignore_for_file: missing_whitespace_between_adjacent_strings import 'dart:io'; +import 'dart:typed_data'; import 'package:mason/mason.dart'; import 'package:mocktail/mocktail.dart'; @@ -1094,7 +1095,7 @@ void main() { group('runSubstitution', () { test('handles malformed content', () { final tempDir = Directory.systemTemp.createTempSync(); - final bytes = [0x80, 0x00]; + final bytes = Uint8List.fromList([0x80, 0x00]); final template = TemplateFile.fromBytes( path.join(tempDir.path, 'malformed.txt'), bytes, diff --git a/packages/mason_api/lib/src/mason_api.dart b/packages/mason_api/lib/src/mason_api.dart index 4d4ad0554..7d36bcdee 100644 --- a/packages/mason_api/lib/src/mason_api.dart +++ b/packages/mason_api/lib/src/mason_api.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; import 'package:cli_util/cli_util.dart'; import 'package:http/http.dart' as http; @@ -184,7 +185,7 @@ class MasonApi { void logout() => _clearCredentials(); /// Publish universal [bundle] to remote registry. - Future publish({required List bundle}) async { + Future publish({required Uint8List bundle}) async { var credentials = _credentials; if (credentials == null) { diff --git a/packages/mason_api/test/src/mason_api_test.dart b/packages/mason_api/test/src/mason_api_test.dart index ae40cf5c2..8781c426b 100644 --- a/packages/mason_api/test/src/mason_api_test.dart +++ b/packages/mason_api/test/src/mason_api_test.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; import 'package:http/http.dart' as http; import 'package:mason_api/mason_api.dart'; @@ -331,7 +332,7 @@ void main() { ); try { - await masonApi.publish(bundle: []); + await masonApi.publish(bundle: Uint8List.fromList([])); fail('should throw'); } on MasonApiPublishFailure catch (error) { expect( @@ -347,7 +348,7 @@ void main() { }); group('publish', () { - final bytes = [42]; + final bytes = Uint8List.fromList([42]); test('throws when user not found', () async { File( diff --git a/packages/mason_cli/test/commands/publish_test.dart b/packages/mason_cli/test/commands/publish_test.dart index f6debd072..8851bdf2b 100644 --- a/packages/mason_cli/test/commands/publish_test.dart +++ b/packages/mason_cli/test/commands/publish_test.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:typed_data'; import 'package:args/args.dart'; import 'package:args/command_runner.dart'; @@ -28,6 +29,7 @@ void main() { setUpAll(() { registerFallbackValue(FakeUri()); + registerFallbackValue(Uint8List.fromList([])); }); group('PublishCommand', () {