Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add runPubGetOffline option #326

Merged
merged 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ Whether to run `pub get` in parallel during bootstrapping.

The default is `true`.

### `command/bootstrap/runPubGetOffline`

Whether to attempt to run `pub get` in offline mode during bootstrapping.

Useful in closed network environments with pre-populated pubcaches.

The default is `false`.

### `command/version/message`

A template for the commit message, that is generated by `melos version`.
Expand Down
4 changes: 3 additions & 1 deletion packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ mixin _BootstrapMixin on _CleanMixin {
useFlutter: workspace.isFlutterWorkspace,
workspace: workspace,
),
'get'
'get',
if (workspace.config.commands.bootstrap.runPubGetOffline) '--offline'
].join(' ');

logger
Expand Down Expand Up @@ -177,6 +178,7 @@ mixin _BootstrapMixin on _CleanMixin {
workspace: workspace,
),
'get',
if (workspace.config.commands.bootstrap.runPubGetOffline) '--offline'
];

final executable = currentPlatform.isWindows ? 'cmd' : '/bin/sh';
Expand Down
23 changes: 21 additions & 2 deletions packages/melos/lib/src/workspace_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class BootstrapCommandConfigs {
const BootstrapCommandConfigs({
this.usePubspecOverrides = false,
this.runPubGetInParallel = true,
this.runPubGetOffline = false,
});

factory BootstrapCommandConfigs.fromYaml(Map<Object?, Object?> yaml) {
Expand All @@ -198,9 +199,17 @@ class BootstrapCommandConfigs {
) ??
true;

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

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

Expand All @@ -215,10 +224,17 @@ class BootstrapCommandConfigs {
/// The default is `true`.
final bool runPubGetInParallel;

/// Whether to attempt to run `pub get` in offline mode during bootstrapping.
/// Useful in closed network environments with pre-populated pubcaches.
///
/// The default is `false`.
final bool runPubGetOffline;

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

Expand All @@ -227,20 +243,23 @@ class BootstrapCommandConfigs {
other is BootstrapCommandConfigs &&
runtimeType == other.runtimeType &&
other.usePubspecOverrides == usePubspecOverrides &&
other.runPubGetInParallel == runPubGetInParallel;
other.runPubGetInParallel == runPubGetInParallel &&
other.runPubGetOffline == runPubGetOffline;

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

@override
String toString() {
return '''
BootstrapCommandConfigs(
usePubspecOverrides: $usePubspecOverrides,
runPubGetInParallel: $runPubGetInParallel,
runPubGetOffline: $runPubGetOffline,
)''';
}
}
Expand Down
53 changes: 53 additions & 0 deletions packages/melos/test/commands/bootstrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:test/test.dart';

import '../matchers.dart';
import '../utils.dart';
import '../workspace_config_test.dart';

io.Directory createTmpDir() {
final dir = io.Directory.systemTemp.createTempSync();
Expand Down Expand Up @@ -575,6 +576,58 @@ e-Because a depends on package_that_does_not_exists any which doesn't exist (cou
);
});

test('can run pub get offline', () async {
final workspaceDir = createTemporaryWorkspaceDirectory(
configBuilder: (path) => MelosWorkspaceConfig.fromYaml(
createYamlMap(
{
'command': {
'bootstrap': {
'runPubGetOffline': true,
},
},
},
defaults: configMapDefaults,
),
path: path,
),
);

final logger = TestLogger();
final config = await MelosWorkspaceConfig.fromDirectory(workspaceDir);
final workspace = await MelosWorkspace.fromConfig(
config,
logger: logger.toMelosLogger(),
);
final melos = Melos(logger: logger, config: config);
final pubExecArgs = pubCommandExecArgs(
useFlutter: workspace.isFlutterWorkspace,
workspace: workspace,
);

await runMelosBootstrap(melos, logger);

expect(
logger.output,
ignoringAnsii(
'''
melos bootstrap
└> ${workspaceDir.path}

Running "${pubExecArgs.join(' ')} get --offline" in workspace packages...

Linking workspace packages...
> SUCCESS

Generating IntelliJ IDE files...
> SUCCESS

-> 0 packages bootstrapped
''',
),
);
});

test('can disable IDE generation using melos config', () {}, skip: true);

test('can supports package filter', () {}, skip: true);
Expand Down
15 changes: 15 additions & 0 deletions packages/melos/test/workspace_config_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@ void main() {
);
});

test('can decode `bootstrap` with pub get offline', () {
expect(
CommandConfigs.fromYaml(const {
'bootstrap': {
'runPubGetOffline': true,
}
}),
const CommandConfigs(
bootstrap: BootstrapCommandConfigs(
runPubGetOffline: true,
),
),
);
});

test('can decode `version`', () {
expect(
CommandConfigs.fromYaml(const {
Expand Down