Skip to content

Commit

Permalink
fix(css): make sass types work with sass-embedded (#18459)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Oct 25, 2024
1 parent 34fdb6b commit 89f8303
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 6 deletions.
9 changes: 8 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ export default tseslint.config(
'n/no-extraneous-import': [
'error',
{
allowModules: ['vite', 'less', 'sass', 'vitest', 'unbuild'],
allowModules: [
'vite',
'less',
'sass',
'sass-embedded',
'vitest',
'unbuild',
],
},
],
'n/no-extraneous-require': [
Expand Down
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@
"postcss",
"search-insights"
]
},
"packageExtensions": {
"sass-embedded": {
"peerDependencies": {
"source-map-js": "*"
},
"peerDependenciesMeta": {
"source-map-js": {
"optional": true
}
}
}
}
},
"stackblitz": {
Expand Down
26 changes: 23 additions & 3 deletions packages/vite/types/internal/cssPreprocessorOptions.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

// @ts-ignore `sass` may not be installed
import type Sass from 'sass'
import type DartSass from 'sass'
// @ts-ignore `sass-embedded` may not be installed
import type SassEmbedded from 'sass-embedded'
// @ts-ignore `less` may not be installed
import type Less from 'less'
// @ts-ignore `less` may not be installed
import type Stylus from 'stylus'

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

// https://github.com/type-challenges/type-challenges/issues/29285
type IsAny<T> = boolean extends (T extends never ? true : false) ? true : false

type DartSassLegacyStringOptionsAsync = DartSass.LegacyStringOptions<'async'>
type SassEmbeddedLegacyStringOptionsAsync =
SassEmbedded.LegacyStringOptions<'async'>
type SassLegacyStringOptionsAsync =
IsAny<DartSassLegacyStringOptionsAsync> extends false
? DartSassLegacyStringOptionsAsync
: SassEmbeddedLegacyStringOptionsAsync

export type SassLegacyPreprocessBaseOptions = Omit<
Sass.LegacyStringOptions<'async'>,
SassLegacyStringOptionsAsync,
| 'data'
| 'file'
| 'outFile'
Expand All @@ -20,8 +33,15 @@ export type SassLegacyPreprocessBaseOptions = Omit<
| 'sourceMapRoot'
>

type DartSassStringOptionsAsync = DartSass.StringOptions<'async'>
type SassEmbeddedStringOptionsAsync = SassEmbedded.StringOptions<'async'>
type SassStringOptionsAsync =
IsAny<DartSassStringOptionsAsync> extends false
? DartSassStringOptionsAsync
: SassEmbeddedStringOptionsAsync

export type SassModernPreprocessBaseOptions = Omit<
Sass.StringOptions<'async'>,
SassStringOptionsAsync,
'url' | 'sourceMap'
>

Expand Down
12 changes: 10 additions & 2 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 89f8303

Please sign in to comment.