Handle pubspec.yaml files with no dependencies (#17195)

Currently, `flutter update-packages --force-upgrade` will
crash if it encounters a pubspec.yaml file with no dependencies
(either regular or dev). The assumption that we'd never see
such pubspec files is no longer valid, as we have such a file
in one of our tests.
This commit is contained in:
Todd Volkert 2018-05-02 21:03:37 -07:00 committed by GitHub
parent 7f0876700a
commit 29775f74fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -656,12 +656,10 @@ class PubspecYaml {
}
}
// By this point we should know where to put our transitive dependencies.
// Only if there were no dependencies or dev_dependencies sections could
// we get here with these still null, and we should not have any such files
// in our repo.
assert(endOfDirectDependencies != null);
assert(endOfDevDependencies != null);
// If there are no dependencies or dev_dependencies sections, these will be
// null. We have such files in our tests, so account for them here.
endOfDirectDependencies ??= output.length;
endOfDevDependencies ??= output.length;
// Now include all the transitive dependencies and transitive dev dependencies.
// The blocks of text to insert for each dependency section.