Skip to content

Commit

Permalink
fix: stylus - handle relative sourcemap sources(#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gin-Quin committed Jun 4, 2022
1 parent 0551a9b commit 77bd3bf
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/transformers/stylus.ts
Expand Up @@ -4,8 +4,13 @@ import stylus from 'stylus';

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

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

type StylusRendererWithSourceMap = ReturnType<typeof stylus> & {
sourcemap: SourceMap;
};

const transformer: Transformer<Options.Stylus> = ({
content,
filename,
Expand All @@ -20,15 +25,20 @@ const transformer: Transformer<Options.Stylus> = ({
const style = stylus(content, {
filename,
...options,
}).set('sourcemap', options.sourcemap);
}).set('sourcemap', options.sourcemap) as StylusRendererWithSourceMap;

style.render((err, css) => {
// istanbul ignore next
if (err) reject(err);
if (style.sourcemap?.sources) {
style.sourcemap.sources = style.sourcemap.sources.map((source) =>
path.resolve(source),
);
}

resolve({
code: css,
map: (style as any).sourcemap,
map: style.sourcemap,
// .map() necessary for windows compatibility
dependencies: style
.deps(filename as string)
Expand Down

0 comments on commit 77bd3bf

Please sign in to comment.