@@ -13,11 +13,7 @@ import { createFilter } from '@rollup/pluginutils';
13
13
*/
14
14
import type { Plugin as RollupPlugin , TransformResult } from 'rollup' ;
15
15
16
- import type {
17
- RollupPluginSassOptions ,
18
- RollupPluginSassOutputFn ,
19
- RollupPluginSassState ,
20
- } from './types' ;
16
+ import type { RollupPluginSassOptions , RollupPluginSassState } from './types' ;
21
17
import {
22
18
getImporterListLegacy ,
23
19
getImporterListModern ,
@@ -182,36 +178,40 @@ export = function plugin(
182
178
}
183
179
} ,
184
180
185
- generateBundle ( outputOptions , _ , isWrite ) {
181
+ async generateBundle ( outputOptions , _ , isWrite ) {
186
182
const { styles } = pluginState ;
187
183
const { output, insert } = pluginOptions ;
188
184
189
185
if ( ! isWrite || ( ! insert && ( ! styles . length || output === false ) ) ) {
190
- return Promise . resolve ( ) ;
186
+ return ;
191
187
}
192
188
193
189
const css = styles . map ( ( style ) => style . content ) . join ( '' ) ;
194
190
195
191
if ( typeof output === 'string' ) {
196
- return fs . promises
197
- . mkdir ( path . dirname ( output as string ) , { recursive : true } )
198
- . then ( ( ) => fs . promises . writeFile ( output as string , css ) ) ;
199
- } else if ( typeof output === 'function' ) {
200
- ( output as RollupPluginSassOutputFn ) ( css , styles ) ;
201
- return Promise . resolve ( ) ;
202
- } else if ( ! insert && outputOptions . file && output === true ) {
192
+ await fs . promises . mkdir ( path . dirname ( output ) , { recursive : true } ) ;
193
+ await fs . promises . writeFile ( output , css ) ;
194
+
195
+ return ;
196
+ }
197
+
198
+ if ( typeof output === 'function' ) {
199
+ output ( css , styles ) ;
200
+ return ;
201
+ }
202
+
203
+ if ( ! insert && outputOptions . file && output === true ) {
203
204
let dest = outputOptions . file ;
204
205
205
206
if ( dest . endsWith ( '.js' ) || dest . endsWith ( '.ts' ) ) {
206
207
dest = dest . slice ( 0 , - 3 ) ;
207
208
}
208
209
dest = `${ dest } .css` ;
209
- return fs . promises
210
- . mkdir ( path . dirname ( dest ) , { recursive : true } )
211
- . then ( ( ) => fs . promises . writeFile ( dest , css ) ) ;
212
- }
213
210
214
- return Promise . resolve ( ) ;
211
+ await fs . promises . mkdir ( path . dirname ( dest ) , { recursive : true } ) ;
212
+ await fs . promises . writeFile ( dest , css ) ;
213
+ return ;
214
+ }
215
215
} ,
216
216
} ;
217
217
} ;
0 commit comments