Add support for _index files (#220)

See sass/sass#690
This commit is contained in:
John Harvey 2018-03-09 22:46:46 +00:00 committed by Natalie Weizenbaum
parent b7b4580bb4
commit e63b8e1b40
4 changed files with 19 additions and 5 deletions

View File

@ -4,3 +4,4 @@
# Name/Organization <email address> # Name/Organization <email address>
Google Inc. Google Inc.
Marks and Spencer Plc. John Harvey John.Harvey@marks-and-spencer.com

View File

@ -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 ## 1.0.0-beta.5.3
* Support hard tabs in the indented syntax. * Support hard tabs in the indented syntax.

View File

@ -7,13 +7,14 @@ import '../util/path.dart';
/// Resolves an imported path using the same logic as the filesystem importer. /// 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`. /// found, it returns `null`.
String resolveImportPath(String path) { String resolveImportPath(String path) {
var extension = p.extension(path); var extension = p.extension(path);
return extension == '.sass' || extension == '.scss' if (extension == '.sass' || extension == '.scss') return _tryPath(path);
? _tryPath(path)
: _tryPathWithExtensions(path); var file = _tryPathWithExtensions(path);
return file != null ? file : _tryPathAsDirectory(path);
} }
/// Like [_tryPath], but checks both `.sass` and `.scss` extensions. /// Like [_tryPath], but checks both `.sass` and `.scss` extensions.
@ -30,3 +31,10 @@ String _tryPath(String path) {
if (fileExists(path)) return path; if (fileExists(path)) return path;
return null; 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;

View File

@ -1,5 +1,5 @@
name: sass name: sass
version: 1.0.0-beta.5.3 version: 1.0.0-dev
description: A Sass implementation in Dart. description: A Sass implementation in Dart.
author: Dart Team <misc@dartlang.org> author: Dart Team <misc@dartlang.org>
homepage: https://github.com/sass/dart-sass homepage: https://github.com/sass/dart-sass