@@ -7,6 +7,7 @@ import 'dart:convert';
7
7
import 'dart:io' ;
8
8
9
9
import 'package:http/http.dart' ;
10
+ import 'package:path/path.dart' as p;
10
11
import 'package:pub_semver/pub_semver.dart' ;
11
12
import 'package:pubspec_parse/pubspec_parse.dart' ;
12
13
import 'package:yaml/yaml.dart' ;
@@ -31,12 +32,6 @@ class PackageExceptionDetails {
31
32
{this .description, bool missingDependency = false })
32
33
: _missingDependency = missingDependency;
33
34
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
-
40
35
static PackageExceptionDetails missingDep (
41
36
String pkgName, VersionConstraint constraint) =>
42
37
PackageExceptionDetails ._(
@@ -75,17 +70,34 @@ class PubspecLock {
75
70
76
71
static Future <PubspecLock > read () async {
77
72
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
+ }
78
89
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 ;
81
93
82
94
var packages = pubspecLock['packages' ] as YamlMap ? ;
83
95
return PubspecLock (packages);
84
96
}
85
97
86
98
List <PackageExceptionDetails > checkPackage (
87
99
String pkgName, VersionConstraint constraint,
88
- {String ? forArgument, bool requireDirect = true }) {
100
+ {String ? forArgument}) {
89
101
var issues = < PackageExceptionDetails > [];
90
102
var missingDetails =
91
103
PackageExceptionDetails .missingDep (pkgName, constraint);
@@ -95,13 +107,6 @@ class PubspecLock {
95
107
if (pkgDataMap == null ) {
96
108
issues.add (missingDetails);
97
109
} else {
98
- var dependency = pkgDataMap['dependency' ] as String ? ;
99
- if (requireDirect &&
100
- dependency != null &&
101
- ! dependency.startsWith ('direct ' )) {
102
- issues.add (missingDetails);
103
- }
104
-
105
110
var source = pkgDataMap['source' ] as String ? ;
106
111
if (source == 'hosted' ) {
107
112
// NOTE: pkgDataMap['description'] should be:
@@ -133,7 +138,6 @@ Future<List<PackageExceptionDetails>> _validateBuildDaemonVersion(
133
138
var buildDaemonIssues = pubspecLock.checkPackage (
134
139
'build_daemon' ,
135
140
VersionConstraint .parse (buildDaemonConstraint),
136
- requireDirect: false ,
137
141
);
138
142
139
143
// Only warn of build_daemon issues if they have a dependency on the package.
@@ -146,8 +150,7 @@ Future<List<PackageExceptionDetails>> _validateBuildDaemonVersion(
146
150
// used by their application.
147
151
if (info.isNewer &&
148
152
pubspecLock
149
- .checkPackage ('build_daemon' , info.buildDaemonConstraint,
150
- requireDirect: false )
153
+ .checkPackage ('build_daemon' , info.buildDaemonConstraint)
151
154
.isEmpty) {
152
155
issues.add (PackageExceptionDetails ._('$issuePreamble \n '
153
156
'A newer version of webdev is available which supports '
@@ -169,7 +172,6 @@ final buildWebCompilersConstraint = VersionConstraint.parse('^4.0.4');
169
172
Future <void > checkPubspecLock (PubspecLock pubspecLock,
170
173
{required bool requireBuildWebCompilers}) async {
171
174
var issues = < PackageExceptionDetails > [];
172
-
173
175
var buildRunnerIssues =
174
176
pubspecLock.checkPackage ('build_runner' , buildRunnerConstraint);
175
177
0 commit comments