From aad407d59a91d2b511a6019c4b1490b07c963677 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 21 Sep 2024 01:57:44 +0800 Subject: [PATCH 1/9] chore(compiler-sfc): suppress deprecation warning of sass legacy api --- packages/compiler-sfc/src/style/preprocessors.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index 6a974368ecc..90879bbbf91 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -30,6 +30,7 @@ const scss: StylePreprocessor = (source, map, options, load = require) => { file: options.filename, outFile: options.filename, sourceMap: !!map, + silenceDeprecations: ['legacy-js-api'], } try { From 637b13793f6f9de5c4a9fca57dec9ed65a19be24 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 22 Sep 2024 13:59:14 +0800 Subject: [PATCH 2/9] refactor: support modern api --- .../compiler-sfc/src/style/preprocessors.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index 90879bbbf91..398353580c5 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -1,4 +1,5 @@ import merge from 'merge-source-map' +import { fileURLToPath, pathToFileURL } from 'url' import type { RawSourceMap } from '@vue/compiler-core' import type { SFCStyleCompileOptions } from '../compileStyle' import { isFunction } from '@vue/shared' @@ -23,23 +24,21 @@ export interface StylePreprocessorResults { // .scss/.sass processor const scss: StylePreprocessor = (source, map, options, load = require) => { - const nodeSass = load('sass') - const finalOptions = { + const nodeSass = load('sass') as typeof import('sass') + const data = getSource(source, options.filename, options.additionalData) + const finalOptions: import('sass').StringOptions<'sync'> = { ...options, - data: getSource(source, options.filename, options.additionalData), - file: options.filename, - outFile: options.filename, + url: pathToFileURL(options.filename), sourceMap: !!map, - silenceDeprecations: ['legacy-js-api'], } try { - const result = nodeSass.renderSync(finalOptions) - const dependencies = result.stats.includedFiles + const result = nodeSass.compileString(data, finalOptions) + const dependencies = result.loadedUrls.map(url => fileURLToPath(url)) if (map) { return { code: result.css.toString(), - map: merge(map, JSON.parse(result.map.toString())), + map: merge(map, JSON.parse(result.sourceMap?.toString() ?? '')), errors: [], dependencies, } From 78f5696d637cf5a1294cc27313d326464779a757 Mon Sep 17 00:00:00 2001 From: daiwei Date: Sun, 22 Sep 2024 17:27:34 +0800 Subject: [PATCH 3/9] chore: minor tweaks --- packages/compiler-sfc/src/style/preprocessors.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index 398353580c5..0e73348a046 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -1,5 +1,4 @@ import merge from 'merge-source-map' -import { fileURLToPath, pathToFileURL } from 'url' import type { RawSourceMap } from '@vue/compiler-core' import type { SFCStyleCompileOptions } from '../compileStyle' import { isFunction } from '@vue/shared' @@ -24,6 +23,7 @@ export interface StylePreprocessorResults { // .scss/.sass processor const scss: StylePreprocessor = (source, map, options, load = require) => { + const { pathToFileURL, fileURLToPath }: typeof import('url') = load('url') const nodeSass = load('sass') as typeof import('sass') const data = getSource(source, options.filename, options.additionalData) const finalOptions: import('sass').StringOptions<'sync'> = { @@ -37,14 +37,14 @@ const scss: StylePreprocessor = (source, map, options, load = require) => { const dependencies = result.loadedUrls.map(url => fileURLToPath(url)) if (map) { return { - code: result.css.toString(), - map: merge(map, JSON.parse(result.sourceMap?.toString() ?? '')), + code: result.css, + map: merge(map, result.sourceMap!), errors: [], dependencies, } } - return { code: result.css.toString(), errors: [], dependencies } + return { code: result.css, errors: [], dependencies } } catch (e: any) { return { code: '', errors: [e], dependencies: [] } } From d0f4d4a43d2196bffddec869cab1b29dfc75c9fd Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 22 Sep 2024 19:31:54 +0800 Subject: [PATCH 4/9] chore: type --- packages/compiler-sfc/src/style/preprocessors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index 0e73348a046..af79a74ee3a 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -24,7 +24,7 @@ export interface StylePreprocessorResults { // .scss/.sass processor const scss: StylePreprocessor = (source, map, options, load = require) => { const { pathToFileURL, fileURLToPath }: typeof import('url') = load('url') - const nodeSass = load('sass') as typeof import('sass') + const nodeSass: typeof import('sass') = load('sass') const data = getSource(source, options.filename, options.additionalData) const finalOptions: import('sass').StringOptions<'sync'> = { ...options, From 73a80e8153e01ef48fbe220683de670d4bb71808 Mon Sep 17 00:00:00 2001 From: edison Date: Sun, 22 Sep 2024 22:21:35 +0800 Subject: [PATCH 5/9] Update preprocessors.ts --- packages/compiler-sfc/src/style/preprocessors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index af79a74ee3a..3a73972c900 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -38,7 +38,7 @@ const scss: StylePreprocessor = (source, map, options, load = require) => { if (map) { return { code: result.css, - map: merge(map, result.sourceMap!), + map: merge(map, JSON.parse(result.sourceMap!.toString())), errors: [], dependencies, } From 211d03b0167e8803fc54527d25123f45aedb2691 Mon Sep 17 00:00:00 2001 From: edison Date: Sun, 22 Sep 2024 22:27:02 +0800 Subject: [PATCH 6/9] Update preprocessors.ts --- packages/compiler-sfc/src/style/preprocessors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index 3a73972c900..af79a74ee3a 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -38,7 +38,7 @@ const scss: StylePreprocessor = (source, map, options, load = require) => { if (map) { return { code: result.css, - map: merge(map, JSON.parse(result.sourceMap!.toString())), + map: merge(map, result.sourceMap!), errors: [], dependencies, } From fd852e484d6fbd5bc0d22945ca72b26219f26d61 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Mon, 23 Sep 2024 10:12:04 +0800 Subject: [PATCH 7/9] refactor: compatibility --- .../compiler-sfc/src/style/preprocessors.ts | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index af79a74ee3a..17f73ff7f53 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -23,28 +23,48 @@ export interface StylePreprocessorResults { // .scss/.sass processor const scss: StylePreprocessor = (source, map, options, load = require) => { - const { pathToFileURL, fileURLToPath }: typeof import('url') = load('url') const nodeSass: typeof import('sass') = load('sass') + const { compileString, renderSync } = nodeSass + const data = getSource(source, options.filename, options.additionalData) - const finalOptions: import('sass').StringOptions<'sync'> = { - ...options, - url: pathToFileURL(options.filename), - sourceMap: !!map, - } + let css: string + let dependencies: string[] + let sourceMap: any try { - const result = nodeSass.compileString(data, finalOptions) - const dependencies = result.loadedUrls.map(url => fileURLToPath(url)) + if (compileString) { + const { pathToFileURL, fileURLToPath }: typeof import('url') = load('url') + + const result = compileString(data, { + ...options, + url: pathToFileURL(options.filename), + sourceMap: !!map, + }) + css = result.css + dependencies = result.loadedUrls.map(url => fileURLToPath(url)) + sourceMap = map ? result.sourceMap! : undefined + } else { + const result = renderSync({ + ...options, + data, + file: options.filename, + outFile: options.filename, + sourceMap: !!map, + }) + css = result.css.toString() + dependencies = result.stats.includedFiles + sourceMap = map ? JSON.parse(result.map!.toString()) : undefined + } + if (map) { return { - code: result.css, - map: merge(map, result.sourceMap!), + code: css, errors: [], dependencies, + map: sourceMap, } } - - return { code: result.css, errors: [], dependencies } + return { code: css, errors: [], dependencies } } catch (e: any) { return { code: '', errors: [e], dependencies: [] } } From f5e05418d06e5dab96a6fa973d0bec03c4df08b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E5=90=B9=E8=89=B2=E5=BE=A1=E5=AE=88?= <85992002+KazariEX@users.noreply.github.com> Date: Mon, 23 Sep 2024 10:58:01 +0800 Subject: [PATCH 8/9] Update packages/compiler-sfc/src/style/preprocessors.ts Co-authored-by: edison --- packages/compiler-sfc/src/style/preprocessors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index 17f73ff7f53..dc857349532 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -61,7 +61,7 @@ const scss: StylePreprocessor = (source, map, options, load = require) => { code: css, errors: [], dependencies, - map: sourceMap, + map: merge(map,sourceMap!), } } return { code: css, errors: [], dependencies } From 1ae6da0a184e9b2a56efb24584333b3e8388b3c8 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 02:58:51 +0000 Subject: [PATCH 9/9] [autofix.ci] apply automated fixes --- packages/compiler-sfc/src/style/preprocessors.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compiler-sfc/src/style/preprocessors.ts b/packages/compiler-sfc/src/style/preprocessors.ts index dc857349532..8c210ad16d1 100644 --- a/packages/compiler-sfc/src/style/preprocessors.ts +++ b/packages/compiler-sfc/src/style/preprocessors.ts @@ -61,7 +61,7 @@ const scss: StylePreprocessor = (source, map, options, load = require) => { code: css, errors: [], dependencies, - map: merge(map,sourceMap!), + map: merge(map, sourceMap!), } } return { code: css, errors: [], dependencies }