Skip to content

Commit 07055aa

Browse files
authored
[go_router] change fix_data.yaml uris to be absolute to fix lints (#3877)
a workaround for dart-lang/sdk#52233 for consumers to use this fix while it's being reviewed/published: 1. copy this [fix_data.yaml](https://github.com/Bdaya-Dev/packages/blob/280bb99050a7a8083d3e73cf5a63e66d18ab64f8/packages/go_router/lib/fix_data.yaml) file with the correct uris from this PR to your project's `lib` folder 2. ensure each file that needs to be fixed using `dart fix` imports the `go_router` package directly, and not proxied via some other `exports`: ```dart import 'package:go_router/go_router.dart'; ```
1 parent 5b7d732 commit 07055aa

File tree

5 files changed

+102
-19
lines changed

5 files changed

+102
-19
lines changed

packages/go_router/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 7.0.1
2+
3+
- Adds a workaround for the `dart fix --apply` issue, https://github.com/dart-lang/sdk/issues/52233.
4+
15
## 7.0.0
26

37
- **BREAKING CHANGE**:

packages/go_router/lib/fix_data.yaml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ transforms:
2121
date: 2023-04-24
2222
bulkApply: true
2323
element:
24-
uris: [ 'go_router.dart' ]
24+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
25+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
2526
method: 'replaceNamed'
2627
inClass: 'GoRouter'
2728
changes:
@@ -35,7 +36,8 @@ transforms:
3536
date: 2023-04-24
3637
bulkApply: true
3738
element:
38-
uris: [ 'go_router.dart' ]
39+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
40+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
3941
method: 'pushReplacementNamed'
4042
inClass: 'GoRouter'
4143
changes:
@@ -50,7 +52,8 @@ transforms:
5052
date: 2023-04-24
5153
bulkApply: true
5254
element:
53-
uris: [ 'go_router.dart' ]
55+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
56+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
5457
method: 'pushNamed'
5558
inClass: 'GoRouter'
5659
changes:
@@ -65,7 +68,8 @@ transforms:
6568
date: 2023-04-24
6669
bulkApply: true
6770
element:
68-
uris: [ 'go_router.dart' ]
71+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
72+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
6973
method: 'goNamed'
7074
inClass: 'GoRouter'
7175
changes:
@@ -80,7 +84,8 @@ transforms:
8084
date: 2023-04-24
8185
bulkApply: true
8286
element:
83-
uris: [ 'go_router.dart' ]
87+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
88+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
8489
method: 'namedLocation'
8590
inClass: 'GoRouter'
8691
changes:
@@ -95,7 +100,8 @@ transforms:
95100
date: 2023-04-24
96101
bulkApply: true
97102
element:
98-
uris: [ 'go_router.dart' ]
103+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
104+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
99105
method: 'namedLocation'
100106
inClass: 'GoRouterState'
101107
changes:
@@ -110,7 +116,8 @@ transforms:
110116
date: 2023-04-24
111117
bulkApply: true
112118
element:
113-
uris: [ 'go_router.dart' ]
119+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
120+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
114121
field: 'queryParams'
115122
inClass: 'GoRouterState'
116123
changes:
@@ -121,7 +128,8 @@ transforms:
121128
date: 2023-04-24
122129
bulkApply: true
123130
element:
124-
uris: [ 'go_router.dart' ]
131+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
132+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
125133
field: 'fullpath'
126134
inClass: 'GoRouterState'
127135
changes:
@@ -132,7 +140,8 @@ transforms:
132140
date: 2023-04-24
133141
bulkApply: true
134142
element:
135-
uris: [ 'go_router.dart' ]
143+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
144+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
136145
field: 'params'
137146
inClass: 'GoRouterState'
138147
changes:
@@ -143,7 +152,8 @@ transforms:
143152
date: 2023-04-24
144153
bulkApply: true
145154
element:
146-
uris: [ 'go_router.dart' ]
155+
# TODO(ahmednfwela): Workaround for https://github.com/dart-lang/sdk/issues/52233
156+
uris: [ 'go_router.dart', 'package:go_router/go_router.dart' ]
147157
field: 'subloc'
148158
inClass: 'GoRouterState'
149159
changes:

packages/go_router/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: go_router
22
description: A declarative router for Flutter based on Navigation 2 supporting
33
deep linking, data-driven routes and more
4-
version: 7.0.0
4+
version: 7.0.1
55
repository: https://github.com/flutter/packages/tree/main/packages/go_router
66
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22
77

@@ -21,4 +21,5 @@ dependencies:
2121
dev_dependencies:
2222
flutter_test:
2323
sdk: flutter
24+
io: ^1.0.4
2425
path: ^1.8.2

packages/go_router/tool/run_tests.dart

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,92 @@
99
// ignore_for_file: avoid_print
1010

1111
import 'dart:io';
12+
import 'package:io/io.dart' as io;
1213
import 'package:path/path.dart' as p;
1314

15+
// This test runner simulates a consumption of go_router that checks if
16+
// the dart fixes are applied correctly.
17+
// This is done by copying the `test_fixes/` directory to a temp directory
18+
// that references `go_router`, and running `dart fix --compare-to-golden`
19+
// on the temp directory.
1420
Future<void> main(List<String> args) async {
15-
if (!Platform.isMacOS) {
16-
print('This test can only be run on macOS.');
17-
exit(0);
21+
final Directory goRouterPackageRoot =
22+
File.fromUri(Platform.script).parent.parent;
23+
24+
final Directory testTempDir = await Directory.systemTemp.createTemp();
25+
26+
// Cleans up the temp directory and exits with a given statusCode.
27+
Future<Never> cleanUpAndExit(int statusCode) async {
28+
await testTempDir.delete(recursive: true);
29+
exit(statusCode);
1830
}
19-
final Directory packageRoot =
20-
Directory(p.dirname(Platform.script.path)).parent;
21-
final int status = await _runProcess(
31+
32+
// Copy the test_fixes folder to the temporary testFixesTargetDir.
33+
//
34+
// This also creates the proper pubspec.yaml in the temp directory.
35+
await _prepareTemplate(
36+
packageRoot: goRouterPackageRoot,
37+
testTempDir: testTempDir,
38+
);
39+
40+
// Run dart pub get in the temp directory to set it up.
41+
final int pubGetStatusCode = await _runProcess(
42+
'dart',
43+
<String>[
44+
'pub',
45+
'get',
46+
],
47+
workingDirectory: testTempDir.path,
48+
);
49+
50+
if (pubGetStatusCode != 0) {
51+
await cleanUpAndExit(pubGetStatusCode);
52+
}
53+
54+
// Run dart fix --compare-to-golden in the temp directory.
55+
final int dartFixStatusCode = await _runProcess(
2256
'dart',
2357
<String>[
2458
'fix',
2559
'--compare-to-golden',
2660
],
27-
workingDirectory: p.join(packageRoot.path, 'test_fixes'),
61+
workingDirectory: testTempDir.path,
2862
);
2963

30-
exit(status);
64+
await cleanUpAndExit(dartFixStatusCode);
65+
}
66+
67+
Future<void> _prepareTemplate({
68+
required Directory packageRoot,
69+
required Directory testTempDir,
70+
}) async {
71+
// The src test_fixes directory.
72+
final Directory testFixesSrcDir =
73+
Directory(p.join(packageRoot.path, 'test_fixes'));
74+
75+
// Copy from src `test_fixes/` to the temp directory.
76+
await io.copyPath(testFixesSrcDir.path, testTempDir.path);
77+
78+
// The pubspec.yaml file to create.
79+
final File targetPubspecFile = File(p.join(testTempDir.path, 'pubspec.yaml'));
80+
81+
final String targetYaml = '''
82+
name: test_fixes
83+
publish_to: "none"
84+
version: 1.0.0
85+
86+
environment:
87+
sdk: ">=2.18.0 <4.0.0"
88+
flutter: ">=3.3.0"
89+
90+
dependencies:
91+
flutter:
92+
sdk: flutter
93+
go_router:
94+
path: ${packageRoot.path}
95+
''';
96+
97+
await targetPubspecFile.writeAsString(targetYaml);
3198
}
3299

33100
Future<Process> _streamOutput(Future<Process> processFuture) async {

script/configs/allowed_unpinned_deps.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- html
4242
- http
4343
- intl
44+
- io
4445
- js
4546
- json_serializable
4647
- lints

0 commit comments

Comments
 (0)