agentSdkInLockfile function
The locked SDK version and the platform suffixes it ships a CLI for, read
from a package-lock.json's text. Null when the lockfile does not lock the
SDK.
Implementation
({String? version, Set<String> platforms})? agentSdkInLockfile(
String lockfile,
) {
final Object? decoded;
try {
decoded = jsonDecode(lockfile);
} on FormatException {
return null;
}
if (decoded is! Map) return null;
final packages = decoded['packages'];
if (packages is! Map) return null;
final sdk = packages['node_modules/$_sdkScope/$_sdkName'];
if (sdk is! Map) return null;
final optional = sdk['optionalDependencies'];
final platforms = <String>{
if (optional is Map)
for (final name in optional.keys.cast<String>())
if (name.startsWith('$_sdkScope/$_sdkName-'))
name.substring('$_sdkScope/$_sdkName-'.length),
};
final version = sdk['version'];
return (version: version is String ? version : null, platforms: platforms);
}