Skip to content

Commit

Permalink
Handle missing pubspec.lock in dependency_services list (#3439)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigurdm authored May 30, 2022
1 parent 0ad17e8 commit 6f20a94
Show file tree
Hide file tree
Showing 3 changed files with 245 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/src/command/dependency_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class DependencyServicesListCommand extends PubCommand {
final dependencies = <Object>[];
final result = <String, Object>{'dependencies': dependencies};

for (final package in currentPackages) {
for (final package in currentPackages.where((p) => !p.isRoot)) {
dependencies.add({
'name': package.name,
'version': package.versionOrHash(),
Expand Down
42 changes: 39 additions & 3 deletions test/dependency_services/dependency_services_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ import '../test_pub.dart';

void manifestAndLockfile(GoldenTestContext context) {
String catFile(String filename) {
final contents = filterUnstableLines(
File(p.join(d.sandbox, appPath, filename)).readAsLinesSync());
final path = p.join(d.sandbox, appPath, filename);
if (File(path).existsSync()) {
final contents = filterUnstableLines(File(path).readAsLinesSync());

return '''
return '''
\$ cat $filename
${contents.join('\n')}''';
} else {
return '''
\$ cat $filename
No such file $filename.''';
}
}

context.expectNextSection('''
Expand Down Expand Up @@ -141,6 +147,36 @@ Future<void> main() async {
});
});

testWithGolden('No pubspec.lock', (context) async {
final server = (await servePackages())
..serve('foo', '1.2.3', deps: {'transitive': '^1.0.0'})
..serve('foo', '2.2.3')
..serve('transitive', '1.0.0');

await d.git('bar.git', [d.libPubspec('bar', '1.0.0')]).create();

await d.dir(appPath, [
d.pubspec({
'name': 'app',
'dependencies': {
'foo': '^1.0.0',
'bar': {
'git': {'url': '../bar.git'},
},
},
})
]).create();

server.dontAllowDownloads();
await listReportApply(
context,
[
_PackageVersion('foo', '2.2.3'),
_PackageVersion('transitive', null),
],
);
});

testWithGolden('Compatible', (context) async {
final server = (await servePackages())
..serve('foo', '1.2.3')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# GENERATED BY: test/dependency_services/dependency_services_test.dart

$ cat pubspec.yaml
{"name":"app","dependencies":{"foo":"^1.0.0","bar":{"git":{"url":"../bar.git"}}},"environment":{"sdk":">=0.1.2 <1.0.0"}}
$ cat pubspec.lock
No such file pubspec.lock.
-------------------------------- END OF OUTPUT ---------------------------------

## Section list
$ dependency_services list
{
"dependencies": [
{
"name": "bar",
"version": "92cdd4ac724a6da0db2a69ac149820aa220e8518",
"kind": "direct",
"constraint": "any",
"source": {
"type": "git",
"description": {
"url": "../bar.git",
"ref": "HEAD",
"resolved-ref": "92cdd4ac724a6da0db2a69ac149820aa220e8518",
"path": "."
}
}
},
{
"name": "foo",
"version": "1.2.3",
"kind": "direct",
"constraint": "^1.0.0",
"source": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
}
},
{
"name": "transitive",
"version": "1.0.0",
"kind": "transitive",
"constraint": "null",
"source": {
"type": "hosted",
"description": {
"name": "transitive",
"url": "http://localhost:$PORT"
}
}
}
]
}

-------------------------------- END OF OUTPUT ---------------------------------

## Section report
$ dependency_services report
{
"dependencies": [
{
"name": "bar",
"version": "92cdd4ac724a6da0db2a69ac149820aa220e8518",
"kind": "direct",
"source": {
"type": "git",
"description": {
"url": "../bar.git",
"ref": "HEAD",
"resolved-ref": "92cdd4ac724a6da0db2a69ac149820aa220e8518",
"path": "."
}
},
"latest": "92cdd4ac724a6da0db2a69ac149820aa220e8518",
"constraint": "any",
"compatible": [],
"singleBreaking": [],
"multiBreaking": [
{
"name": "foo",
"version": "2.2.3",
"kind": "direct",
"source": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
},
"constraintBumped": "^2.2.3",
"constraintWidened": ">=1.0.0 <3.0.0",
"constraintBumpedIfNeeded": "^2.2.3",
"previousVersion": "1.2.3",
"previousConstraint": "^1.0.0",
"previousSource": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
}
}
]
},
{
"name": "foo",
"version": "1.2.3",
"kind": "direct",
"source": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
},
"latest": "2.2.3",
"constraint": "^1.0.0",
"compatible": [],
"singleBreaking": [
{
"name": "foo",
"version": "2.2.3",
"kind": "direct",
"source": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
},
"constraintBumped": "^2.2.3",
"constraintWidened": ">=1.0.0 <3.0.0",
"constraintBumpedIfNeeded": "^2.2.3",
"previousVersion": "1.2.3",
"previousConstraint": "^1.0.0",
"previousSource": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
}
}
],
"multiBreaking": [
{
"name": "foo",
"version": "2.2.3",
"kind": "direct",
"source": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
},
"constraintBumped": "^2.2.3",
"constraintWidened": ">=1.0.0 <3.0.0",
"constraintBumpedIfNeeded": "^2.2.3",
"previousVersion": "1.2.3",
"previousConstraint": "^1.0.0",
"previousSource": {
"type": "hosted",
"description": {
"name": "foo",
"url": "http://localhost:$PORT"
}
}
}
]
},
{
"name": "transitive",
"version": "1.0.0",
"kind": "transitive",
"source": {
"type": "hosted",
"description": {
"name": "transitive",
"url": "http://localhost:$PORT"
}
},
"latest": "1.0.0",
"constraint": null,
"compatible": [],
"singleBreaking": [],
"multiBreaking": []
}
]
}

-------------------------------- END OF OUTPUT ---------------------------------

## Section apply
$ echo '{"dependencyChanges":[{"name":"foo","version":"2.2.3"},{"name":"transitive","version":null}]}' | dependency_services apply
{"dependencies":[]}

-------------------------------- END OF OUTPUT ---------------------------------

$ cat pubspec.yaml
{"name":"app","dependencies":{"foo":^2.2.3,"bar":{"git":{"url":"../bar.git"}}},"environment":{"sdk":">=0.1.2 <1.0.0"}}
$ cat pubspec.lock
No such file pubspec.lock.

0 comments on commit 6f20a94

Please sign in to comment.