Index: utils/pub/validator/lib.dart |
diff --git a/utils/pub/validator/lib.dart b/utils/pub/validator/lib.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..64f44c6365f5694c8468c8b73d513a0a171a7416 |
--- /dev/null |
+++ b/utils/pub/validator/lib.dart |
@@ -0,0 +1,43 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+library lib_validator; |
+ |
+import 'dart:io'; |
+ |
+import '../entrypoint.dart'; |
+import '../io.dart'; |
+import '../system_cache.dart'; |
+import '../utils.dart'; |
+import '../validator.dart'; |
+ |
+// TODO(nweiz): When issue 7196 is fixed, complain about non-Dart files in lib. |
+/// A validator that checks that libraries in "lib/" (and not "lib/src/") exist |
+/// and are well-formed. |
+class LibValidator extends Validator { |
+ LibValidator(Entrypoint entrypoint) |
+ : super(entrypoint); |
+ |
+ Future validate() { |
+ var libDir = join(entrypoint.root.dir, "lib"); |
+ return dirExists(libDir).chain((libDirExists) { |
+ if (!libDirExists) { |
+ errors.add('Your package must have a "lib/" directory so users have ' |
Bob Nystrom
2012/12/12 00:11:51
In pub install, it's only a warning if you depend
nweiz
2012/12/12 00:53:34
We decided to make this an error because there's n
|
+ 'something to import.'); |
+ return new Future.immediate(null); |
+ } |
+ |
+ return listDir(libDir).transform((files) { |
+ files = files.map((file) => relativeTo(file, libDir)); |
+ if (files.isEmpty) { |
+ errors.add('The "lib/" directory may not be empty so users have ' |
+ 'something to import'); |
+ } else if (files.length == 1 && files.first == "src") { |
+ errors.add('The "lib/" directory must contain something other than ' |
+ '"src/" so users have something to import'); |
+ } |
+ }); |
+ }); |
+ } |
+} |