Skip to content

Commit

Permalink
Always use absolute URLs in stdout source maps (#1021)
Browse files Browse the repository at this point in the history
Fixes #1020.
  • Loading branch information
jathak authored Jun 5, 2020
1 parent 69627fb commit 7d6dae0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.26.8

* Fixes an error when emitting source maps to stdout.

## 1.26.7

* No user-visible changes.
Expand Down
12 changes: 7 additions & 5 deletions lib/src/executable/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@ class ExecutableOptions {
return extension == ".scss" || extension == ".sass" || extension == ".css";
}

/// Returns whether we're writing to stdout instead of a file or files.
bool get _writeToStdout =>
sourcesToDestinations.length == 1 &&
sourcesToDestinations.values.single == null;

/// Whether to emit a source map file.
bool get emitSourceMap {
if (!(_options['source-map'] as bool)) {
Expand All @@ -399,10 +404,7 @@ class ExecutableOptions {
_fail("--embed-source-map isn't allowed with --no-source-map.");
}
}

var writeToStdout = sourcesToDestinations.length == 1 &&
sourcesToDestinations.values.single == null;
if (!writeToStdout) return _options['source-map'] as bool;
if (!_writeToStdout) return _options['source-map'] as bool;

if (_ifParsed('source-map-urls') == 'relative') {
_fail(
Expand Down Expand Up @@ -458,7 +460,7 @@ class ExecutableOptions {
if (url.scheme.isNotEmpty && url.scheme != 'file') return url;

var path = p.fromUri(url);
return p.toUri(_options['source-map-urls'] == 'relative'
return p.toUri(_options['source-map-urls'] == 'relative' && !_writeToStdout
? p.relative(path, from: p.dirname(destination))
: p.absolute(path));
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.26.7
version: 1.26.8
description: A Sass implementation in Dart.
author: Sass Team
homepage: https://github.com/sass/dart-sass
Expand Down
14 changes: 14 additions & 0 deletions test/cli/shared/source_maps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ void sharedTests(Future<TestProcess> runSass(Iterable<String> arguments)) {
expect(map, containsPair("file", "out.css"));
});
});

test("with stdout as the target", () async {
var sass = await runSass(["--embed-source-map", "test.scss"]);
expect(
sass.stdout,
emitsInOrder([
"a {",
" b: 3;",
"}",
"",
startsWith("/*# sourceMappingURL=data:")
]));
await sass.shouldExit(0);
});
});
}

Expand Down

0 comments on commit 7d6dae0

Please sign in to comment.