writePackageConfigFile method

Future<void> writePackageConfigFile()

Writes the .dart_tool/package_config.json file and workspace references to it.

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.

Implementation

Future<void> writePackageConfigFile() async {
  ensureDir(p.dirname(packageConfigPath));
  writeTextFile(
    packageConfigPath,
    await _packageConfigFile(
      cache,
      entrypointSdkConstraint: workspaceRoot
          .pubspec.sdkConstraints[sdk.identifier]?.effectiveConstraint,
    ),
  );
  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);
      writeTextFile(
        workspaceRefPath,
        '${const JsonEncoder.withIndent('  ').convert({
              'workspaceRoot': relativeRootPath,
            })}\n',
      );
    }
  }
}