Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: sass dependency list referencing source file in win32 #621

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"packageManager": "[email protected]",
"volta": {
"node": "14.19.2"
"node": "20.10.0"
},
"files": [
"dist/"
Expand Down
18 changes: 13 additions & 5 deletions src/transformers/scss.ts
Original file line number Diff line number Diff line change
@@ -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
Loading