resolveIfUnresolved function
Makes sure projectPath resolves, and returns what is wrong, or null.
Runs dart pub get --offline — about a second, no network, no writes when
the resolution is current — and, only if that fails, dart pub get, which
may download what the cache lost. A failure returns pub's own message,
which names the real cause (version solving failed, a missing path
dependency) instead of a downstream symptom. After a successful resolve,
resolutionProblems must come back empty.
checkBridgeFreshness refuses an unresolved package, because resolving
writes to it. A test of its own examples may resolve them as a setup step,
as D4rtTester.prepareBridges does: what pub get writes — .dart_tool/
and pubspec.lock — is gitignored in this workspace.
Implementation
Future<String?> resolveIfUnresolved(String projectPath) async {
final before = resolutionProblems(projectPath);
var result = await _pubGet(projectPath, offline: true);
if (result.exitCode != 0) {
result = await _pubGet(projectPath, offline: false);
}
if (result.exitCode != 0) {
return [
'`dart pub get` failed in $projectPath:',
'${result.stderr}'.trim(),
if (before.isNotEmpty) ...[
'Its package config was already broken:',
...before.map((problem) => ' $problem'),
],
].join('\n');
}
final after = resolutionProblems(projectPath);
if (after.isEmpty) return null;
return [
'$projectPath resolved, but its package config is still broken:',
...after.map((problem) => ' $problem'),
].join('\n');
}