in lib/src/package_analyzer.dart [95:203]
Future<Summary> _inspect(String pkgDir, InspectOptions options) async {
final context = PackageContext(
toolEnvironment: _toolEnv,
packageDir: pkgDir,
options: options,
urlChecker: _urlChecker,
);
final dartFiles = <String>[];
final fileList = listFiles(pkgDir, deleteBadExtracted: true);
await for (final file in fileList) {
final isInBin = path.isWithin('bin', file);
final isInLib = path.isWithin('lib', file);
final isDart = file.endsWith('.dart');
if (isDart && (isInLib || isInBin)) {
dartFiles.add(file);
}
}
Pubspec? pubspec;
try {
pubspec = context.pubspec;
} catch (e, st) {
log.info('Unable to read pubspec.yaml', e, st);
return Summary(
runtimeInfo: _toolEnv.runtimeInfo,
packageName: null,
packageVersion: null,
pubspec: pubspec,
allDependencies: null,
licenseFile: null,
tags: null,
report: null,
errorMessage: pubspecParseError(e),
);
}
if (pubspec.hasUnknownSdks) {
context.errors.add('The following unknown SDKs are in `pubspec.yaml`:\n'
' `${pubspec.unknownSdks}`.\n\n'
'`pana` doesn’t recognize them; please remove the `sdk` entry or '
'[report the issue](https://github.com/dart-lang/pana/issues).');
}
final pkgResolution = await context.resolveDependencies();
if (pkgResolution != null && options.dartdocOutputDir != null) {
for (var i = 0; i <= options.dartdocRetry; i++) {
try {
final r = await _toolEnv.dartdoc(
pkgDir,
options.dartdocOutputDir!,
validateLinks: i == 0,
timeout: options.dartdocTimeout,
);
if (!r.wasTimeout) {
break;
}
} catch (e, st) {
log.severe('Could not run dartdoc.', e, st);
}
}
}
final tags = <String>[];
if (pkgResolution != null) {
List<CodeProblem>? analyzerItems;
if (dartFiles.isNotEmpty) {
try {
analyzerItems = await context.staticAnalysis();
} on ToolException catch (e) {
context.errors
.add(runningDartanalyzerFailed(context.usesFlutter, e.message));
}
} else {
analyzerItems = <CodeProblem>[];
}
if (analyzerItems != null && !analyzerItems.any((item) => item.isError)) {
final tagger = Tagger(pkgDir);
final explanations = <Explanation>[];
tagger.sdkTags(tags, explanations);
tagger.platformTags(tags, explanations);
tagger.runtimeTags(tags, explanations);
tagger.flutterPluginTags(tags, explanations);
tagger.nullSafetyTags(tags, explanations);
}
}
final licenseFile = await detectLicenseInDir(pkgDir);
final errorMessage = context.errors.isEmpty
? null
: context.errors.map((e) => e.trim()).join('\n\n');
return Summary(
runtimeInfo: _toolEnv.runtimeInfo,
packageName: pubspec.name,
packageVersion: pubspec.version,
pubspec: pubspec,
allDependencies:
pkgResolution?.dependencies.map((d) => d.package).toList(),
licenseFile: licenseFile,
tags: tags,
report: await createReport(context),
urlProblems: context.urlProblems.entries
.map((e) => UrlProblem(url: e.key, problem: e.value))
.toList()
..sort((a, b) => a.url.compareTo(b.url)),
errorMessage: errorMessage,
);
}