Skip to content

Commit 4581e83

Browse files
authored
refactor: use types from sass instead of @types/sass (#16340)
1 parent 5647d07 commit 4581e83

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"@types/micromatch": "^4.0.6",
5656
"@types/node": "^20.11.30",
5757
"@types/picomatch": "^2.3.3",
58-
"@types/sass": "~1.43.1",
5958
"@types/semver": "^7.5.8",
6059
"@types/stylus": "^0.48.42",
6160
"@types/ws": "^8.5.10",

packages/vite/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"rollup-plugin-dts": "^6.1.0",
145145
"rollup-plugin-esbuild": "^6.1.1",
146146
"rollup-plugin-license": "^3.3.1",
147+
"sass": "^1.72.0",
147148
"sirv": "^2.0.4",
148149
"source-map-support": "^0.5.21",
149150
"strip-ansi": "^7.1.0",

packages/vite/src/node/plugins/css.ts

+15-10
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,8 @@ type StylePreprocessorOptions = {
19131913
enableSourcemap: boolean
19141914
}
19151915

1916-
type SassStylePreprocessorOptions = StylePreprocessorOptions & Sass.Options
1916+
type SassStylePreprocessorOptions = StylePreprocessorOptions &
1917+
Omit<Sass.LegacyOptions<'async'>, 'data' | 'file' | 'outFile'>
19171918

19181919
type StylusStylePreprocessorOptions = StylePreprocessorOptions & {
19191920
define?: Record<string, any>
@@ -2017,8 +2018,8 @@ function cleanScssBugUrl(url: string) {
20172018
}
20182019

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

20822083
// NOTE: `sass` always runs it's own importer first, and only falls back to
20832084
// the `importer` option when it can't resolve a path
2084-
const _internalImporter: Sass.Importer = (url, importer, done) => {
2085+
const _internalImporter: Sass.LegacyAsyncImporter = (
2086+
url,
2087+
importer,
2088+
done,
2089+
) => {
20852090
internalImporter(url, importer, options.filename).then((data) =>
20862091
done?.(data),
20872092
)
@@ -2093,7 +2098,7 @@ const makeScssWorker = (
20932098
: importer.unshift(options.importer)
20942099
}
20952100

2096-
const finalOptions: Sass.Options = {
2101+
const finalOptions: Sass.LegacyOptions<'async'> = {
20972102
...options,
20982103
data,
20992104
file: options.filename,
@@ -2110,16 +2115,16 @@ const makeScssWorker = (
21102115
return new Promise<{
21112116
css: string
21122117
map?: string | undefined
2113-
stats: Sass.Result['stats']
2118+
stats: Sass.LegacyResult['stats']
21142119
}>((resolve, reject) => {
21152120
sass.render(finalOptions, (err, res) => {
21162121
if (err) {
21172122
reject(err)
21182123
} else {
21192124
resolve({
2120-
css: res.css.toString(),
2121-
map: res.map?.toString(),
2122-
stats: res.stats,
2125+
css: res!.css.toString(),
2126+
map: res!.map?.toString(),
2127+
stats: res!.stats,
21232128
})
21242129
}
21252130
})
@@ -2213,7 +2218,7 @@ async function rebaseUrls(
22132218
alias: Alias[],
22142219
variablePrefix: string,
22152220
resolver: ResolveFn,
2216-
): Promise<Sass.ImporterReturnType> {
2221+
): Promise<Sass.LegacyImporterResult> {
22172222
file = path.resolve(file) // ensure os-specific flashes
22182223
// in the same dir, no need to rebase
22192224
const fileDir = path.dirname(file)

pnpm-lock.yaml

+6-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)