writePackageConfigFiles method
Writes the .dart_tool/package_config.json file and workspace references to it.
Compares it to the existing .dart_tool/package_config.json and does not rewrite it unless it is
Also writes the .dart_tool.package_graph.json file.
If the workspace is non-trivial: For each package in the workspace write:
.dart_tool/pub/workspace_ref.json
with a pointer to the workspace root
package dir.
Also marks the package active in PUB_CACHE/active_roots/
.
Implementation
Future<void> writePackageConfigFiles() async {
ensureDir(p.dirname(packageConfigPath));
writeTextFileIfDifferent(
packageConfigPath,
await _packageConfigFile(
cache,
entrypointSdkConstraint:
workspaceRoot
.pubspec
.sdkConstraints[sdk.identifier]
?.effectiveConstraint,
),
);
writeTextFileIfDifferent(packageGraphPath, await _packageGraphFile(cache));
if (workspaceRoot.workspaceChildren.isNotEmpty) {
for (final package in workspaceRoot.transitiveWorkspace) {
final workspaceRefDir = p.join(package.dir, '.dart_tool', 'pub');
final workspaceRefPath = p.join(workspaceRefDir, 'workspace_ref.json');
ensureDir(workspaceRefDir);
final relativeRootPath = p.relative(
workspaceRoot.dir,
from: workspaceRefDir,
);
final workspaceRef = const JsonEncoder.withIndent(
' ',
).convert({'workspaceRoot': relativeRootPath});
writeTextFileIfDifferent(workspaceRefPath, '$workspaceRef\n');
}
}
if (lockFile.packages.values.any((id) => id.source is CachedSource)) {
cache.markRootActive(packageConfigPath);
}
}