diff --git a/src/transformers/stylus.ts b/src/transformers/stylus.ts index 4807dca0..e7678d4d 100644 --- a/src/transformers/stylus.ts +++ b/src/transformers/stylus.ts @@ -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 & { + sourcemap: SourceMap; +}; + const transformer: Transformer = ({ content, filename, @@ -20,15 +25,20 @@ const transformer: Transformer = ({ 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)