From 9d71ae07802c1ebb14ffbf0f9861443e52cd856e Mon Sep 17 00:00:00 2001 From: lepzulnag Date: Fri, 6 May 2022 11:03:08 +0200 Subject: [PATCH 1/2] fix: stylus relative sourcemap sources --- src/transformers/stylus.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/transformers/stylus.ts b/src/transformers/stylus.ts index 4807dca0..b2c2b2f5 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,16 @@ 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); + const map = style.sourcemap.sources.map((source) => path.resolve(source)); resolve({ code: css, - map: (style as any).sourcemap, + map, // .map() necessary for windows compatibility dependencies: style .deps(filename as string) From b7307ed528b040f57b3aa381148062b58004dd1a Mon Sep 17 00:00:00 2001 From: lepzulnag Date: Fri, 6 May 2022 11:46:23 +0200 Subject: [PATCH 2/2] fix: handle no sourcemap case --- src/transformers/stylus.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/transformers/stylus.ts b/src/transformers/stylus.ts index b2c2b2f5..e7678d4d 100644 --- a/src/transformers/stylus.ts +++ b/src/transformers/stylus.ts @@ -30,11 +30,15 @@ const transformer: Transformer = ({ style.render((err, css) => { // istanbul ignore next if (err) reject(err); - const map = style.sourcemap.sources.map((source) => path.resolve(source)); + if (style.sourcemap?.sources) { + style.sourcemap.sources = style.sourcemap.sources.map((source) => + path.resolve(source), + ); + } resolve({ code: css, - map, + map: style.sourcemap, // .map() necessary for windows compatibility dependencies: style .deps(filename as string)