Skip to content
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
17 changes: 16 additions & 1 deletion src/sassCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ export async function sassCompiler(
}
}

// Normalize absolute Windows paths in @use/@import/@forward directives.
// On Windows, drive letters like C:/ are misinterpreted as URL schemes by
// Sass, so we extract the directory into loadPaths and rewrite the import
// to just the module name.
const winAbsPathRegex = /@(use|import|forward)\s+(['"])([A-Za-z]:[/\\][^'"]+)\2/g
result = result.replace(winAbsPathRegex, (match, kw, quote, absPath) => {
const nativePath = absPath.replace(/\//g, path.sep)
const dir = path.dirname(nativePath)
const basename = path.basename(nativePath)
if (!compileOptions.loadPaths.includes(dir)) {
compileOptions.loadPaths.push(dir)
}
return `@${kw} ${quote}${basename}${quote}`
})

// 优先使用新的 compile API(如果可用),否则回退到 compileString
let compiledResult: any

Expand Down Expand Up @@ -249,6 +264,6 @@ export async function sassCompiler(
console.error(
`Error:\n transform-to-unocss(sassCompiler) ${error.toString()}`,
)
return undefined
return css
}
}
4 changes: 2 additions & 2 deletions test/sassCompiler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ describe('sassCompiler', () => {
undefined,
true,
)
// Should not throw, but return undefined and log error
expect(result).toBeUndefined()
// Should not throw, but return the original CSS and log error
expect(result).toBe(css)
})
})

Expand Down