Skip to content

Commit

Permalink
fix: sass dependency list referencing source file in win32
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Dec 17, 2023
1 parent 7f42697 commit 04133f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -23,7 +23,7 @@
},
"packageManager": "pnpm@8.12.1",
"volta": {
"node": "14.19.2"
"node": "20.10.0"
},
"files": [
"dist/"
Expand Down
18 changes: 13 additions & 5 deletions src/transformers/scss.ts
@@ -1,5 +1,5 @@
import { readFileSync } from 'fs';
import { isAbsolute, join } from 'path';
import path from 'path';

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

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

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

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

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

const compiled = renderSync(sassOptions);

// We need to normalize the path for windows, because the sass compiler
// returns a windows path in posix format __just for the entry__ (the dependency list below is fine 🤷)
// More info: https://github.com/sveltejs/svelte-preprocess/issues/619
const normalizedEntryPath =
process.platform === 'win32'
? compiled.stats.entry.split('/').join(path.win32.sep)
: compiled.stats.entry;

// For some reason, scss includes the main 'file' in the array, we don't want that
// Unfortunately I didn't manage to reproduce this in the test env
// More info: https://github.com/sveltejs/svelte-preprocess/issues/346
const absoluteEntryPath = isAbsolute(compiled.stats.entry)
? compiled.stats.entry
: join(process.cwd(), compiled.stats.entry);
const absoluteEntryPath = path.isAbsolute(normalizedEntryPath)
? normalizedEntryPath
: path.join(process.cwd(), normalizedEntryPath);

const processed = {
code: compiled.css.toString(),
Expand Down

0 comments on commit 04133f7

Please sign in to comment.