Skip to content

Commit

Permalink
feat: add "--no-example" arg to "pub get " command for melos bootstrap (
Browse files Browse the repository at this point in the history
#604)

* add --no-example arg for melos bs

- add ``` --no-example ``` arg for ```dart/flutter pub get``` of bootstrap command

* fix: set "noExample" param to optional

* add document for ```--no-example``` flag

---------

Co-authored-by: Lukas Klingsbo <[email protected]>
  • Loading branch information
ankiimation and spydon authored Dec 18, 2023
1 parent 4c7fd17 commit 8b69f51
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
7 changes: 7 additions & 0 deletions docs/commands/bootstrap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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_.

Expand Down
7 changes: 6 additions & 1 deletion packages/melos/lib/src/command_runner/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,10 +44,10 @@ class BootstrapCommand extends MelosCommand {
@override
FutureOr<void>? run() {
final melos = Melos(logger: logger, config: config);

return melos.bootstrap(
global: global,
packageFilters: parsePackageFilters(config.path),
noExample: argResults?['no-example'] as bool,
);
}
}
24 changes: 18 additions & 6 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mixin _BootstrapMixin on _CleanMixin {
Future<void> bootstrap({
GlobalOptions? global,
PackageFilters? packageFilters,
bool noExample = false,
}) async {
final workspace =
await createWorkspace(global: global, packageFilters: packageFilters);
Expand All @@ -19,6 +20,7 @@ mixin _BootstrapMixin on _CleanMixin {
workspace: workspace,
),
'get',
if (noExample == true) '--no-example',
if (bootstrapCommandConfig.runPubGetOffline) '--offline',
].join(' ');

Expand Down Expand Up @@ -50,7 +52,10 @@ mixin _BootstrapMixin on _CleanMixin {
}).drain<void>();
}

await _linkPackagesWithPubspecOverrides(workspace);
await _linkPackagesWithPubspecOverrides(
workspace,
noExample: noExample,
);
} on BootstrapException catch (exception) {
_logBootstrapException(exception, workspace);
rethrow;
Expand All @@ -77,8 +82,9 @@ mixin _BootstrapMixin on _CleanMixin {
}

Future<void> _linkPackagesWithPubspecOverrides(
MelosWorkspace workspace,
) async {
MelosWorkspace workspace, {
required bool noExample,
}) async {
final filteredPackages = workspace.filteredPackages.values;

await Stream.fromIterable(filteredPackages).parallel(
Expand All @@ -105,7 +111,11 @@ mixin _BootstrapMixin on _CleanMixin {
bootstrappedPackages.add(example);
}
}
await _runPubGetForPackage(workspace, package);
await _runPubGetForPackage(
workspace,
package,
noExample: noExample,
);

bootstrappedPackages.forEach(_logBootstrapSuccess);
},
Expand Down Expand Up @@ -170,14 +180,16 @@ mixin _BootstrapMixin on _CleanMixin {

Future<void> _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',
];

Expand Down

0 comments on commit 8b69f51

Please sign in to comment.