Skip to content

Commit 519b0b6

Browse files
committed
fix: πŸ› prevent svelte file from being added to scss dep list
βœ… Closes: #346
1 parent bbf9e3a commit 519b0b6

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Diff for: β€Žsrc/transformers/scss.ts

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { readFileSync } from 'fs';
2-
import { join } from 'path';
2+
import { join, isAbsolute } from 'path';
33

44
import type { Importer, Result } from 'sass';
55

@@ -8,18 +8,23 @@ import type { Transformer, Processed, Options } from '../types';
88

99
let sass: Options.Sass['implementation'];
1010

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);
1618

17-
function getResultForResolve(result: Result): ResolveResult {
18-
return {
19+
const processed = {
1920
code: result.css.toString(),
2021
map: result.map?.toString(),
21-
dependencies: result.stats.includedFiles,
22+
dependencies: Array.from(result.stats.includedFiles).filter(
23+
(filepath) => filepath !== absoluteEntryPath,
24+
),
2225
};
26+
27+
return processed;
2328
}
2429

2530
const tildeImporter: Importer = (url, prev) => {
@@ -90,14 +95,14 @@ const transformer: Transformer<Options.Sass> = async ({
9095
}
9196

9297
if (renderSync) {
93-
return getResultForResolve(implementation.renderSync(sassOptions));
98+
return getProcessedResult(implementation.renderSync(sassOptions));
9499
}
95100

96101
return new Promise<Processed>((resolve, reject) => {
97102
implementation.render(sassOptions, (err, result) => {
98103
if (err) return reject(err);
99104

100-
resolve(getResultForResolve(result));
105+
resolve(getProcessedResult(result));
101106
});
102107
});
103108
};

0 commit comments

Comments
Β (0)