From 4980fea9cb92b992afb0297388dbc29c8b50bc7e Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 6 May 2022 12:17:08 +0800 Subject: [PATCH] build(deps): bump vite from 2.9.7 to 2.9.8 --- package.json | 6 ++-- packages/playground/ssr/package.json | 4 +-- packages/uni-app-vite/package.json | 2 +- .../src/vite/plugins/vitejs/plugins/css.ts | 31 ++++++++++++++----- .../src/vite/plugins/vitejs/utils.ts | 13 +++++--- packages/uni-h5/package.json | 2 +- packages/vite-plugin-uni/package.json | 4 +-- pnpm-lock.yaml | 16 +++++----- scripts/checkVersion.js | 8 ++--- 9 files changed, 52 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index b407d0f66..b084c5c35 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "@types/jest": "^26.0.23", "@types/node": "^17.0.31", "@typescript-eslint/parser": "^5.14.0", - "@vitejs/plugin-vue": "^2.3.1", + "@vitejs/plugin-vue": "^2.3.2", "@vitejs/plugin-vue-jsx": "^1.3.10", "@vue/reactivity": "3.2.33", "@vue/runtime-core": "3.2.33", @@ -85,9 +85,9 @@ "semver": "^7.3.5", "ts-jest": "^27.0.3", "typescript": "4.6.4", - "vite": "^2.9.7", + "vite": "^2.9.8", "vue": "3.2.33", - "vue-router": "^4.0.14", + "vue-router": "^4.0.15", "yorkie": "^2.0.0" }, "name": "uni-app-next" diff --git a/packages/playground/ssr/package.json b/packages/playground/ssr/package.json index b35adda1c..c207b90a7 100644 --- a/packages/playground/ssr/package.json +++ b/packages/playground/ssr/package.json @@ -13,7 +13,7 @@ "@dcloudio/uni-components": "../../uni-components", "@dcloudio/uni-h5": "../../uni-h5", "vue": "3.2.33", - "vue-router": "^4.0.14", + "vue-router": "^4.0.15", "vuex": "^4.0.2" }, "devDependencies": { @@ -21,6 +21,6 @@ "compression": "^1.7.4", "cypress": "^7.3.0", "serve-static": "^1.14.1", - "vite": "^2.9.7" + "vite": "^2.9.8" } } diff --git a/packages/uni-app-vite/package.json b/packages/uni-app-vite/package.json index a403d3ddc..2b493e54c 100644 --- a/packages/uni-app-vite/package.json +++ b/packages/uni-app-vite/package.json @@ -29,7 +29,7 @@ "@dcloudio/uni-shared": "3.0.0-alpha-3040820220424001", "@dcloudio/uts": "3.0.0-alpha-3040820220424001", "@rollup/pluginutils": "^4.2.0", - "@vitejs/plugin-vue": "^2.3.1", + "@vitejs/plugin-vue": "^2.3.2", "@vue/compiler-dom": "3.2.33", "@vue/compiler-sfc": "3.2.33", "cac": "6.7.9", diff --git a/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts b/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts index 5035de0aa..ce8965f15 100644 --- a/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts +++ b/packages/uni-cli-shared/src/vite/plugins/vitejs/plugins/css.ts @@ -83,6 +83,7 @@ export const cssLangRE = new RegExp(cssLangs) const cssModuleRE = new RegExp(`\\.module${cssLangs}`) const directRequestRE = /(\?|&)direct\b/ export const commonjsProxyRE = /\?commonjs-proxy/ +const varRE = /^var\(/i const enum PreprocessLang { less = 'less', @@ -558,8 +559,8 @@ async function compileCSS( .default(postcssPlugins) .process(code, { ...postcssOptions, - to: cleanUrl(id), - from: cleanUrl(id), + to: id, + from: id, map: { inline: false, annotation: false, @@ -737,7 +738,7 @@ type CssUrlReplacer = ( // https://drafts.csswg.org/css-syntax-3/#identifier-code-point export const cssUrlRE = /(?<=^|[^\w\-\u0080-\uffff])url\(\s*('[^']+'|"[^"]+"|[^'")]+)\s*\)/ -const cssImageSetRE = /image-set\(([^)]+)\)/ +const cssImageSetRE = /(?<=image-set\()((?:[\w\-]+\([^\)]*\)|[^)])*)(?=\))/ const UrlRewritePostcssPlugin: Postcss.PluginCreator<{ replacer: CssUrlReplacer @@ -758,7 +759,9 @@ const UrlRewritePostcssPlugin: Postcss.PluginCreator<{ const importer = declaration.source?.input.file return opts.replacer(rawUrl, importer) } - const rewriterToUse = isCssUrl ? rewriteCssUrls : rewriteCssImageSet + const rewriterToUse = isCssImageSet + ? rewriteCssImageSet + : rewriteCssUrls promises.push( rewriterToUse(declaration.value, replacerForDeclaration).then( (url) => { @@ -780,9 +783,16 @@ function rewriteCssUrls( css: string, replacer: CssUrlReplacer ): Promise { - return asyncReplace(css, cssUrlRE, async (match) => { - const [matched, rawUrl] = match - return await doUrlReplace(rawUrl, matched, replacer) + return asyncReplace(css, cssImageSetRE, async (match) => { + const [, rawUrl] = match + const url = await processSrcSet(rawUrl, async ({ url }) => { + // the url maybe url(...) + if (cssUrlRE.test(url)) { + return await rewriteCssUrls(url, replacer) + } + return await doUrlReplace(url, url, replacer) + }) + return url }) } @@ -809,7 +819,12 @@ async function doUrlReplace( wrap = first rawUrl = rawUrl.slice(1, -1) } - if (isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl.startsWith('#')) { + if ( + isExternalUrl(rawUrl) || + isDataUrl(rawUrl) || + rawUrl.startsWith('#') || + varRE.test(rawUrl) + ) { return matched } diff --git a/packages/uni-cli-shared/src/vite/plugins/vitejs/utils.ts b/packages/uni-cli-shared/src/vite/plugins/vitejs/utils.ts index 9d9c922c7..b9c243514 100644 --- a/packages/uni-cli-shared/src/vite/plugins/vitejs/utils.ts +++ b/packages/uni-cli-shared/src/vite/plugins/vitejs/utils.ts @@ -126,6 +126,7 @@ interface ImageCandidate { descriptor: string } const escapedSpaceCharacters = /( |\\t|\\n|\\f|\\r)+/g +const imageSetUrlRE = /^(?:[\w\-]+\(.*?\)|'.*?'|".*?"|\S*)/ export async function processSrcSet( srcs: string, replacer: (arg: ImageCandidate) => Promise @@ -133,11 +134,13 @@ export async function processSrcSet( const imageCandidates: ImageCandidate[] = srcs .split(',') .map((s) => { - const [url, descriptor] = s - .replace(escapedSpaceCharacters, ' ') - .trim() - .split(' ', 2) - return { url, descriptor } + const src = s.replace(escapedSpaceCharacters, ' ').trim() + const [url] = imageSetUrlRE.exec(src) || [] + + return { + url, + descriptor: src?.slice(url.length).trim(), + } }) .filter(({ url }) => !!url) diff --git a/packages/uni-h5/package.json b/packages/uni-h5/package.json index 3af939baf..13c81a219 100644 --- a/packages/uni-h5/package.json +++ b/packages/uni-h5/package.json @@ -37,7 +37,7 @@ "@vue/shared": "3.2.33", "localstorage-polyfill": "^1.0.1", "safe-area-insets": "^1.4.1", - "vue-router": "^4.0.14", + "vue-router": "^4.0.15", "xmlhttprequest": "^1.8.0" }, "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da", diff --git a/packages/vite-plugin-uni/package.json b/packages/vite-plugin-uni/package.json index b830c1332..c55cb7ce9 100644 --- a/packages/vite-plugin-uni/package.json +++ b/packages/vite-plugin-uni/package.json @@ -29,7 +29,7 @@ "@dcloudio/uni-shared": "3.0.0-alpha-3040820220424001", "@rollup/pluginutils": "^4.2.0", "@vitejs/plugin-legacy": "^1.8.2", - "@vitejs/plugin-vue": "^2.3.1", + "@vitejs/plugin-vue": "^2.3.2", "@vitejs/plugin-vue-jsx": "^1.3.10", "@vue/compiler-core": "3.2.33", "@vue/compiler-dom": "3.2.33", @@ -54,7 +54,7 @@ "chokidar": "^3.5.3" }, "peerDependencies": { - "vite": "^2.9.7" + "vite": "^2.9.8" }, "uni-app": { "compilerVersion": "3.4.8" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fcb49f08f..aa2080f86 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,7 +20,7 @@ importers: '@types/jest': ^26.0.23 '@types/node': ^17.0.31 '@typescript-eslint/parser': ^5.14.0 - '@vitejs/plugin-vue': ^2.3.1 + '@vitejs/plugin-vue': ^2.3.2 '@vitejs/plugin-vue-jsx': ^1.3.10 '@vue/reactivity': 3.2.33 '@vue/runtime-core': 3.2.33 @@ -48,9 +48,9 @@ importers: semver: ^7.3.5 ts-jest: ^27.0.3 typescript: 4.6.4 - vite: ^2.9.7 + vite: ^2.9.8 vue: 3.2.33 - vue-router: ^4.0.14 + vue-router: ^4.0.15 yorkie: ^2.0.0 devDependencies: '@babel/preset-env': 7.17.10 @@ -111,9 +111,9 @@ importers: compression: ^1.7.4 cypress: ^7.3.0 serve-static: ^1.14.1 - vite: ^2.9.7 + vite: ^2.9.8 vue: 3.2.33 - vue-router: ^4.0.14 + vue-router: ^4.0.15 vuex: ^4.0.2 dependencies: '@dcloudio/uni-app': link:../../uni-app @@ -212,7 +212,7 @@ importers: '@rollup/pluginutils': ^4.2.0 '@types/debug': ^4.1.7 '@types/fs-extra': ^9.0.13 - '@vitejs/plugin-vue': ^2.3.1 + '@vitejs/plugin-vue': ^2.3.2 '@vue/compiler-core': 3.2.33 '@vue/compiler-dom': 3.2.33 '@vue/compiler-sfc': 3.2.33 @@ -441,7 +441,7 @@ importers: localstorage-polyfill: ^1.0.1 safe-area-insets: ^1.4.1 vue: 3.2.33 - vue-router: ^4.0.14 + vue-router: ^4.0.15 xmlhttprequest: ^1.8.0 dependencies: '@dcloudio/uni-h5-vite': link:../uni-h5-vite @@ -794,7 +794,7 @@ importers: '@types/fs-extra': ^9.0.13 '@types/sass': ^1.16.0 '@vitejs/plugin-legacy': ^1.8.2 - '@vitejs/plugin-vue': ^2.3.1 + '@vitejs/plugin-vue': ^2.3.2 '@vitejs/plugin-vue-jsx': ^1.3.10 '@vue/babel-plugin-jsx': ^1.1.1 '@vue/compiler-core': 3.2.33 diff --git a/scripts/checkVersion.js b/scripts/checkVersion.js index ef226a4d5..056f9c5e8 100644 --- a/scripts/checkVersion.js +++ b/scripts/checkVersion.js @@ -13,22 +13,22 @@ const pkgs = { latest: '3.2.33', }, 'vue-router': { - latest: '4.0.14', + latest: '4.0.15', }, vuex: { latest: '4.0.2', }, pinia: { - latest: '2.0.13', + latest: '2.0.14', }, 'vue-i18n': { next: '9.1.9', }, vite: { - latest: '2.9.7', + latest: '2.9.8', }, '@vitejs/plugin-vue': { - latest: '2.3.1', + latest: '2.3.2', }, '@vitejs/plugin-vue-jsx': { latest: '1.3.10', -- GitLab