@@ -48,9 +48,10 @@ export const parseCss = async (
4848 }
4949
5050 const data = await getData ( file . toString ( ) , fileName , options . additionalData )
51- const finalImporter : Sass . LegacyAsyncImporter [ ] = [ ]
51+ if ( options . api === 'legacy' ) {
52+ // Legacy API
53+ const finalImporter : Sass . LegacyAsyncImporter [ ] = [ ]
5254
53- if ( options . api !== 'modern' && options . api !== 'modern-compiler' ) {
5455 if ( options . importer ) {
5556 Array . isArray ( options . importer )
5657 ? finalImporter . push ( ...options . importer )
@@ -64,7 +65,6 @@ export const parseCss = async (
6465 {
6566 ...options ,
6667 data,
67- pkgImporter : new sass . NodePackageImporter ( ) ,
6868 file : fileName ,
6969 includePaths : [ 'node_modules' ] ,
7070 importer : finalImporter ,
@@ -83,16 +83,21 @@ export const parseCss = async (
8383 const splitted = result . css . toString ( ) . split ( SPLIT_STR )
8484 return { localStyle : splitted [ 1 ] || '' , globalStyle : splitted [ 0 ] }
8585 } else {
86+ // Modern API (modern / modern-compiler)
87+ const finalImporters : Sass . Importer < 'async' > [ ] = [ ]
88+
8689 if ( options . importers ) {
8790 Array . isArray ( options . importers )
88- ? finalImporter . push ( ...options . importers )
89- : finalImporter . push ( options . importers )
91+ ? finalImporters . push ( ...options . importers )
92+ : finalImporters . push ( options . importers )
9093 }
9194
92- const sassOptions = { ...options }
93- sassOptions . url = pathToFileURL ( fileName )
94- sassOptions . pkgImporter = new sass . NodePackageImporter ( )
95- sassOptions . importers = finalImporter
95+ const sassOptions : Sass . StringOptions < 'async' > = {
96+ ...options ,
97+ url : pathToFileURL ( fileName ) ,
98+ importers : finalImporters ,
99+ syntax : fileName . endsWith ( '.sass' ) ? 'indented' : 'scss' ,
100+ }
96101
97102 const result = await sass . compileStringAsync ( data , sassOptions )
98103 const splitted = result . css . toString ( ) . split ( SPLIT_STR )
0 commit comments