Skip to content

Commit 300f970

Browse files
[tool] Include dev_dependencies in make-deps-path-based (#6146)
1 parent edddaf1 commit 300f970

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

script/tool/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 0.8.9
22

3+
- Includes `dev_dependencies` when overridding dependencies using
4+
`make-deps-path-based`.
35
- Bypasses version and CHANGELOG checks for Dependabot PRs for packages
46
that are known not to be client-affecting.
57

script/tool/lib/src/make_deps_path_based_command.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ class MakeDepsPathBasedCommand extends PluginCommand {
154154
throw ToolExit(_exitCannotUpdatePubspec);
155155
}
156156

157-
final Iterable<String> packagesToOverride = pubspec.dependencies.keys.where(
158-
(String packageName) => localDependencies.containsKey(packageName));
157+
final Iterable<String> combinedDependencies = <String>[
158+
...pubspec.dependencies.keys,
159+
...pubspec.devDependencies.keys,
160+
];
161+
final Iterable<String> packagesToOverride = combinedDependencies
162+
.where(
163+
(String packageName) => localDependencies.containsKey(packageName))
164+
.toList();
159165
if (packagesToOverride.isNotEmpty) {
160166
final String commonBasePath = packagesDir.path;
161167
// Find the relative path to the common base.

script/tool/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: flutter_plugin_tools
22
description: Productivity utils for flutter/plugins and flutter/packages
33
repository: https://github.com/flutter/plugins/tree/main/script/tool
4-
version: 0.8.8
4+
version: 0.8.9
55

66
dependencies:
77
args: ^2.1.0

script/tool/test/make_deps_path_based_command_test.dart

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ void main() {
6060
package.pubspecFile.writeAsStringSync(lines.join('\n'));
6161
}
6262

63+
/// Adds a 'dev_dependencies:' section with entries for each package in
64+
/// [dependencies] to [package].
65+
void _addDevDependenciesSection(
66+
RepositoryPackage package, Iterable<String> devDependencies) {
67+
final String originalContent = package.pubspecFile.readAsStringSync();
68+
package.pubspecFile.writeAsStringSync('''
69+
$originalContent
70+
71+
dev_dependencies:
72+
${devDependencies.map((String dep) => ' $dep: ^1.0.0').join('\n')}
73+
''');
74+
}
75+
6376
test('no-ops for no plugins', () async {
6477
createFakePackage('foo', packagesDir, isFlutter: true);
6578
final RepositoryPackage packageBar =
@@ -81,7 +94,7 @@ void main() {
8194
expect(packageBar.pubspecFile.readAsStringSync(), originalPubspecContents);
8295
});
8396

84-
test('rewrites references', () async {
97+
test('rewrites "dependencies" references', () async {
8598
final RepositoryPackage simplePackage =
8699
createFakePackage('foo', packagesDir, isFlutter: true);
87100
final Directory pluginGroup = packagesDir.childDirectory('bar');
@@ -142,6 +155,35 @@ void main() {
142155
]));
143156
});
144157

158+
test('rewrites "dev_dependencies" references', () async {
159+
createFakePackage('foo', packagesDir);
160+
final RepositoryPackage builderPackage =
161+
createFakePackage('foo_builder', packagesDir);
162+
163+
_addDevDependenciesSection(builderPackage, <String>[
164+
'foo',
165+
]);
166+
167+
final List<String> output = await runCapturingPrint(
168+
runner, <String>['make-deps-path-based', '--target-dependencies=foo']);
169+
170+
expect(
171+
output,
172+
containsAll(<String>[
173+
'Rewriting references to: foo...',
174+
' Modified packages/foo_builder/pubspec.yaml',
175+
]));
176+
177+
expect(
178+
builderPackage.pubspecFile.readAsLinesSync(),
179+
containsAllInOrder(<String>[
180+
'# FOR TESTING ONLY. DO NOT MERGE.',
181+
'dependency_overrides:',
182+
' foo:',
183+
' path: ../foo',
184+
]));
185+
});
186+
145187
// This test case ensures that running CI using this command on an interim
146188
// PR that itself used this command won't fail on the rewrite step.
147189
test('running a second time no-ops without failing', () async {

0 commit comments

Comments
 (0)