projectResolutionDirectory property

FutureOr<Directory> get projectResolutionDirectory

The directory where dart pub get writes the resolution of the project (pubspec.lock and .dart_tool/package_config.json).

Usually this is the projectDirectory itself. For a member of a pub workspace (resolution: workspace in its pubspec.yaml) it is the workspace root: the nearest ancestor directory that holds .dart_tool/package_config.json. If no ancestor holds it yet (pub get not run), the projectDirectory is returned.

Implementation

FutureOr<Directory> get projectResolutionDirectory =>
    projectDirectory.resolveMapped((projDir) {
      if (_hasPackageConfig(projDir) || !_isWorkspaceMember(projDir)) {
        return projDir;
      }

      var dir = projDir.parent;
      while (true) {
        if (_hasPackageConfig(dir)) {
          log('INFO', 'Resolved workspace root: $dir');
          return dir;
        }
        var parent = dir.parent;
        if (parent.path == dir.path) break;
        dir = parent;
      }

      return projDir;
    });