@@ -7,6 +7,7 @@ import 'dart:convert';
77import 'dart:io' ;
88
99import 'package:http/http.dart' ;
10+ import 'package:path/path.dart' as p;
1011import 'package:pub_semver/pub_semver.dart' ;
1112import 'package:pubspec_parse/pubspec_parse.dart' ;
1213import 'package:yaml/yaml.dart' ;
@@ -31,12 +32,6 @@ class PackageExceptionDetails {
3132 {this .description, bool missingDependency = false })
3233 : _missingDependency = missingDependency;
3334
34- static const noPubspecLock =
35- PackageExceptionDetails ._('`pubspec.lock` does not exist.' ,
36- description: 'Run `$appName ` in a Dart package directory. '
37- 'Run `dart pub get` first.' ,
38- missingDependency: true );
39-
4035 static PackageExceptionDetails missingDep (
4136 String pkgName, VersionConstraint constraint) =>
4237 PackageExceptionDetails ._(
@@ -75,17 +70,34 @@ class PubspecLock {
7570
7671 static Future <PubspecLock > read () async {
7772 await _runPubDeps ();
73+ var dir = p.absolute (p.current);
74+ while (true ) {
75+ final candidate = p.join (
76+ dir,
77+ '.dart_tool' ,
78+ 'package_config.json' ,
79+ );
80+ if (File (candidate).existsSync ()) break ;
81+ final next = p.dirname (dir);
82+ if (next == dir) {
83+ // Give up.
84+ dir = p.current;
85+ break ;
86+ }
87+ dir = next;
88+ }
7889
79- var pubspecLock =
80- loadYaml (await File ('pubspec.lock' ).readAsString ()) as YamlMap ;
90+ var pubspecLock = loadYaml (
91+ await File (p.relative (p.join (dir, 'pubspec.lock' ))).readAsString ())
92+ as YamlMap ;
8193
8294 var packages = pubspecLock['packages' ] as YamlMap ? ;
8395 return PubspecLock (packages);
8496 }
8597
8698 List <PackageExceptionDetails > checkPackage (
8799 String pkgName, VersionConstraint constraint,
88- {String ? forArgument, bool requireDirect = true }) {
100+ {String ? forArgument}) {
89101 var issues = < PackageExceptionDetails > [];
90102 var missingDetails =
91103 PackageExceptionDetails .missingDep (pkgName, constraint);
@@ -95,13 +107,6 @@ class PubspecLock {
95107 if (pkgDataMap == null ) {
96108 issues.add (missingDetails);
97109 } else {
98- var dependency = pkgDataMap['dependency' ] as String ? ;
99- if (requireDirect &&
100- dependency != null &&
101- ! dependency.startsWith ('direct ' )) {
102- issues.add (missingDetails);
103- }
104-
105110 var source = pkgDataMap['source' ] as String ? ;
106111 if (source == 'hosted' ) {
107112 // NOTE: pkgDataMap['description'] should be:
@@ -133,7 +138,6 @@ Future<List<PackageExceptionDetails>> _validateBuildDaemonVersion(
133138 var buildDaemonIssues = pubspecLock.checkPackage (
134139 'build_daemon' ,
135140 VersionConstraint .parse (buildDaemonConstraint),
136- requireDirect: false ,
137141 );
138142
139143 // Only warn of build_daemon issues if they have a dependency on the package.
@@ -146,8 +150,7 @@ Future<List<PackageExceptionDetails>> _validateBuildDaemonVersion(
146150 // used by their application.
147151 if (info.isNewer &&
148152 pubspecLock
149- .checkPackage ('build_daemon' , info.buildDaemonConstraint,
150- requireDirect: false )
153+ .checkPackage ('build_daemon' , info.buildDaemonConstraint)
151154 .isEmpty) {
152155 issues.add (PackageExceptionDetails ._('$issuePreamble \n '
153156 'A newer version of webdev is available which supports '
@@ -169,7 +172,6 @@ final buildWebCompilersConstraint = VersionConstraint.parse('^4.0.4');
169172Future <void > checkPubspecLock (PubspecLock pubspecLock,
170173 {required bool requireBuildWebCompilers}) async {
171174 var issues = < PackageExceptionDetails > [];
172-
173175 var buildRunnerIssues =
174176 pubspecLock.checkPackage ('build_runner' , buildRunnerConstraint);
175177
0 commit comments