Skip to content

Commit

Permalink
feat: add command/bootstrap/runPubGetInParallel melos.yaml option (
Browse files Browse the repository at this point in the history
  • Loading branch information
blaugold authored Apr 28, 2022
1 parent 1fdff16 commit f48e8f1
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ Whether to use `pubspec_overrides.yaml` for overriding workspace dependencies du

Enabling this option requires Dart **2.17.0** or greater.

### `command/bootstrap/runPubGetInParallel`

Whether to run `pub get` in parallel during bootstrapping.

The default is `true`.

### `command/version/message`

A template for the commit message, that is generated by `melos version`.
Expand Down
10 changes: 8 additions & 2 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ mixin _BootstrapMixin on _CleanMixin {
└> ${AnsiStyles.blue(printablePath(package.pathRelativeToWorkspace))}''',
);
},
parallelism: canRunPubGetConcurrently ? null : 1,
parallelism: workspace.config.commands.bootstrap.runPubGetInParallel &&
canRunPubGetConcurrently
? null
: 1,
).drain<void>();
}

Expand Down Expand Up @@ -163,7 +166,10 @@ mixin _BootstrapMixin on _CleanMixin {
);
return package;
},
parallelism: canRunPubGetConcurrently ? null : 1,
parallelism: workspace.config.commands.bootstrap.runPubGetInParallel &&
canRunPubGetConcurrently
? null
: 1,
);

Future<void> _runPubGetForPackage(
Expand Down
24 changes: 22 additions & 2 deletions packages/melos/lib/src/workspace_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ CommandConfigs(
class BootstrapCommandConfigs {
const BootstrapCommandConfigs({
this.usePubspecOverrides = false,
this.runPubGetInParallel = true,
});

factory BootstrapCommandConfigs.fromYaml(Map<Object?, Object?> yaml) {
Expand All @@ -190,8 +191,16 @@ class BootstrapCommandConfigs {
) ??
false;

final runPubGetInParallel = assertKeyIsA<bool?>(
key: 'runPubGetInParallel',
map: yaml,
path: 'command/bootstrap',
) ??
true;

return BootstrapCommandConfigs(
usePubspecOverrides: usePubspecOverrides,
runPubGetInParallel: runPubGetInParallel,
);
}

Expand All @@ -201,26 +210,37 @@ class BootstrapCommandConfigs {
/// dependencies during development.
final bool usePubspecOverrides;

/// Whether to run `pub get` in parallel during bootstrapping.
///
/// The default is `true`.
final bool runPubGetInParallel;

Map<String, Object?> toJson() {
return {
'usePubspecOverrides': usePubspecOverrides,
'runPubGetInParallel': runPubGetInParallel,
};
}

@override
bool operator ==(Object other) =>
other is BootstrapCommandConfigs &&
runtimeType == other.runtimeType &&
other.usePubspecOverrides == usePubspecOverrides;
other.usePubspecOverrides == usePubspecOverrides &&
other.runPubGetInParallel == runPubGetInParallel;

@override
int get hashCode => runtimeType.hashCode ^ usePubspecOverrides.hashCode;
int get hashCode =>
runtimeType.hashCode ^
usePubspecOverrides.hashCode ^
runPubGetInParallel.hashCode;

@override
String toString() {
return '''
BootstrapCommandConfigs(
usePubspecOverrides: $usePubspecOverrides,
runPubGetInParallel: $runPubGetInParallel,
)''';
}
}
Expand Down
18 changes: 18 additions & 0 deletions packages/melos/test/workspace_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ void main() {
expect(value.usePubspecOverrides, false);
});

test('runPubGetInParallel is optional', () {
// ignore: use_named_constants
const value = BootstrapCommandConfigs();

expect(value.runPubGetInParallel, true);
});

group('fromYaml', () {
test('accepts empty object', () {
expect(
Expand All @@ -47,15 +54,26 @@ void main() {
);
});

test('throws if runPubGetInParallel is not a bool', () {
expect(
() => BootstrapCommandConfigs.fromYaml(const {
'runPubGetInParallel': 42,
}),
throwsMelosConfigException(),
);
});

test('can decode values', () {
expect(
BootstrapCommandConfigs.fromYaml(
const {
'usePubspecOverrides': true,
'runPubGetInParallel': false,
},
),
const BootstrapCommandConfigs(
usePubspecOverrides: true,
runPubGetInParallel: false,
),
);
});
Expand Down

0 comments on commit f48e8f1

Please sign in to comment.