Commit 9a0a0d99 authored by John McCutchan's avatar John McCutchan Committed by GitHub

Fix package:<project_package> imports in hot reload mode (#5372)

parent 3e82d328
...@@ -306,18 +306,26 @@ class DevFS { ...@@ -306,18 +306,26 @@ class DevFS {
for (String packageName in packageMap.map.keys) { for (String packageName in packageMap.map.keys) {
Uri uri = packageMap.map[packageName]; Uri uri = packageMap.map[packageName];
// Ignore self-references. // This project's own package.
if (uri.toString() == 'lib/') final bool isProjectPackage = uri.toString() == 'lib/';
continue; final String directoryName =
isProjectPackage ? 'lib' : 'packages/$packageName';
// If this is the project's package, we need to pass both
// package:<package_name> and lib/ as paths to be checked against
// the filter because we must support both package: imports and relative
// path imports within the project's own code.
final String packagesDirectoryName =
isProjectPackage ? 'packages/$packageName' : null;
Directory directory = new Directory.fromUri(uri); Directory directory = new Directory.fromUri(uri);
bool packageExists = bool packageExists =
await _scanDirectory(directory, await _scanDirectory(directory,
directoryName: 'packages/$packageName', directoryName: directoryName,
recursive: true, recursive: true,
packagesDirectoryName: packagesDirectoryName,
fileFilter: fileFilter); fileFilter: fileFilter);
if (packageExists) { if (packageExists) {
sb ??= new StringBuffer(); sb ??= new StringBuffer();
sb.writeln('$packageName:packages/$packageName'); sb.writeln('$packageName:$directoryName');
} }
} }
} }
...@@ -460,6 +468,7 @@ class DevFS { ...@@ -460,6 +468,7 @@ class DevFS {
{String directoryName, {String directoryName,
bool recursive: false, bool recursive: false,
bool ignoreDotFiles: true, bool ignoreDotFiles: true,
String packagesDirectoryName,
Set<String> fileFilter}) async { Set<String> fileFilter}) async {
String prefix = directoryName; String prefix = directoryName;
if (prefix == null) { if (prefix == null) {
...@@ -479,10 +488,26 @@ class DevFS { ...@@ -479,10 +488,26 @@ class DevFS {
// Skip dot files. // Skip dot files.
continue; continue;
} }
final String devicePath = final String relativePath =
path.join(prefix, path.relative(file.path, from: directory.path)); path.relative(file.path, from: directory.path);
final String devicePath = path.join(prefix, relativePath);
bool filtered = false;
if ((fileFilter != null) && if ((fileFilter != null) &&
!fileFilter.contains(devicePath)) { !fileFilter.contains(devicePath)) {
if (packagesDirectoryName != null) {
// Double check the filter for packages/packagename/
final String packagesDevicePath =
path.join(packagesDirectoryName, relativePath);
if (!fileFilter.contains(packagesDevicePath)) {
// File was not in the filter set.
filtered = true;
}
} else {
// File was not in the filter set.
filtered = true;
}
}
if (filtered) {
// Skip files that are not included in the filter. // Skip files that are not included in the filter.
continue; continue;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment