From 89f8303e727791aa7be6f35833a708b6a50e9120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 26 Oct 2024 01:01:17 +0900 Subject: [PATCH] fix(css): make sass types work with sass-embedded (#18459) --- eslint.config.js | 9 ++++++- package.json | 12 +++++++++ .../internal/cssPreprocessorOptions.d.ts | 26 ++++++++++++++++--- pnpm-lock.yaml | 12 +++++++-- 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 0c936aa7986ff1..d34a24adc7cdd3 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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': [ diff --git a/package.json b/package.json index 921cf3d0aa0fc9..413f0e4ef51653 100644 --- a/package.json +++ b/package.json @@ -116,6 +116,18 @@ "postcss", "search-insights" ] + }, + "packageExtensions": { + "sass-embedded": { + "peerDependencies": { + "source-map-js": "*" + }, + "peerDependenciesMeta": { + "source-map-js": { + "optional": true + } + } + } } }, "stackblitz": { diff --git a/packages/vite/types/internal/cssPreprocessorOptions.d.ts b/packages/vite/types/internal/cssPreprocessorOptions.d.ts index 5064ac18f02a63..de962a8851dea8 100644 --- a/packages/vite/types/internal/cssPreprocessorOptions.d.ts +++ b/packages/vite/types/internal/cssPreprocessorOptions.d.ts @@ -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 = boolean extends (T extends never ? true : false) ? true : false + +type DartSassLegacyStringOptionsAsync = DartSass.LegacyStringOptions<'async'> +type SassEmbeddedLegacyStringOptionsAsync = + SassEmbedded.LegacyStringOptions<'async'> +type SassLegacyStringOptionsAsync = + IsAny 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 extends false + ? DartSassStringOptionsAsync + : SassEmbeddedStringOptionsAsync + export type SassModernPreprocessBaseOptions = Omit< - Sass.StringOptions<'async'>, + SassStringOptionsAsync, 'url' | 'sourceMap' > diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4321578f166af6..9c685b48a591e5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: