Skip to content

Commit 9b21c14

Browse files
authored
Look for Flutter packages in bin/cache/pkg/ as well as packages/ (#1778)
Closes #1775
1 parent ca0d52f commit 9b21c14

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/src/flutter.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ final Version version = () {
2626
}();
2727

2828
/// Returns the path to the package [name] within Flutter.
29+
///
30+
/// Flutter packages exist in both `$flutter/packages` and
31+
/// `$flutter/bin/cache/pkg`. This checks both locations in order. If [name]
32+
/// exists in neither place, it returns the `$flutter/packages` location which
33+
/// is more human-readable for error messages.
2934
String packagePath(String name) {
3035
if (!isAvailable) {
3136
throw new ApplicationException(
@@ -34,5 +39,11 @@ String packagePath(String name) {
3439
'pub through the "flutter" executable.');
3540
}
3641

37-
return p.join(rootDirectory, 'packages', name);
42+
var packagePath = p.join(rootDirectory, 'packages', name);
43+
if (dirExists(packagePath)) return packagePath;
44+
45+
var cachePath = p.join(rootDirectory, 'bin', 'cache', 'pkg', name);
46+
if (dirExists(cachePath)) return cachePath;
47+
48+
return packagePath;
3849
}

test/sdk_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ main() {
2424
d.libDir('foo', 'foo 0.0.1'),
2525
d.libPubspec('foo', '0.0.1', deps: {'bar': 'any'})
2626
])
27+
]),
28+
d.dir('bin/cache/pkg', [
29+
d.dir('baz',
30+
[d.libDir('baz', 'foo 0.0.1'), d.libPubspec('baz', '0.0.1')])
2731
])
2832
]).create();
2933
});
@@ -44,6 +48,21 @@ main() {
4448
]).validate();
4549
});
4650

51+
test("gets an SDK dependency from bin/cache/pkg", () async {
52+
await d.appDir({
53+
"baz": {"sdk": "flutter"}
54+
}).create();
55+
await pubCommand(command,
56+
environment: {'FLUTTER_ROOT': p.join(d.sandbox, 'flutter')});
57+
58+
await d.dir(appPath, [
59+
d.packagesFile({
60+
'myapp': '.',
61+
'baz': p.join(d.sandbox, 'flutter', 'bin', 'cache', 'pkg', 'baz')
62+
})
63+
]).validate();
64+
});
65+
4766
test("unlocks an SDK dependency when the version changes", () async {
4867
await d.appDir({
4968
"foo": {"sdk": "flutter"}

0 commit comments

Comments
 (0)