diff --git a/packages/go_router/CHANGELOG.md b/packages/go_router/CHANGELOG.md index d46e9de8c32..ca33cc8a570 100644 --- a/packages/go_router/CHANGELOG.md +++ b/packages/go_router/CHANGELOG.md @@ -1,3 +1,7 @@ +## 7.0.1 + +- Adds a workaround for the `dart fix --apply` issue, https://github.com/dart-lang/sdk/issues/52233. + ## 7.0.0 - **BREAKING CHANGE**: diff --git a/packages/go_router/lib/fix_data.yaml b/packages/go_router/lib/fix_data.yaml index 99f978243a0..fb73a4fd743 100644 --- a/packages/go_router/lib/fix_data.yaml +++ b/packages/go_router/lib/fix_data.yaml @@ -21,7 +21,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'replaceNamed' inClass: 'GoRouter' changes: @@ -35,7 +36,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushReplacementNamed' inClass: 'GoRouter' changes: @@ -50,7 +52,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'pushNamed' inClass: 'GoRouter' changes: @@ -65,7 +68,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'goNamed' inClass: 'GoRouter' changes: @@ -80,7 +84,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouter' changes: @@ -95,7 +100,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] method: 'namedLocation' inClass: 'GoRouterState' changes: @@ -110,7 +116,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'queryParams' inClass: 'GoRouterState' changes: @@ -121,7 +128,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'fullpath' inClass: 'GoRouterState' changes: @@ -132,7 +140,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'params' inClass: 'GoRouterState' changes: @@ -143,7 +152,8 @@ transforms: date: 2023-04-24 bulkApply: true element: - uris: [ 'go_router.dart' ] + # TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233 + uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ] field: 'subloc' inClass: 'GoRouterState' changes: diff --git a/packages/go_router/pubspec.yaml b/packages/go_router/pubspec.yaml index 4d1cb1fda84..0104fca6eaf 100644 --- a/packages/go_router/pubspec.yaml +++ b/packages/go_router/pubspec.yaml @@ -1,7 +1,7 @@ name: go_router description: A declarative router for Flutter based on Navigation 2 supporting deep linking, data-driven routes and more -version: 7.0.0 +version: 7.0.1 repository: https://github.com/flutter/packages/tree/main/packages/go_router issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22 @@ -21,4 +21,5 @@ dependencies: dev_dependencies: flutter_test: sdk: flutter + io: ^1.0.4 path: ^1.8.2 diff --git a/packages/go_router/tool/run_tests.dart b/packages/go_router/tool/run_tests.dart index 39fe8cc0361..58c689bf942 100644 --- a/packages/go_router/tool/run_tests.dart +++ b/packages/go_router/tool/run_tests.dart @@ -9,25 +9,92 @@ // ignore_for_file: avoid_print import 'dart:io'; +import 'package:io/io.dart' as io; import 'package:path/path.dart' as p; +// This test runner simulates a consumption of go_router that checks if +// the dart fixes are applied correctly. +// This is done by copying the `test_fixes/` directory to a temp directory +// that references `go_router`, and running `dart fix --compare-to-golden` +// on the temp directory. Future main(List args) async { - if (!Platform.isMacOS) { - print('This test can only be run on macOS.'); - exit(0); + final Directory goRouterPackageRoot = + File.fromUri(Platform.script).parent.parent; + + final Directory testTempDir = await Directory.systemTemp.createTemp(); + + // Cleans up the temp directory and exits with a given statusCode. + Future cleanUpAndExit(int statusCode) async { + await testTempDir.delete(recursive: true); + exit(statusCode); } - final Directory packageRoot = - Directory(p.dirname(Platform.script.path)).parent; - final int status = await _runProcess( + + // Copy the test_fixes folder to the temporary testFixesTargetDir. + // + // This also creates the proper pubspec.yaml in the temp directory. + await _prepareTemplate( + packageRoot: goRouterPackageRoot, + testTempDir: testTempDir, + ); + + // Run dart pub get in the temp directory to set it up. + final int pubGetStatusCode = await _runProcess( + 'dart', + [ + 'pub', + 'get', + ], + workingDirectory: testTempDir.path, + ); + + if (pubGetStatusCode != 0) { + await cleanUpAndExit(pubGetStatusCode); + } + + // Run dart fix --compare-to-golden in the temp directory. + final int dartFixStatusCode = await _runProcess( 'dart', [ 'fix', '--compare-to-golden', ], - workingDirectory: p.join(packageRoot.path, 'test_fixes'), + workingDirectory: testTempDir.path, ); - exit(status); + await cleanUpAndExit(dartFixStatusCode); +} + +Future _prepareTemplate({ + required Directory packageRoot, + required Directory testTempDir, +}) async { + // The src test_fixes directory. + final Directory testFixesSrcDir = + Directory(p.join(packageRoot.path, 'test_fixes')); + + // Copy from src `test_fixes/` to the temp directory. + await io.copyPath(testFixesSrcDir.path, testTempDir.path); + + // The pubspec.yaml file to create. + final File targetPubspecFile = File(p.join(testTempDir.path, 'pubspec.yaml')); + + final String targetYaml = ''' +name: test_fixes +publish_to: "none" +version: 1.0.0 + +environment: + sdk: ">=2.18.0 <4.0.0" + flutter: ">=3.3.0" + +dependencies: + flutter: + sdk: flutter + go_router: + path: ${packageRoot.path} +'''; + + await targetPubspecFile.writeAsString(targetYaml); } Future _streamOutput(Future processFuture) async { diff --git a/script/configs/allowed_unpinned_deps.yaml b/script/configs/allowed_unpinned_deps.yaml index 7598a99afed..1cf35c8881e 100644 --- a/script/configs/allowed_unpinned_deps.yaml +++ b/script/configs/allowed_unpinned_deps.yaml @@ -41,6 +41,7 @@ - html - http - intl +- io - js - json_serializable - lints