Skip to content

Commit ca63b1b

Browse files
authored
Don't try to resolve relative Node importer URLs for source maps (#923)
* Don't try to resolve relative Node importer URLs for source maps Closes #922 * Reformat
1 parent 31c0960 commit ca63b1b

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
## 1.24.4
2+
3+
### JavaScript API
4+
5+
* Fix a bug where source map generation would crash with an absolute source map
6+
path and a custom importer that returns string file contents.
7+
18
## 1.24.3
29

10+
### Command Line Interface
11+
312
* Fix a bug where `sass --version` would crash for certain executable
413
distributions.
514

615
## 1.24.2
716

17+
### JavaScript API
18+
819
* Fix a bug introduced in the previous release that prevented custom importers
920
in Node.js from loading import-only files.
1021

lib/src/node.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,12 @@ RenderResult _newRenderResult(
351351
for (var i = 0; i < result.sourceMap.urls.length; i++) {
352352
var source = result.sourceMap.urls[i];
353353
if (source == "stdin") continue;
354+
355+
// URLs handled by Node importers that directly return file contents are
356+
// preserved in their original (usually relative) form. They may or may
357+
// not be intended as `file:` URLs, but there's nothing we can do about it
358+
// either way so we keep them as-is.
359+
if (p.url.isRelative(source) || p.url.isRootRelative(source)) continue;
354360
result.sourceMap.urls[i] = p.url.relative(source, from: sourceMapDirUrl);
355361
}
356362

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass
2-
version: 1.24.3
2+
version: 1.24.4
33
description: A Sass implementation in Dart.
44
author: Sass Team
55
homepage: https://github.com/sass/dart-sass

test/node_api/source_map_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,21 @@ void main() {
195195
var map = _jsonUtf8.decode(result.map) as Map<String, Object>;
196196
expect(map, containsPair("file", "stdin.css"));
197197
});
198+
199+
// Regression test for sass/dart-sass#922
200+
test("contains a URL handled by an importer when sourceMap is absolute",
201+
() {
202+
var map = _renderSourceMap(RenderOptions(
203+
data: '''
204+
@import "other";
205+
a {b: c}
206+
''',
207+
importer: allowInterop(
208+
(void _, void __) => NodeImporterResult(contents: 'x {y: z}')),
209+
sourceMap: p.absolute("out.css.map"),
210+
outFile: 'out.css'));
211+
expect(map, containsPair("sources", ["other", "stdin"]));
212+
});
198213
});
199214

200215
test("with omitSourceMapUrl, doesn't include a source map comment", () {

0 commit comments

Comments
 (0)