Skip to content

Commit ec14539

Browse files
authored
feat: add version constraints to update method (#37)
* feat: add version constraints to update * format
1 parent 3e69c19 commit ec14539

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/src/pub_updater.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,17 @@ class PubUpdater {
4949
Future<ProcessResult> update({
5050
required String packageName,
5151
ProcessManager processManager = const LocalProcessManager(),
52+
String? versionConstraint,
5253
}) {
5354
return processManager.run(
54-
['dart', 'pub', 'global', 'activate', packageName],
55+
[
56+
'dart',
57+
'pub',
58+
'global',
59+
'activate',
60+
packageName,
61+
if (versionConstraint != null) versionConstraint,
62+
],
5563
);
5664
}
5765

test/pub_update_test.dart

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@ class FakeProcessResult extends Fake implements ProcessResult {}
1919

2020
const emptyResponseBody = '{}';
2121

22-
const command = ['dart', 'pub', 'global', 'activate', 'very_good_cli'];
22+
const command = [
23+
'dart',
24+
'pub',
25+
'global',
26+
'activate',
27+
'very_good_cli',
28+
];
29+
const commandWithConstraint = [
30+
'dart',
31+
'pub',
32+
'global',
33+
'activate',
34+
'very_good_cli',
35+
'>=0.4.0',
36+
];
2337

2438
const customBaseUrl = 'https://custom-domain.com/api/packages/';
2539

@@ -206,6 +220,16 @@ void main() {
206220
);
207221
verify(() => processManager.run(command)).called(1);
208222
});
223+
224+
test('makes correct call to process.run with version constraint',
225+
() async {
226+
await pubUpdater.update(
227+
packageName: 'very_good_cli',
228+
processManager: processManager,
229+
versionConstraint: '>=0.4.0',
230+
);
231+
verify(() => processManager.run(commandWithConstraint)).called(1);
232+
});
209233
});
210234
});
211235
}

0 commit comments

Comments
 (0)