From c8e2e078574617c3bc2df26188db982a678ae2b9 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Mon, 25 Jul 2022 20:18:03 -0400 Subject: [PATCH] [tool] Include `dev_dependencies` in `make-deps-path-based` (#6146) --- script/tool/CHANGELOG.md | 4 +- .../lib/src/make_deps_path_based_command.dart | 10 ++++- script/tool/pubspec.yaml | 2 +- .../make_deps_path_based_command_test.dart | 44 ++++++++++++++++++- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/script/tool/CHANGELOG.md b/script/tool/CHANGELOG.md index a84e9af639..f0534c23a2 100644 --- a/script/tool/CHANGELOG.md +++ b/script/tool/CHANGELOG.md @@ -1,5 +1,7 @@ -## NEXT +## 0.8.9 +- Includes `dev_dependencies` when overridding dependencies using + `make-deps-path-based`. - Bypasses version and CHANGELOG checks for Dependabot PRs for packages that are known not to be client-affecting. diff --git a/script/tool/lib/src/make_deps_path_based_command.dart b/script/tool/lib/src/make_deps_path_based_command.dart index 4bbecb4d22..805dd68a0a 100644 --- a/script/tool/lib/src/make_deps_path_based_command.dart +++ b/script/tool/lib/src/make_deps_path_based_command.dart @@ -154,8 +154,14 @@ class MakeDepsPathBasedCommand extends PluginCommand { throw ToolExit(_exitCannotUpdatePubspec); } - final Iterable packagesToOverride = pubspec.dependencies.keys.where( - (String packageName) => localDependencies.containsKey(packageName)); + final Iterable combinedDependencies = [ + ...pubspec.dependencies.keys, + ...pubspec.devDependencies.keys, + ]; + final Iterable packagesToOverride = combinedDependencies + .where( + (String packageName) => localDependencies.containsKey(packageName)) + .toList(); if (packagesToOverride.isNotEmpty) { final String commonBasePath = packagesDir.path; // Find the relative path to the common base. diff --git a/script/tool/pubspec.yaml b/script/tool/pubspec.yaml index b8233de11b..a4ecbfb75e 100644 --- a/script/tool/pubspec.yaml +++ b/script/tool/pubspec.yaml @@ -1,7 +1,7 @@ name: flutter_plugin_tools description: Productivity utils for flutter/plugins and flutter/packages repository: https://github.com/flutter/plugins/tree/main/script/tool -version: 0.8.8 +version: 0.8.9 dependencies: args: ^2.1.0 diff --git a/script/tool/test/make_deps_path_based_command_test.dart b/script/tool/test/make_deps_path_based_command_test.dart index 2644e814f5..33d6be261e 100644 --- a/script/tool/test/make_deps_path_based_command_test.dart +++ b/script/tool/test/make_deps_path_based_command_test.dart @@ -60,6 +60,19 @@ void main() { package.pubspecFile.writeAsStringSync(lines.join('\n')); } + /// Adds a 'dev_dependencies:' section with entries for each package in + /// [dependencies] to [package]. + void _addDevDependenciesSection( + RepositoryPackage package, Iterable devDependencies) { + final String originalContent = package.pubspecFile.readAsStringSync(); + package.pubspecFile.writeAsStringSync(''' +$originalContent + +dev_dependencies: +${devDependencies.map((String dep) => ' $dep: ^1.0.0').join('\n')} +'''); + } + test('no-ops for no plugins', () async { createFakePackage('foo', packagesDir, isFlutter: true); final RepositoryPackage packageBar = @@ -81,7 +94,7 @@ void main() { expect(packageBar.pubspecFile.readAsStringSync(), originalPubspecContents); }); - test('rewrites references', () async { + test('rewrites "dependencies" references', () async { final RepositoryPackage simplePackage = createFakePackage('foo', packagesDir, isFlutter: true); final Directory pluginGroup = packagesDir.childDirectory('bar'); @@ -142,6 +155,35 @@ void main() { ])); }); + test('rewrites "dev_dependencies" references', () async { + createFakePackage('foo', packagesDir); + final RepositoryPackage builderPackage = + createFakePackage('foo_builder', packagesDir); + + _addDevDependenciesSection(builderPackage, [ + 'foo', + ]); + + final List output = await runCapturingPrint( + runner, ['make-deps-path-based', '--target-dependencies=foo']); + + expect( + output, + containsAll([ + 'Rewriting references to: foo...', + ' Modified packages/foo_builder/pubspec.yaml', + ])); + + expect( + builderPackage.pubspecFile.readAsLinesSync(), + containsAllInOrder([ + '# FOR TESTING ONLY. DO NOT MERGE.', + 'dependency_overrides:', + ' foo:', + ' path: ../foo', + ])); + }); + // This test case ensures that running CI using this command on an interim // PR that itself used this command won't fail on the rewrite step. test('running a second time no-ops without failing', () async {