Skip to content

Commit 89f8303

Browse files
authored
fix(css): make sass types work with sass-embedded (#18459)
1 parent 34fdb6b commit 89f8303

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

eslint.config.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ export default tseslint.config(
8585
'n/no-extraneous-import': [
8686
'error',
8787
{
88-
allowModules: ['vite', 'less', 'sass', 'vitest', 'unbuild'],
88+
allowModules: [
89+
'vite',
90+
'less',
91+
'sass',
92+
'sass-embedded',
93+
'vitest',
94+
'unbuild',
95+
],
8996
},
9097
],
9198
'n/no-extraneous-require': [

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@
116116
"postcss",
117117
"search-insights"
118118
]
119+
},
120+
"packageExtensions": {
121+
"sass-embedded": {
122+
"peerDependencies": {
123+
"source-map-js": "*"
124+
},
125+
"peerDependenciesMeta": {
126+
"source-map-js": {
127+
"optional": true
128+
}
129+
}
130+
}
119131
}
120132
},
121133
"stackblitz": {

packages/vite/types/internal/cssPreprocessorOptions.d.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
/* eslint-disable @typescript-eslint/ban-ts-comment */
22

33
// @ts-ignore `sass` may not be installed
4-
import type Sass from 'sass'
4+
import type DartSass from 'sass'
5+
// @ts-ignore `sass-embedded` may not be installed
6+
import type SassEmbedded from 'sass-embedded'
57
// @ts-ignore `less` may not be installed
68
import type Less from 'less'
79
// @ts-ignore `less` may not be installed
810
import type Stylus from 'stylus'
911

1012
/* eslint-enable @typescript-eslint/ban-ts-comment */
1113

14+
// https://github.com/type-challenges/type-challenges/issues/29285
15+
type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false
16+
17+
type DartSassLegacyStringOptionsAsync = DartSass.LegacyStringOptions<'async'>
18+
type SassEmbeddedLegacyStringOptionsAsync =
19+
SassEmbedded.LegacyStringOptions<'async'>
20+
type SassLegacyStringOptionsAsync =
21+
IsAny<DartSassLegacyStringOptionsAsync> extends false
22+
? DartSassLegacyStringOptionsAsync
23+
: SassEmbeddedLegacyStringOptionsAsync
24+
1225
export type SassLegacyPreprocessBaseOptions = Omit<
13-
Sass.LegacyStringOptions<'async'>,
26+
SassLegacyStringOptionsAsync,
1427
| 'data'
1528
| 'file'
1629
| 'outFile'
@@ -20,8 +33,15 @@ export type SassLegacyPreprocessBaseOptions = Omit<
2033
| 'sourceMapRoot'
2134
>
2235

36+
type DartSassStringOptionsAsync = DartSass.StringOptions<'async'>
37+
type SassEmbeddedStringOptionsAsync = SassEmbedded.StringOptions<'async'>
38+
type SassStringOptionsAsync =
39+
IsAny<DartSassStringOptionsAsync> extends false
40+
? DartSassStringOptionsAsync
41+
: SassEmbeddedStringOptionsAsync
42+
2343
export type SassModernPreprocessBaseOptions = Omit<
24-
Sass.StringOptions<'async'>,
44+
SassStringOptionsAsync,
2545
'url' | 'sourceMap'
2646
>
2747

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)