From 4581e8371d0c2481e859f4496f928d1dcacd3a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 3 Apr 2024 17:10:23 +0900 Subject: [PATCH] refactor: use types from sass instead of @types/sass (#16340) --- package.json | 1 - packages/vite/package.json | 1 + packages/vite/src/node/plugins/css.ts | 25 +++++++++++++++---------- pnpm-lock.yaml | 22 ++++++---------------- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 87cc9248a04461..b1c5a53de425ea 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,6 @@ "@types/micromatch": "^4.0.6", "@types/node": "^20.11.30", "@types/picomatch": "^2.3.3", - "@types/sass": "~1.43.1", "@types/semver": "^7.5.8", "@types/stylus": "^0.48.42", "@types/ws": "^8.5.10", diff --git a/packages/vite/package.json b/packages/vite/package.json index bea182f9591ae9..25b9aa2c09e57b 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -144,6 +144,7 @@ "rollup-plugin-dts": "^6.1.0", "rollup-plugin-esbuild": "^6.1.1", "rollup-plugin-license": "^3.3.1", + "sass": "^1.72.0", "sirv": "^2.0.4", "source-map-support": "^0.5.21", "strip-ansi": "^7.1.0", diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 90dbb6352378bc..96e0890de3519b 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1913,7 +1913,8 @@ type StylePreprocessorOptions = { enableSourcemap: boolean } -type SassStylePreprocessorOptions = StylePreprocessorOptions & Sass.Options +type SassStylePreprocessorOptions = StylePreprocessorOptions & + Omit, 'data' | 'file' | 'outFile'> type StylusStylePreprocessorOptions = StylePreprocessorOptions & { define?: Record @@ -2017,8 +2018,8 @@ function cleanScssBugUrl(url: string) { } function fixScssBugImportValue( - data: Sass.ImporterReturnType, -): Sass.ImporterReturnType { + data: Sass.LegacyImporterResult, +): Sass.LegacyImporterResult { // the scss bug doesn't load files properly so we have to load it ourselves // to prevent internal error when it loads itself if ( @@ -2081,7 +2082,11 @@ const makeScssWorker = ( // NOTE: `sass` always runs it's own importer first, and only falls back to // the `importer` option when it can't resolve a path - const _internalImporter: Sass.Importer = (url, importer, done) => { + const _internalImporter: Sass.LegacyAsyncImporter = ( + url, + importer, + done, + ) => { internalImporter(url, importer, options.filename).then((data) => done?.(data), ) @@ -2093,7 +2098,7 @@ const makeScssWorker = ( : importer.unshift(options.importer) } - const finalOptions: Sass.Options = { + const finalOptions: Sass.LegacyOptions<'async'> = { ...options, data, file: options.filename, @@ -2110,16 +2115,16 @@ const makeScssWorker = ( return new Promise<{ css: string map?: string | undefined - stats: Sass.Result['stats'] + stats: Sass.LegacyResult['stats'] }>((resolve, reject) => { sass.render(finalOptions, (err, res) => { if (err) { reject(err) } else { resolve({ - css: res.css.toString(), - map: res.map?.toString(), - stats: res.stats, + css: res!.css.toString(), + map: res!.map?.toString(), + stats: res!.stats, }) } }) @@ -2213,7 +2218,7 @@ async function rebaseUrls( alias: Alias[], variablePrefix: string, resolver: ResolveFn, -): Promise { +): Promise { file = path.resolve(file) // ensure os-specific flashes // in the same dir, no need to rebase const fileDir = path.dirname(file) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4f310cf11e5d26..4e94967890a621 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -66,9 +66,6 @@ importers: '@types/picomatch': specifier: ^2.3.3 version: 2.3.3 - '@types/sass': - specifier: ~1.43.1 - version: 1.43.1 '@types/semver': specifier: ^7.5.8 version: 7.5.8 @@ -405,6 +402,9 @@ importers: rollup-plugin-license: specifier: ^3.3.1 version: 3.3.1(rollup@4.13.0) + sass: + specifier: ^1.72.0 + version: 1.72.0 sirv: specifier: ^2.0.4 version: 2.0.4(patch_hash=amdes53ifqfntejkflpaq5ifce) @@ -4360,12 +4360,6 @@ packages: resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} dev: true - /@types/sass@1.43.1: - resolution: {integrity: sha512-BPdoIt1lfJ6B7rw35ncdwBZrAssjcwzI5LByIrYs+tpXlj/CAkuVdRsgZDdP4lq5EjyWzwxZCqAoFyHKFwp32g==} - dependencies: - '@types/node': 20.11.30 - dev: true - /@types/semver@7.5.8: resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} dev: true @@ -4639,7 +4633,7 @@ packages: '@vue/shared': 3.4.21 entities: 4.5.0 estree-walker: 2.0.2 - source-map-js: 1.0.2 + source-map-js: 1.2.0 /@vue/compiler-dom@3.2.0: resolution: {integrity: sha512-CqfATmX04+58LNBTTUPRBLyYGLP0bxtL+8b7B8pEvXja7fpmxiYcKBQsdaXfyqoRJsaTzA7eVXQt/t0dYhu/SQ==} @@ -4665,7 +4659,7 @@ packages: estree-walker: 2.0.2 magic-string: 0.30.8 postcss: 8.4.38 - source-map-js: 1.0.2 + source-map-js: 1.2.0 /@vue/compiler-ssr@3.4.21: resolution: {integrity: sha512-M5+9nI2lPpAsgXOGQobnIueVqc9sisBFexh5yMIMRAPYLa7+5wEJs8iqOZc1WAa9WQbx9GR2twgznU8LTIiZ4Q==} @@ -9168,7 +9162,7 @@ packages: dependencies: chokidar: 3.6.0(patch_hash=bckcfsslxcffppz65mxcq6naau) immutable: 4.0.0 - source-map-js: 1.0.2 + source-map-js: 1.2.0 dev: true /sax@1.3.0: @@ -9348,10 +9342,6 @@ packages: is-fullwidth-code-point: 5.0.0 dev: true - /source-map-js@1.0.2: - resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} - engines: {node: '>=0.10.0'} - /source-map-js@1.2.0: resolution: {integrity: sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==} engines: {node: '>=0.10.0'}