fix(css): make sass types work with sass-embedded (#18459)

This commit is contained in:
翠 / green 2024-10-26 01:01:17 +09:00 committed by GitHub
parent 34fdb6bef5
commit 89f8303e72
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 53 additions and 6 deletions

View File

@ -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': [

View File

@ -116,6 +116,18 @@
"postcss",
"search-insights"
]
},
"packageExtensions": {
"sass-embedded": {
"peerDependencies": {
"source-map-js": "*"
},
"peerDependenciesMeta": {
"source-map-js": {
"optional": true
}
}
}
}
},
"stackblitz": {

View File

@ -1,7 +1,9 @@
/* 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
@ -9,8 +11,19 @@ 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'
@ -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'
>

View File

@ -7,6 +7,8 @@ settings:
overrides:
vite: workspace:*
packageExtensionsChecksum: 632c5477927702fb9badd3e595784820
patchedDependencies:
acorn@8.13.0:
hash: alg6ojsgkjjglvaj7cjzzaqhim
@ -390,7 +392,7 @@ importers:
version: 1.80.3
sass-embedded:
specifier: ^1.80.3
version: 1.80.3
version: 1.80.3(source-map-js@1.2.1)
sirv:
specifier: ^3.0.0
version: 3.0.0(patch_hash=plxlsciwiebyhal5sm4vtpekka)
@ -6416,6 +6418,11 @@ packages:
resolution: {integrity: sha512-aTxTl4ToSAWg7ILFgAe+kMenj+zNlwHmHK/ZNPrOM8+HTef1Q6zuxolptYLijmHdZHKSMOkWYHgo5MMN6+GIyg==}
engines: {node: '>=16.0.0'}
hasBin: true
peerDependencies:
source-map-js: '*'
peerDependenciesMeta:
source-map-js:
optional: true
sass@1.80.3:
resolution: {integrity: sha512-ptDWyVmDMVielpz/oWy3YP3nfs7LpJTHIJZboMVs8GEC9eUmtZTZhMHlTW98wY4aEorDfjN38+Wr/XjskFWcfA==}
@ -12124,7 +12131,7 @@ snapshots:
sass-embedded-win32-x64@1.80.3:
optional: true
sass-embedded@1.80.3:
sass-embedded@1.80.3(source-map-js@1.2.1):
dependencies:
'@bufbuild/protobuf': 2.1.0
buffer-builder: 0.2.0
@ -12154,6 +12161,7 @@ snapshots:
sass-embedded-win32-arm64: 1.80.3
sass-embedded-win32-ia32: 1.80.3
sass-embedded-win32-x64: 1.80.3
source-map-js: 1.2.1
sass@1.80.3:
dependencies: