Skip to content

Commit 77bd3bf

Browse files
authoredJun 4, 2022
fix: stylus - handle relative sourcemap sources(#513)
1 parent 0551a9b commit 77bd3bf

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

‎src/transformers/stylus.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import stylus from 'stylus';
44

55
import { getIncludePaths } from '../modules/utils';
66

7+
import type { SourceMap } from 'magic-string';
78
import type { Transformer, Options } from '../types';
89

10+
type StylusRendererWithSourceMap = ReturnType<typeof stylus> & {
11+
sourcemap: SourceMap;
12+
};
13+
914
const transformer: Transformer<Options.Stylus> = ({
1015
content,
1116
filename,
@@ -20,15 +25,20 @@ const transformer: Transformer<Options.Stylus> = ({
2025
const style = stylus(content, {
2126
filename,
2227
...options,
23-
}).set('sourcemap', options.sourcemap);
28+
}).set('sourcemap', options.sourcemap) as StylusRendererWithSourceMap;
2429

2530
style.render((err, css) => {
2631
// istanbul ignore next
2732
if (err) reject(err);
33+
if (style.sourcemap?.sources) {
34+
style.sourcemap.sources = style.sourcemap.sources.map((source) =>
35+
path.resolve(source),
36+
);
37+
}
2838

2939
resolve({
3040
code: css,
31-
map: (style as any).sourcemap,
41+
map: style.sourcemap,
3242
// .map() necessary for windows compatibility
3343
dependencies: style
3444
.deps(filename as string)

0 commit comments

Comments
 (0)
Please sign in to comment.