Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use absolute URLs in stdout source maps #1021

Merged
merged 1 commit into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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