|
5 | 5 | import 'dart:async'; |
6 | 6 | import 'dart:collection'; |
7 | 7 |
|
8 | | -import 'package:meta/meta.dart'; |
9 | 8 | import 'package:path/path.dart' as p; |
10 | 9 | import 'package:stack_trace/stack_trace.dart'; |
11 | 10 | import 'package:stream_transform/stream_transform.dart'; |
@@ -165,32 +164,26 @@ class _Watcher { |
165 | 164 | /// |
166 | 165 | /// Returns whether all necessary recompilations succeeded. |
167 | 166 | Future<bool> _handleAdd(String path) async { |
168 | | - var success = await _retryPotentialImports(path); |
169 | | - if (!success && _options.stopOnError) return false; |
170 | | - |
171 | 167 | var destination = _destinationFor(path); |
172 | | - if (destination == null) return true; |
173 | 168 |
|
174 | | - _graph.addCanonical( |
| 169 | + var success = destination == null || await compile(path, destination); |
| 170 | + var downstream = _graph.addCanonical( |
175 | 171 | FilesystemImporter('.'), _canonicalize(path), p.toUri(path)); |
176 | | - |
177 | | - return await compile(path, destination); |
| 172 | + return await _recompileDownstream(downstream) && success; |
178 | 173 | } |
179 | 174 |
|
180 | 175 | /// Handles a remove event for the stylesheet at [url]. |
181 | 176 | /// |
182 | 177 | /// Returns whether all necessary recompilations succeeded. |
183 | 178 | Future<bool> _handleRemove(String path) async { |
184 | 179 | var url = _canonicalize(path); |
185 | | - var success = await _retryPotentialImports(path); |
186 | | - if (!success && _options.stopOnError) return false; |
187 | | - if (!_graph.nodes.containsKey(url)) return true; |
188 | 180 |
|
189 | | - var destination = _destinationFor(path); |
190 | | - if (destination != null) _delete(destination); |
| 181 | + if (_graph.nodes.containsKey(url)) { |
| 182 | + var destination = _destinationFor(path); |
| 183 | + if (destination != null) _delete(destination); |
| 184 | + } |
191 | 185 |
|
192 | | - var downstream = _graph.nodes[url].downstream; |
193 | | - _graph.remove(url); |
| 186 | + var downstream = _graph.remove(FilesystemImporter('.'), url); |
194 | 187 | return await _recompileDownstream(downstream); |
195 | 188 | } |
196 | 189 |
|
@@ -278,56 +271,4 @@ class _Watcher { |
278 | 271 |
|
279 | 272 | return null; |
280 | 273 | } |
281 | | - |
282 | | - /// Re-runs all imports in [_graph] that might refer to [path], and recompiles |
283 | | - /// the files that contain those imports if they end up importing new |
284 | | - /// stylesheets. |
285 | | - /// |
286 | | - /// Returns whether all recompilations succeeded. |
287 | | - Future<bool> _retryPotentialImports(String path) async { |
288 | | - var name = _name(p.basename(path)); |
289 | | - var changed = <StylesheetNode>[]; |
290 | | - for (var node in _graph.nodes.values) { |
291 | | - var importChanged = false; |
292 | | - void recanonicalize(Uri url, StylesheetNode upstream, |
293 | | - {@required bool forImport}) { |
294 | | - if (_name(p.url.basename(url.path)) != name) return; |
295 | | - _graph.clearCanonicalize(url); |
296 | | - |
297 | | - // If the import produces a different canonicalized URL than it did |
298 | | - // before, it changed and the stylesheet needs to be recompiled. |
299 | | - if (!importChanged) { |
300 | | - Uri newCanonicalUrl; |
301 | | - try { |
302 | | - newCanonicalUrl = _graph.importCache |
303 | | - .canonicalize(url, |
304 | | - baseImporter: node.importer, |
305 | | - baseUrl: node.canonicalUrl, |
306 | | - forImport: forImport) |
307 | | - ?.item2; |
308 | | - } catch (_) { |
309 | | - // If the call to canonicalize failed, do nothing. We'll surface |
310 | | - // the error more nicely when we try to recompile the file. |
311 | | - } |
312 | | - importChanged = newCanonicalUrl != upstream?.canonicalUrl; |
313 | | - } |
314 | | - } |
315 | | - |
316 | | - for (var entry in node.upstream.entries) { |
317 | | - recanonicalize(entry.key, entry.value, forImport: false); |
318 | | - } |
319 | | - for (var entry in node.upstreamImports.entries) { |
320 | | - recanonicalize(entry.key, entry.value, forImport: true); |
321 | | - } |
322 | | - if (importChanged) changed.add(node); |
323 | | - } |
324 | | - |
325 | | - return await _recompileDownstream(changed); |
326 | | - } |
327 | | - |
328 | | - /// Removes an extension from [extension], and a leading underscore if it has one. |
329 | | - String _name(String basename) { |
330 | | - basename = p.withoutExtension(basename); |
331 | | - return basename.startsWith("_") ? basename.substring(1) : basename; |
332 | | - } |
333 | 274 | } |
0 commit comments