Skip to content

Commit

Permalink
Simplified routine to build the pub execution command and added tests…
Browse files Browse the repository at this point in the history
… for it
  • Loading branch information
acoutts committed Apr 28, 2022
1 parent 7a9a915 commit ca2d3a8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 22 deletions.
46 changes: 24 additions & 22 deletions packages/melos/lib/src/commands/bootstrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,10 @@ mixin _BootstrapMixin on _CleanMixin {
Package package, {
bool inTemporaryProject = false,
}) async {
late final List<String> execArgs;

if (workspace.sdkPath.isNotEmpty) {
/// Custom sdkpath, provide the appropriate paths
execArgs = <String>[
if (package.isFlutterApp)
'${workspace.sdkPath}flutter'
else if (utils.isPubSubcommand(sdkPath: workspace.sdkPath))
'${workspace.sdkPath}dart',
'pub',
'get',
];
} else {
execArgs = <String>[
if (package.isFlutterApp)
'flutter'
else if (utils.isPubSubcommand(sdkPath: workspace.sdkPath))
'dart',
'pub',
'get',
];
}
final execArgs = getPubCommandExecArgs(
isFlutterApp: package.isFlutterApp,
sdkPath: workspace.sdkPath,
);

final executable = currentPlatform.isWindows ? 'cmd' : '/bin/sh';
final packagePath = inTemporaryProject
Expand Down Expand Up @@ -425,6 +407,26 @@ final _managedDependencyOverridesRegex = RegExp(
multiLine: true,
);

/// Given a workspace and package, this assembles the correct command
/// to run pub get.
/// Takes into account a potential sdk path being provided.
/// If no sdk path is provided then it will assume to use the pub
/// command available in PATH.
@visibleForTesting
List<String> getPubCommandExecArgs({
required bool isFlutterApp,
required String? sdkPath,
}) {
return [
if (isFlutterApp)
'${sdkPath ?? ''}flutter'
else if (utils.isPubSubcommand(sdkPath: sdkPath))
'${sdkPath ?? ''}dart',
'pub',
'get',
];
}

/// Merges the [melosDependencyOverrides] for other workspace packages into the
/// `pubspec_overrides.yaml` file for a package.
///
Expand Down
24 changes: 24 additions & 0 deletions packages/melos/test/commands/bootstrap_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,30 @@ e-Because a depends on package_that_does_not_exists any which doesn't exist (cou
test('can disable IDE generation using melos config', () {}, skip: true);

test('can supports package filter', () {}, skip: true);

group('getPubCommandExecArgs', () {
test('no sdk path specified', () {
final res = getPubCommandExecArgs(
sdkPath: null,
isFlutterApp: true,
);
expect(
res,
['flutter', 'pub', 'get'],
);
});

test('with sdk path specified', () {
final res = getPubCommandExecArgs(
sdkPath: '/users/test-user/projects/flutter/bin/',
isFlutterApp: true,
);
expect(
res,
['/users/test-user/projects/flutter/bin/flutter', 'pub', 'get'],
);
});
});
});
}

Expand Down

0 comments on commit ca2d3a8

Please sign in to comment.