feat(css): add more stricter typing of lightningcss (#18460)

This commit is contained in:
翠 / green 2024-10-28 14:59:44 +09:00 committed by GitHub
parent 3a27f627df
commit b9b925eb3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 28 deletions

View File

@ -90,6 +90,7 @@ export default tseslint.config(
'less',
'sass',
'sass-embedded',
'lightningcss',
'vitest',
'unbuild',
],

View File

@ -219,7 +219,7 @@ export type { Terser } from 'dep-types/terser'
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'dep-types/anymatch'
export type { LightningCSSOptions } from 'dep-types/lightningcss'
export type { LightningCSSOptions } from 'types/internal/lightningcssOptions'
// Backward compatibility
export type { ModuleGraph, ModuleNode } from './server/mixedModuleGraph'

View File

@ -21,7 +21,7 @@ import type Sass from 'sass'
import type Stylus from 'stylus'
import type Less from 'less'
import type { Alias } from 'dep-types/alias'
import type { LightningCSSOptions } from 'dep-types/lightningcss'
import type { LightningCSSOptions } from 'types/internal/lightningcssOptions'
import type { TransformOptions } from 'esbuild'
import { formatMessages, transform } from 'esbuild'
import type { RawSourceMap } from '@ampproject/remapping'
@ -181,9 +181,7 @@ export interface CSSModulesOptions {
}
export type ResolvedCSSOptions = Omit<CSSOptions, 'lightningcss'> & {
lightningcss?: LightningCSSOptions & {
targets: LightningCSSOptions['targets']
}
lightningcss?: LightningCSSOptions
}
export function resolveCSSOptions(

View File

@ -1,23 +0,0 @@
import type {
CSSModulesConfig,
Drafts,
NonStandard,
PseudoClasses,
Targets,
} from 'lightningcss'
/**
* Options are spread, so you can also use options that are not typed here like
* visitor (not exposed because it would impact too much the bundle size)
*/
export type LightningCSSOptions = {
targets?: Targets
include?: number
exclude?: number
drafts?: Drafts
nonStandard?: NonStandard
pseudoClasses?: PseudoClasses
unusedSymbols?: string[]
cssModules?: CSSModulesConfig
errorRecovery?: boolean
}

View File

@ -0,0 +1,18 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore `sass` may not be installed
import type Lightningcss from 'lightningcss'
/* eslint-enable @typescript-eslint/ban-ts-comment */
export type LightningCSSOptions = Omit<
Lightningcss.BundleAsyncOptions<Lightningcss.CustomAtRules>,
| 'filename'
| 'resolver'
| 'minify'
| 'sourceMap'
| 'analyzeDependencies'
// properties not overridden by Vite, but does not make sense to set by end users
| 'inputSourceMap'
| 'projectRoot'
>