New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache separate canonical URLs for @use and @import #908
Conversation
lib/src/stylesheet_graph.dart
Outdated
@@ -92,14 +93,17 @@ class StylesheetGraph { | |||
|
|||
/// Returns a map from non-canonicalized imported URLs in [stylesheet], which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document the new map value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this doc comment still needs to be updated.
lib/src/stylesheet_graph.dart
Outdated
@@ -237,8 +242,9 @@ class StylesheetNode { | |||
/// stylesheets those imports refer to. | |||
/// | |||
/// This may have `null` values, which indicate failed imports. | |||
Map<Uri, StylesheetNode> get upstream => UnmodifiableMapView(_upstream); | |||
Map<Uri, StylesheetNode> _upstream; | |||
Map<Tuple2<Uri, bool>, StylesheetNode> get upstream => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's plausible that we'll want to expose this class publicly relatively soon, and I really don't want to have to break this API once we remove imports. WDYT about making upstream
refer only to @use
and @import
, and have a separate upstreamImports
field that only contains imports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. I went back and forth on whether to key on a tuple or just have two maps while I was writing this. Would it make sense to do the same in ImportCache
for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since ImportCache
's map isn't part of its public API, I think it's fine to have it stay as tuple-keyed.
lib/src/executable/watch.dart
Outdated
} | ||
} | ||
|
||
node.upstream.forEach(recanonicalize); | ||
forImport = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than using this as implicit state, I'd just pass it to recanonicalize()
. It does mean you'll have to expand those forEach()
calls, but I think the clarity of flow is worth it.
lib/src/stylesheet_graph.dart
Outdated
for (var upstream in node.upstream.values) { | ||
for (var upstream in { | ||
...node.upstream.values, | ||
...node.upstreamImports.values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use Iterable.followedBy()
here to avoid copying everything into a set eagerly. There's a possibility we'll visit a file twice, but that seems unlikely and it won't affect the result.
Similar below.
lib/src/stylesheet_graph.dart
Outdated
@@ -92,14 +93,17 @@ class StylesheetGraph { | |||
|
|||
/// Returns a map from non-canonicalized imported URLs in [stylesheet], which |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this doc comment still needs to be updated.
/// | ||
/// The first is a list of URLs from all `@use` and `@forward` rules in | ||
/// [stylesheet]. The second is a list of all imports in [stylesheet]. | ||
Tuple2<List<Uri>, List<DynamicImport>> findDependencies( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't imports represented as Uri
s as well?
lib/src/stylesheet_graph.dart
Outdated
/// A map from non-canonicalized import URLs in [stylesheet] to the | ||
/// stylesheets those imports refer to. | ||
/// A map from non-canonicalized `@use` and `@forward` URLs in [stylesheet] to | ||
/// the stylesheets those rules refer to. | ||
/// | ||
/// This may have `null` values, which indicate failed imports. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// This may have `null` values, which indicate failed imports. | |
/// This may have `null` values, which indicate failed loads. |
@nex3: Can you restart the AppVeyor build? I don't think I have permission |
Done. |
lib/src/executable/watch.dart
Outdated
@@ -288,8 +288,8 @@ class _Watcher { | |||
var changed = <StylesheetNode>[]; | |||
for (var node in _graph.nodes.values) { | |||
var importChanged = false; | |||
for (var url in node.upstream.keys) { | |||
if (_name(p.url.basename(url.path)) != name) continue; | |||
void recanonicalize(Uri url, StylesheetNode upstream, bool forImport) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit:
void recanonicalize(Uri url, StylesheetNode upstream, bool forImport) { | |
void recanonicalize(Uri url, StylesheetNode upstream, {@required bool forImport}) { |
This just helps make it clearer at the callsite what the boolean means.
Fixes #899.
The cache for canonical URLs is now keyed on both the rule URL and
whether that URL was canonicalized for an
@import
rule.