From 4d78316cb7da3f71ffc9901e684349a5e3e5cf28 Mon Sep 17 00:00:00 2001 From: georgpukk Date: Wed, 11 Mar 2020 23:48:00 +0200 Subject: [PATCH] Fix a check that prevents compiling .css files to themselves (#968) Co-Authored-By: Natalie Weizenbaum --- CHANGELOG.md | 5 +++++ lib/src/executable/watch.dart | 2 +- pubspec.yaml | 2 +- test/cli/shared/watch.dart | 28 ++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddac713a..5d1f0099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.26.3 + +* Fix a bug where `--watch` mode could go into an infinite loop compiling CSS + files to themselves. + ## 1.26.2 * More aggressively eliminate redundant selectors in the `selector.extend()` and diff --git a/lib/src/executable/watch.dart b/lib/src/executable/watch.dart index 48dd37d7..7f40e00f 100644 --- a/lib/src/executable/watch.dart +++ b/lib/src/executable/watch.dart @@ -267,7 +267,7 @@ class _Watcher { p.setExtension(p.relative(source, from: sourceDir), '.css')); // Don't compile ".css" files to their own locations. - if (destination != source) return destination; + if (!p.equals(destination, source)) return destination; } return null; diff --git a/pubspec.yaml b/pubspec.yaml index dfc90747..15b23bcc 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.26.2 +version: 1.26.3 description: A Sass implementation in Dart. author: Sass Team homepage: https://github.com/sass/dart-sass diff --git a/test/cli/shared/watch.dart b/test/cli/shared/watch.dart index 0f6ff10d..bc95936c 100644 --- a/test/cli/shared/watch.dart +++ b/test/cli/shared/watch.dart @@ -173,6 +173,34 @@ void sharedTests(Future runSass(Iterable arguments)) { ]).validate(); }); + test( + "when it's modified twice when watched from a directory that is " + "also a destination", () async { + await d.file("test.scss", "a {b: c}").create(); + + var sass = await watch(["."]); + await expectLater( + sass.stdout, emits('Compiled test.scss to test.css.')); + await expectLater(sass.stdout, _watchingForChanges); + await tickIfPoll(); + + await d.file("test.scss", "r {o: g}").create(); + await expectLater( + sass.stdout, emits('Compiled test.scss to test.css.')); + + await tickIfPoll(); + + await d.file("test.scss", "x {y: z}").create(); + await expectLater( + sass.stdout, emits('Compiled test.scss to test.css.')); + + await sass.kill(); + + await d + .file("test.css", equalsIgnoringWhitespace("x { y: z; }")) + .validate(); + }); + group("when its dependency is modified", () { test("through @import", () async { await d.file("_other.scss", "a {b: c}").create();