Fix importing files relative to "package:" imports (#638)

The PackageImporter wasn't accepting paths relative to its
canonicalized outputs as inputs.

Closes #631
This commit is contained in:
Natalie Weizenbaum 2019-04-03 13:57:52 -07:00 committed by GitHub
parent 9999835df0
commit 8c9412b520
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 3 deletions

View File

@ -1,3 +1,14 @@
## 1.17.5
* Fix importing files relative to `package:`-imported files.
### Dart API
* Explicitly require that importers' `canonicalize()` methods be able to take
paths relative to their outputs as valid inputs. This isn't considered a
breaking change because the importer infrastructure already required this in
practice.
## 1.17.4
* Consistently parse U+000C FORM FEED, U+000D CARRIAGE RETURN, and sequences of

View File

@ -68,8 +68,10 @@ abstract class AsyncImporter {
///
/// If no stylesheets are found, the importer should return `null`.
///
/// Sass assumes that calling [canonicalize] multiple times with the same URL
/// will return the same result.
/// Calling [canonicalize] multiple times with the same URL must return the
/// same result. Calling [canonicalize] with a URL returned by [canonicalize]
/// must return that URL. Calling [canonicalize] with a URL relative to one
/// returned by [canonicalize] must return a meaningful result.
FutureOr<Uri> canonicalize(Uri url);
/// Loads the Sass text for the given [url], or returns `null` if

View File

@ -29,6 +29,7 @@ class PackageImporter extends Importer {
PackageImporter(this._packageResolver);
Uri canonicalize(Uri url) {
if (url.scheme == 'file') return _filesystemImporter.canonicalize(url);
if (url.scheme != 'package') return null;
var resolved = _packageResolver.resolveUri(url);

View File

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

View File

@ -100,6 +100,22 @@ main() {
expect(css, equals("a {\n b: 3;\n}"));
});
test("can resolve relative paths in a package", () async {
await d.dir("subdir", [
d.file("test.scss", "@import 'other'"),
d.file("_other.scss", "a {b: 1 + 2}"),
]).create();
await d
.file("test.scss", '@import "package:fake_package/test";')
.create();
var resolver = SyncPackageResolver.config(
{"fake_package": p.toUri(d.path('subdir'))});
var css = compile(d.path("test.scss"), packageResolver: resolver);
expect(css, equals("a {\n b: 3;\n}"));
});
test("doesn't import a package URL from a missing package", () async {
await d
.file("test.scss", '@import "package:fake_package/test_aux";')