in lib/src/entrypoint.dart [497:579]
void assertUpToDate() {
if (isCached) return;
if (!entryExists(lockFilePath)) {
dataError(
'No $lockFilePath file found, please run "$topLevelProgram pub get" first.');
}
if (!entryExists(packageConfigFile)) {
dataError(
'No $packageConfigFile file found, please run "$topLevelProgram pub get".\n'
'\n'
'Starting with Dart 2.7, the package_config.json file configures '
'resolution of package import URIs; run "$topLevelProgram pub get" to generate it.',
);
}
// Manually parse the lockfile because a full YAML parse is relatively slow
// and this is on the hot path for "pub run".
var lockFileText = readTextFile(lockFilePath);
var hasPathDependencies = lockFileText.contains('\n source: path\n');
var pubspecModified = File(pubspecPath).lastModifiedSync();
var lockFileModified = File(lockFilePath).lastModifiedSync();
var touchedLockFile = false;
if (lockFileModified.isBefore(pubspecModified) || hasPathDependencies) {
// If `pubspec.lock` is newer than `pubspec.yaml` or we have path
// dependencies, then we check that `pubspec.lock` is a correct solution
// for the requirements in `pubspec.yaml`. This aims to:
// * Prevent missing packages when `pubspec.lock` is checked into git.
// * Mitigate missing transitive dependencies when the `pubspec.yaml` in
// a path dependency is changed.
_assertLockFileUpToDate();
if (_arePackagesAvailable()) {
touchedLockFile = true;
touch(lockFilePath);
} else {
dataError('The $pubspecPath file has changed since the $lockFilePath '
'file was generated, please run "$topLevelProgram pub get" again.');
}
}
if (fileExists(packagesFile)) {
var packagesModified = File(packagesFile).lastModifiedSync();
if (packagesModified.isBefore(lockFileModified)) {
_checkPackagesFileUpToDate();
touch(packagesFile);
} else if (touchedLockFile) {
touch(packagesFile);
}
}
var packageConfigModified = File(packageConfigFile).lastModifiedSync();
if (packageConfigModified.isBefore(lockFileModified) ||
hasPathDependencies) {
// If `package_config.json` is newer than `pubspec.lock` or we have
// path dependencies, then we check that `package_config.json` is a
// correct configuration on the local machine. This aims to:
// * Mitigate issues when copying a folder from one machine to another.
// * Force `pub get` if a path dependency has changed language verison.
_checkPackageConfigUpToDate();
touch(packageConfigFile);
} else if (touchedLockFile) {
touch(packageConfigFile);
}
for (var match in _sdkConstraint.allMatches(lockFileText)) {
var identifier = match[1] == 'sdk' ? 'dart' : match[1]!.trim();
var sdk = sdks[identifier]!;
// Don't complain if there's an SDK constraint for an unavailable SDK. For
// example, the Flutter SDK being unavailable just means that we aren't
// running from within the `flutter` executable, and we want users to be
// able to `pub run` non-Flutter tools even in a Flutter app.
if (!sdk.isAvailable) continue;
var parsedConstraint = VersionConstraint.parse(match[2]!);
if (!parsedConstraint.allows(sdk.version!)) {
dataError('${sdk.name} ${sdk.version} is incompatible with your '
"dependencies' SDK constraints. Please run \"$topLevelProgram pub get\" again.");
}
}
}