@@ -37,25 +37,51 @@ const getFilePath = (fileName: string) =>
37
37
export class DtsSnapshotCreator {
38
38
constructor ( private readonly logger : Logger ) { }
39
39
40
- getClasses ( processor : postcss . Processor , css : string , fileName : string ) {
40
+ getClasses (
41
+ processor : postcss . Processor ,
42
+ css : string ,
43
+ fileName : string ,
44
+ options : Options = { } ,
45
+ ) {
41
46
try {
42
47
const fileType = getFileType ( fileName ) ;
43
48
let transformedCss = '' ;
44
49
50
+ let renderOptions : Options [ 'renderOptions' ] | { } = { } ;
51
+ if ( options . renderOptions ) {
52
+ if ( fileType === FileTypes . less && options . renderOptions . less ) {
53
+ renderOptions = options . renderOptions . less ;
54
+ } else if ( fileType === FileTypes . scss && options . renderOptions . scss ) {
55
+ renderOptions = options . renderOptions . scss ;
56
+ }
57
+ }
58
+
45
59
if ( fileType === FileTypes . less ) {
60
+ let error ;
46
61
less . render (
47
62
css ,
48
- { syncImport : true , filename : fileName } as any ,
63
+ {
64
+ syncImport : true ,
65
+ filename : fileName ,
66
+ ...renderOptions ,
67
+ } as any ,
49
68
( err , output ) => {
50
- transformedCss = output . css . toString ( ) ;
69
+ error = err ;
70
+ if ( output ) {
71
+ transformedCss = output . css . toString ( ) ;
72
+ }
51
73
} ,
52
74
) ;
75
+ if ( error ) {
76
+ throw error ;
77
+ }
53
78
} else if ( fileType === FileTypes . scss ) {
54
79
const filePath = getFilePath ( fileName ) ;
55
80
transformedCss = sass
56
81
. renderSync ( {
57
82
data : css ,
58
83
includePaths : [ filePath ] ,
84
+ ...options ,
59
85
} )
60
86
. css . toString ( ) ;
61
87
} else {
@@ -116,7 +142,7 @@ export default classes;
116
142
return scriptSnapshot ;
117
143
}
118
144
119
- const classes = this . getClasses ( processor , css , fileName ) ;
145
+ const classes = this . getClasses ( processor , css , fileName , options ) ;
120
146
const dts = this . createExports ( classes , options ) ;
121
147
return ts . ScriptSnapshot . fromString ( dts ) ;
122
148
}
0 commit comments