OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library lib_validator; | 5 library lib_validator; |
6 | 6 |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 | 8 |
9 import '../entrypoint.dart'; | 9 import '../entrypoint.dart'; |
10 import '../io.dart'; | 10 import '../io.dart'; |
11 import '../system_cache.dart'; | 11 import '../system_cache.dart'; |
12 import '../utils.dart'; | 12 import '../utils.dart'; |
13 import '../validator.dart'; | 13 import '../validator.dart'; |
14 | 14 |
15 // TODO(nweiz): When issue 7196 is fixed, complain about non-Dart files in lib. | 15 // TODO(nweiz): When issue 7196 is fixed, complain about non-Dart files in lib. |
16 /// A validator that checks that libraries in "lib/" (and not "lib/src/") exist | 16 /// A validator that checks that libraries in "lib/" (and not "lib/src/") exist |
17 /// and are well-formed. | 17 /// and are well-formed. |
18 class LibValidator extends Validator { | 18 class LibValidator extends Validator { |
19 LibValidator(Entrypoint entrypoint) | 19 LibValidator(Entrypoint entrypoint) |
20 : super(entrypoint); | 20 : super(entrypoint); |
21 | 21 |
22 Future validate() { | 22 Future validate() { |
23 var libDir = join(entrypoint.root.dir, "lib"); | 23 var libDir = join(entrypoint.root.dir, "lib"); |
24 | 24 |
25 return dirExists(libDir).chain((libDirExists) { | 25 return dirExists(libDir).chain((libDirExists) { |
26 if (!libDirExists) { | 26 if (!libDirExists) { |
27 errors.add('Your package must have a "lib/" directory so users have ' | 27 errors.add('You must have a "lib" directory.\n' |
28 'something to import.'); | 28 "Without that, users cannot import any code from your package."); |
29 return new Future.immediate(null); | 29 return new Future.immediate(null); |
30 } | 30 } |
31 | 31 |
32 // TODO(rnystrom): listDir() returns real file paths after symlinks are | 32 // TODO(rnystrom): listDir() returns real file paths after symlinks are |
33 // resolved. This means if libDir contains a symlink, the resulting paths | 33 // resolved. This means if libDir contains a symlink, the resulting paths |
34 // won't appear to be within it, which confuses relativeTo(). Work around | 34 // won't appear to be within it, which confuses relativeTo(). Work around |
35 // that here by making sure we have the real path to libDir. Remove this | 35 // that here by making sure we have the real path to libDir. Remove this |
36 // when #7346 is fixed. | 36 // when #7346 is fixed. |
37 libDir = new File(libDir).fullPathSync(); | 37 libDir = new File(libDir).fullPathSync(); |
38 | 38 |
39 return listDir(libDir).transform((files) { | 39 return listDir(libDir).transform((files) { |
40 files = files.map((file) => relativeTo(file, libDir)); | 40 files = files.map((file) => relativeTo(file, libDir)); |
41 if (files.isEmpty) { | 41 if (files.isEmpty) { |
42 errors.add('The "lib/" directory may not be empty so users have ' | 42 errors.add('You must have a non-empty "lib" directory.\n' |
43 'something to import'); | 43 "Without that, users cannot import any code from your package."); |
44 } else if (files.length == 1 && files.first == "src") { | 44 } else if (files.length == 1 && files.first == "src") { |
45 errors.add('The "lib/" directory must contain something other than ' | 45 errors.add('The "lib" directory must contain something other than ' |
46 '"src/" so users have something to import'); | 46 '"src".\n' |
| 47 "Otherwise, users cannot import any code from your package."); |
47 } | 48 } |
48 }); | 49 }); |
49 }); | 50 }); |
50 } | 51 } |
51 } | 52 } |
OLD | NEW |