From cf9f46ceb6bcceb6f159ccb47698651b01fe9396 Mon Sep 17 00:00:00 2001 From: Felix Angelov Date: Mon, 14 Feb 2022 16:57:28 -0600 Subject: [PATCH] fix(packages_get): recursive installation ignored directories fixes (#283) --- lib/src/cli/cli.dart | 17 +++++++--- test/src/commands/packages_test.dart | 48 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/lib/src/cli/cli.dart b/lib/src/cli/cli.dart index b2bd2fb3..3e3e2ff6 100644 --- a/lib/src/cli/cli.dart +++ b/lib/src/cli/cli.dart @@ -55,12 +55,21 @@ class _Cmd { } } -final _ignoredDirectories = RegExp( - 'ios|android|windows|linux|macos|.symlinks|.plugin_symlinks|.dart_tool|build', -); +const _ignoredDirectories = { + 'ios', + 'android', + 'windows', + 'linux', + 'macos', + '.symlinks', + '.plugin_symlinks', + '.dart_tool', + 'build', +}; bool _isPubspec(FileSystemEntity entity) { - if (entity.path.contains(_ignoredDirectories)) return false; + final segments = p.split(entity.path).toSet(); + if (segments.intersection(_ignoredDirectories).isNotEmpty) return false; if (entity is! File) return false; return p.basename(entity.path) == 'pubspec.yaml'; } diff --git a/test/src/commands/packages_test.dart b/test/src/commands/packages_test.dart index 7cb57c8e..bfe332b1 100644 --- a/test/src/commands/packages_test.dart +++ b/test/src/commands/packages_test.dart @@ -232,6 +232,54 @@ void main() { ); }).called(2); }); + + test( + 'completes normally ' + 'when pubspec.yaml exists and directory is not ignored (recursive)', + () async { + final tempDirectory = Directory.systemTemp.createTempSync(); + final directory = Directory( + path.join(tempDirectory.path, 'macos_plugin'), + ); + final pubspecA = File( + path.join(directory.path, 'example_a', 'pubspec.yaml'), + ); + final pubspecB = File( + path.join(directory.path, 'example_b', 'pubspec.yaml'), + ); + pubspecA + ..createSync(recursive: true) + ..writeAsStringSync( + ''' + name: example_a + version: 0.1.0 + + environment: + sdk: ">=2.12.0 <3.0.0" + ''', + ); + pubspecB + ..createSync(recursive: true) + ..writeAsStringSync( + ''' + name: example_b + version: 0.1.0 + + environment: + sdk: ">=2.12.0 <3.0.0" + ''', + ); + + final result = await commandRunner.run( + ['packages', 'get', '--recursive', directory.path], + ); + expect(result, equals(ExitCode.success.code)); + verify(() { + logger.progress( + any(that: contains('Running "flutter packages get" in')), + ); + }).called(2); + }); }); }); }