From b24ab0ebaa67c28c52e229b1facdc0fbe162b3b1 Mon Sep 17 00:00:00 2001 From: anKii <41232001+ankiimation@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:01:05 +0700 Subject: [PATCH 1/3] add --no-example arg for melos bs - add ``` --no-example ``` arg for ```dart/flutter pub get``` of bootstrap command --- .../lib/src/command_runner/bootstrap.dart | 7 +++++- .../melos/lib/src/commands/bootstrap.dart | 24 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/packages/melos/lib/src/command_runner/bootstrap.dart b/packages/melos/lib/src/command_runner/bootstrap.dart index 2650339d3..118a21688 100644 --- a/packages/melos/lib/src/command_runner/bootstrap.dart +++ b/packages/melos/lib/src/command_runner/bootstrap.dart @@ -23,6 +23,11 @@ import 'base.dart'; class BootstrapCommand extends MelosCommand { BootstrapCommand(super.config) { setupPackageFilterParser(); + argParser.addFlag( + 'no-example', + negatable: false, + help: 'Run pub get with/without example pub get', + ); } @override @@ -39,10 +44,10 @@ class BootstrapCommand extends MelosCommand { @override FutureOr? run() { final melos = Melos(logger: logger, config: config); - return melos.bootstrap( global: global, packageFilters: parsePackageFilters(config.path), + noExample: argResults?['no-example'] as bool, ); } } diff --git a/packages/melos/lib/src/commands/bootstrap.dart b/packages/melos/lib/src/commands/bootstrap.dart index 33fa7a830..0d9f66195 100644 --- a/packages/melos/lib/src/commands/bootstrap.dart +++ b/packages/melos/lib/src/commands/bootstrap.dart @@ -4,6 +4,7 @@ mixin _BootstrapMixin on _CleanMixin { Future bootstrap({ GlobalOptions? global, PackageFilters? packageFilters, + required bool noExample, }) async { final workspace = await createWorkspace(global: global, packageFilters: packageFilters); @@ -19,6 +20,7 @@ mixin _BootstrapMixin on _CleanMixin { workspace: workspace, ), 'get', + if (noExample == true) '--no-example', if (bootstrapCommandConfig.runPubGetOffline) '--offline', ].join(' '); @@ -50,7 +52,10 @@ mixin _BootstrapMixin on _CleanMixin { }).drain(); } - await _linkPackagesWithPubspecOverrides(workspace); + await _linkPackagesWithPubspecOverrides( + workspace, + noExample: noExample, + ); } on BootstrapException catch (exception) { _logBootstrapException(exception, workspace); rethrow; @@ -77,8 +82,9 @@ mixin _BootstrapMixin on _CleanMixin { } Future _linkPackagesWithPubspecOverrides( - MelosWorkspace workspace, - ) async { + MelosWorkspace workspace, { + required bool noExample, + }) async { final filteredPackages = workspace.filteredPackages.values; await Stream.fromIterable(filteredPackages).parallel( @@ -105,7 +111,11 @@ mixin _BootstrapMixin on _CleanMixin { bootstrappedPackages.add(example); } } - await _runPubGetForPackage(workspace, package); + await _runPubGetForPackage( + workspace, + package, + noExample: noExample, + ); bootstrappedPackages.forEach(_logBootstrapSuccess); }, @@ -170,14 +180,16 @@ mixin _BootstrapMixin on _CleanMixin { Future _runPubGetForPackage( MelosWorkspace workspace, - Package package, - ) async { + Package package, { + required bool noExample, + }) async { final command = [ ...pubCommandExecArgs( useFlutter: package.isFlutterPackage, workspace: workspace, ), 'get', + if (noExample) '--no-example', if (workspace.config.commands.bootstrap.runPubGetOffline) '--offline', ]; From 9df8c2bc7d2464f5ffd39dc8843258ee4bee47d9 Mon Sep 17 00:00:00 2001 From: anKii <41232001+ankiimation@users.noreply.github.com> Date: Mon, 27 Nov 2023 11:38:28 +0700 Subject: [PATCH 2/3] fix: set "noExample" param to optional --- packages/melos/lib/src/commands/bootstrap.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/melos/lib/src/commands/bootstrap.dart b/packages/melos/lib/src/commands/bootstrap.dart index 0d9f66195..6160418e4 100644 --- a/packages/melos/lib/src/commands/bootstrap.dart +++ b/packages/melos/lib/src/commands/bootstrap.dart @@ -4,7 +4,7 @@ mixin _BootstrapMixin on _CleanMixin { Future bootstrap({ GlobalOptions? global, PackageFilters? packageFilters, - required bool noExample, + bool noExample = false, }) async { final workspace = await createWorkspace(global: global, packageFilters: packageFilters); From dd7bc109fa03f44a607ceeb5f2d67e1c4fa2e4e9 Mon Sep 17 00:00:00 2001 From: anKii <41232001+ankiimation@users.noreply.github.com> Date: Mon, 18 Dec 2023 17:10:28 +0700 Subject: [PATCH 3/3] add document for ```--no-example``` flag --- docs/commands/bootstrap.mdx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/commands/bootstrap.mdx b/docs/commands/bootstrap.mdx index e2977fb1b..5aa7f1151 100644 --- a/docs/commands/bootstrap.mdx +++ b/docs/commands/bootstrap.mdx @@ -19,6 +19,13 @@ melos bs Bootstrapping has two primary functions: 1. Installing all package dependencies (internally using `pub get`). + Optionally, you can use the `--no-example`` flag to exclude flutter package's example's dependencies (https://github.com/dart-lang/pub/pull/3856): + ```bash + melos bootstrap --no-example + # or + melos bs --no-example + ``` + this will run `pub get --no-example` instead of `pub get` 2. Locally linking any packages together via path dependency overrides _without having to edit your pubspec.yaml_.