withUpdatedPubspecs method
Creates an entrypoint at the same location, but with each pubspec in
updatedPubspec
replacing the with one for the corresponding package.
Implementation
Entrypoint withUpdatedPubspecs(Map<Package, Pubspec> updatedPubspecs) {
final existingPubspecs = <String, Pubspec>{};
// First extract all pubspecs from the workspace.
for (final package in workspaceRoot.transitiveWorkspace) {
existingPubspecs[package.dir] =
updatedPubspecs[package] ?? package.pubspec;
}
final newWorkspaceRoot = Package.load(
workspaceRoot.dir,
cache.sources,
loadPubspec: (
dir, {
expectedName,
required withPubspecOverrides,
}) =>
existingPubspecs[dir] ??
Pubspec.load(
dir,
cache.sources,
containingDescription: RootDescription(dir),
),
);
final newWorkPackage = newWorkspaceRoot.transitiveWorkspace
.firstWhere((package) => package.dir == workPackage.dir);
return Entrypoint._(
workingDir,
_lockFile,
_example,
_packageGraph,
cache,
(root: newWorkspaceRoot, work: newWorkPackage),
isCachedGlobal,
);
}