@@ -12,10 +12,11 @@ import 'package:clock/clock.dart';
1212import 'package:collection/collection.dart' ;
1313import 'package:logging/logging.dart' show Logger, Level, LogRecord;
1414import 'package:pana/pana.dart' ;
15+ // ignore: implementation_imports
16+ import 'package:pana/src/logging.dart' ;
1517import 'package:path/path.dart' as p;
1618import 'package:pub_semver/pub_semver.dart' ;
1719import 'package:pub_worker/src/bin/dartdoc_wrapper.dart' ;
18- import 'package:pub_worker/src/fetch_pubspec.dart' ;
1920import 'package:pub_worker/src/sdks.dart' ;
2021import 'package:pub_worker/src/utils.dart' ;
2122import 'package:pubspec_parse/pubspec_parse.dart' as pubspek;
@@ -54,8 +55,11 @@ Future<void> main(List<String> args) async {
5455 final pubHostedUrl =
5556 Platform .environment['PUB_HOSTED_URL' ] ?? 'https://pub.dartlang.org' ;
5657 final pubCache = Platform .environment['PUB_CACHE' ]! ;
57- final rawDartdocOutputFolder =
58- await Directory .systemTemp.createTemp ('dartdoc-$package ' );
58+ final tempDir = await Directory .systemTemp.createTemp ('pana-$package ' );
59+ final rawDartdocOutputFolder = Directory (p.join (tempDir.path, 'raw-dartdoc' ));
60+ await rawDartdocOutputFolder.create (recursive: true );
61+ final pkgDownloadDir = Directory (p.join (tempDir.path, package));
62+ await pkgDownloadDir.create (recursive: true );
5963
6064 // Setup logging
6165 Logger .root.level = Level .INFO ;
@@ -78,16 +82,24 @@ Future<void> main(List<String> args) async {
7882 }
7983 });
8084
81- // Fetch the pubspec so we detect which SDK to use for analysis
82- // TODO(https://github.com/dart-lang/pub-dev/issues/7268): Download the archive,
83- // extract and load the pubspec.yaml, that way we won't have to list versions.
84- final pubspec = await fetchPubspec (
85- package: package,
86- version: version,
87- pubHostedUrl: pubHostedUrl,
85+ // Download package using the Dart SDK in the path, output will be
86+ // `<output-dir>/<package>-<version>`
87+ await runConstrained (
88+ [
89+ 'dart' ,
90+ 'pub' ,
91+ 'unpack' ,
92+ '$package :$version ' ,
93+ '--output' ,
94+ pkgDownloadDir.path,
95+ '--no-resolve' ,
96+ ],
97+ environment: {
98+ 'PUB_HOSTED_URL' : pubHostedUrl,
99+ },
88100 );
89-
90- final detected = await _detectSdks (pubspec );
101+ final pkgDir = Directory (p. join (pkgDownloadDir.path, '$ package -$ version ' ));
102+ final detected = await _detectSdks (pkgDir.path );
91103
92104 final toolEnv = await ToolEnvironment .create (
93105 dartSdkConfig: SdkConfig (
@@ -107,11 +119,8 @@ Future<void> main(List<String> args) async {
107119 final resourcesOutputDir =
108120 await Directory (p.join (outputFolder, 'resources' )).create ();
109121 final pana = PackageAnalyzer (toolEnv);
110- // TODO: add a cache purge + retry if the download would fail
111- // (e.g. the package version cache wasn't invalidated).
112- var summary = await pana.inspectPackage (
113- package,
114- version: version,
122+ var summary = await pana.inspectDir (
123+ pkgDir.path,
115124 options: InspectOptions (
116125 pubHostedUrl: Platform .environment['PUB_HOSTED_URL' ]! ,
117126 dartdocTimeout: _dartdocTimeout,
@@ -168,7 +177,7 @@ Future<void> main(List<String> args) async {
168177 docDir: rawDartdocOutputFolder.path,
169178 );
170179
171- await rawDartdocOutputFolder .delete (recursive: true );
180+ await tempDir .delete (recursive: true );
172181}
173182
174183final _workerConfigDirectory = Directory ('/home/worker/config' );
@@ -185,7 +194,11 @@ String? _configHomePath(String sdk, String kind) {
185194}
186195
187196Future <({String configKind, String ? dartSdkPath, String ? flutterSdkPath})>
188- _detectSdks (Pubspec pubspec) async {
197+ _detectSdks (String pkgDir) async {
198+ // Load the pubspec so we detect which SDK to use for analysis
199+ final pubspecFile = File (p.join (pkgDir, 'pubspec.yaml' ));
200+ final pubspec = Pubspec .parseYaml (await pubspecFile.readAsString ());
201+
189202 // Discover installed Dart and Flutter SDKs.
190203 // This reads sibling folders to the Dart and Flutter SDK.
191204 final dartSdks = await InstalledSdk .scanDirectory (
@@ -266,6 +279,8 @@ Future<({String configKind, String? dartSdkPath, String? flutterSdkPath})>
266279 allowsMissingVersion: true ,
267280 );
268281 if (matchesInstalledSdks) {
282+ // TODO(https://github.com/dart-lang/pub-dev/issues/7268): Also use `pub get` for better SDK selection.
283+
269284 return (
270285 configKind: 'stable' ,
271286 dartSdkPath: installedDartSdk? .path,
0 commit comments