Skip to content

Commit

Permalink
refactor: use types from sass instead of @types/sass (#16340)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Apr 3, 2024
1 parent 5647d07 commit 4581e83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"@types/micromatch": "^4.0.6",
"@types/node": "^20.11.30",
"@types/picomatch": "^2.3.3",
"@types/sass": "~1.43.1",
"@types/semver": "^7.5.8",
"@types/stylus": "^0.48.42",
"@types/ws": "^8.5.10",
Expand Down
1 change: 1 addition & 0 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-license": "^3.3.1",
"sass": "^1.72.0",
"sirv": "^2.0.4",
"source-map-support": "^0.5.21",
"strip-ansi": "^7.1.0",
Expand Down
25 changes: 15 additions & 10 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,8 @@ type StylePreprocessorOptions = {
enableSourcemap: boolean
}

type SassStylePreprocessorOptions = StylePreprocessorOptions & Sass.Options
type SassStylePreprocessorOptions = StylePreprocessorOptions &
Omit<Sass.LegacyOptions<'async'>, 'data' | 'file' | 'outFile'>

type StylusStylePreprocessorOptions = StylePreprocessorOptions & {
define?: Record<string, any>
Expand Down Expand Up @@ -2017,8 +2018,8 @@ function cleanScssBugUrl(url: string) {
}

function fixScssBugImportValue(
data: Sass.ImporterReturnType,
): Sass.ImporterReturnType {
data: Sass.LegacyImporterResult,
): Sass.LegacyImporterResult {
// the scss bug doesn't load files properly so we have to load it ourselves
// to prevent internal error when it loads itself
if (
Expand Down Expand Up @@ -2081,7 +2082,11 @@ const makeScssWorker = (

// NOTE: `sass` always runs it's own importer first, and only falls back to
// the `importer` option when it can't resolve a path
const _internalImporter: Sass.Importer = (url, importer, done) => {
const _internalImporter: Sass.LegacyAsyncImporter = (
url,
importer,
done,
) => {
internalImporter(url, importer, options.filename).then((data) =>
done?.(data),
)
Expand All @@ -2093,7 +2098,7 @@ const makeScssWorker = (
: importer.unshift(options.importer)
}

const finalOptions: Sass.Options = {
const finalOptions: Sass.LegacyOptions<'async'> = {
...options,
data,
file: options.filename,
Expand All @@ -2110,16 +2115,16 @@ const makeScssWorker = (
return new Promise<{
css: string
map?: string | undefined
stats: Sass.Result['stats']
stats: Sass.LegacyResult['stats']
}>((resolve, reject) => {
sass.render(finalOptions, (err, res) => {
if (err) {
reject(err)
} else {
resolve({
css: res.css.toString(),
map: res.map?.toString(),
stats: res.stats,
css: res!.css.toString(),
map: res!.map?.toString(),
stats: res!.stats,
})
}
})
Expand Down Expand Up @@ -2213,7 +2218,7 @@ async function rebaseUrls(
alias: Alias[],
variablePrefix: string,
resolver: ResolveFn,
): Promise<Sass.ImporterReturnType> {
): Promise<Sass.LegacyImporterResult> {
file = path.resolve(file) // ensure os-specific flashes
// in the same dir, no need to rebase
const fileDir = path.dirname(file)
Expand Down
22 changes: 6 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4581e83

Please sign in to comment.