Skip to content

Commit 209312f

Browse files
authoredDec 18, 2023
fix: sass dependency list referencing source file in win32 (#621)
1 parent 7f42697 commit 209312f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
},
2424
"packageManager": "pnpm@8.12.1",
2525
"volta": {
26-
"node": "14.19.2"
26+
"node": "20.10.0"
2727
},
2828
"files": [
2929
"dist/"

‎src/transformers/scss.ts

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

44
import { getIncludePaths, findUp } from '../modules/utils';
55

@@ -19,7 +19,7 @@ const tildeImporter: LegacySyncImporter = (url, prev) => {
1919
prev = decodeURIComponent(prev);
2020
}
2121

22-
const modulePath = join('node_modules', ...url.slice(1).split(/[\\/]/g));
22+
const modulePath = path.join('node_modules', ...url.slice(1).split(/[\\/]/g));
2323

2424
const foundPath = findUp({ what: modulePath, from: prev });
2525

@@ -68,12 +68,20 @@ const transformer: Transformer<Options.Sass> = async ({
6868

6969
const compiled = renderSync(sassOptions);
7070

71+
// We need to normalize the path for windows, because the sass compiler
72+
// returns a windows path in posix format __just for the entry__ (the dependency list below is fine 🤷)
73+
// More info: https://github.com/sveltejs/svelte-preprocess/issues/619
74+
const normalizedEntryPath =
75+
process.platform === 'win32'
76+
? compiled.stats.entry.split('/').join(path.win32.sep)
77+
: compiled.stats.entry;
78+
7179
// For some reason, scss includes the main 'file' in the array, we don't want that
7280
// Unfortunately I didn't manage to reproduce this in the test env
7381
// More info: https://github.com/sveltejs/svelte-preprocess/issues/346
74-
const absoluteEntryPath = isAbsolute(compiled.stats.entry)
75-
? compiled.stats.entry
76-
: join(process.cwd(), compiled.stats.entry);
82+
const absoluteEntryPath = path.isAbsolute(normalizedEntryPath)
83+
? normalizedEntryPath
84+
: path.join(process.cwd(), normalizedEntryPath);
7785

7886
const processed = {
7987
code: compiled.css.toString(),

0 commit comments

Comments
 (0)
Please sign in to comment.