Index: utils/pub/io.dart |
diff --git a/utils/pub/io.dart b/utils/pub/io.dart |
index c622b9505ddc0b81ca2d1a5ff8d0526f0b02d519..2be46c8189aef32abc84295a46be960719546919 100644 |
--- a/utils/pub/io.dart |
+++ b/utils/pub/io.dart |
@@ -279,6 +279,44 @@ Future<File> createSymlink(from, to) { |
} |
/** |
+ * Creates a new symlink that creates an alias from the package [from] to [to], |
+ * both of which can be a [String], [File], or [Directory]. Returns a [Future] |
+ * which completes to the symlink file (i.e. [to]). |
+ * |
+ * Unlike [createSymlink], this has heuristics to detect if [from] is using |
+ * the old or new style of package layout. If it's using the new style, then |
+ * it will create a symlink to the "lib" directory contained inside that |
+ * package directory. Otherwise, it just symlinks to the package directory |
+ * itself. |
+ */ |
+// TODO(rnystrom): Remove this when old style packages are no longer supported. |
+// See: http://code.google.com/p/dart/issues/detail?id=4964. |
+Future<File> createPackageSymlink(from, to) { |
+ // If from contains any Dart files at the top level (aside from build.dart) |
+ // we assume that means it's an old style package. |
+ return listDir(from).chain((contents) { |
+ var isOldStyle = contents.some( |
+ (file) => file.endsWith('.dart') && basename(file) != 'build.dart'); |
+ |
+ if (isOldStyle) { |
nweiz
2012/09/10 19:24:47
Shouldn't we print some sort of deprecation warnin
Bob Nystrom
2012/09/11 19:36:59
I don't want to warn when a dependency has the old
|
+ return createSymlink(from, to); |
nweiz
2012/09/10 19:24:47
Style nit: avoid the extra indentation of the else
Bob Nystrom
2012/09/11 19:36:59
Done.
|
+ } else { |
+ // It's a new style package, so symlink to the 'lib' directory. But only |
+ // if the package actually *has* one. Otherwise, we won't create a |
+ // symlink at all. |
nweiz
2012/09/10 19:24:47
It seems potentially confusing to users to just si
Bob Nystrom
2012/09/11 19:36:59
Done. Prints warning.
|
+ from = join(from, 'lib'); |
+ return dirExists(from).chain((exists) { |
+ if (exists) { |
+ return createSymlink(from, to); |
+ } else { |
+ return new Future.immediate(to); |
+ } |
+ }); |
+ } |
+ }); |
+} |
+ |
+/** |
* Given [entry] which may be a [String], [File], or [Directory] relative to |
* the current working directory, returns its full canonicalized path. |
*/ |