From e63b8e1b401a907219ef205f8b574095c3ae66da Mon Sep 17 00:00:00 2001 From: John Harvey Date: Fri, 9 Mar 2018 22:46:46 +0000 Subject: [PATCH] Add support for _index files (#220) See sass/sass#690 --- AUTHORS | 1 + CHANGELOG.md | 5 +++++ lib/src/importer/utils.dart | 16 ++++++++++++---- pubspec.yaml | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index e8063a8c..cc4be969 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,3 +4,4 @@ # Name/Organization Google Inc. +Marks and Spencer Plc. John Harvey John.Harvey@marks-and-spencer.com diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d34dbaf..62506a3a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.0.0-beta.6 + +* Add support for importing an `_index.scss` or `_index.sass` file when + importing a directory. + ## 1.0.0-beta.5.3 * Support hard tabs in the indented syntax. diff --git a/lib/src/importer/utils.dart b/lib/src/importer/utils.dart index 242b371a..e00d8ba1 100644 --- a/lib/src/importer/utils.dart +++ b/lib/src/importer/utils.dart @@ -7,13 +7,14 @@ import '../util/path.dart'; /// Resolves an imported path using the same logic as the filesystem importer. /// -/// This tries to fill in extensions and partial prefixes. If no file can be +/// This tries to fill in extensions and partial prefixes and check if a directory default. If no file can be /// found, it returns `null`. String resolveImportPath(String path) { var extension = p.extension(path); - return extension == '.sass' || extension == '.scss' - ? _tryPath(path) - : _tryPathWithExtensions(path); + if (extension == '.sass' || extension == '.scss') return _tryPath(path); + + var file = _tryPathWithExtensions(path); + return file != null ? file : _tryPathAsDirectory(path); } /// Like [_tryPath], but checks both `.sass` and `.scss` extensions. @@ -30,3 +31,10 @@ String _tryPath(String path) { if (fileExists(path)) return path; return null; } + +/// Returns the resolved index file for [path] if [path] is a directory and the +/// index file exists. +/// +/// Otherwise, returns `null`. +String _tryPathAsDirectory(String path) => + dirExists(path) ? _tryPathWithExtensions(p.join(path, 'index')) : null; diff --git a/pubspec.yaml b/pubspec.yaml index dedce4ca..ebdb55c7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: sass -version: 1.0.0-beta.5.3 +version: 1.0.0-dev description: A Sass implementation in Dart. author: Dart Team homepage: https://github.com/sass/dart-sass