1
1
import { readFileSync } from 'fs' ;
2
- import { join } from 'path' ;
2
+ import { join , isAbsolute } from 'path' ;
3
3
4
4
import type { Importer , Result } from 'sass' ;
5
5
@@ -8,18 +8,23 @@ import type { Transformer, Processed, Options } from '../types';
8
8
9
9
let sass : Options . Sass [ 'implementation' ] ;
10
10
11
- type ResolveResult = {
12
- code : string ;
13
- map : string | undefined ;
14
- dependencies : string [ ] ;
15
- } ;
11
+ function getProcessedResult ( result : Result ) : Processed {
12
+ // For some reason, scss includes the main 'file' in the array, we don't want that
13
+ // Unfortunately I didn't manage to reproduce this in the test env
14
+ // More info: https://github.com/sveltejs/svelte-preprocess/issues/346
15
+ const absoluteEntryPath = isAbsolute ( result . stats . entry )
16
+ ? result . stats . entry
17
+ : join ( process . cwd ( ) , result . stats . entry ) ;
16
18
17
- function getResultForResolve ( result : Result ) : ResolveResult {
18
- return {
19
+ const processed = {
19
20
code : result . css . toString ( ) ,
20
21
map : result . map ?. toString ( ) ,
21
- dependencies : result . stats . includedFiles ,
22
+ dependencies : Array . from ( result . stats . includedFiles ) . filter (
23
+ ( filepath ) => filepath !== absoluteEntryPath ,
24
+ ) ,
22
25
} ;
26
+
27
+ return processed ;
23
28
}
24
29
25
30
const tildeImporter : Importer = ( url , prev ) => {
@@ -90,14 +95,14 @@ const transformer: Transformer<Options.Sass> = async ({
90
95
}
91
96
92
97
if ( renderSync ) {
93
- return getResultForResolve ( implementation . renderSync ( sassOptions ) ) ;
98
+ return getProcessedResult ( implementation . renderSync ( sassOptions ) ) ;
94
99
}
95
100
96
101
return new Promise < Processed > ( ( resolve , reject ) => {
97
102
implementation . render ( sassOptions , ( err , result ) => {
98
103
if ( err ) return reject ( err ) ;
99
104
100
- resolve ( getResultForResolve ( result ) ) ;
105
+ resolve ( getProcessedResult ( result ) ) ;
101
106
} ) ;
102
107
} ) ;
103
108
} ;
0 commit comments