From e1a0204f9003db016109439e6ad8e4e06e150744 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Sat, 13 Jan 2024 16:39:13 +0800 Subject: [PATCH] =?UTF-8?q?wip(uvue):=20=E4=BC=98=E5=8C=96=20web=20?= =?UTF-8?q?=E7=AB=AF=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA=EF=BC=8Csourcemap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/uni-h5-vite/src/plugins/sourcemap.ts | 48 ++++++++++--------- packages/uni-uts-v1/package.json | 3 +- pnpm-lock.yaml | 25 +++------- 3 files changed, 35 insertions(+), 41 deletions(-) diff --git a/packages/uni-h5-vite/src/plugins/sourcemap.ts b/packages/uni-h5-vite/src/plugins/sourcemap.ts index 95405cdf5a..b5504b2b03 100644 --- a/packages/uni-h5-vite/src/plugins/sourcemap.ts +++ b/packages/uni-h5-vite/src/plugins/sourcemap.ts @@ -31,33 +31,37 @@ class PendingRequests extends Map { _inputDir!: string _server!: ViteDevServer set(key: string, value: PendingRequest) { - value.request = Promise.resolve(value.request).then(async (request) => { - const map = request?.map - if (map) { - const mod = await this._server.moduleGraph.ensureEntryFromUrl(key) - if (mod.file && isAbsolute(mod.file)) { - const dir = normalizePath(dirname(mod.file)) - if (dir.startsWith(this._inputDir)) { - for ( - let sourcesIndex = 0; - sourcesIndex < map.sources.length; - ++sourcesIndex - ) { - const sourcePath = map.sources[sourcesIndex] - if (sourcePath) { - // 将相对路径转换为绝对路径 - if (!isAbsolute(sourcePath)) { - map.sources[sourcesIndex] = normalizePath( - join(dir, sourcePath) - ) + value.request = value.request + .then(async (request) => { + const map = request?.map + if (map) { + const mod = await this._server.moduleGraph.ensureEntryFromUrl(key) + if (mod.file && isAbsolute(mod.file)) { + const dir = normalizePath(dirname(mod.file)) + if (dir.startsWith(this._inputDir)) { + for ( + let sourcesIndex = 0; + sourcesIndex < map.sources.length; + ++sourcesIndex + ) { + const sourcePath = map.sources[sourcesIndex] + if (sourcePath) { + // 将相对路径转换为绝对路径 + if (!isAbsolute(sourcePath)) { + map.sources[sourcesIndex] = normalizePath( + join(dir, sourcePath) + ) + } } } } } } - } - return request - }) + return request + }) + .catch(() => { + return null + }) return super.set(key, value) } } diff --git a/packages/uni-uts-v1/package.json b/packages/uni-uts-v1/package.json index ee5574a463..f94eff4581 100644 --- a/packages/uni-uts-v1/package.json +++ b/packages/uni-uts-v1/package.json @@ -18,11 +18,12 @@ }, "license": "Apache-2.0", "dependencies": { + "@babel/code-frame": "^7.23.5", "@dcloudio/uts": "3.0.0-alpha-4000020240111001", "@rollup/pluginutils": "^5.0.5", "@vue/shared": "3.3.11", - "android-versions": "^1.8.1", "adm-zip": "^0.5.9", + "android-versions": "^1.8.1", "colors": "^1.4.0", "fast-glob": "^3.2.11", "find-cache-dir": "^3.3.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9cbcb86285..81ef9f8e74 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1397,6 +1397,9 @@ importers: packages/uni-uts-v1: dependencies: + '@babel/code-frame': + specifier: ^7.23.5 + version: 7.23.5 '@dcloudio/uts': specifier: 3.0.0-alpha-4000020240111001 version: link:../uts @@ -1651,12 +1654,6 @@ packages: /@antfu/utils@0.7.6: resolution: {integrity: sha512-pvFiLP2BeOKA/ZOS6jxx4XhKzdVLHDhGlFEaZ2flWWYf2xOqVniqpk38I04DFRyz+L0ASggl7SkItTc+ZLju4w==} - /@babel/code-frame@7.21.4: - resolution: {integrity: sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/highlight': 7.18.6 - /@babel/code-frame@7.23.5: resolution: {integrity: sha512-CgH3s1a96LipHCmSUmYFPwY7MNx8C3avkq7i4Wl3cfa662ldtUe4VM1TPXX70pfmrlWTb6jLqTYrZyT2ZTJBgA==} engines: {node: '>=6.9.0'} @@ -1913,14 +1910,6 @@ packages: transitivePeerDependencies: - supports-color - /@babel/highlight@7.18.6: - resolution: {integrity: sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==} - engines: {node: '>=6.9.0'} - dependencies: - '@babel/helper-validator-identifier': 7.19.1 - chalk: 2.4.2 - js-tokens: 4.0.0 - /@babel/highlight@7.23.4: resolution: {integrity: sha512-acGdbYSfp2WheJoJm/EBBBLh/ID8KDc64ISZ9DYtBmC8/Q204PZJLHyzeB5qMzJ5trcOkybd78M4x2KWsUq++A==} engines: {node: '>=6.9.0'} @@ -2758,7 +2747,7 @@ packages: resolution: {integrity: sha512-AhQoI3YjWi6u/y/ntv7k48mcrCXmus0t79J9qPNlk/lAsFlCiJ047RmbfMOawySTHtywXhbXgpx/8nXMYd+oFw==} engines: {node: '>=6.9.0'} dependencies: - '@babel/code-frame': 7.21.4 + '@babel/code-frame': 7.23.5 '@babel/generator': 7.21.5 '@babel/helper-environment-visitor': 7.21.5 '@babel/helper-function-name': 7.21.0 @@ -7930,7 +7919,7 @@ packages: resolution: {integrity: sha512-rMyFe1+jnyAAf+NHwTclDz0eAaLkVDdKVHHBFWsBWHnnh5YeJMNWWsv7AbFYXfK3oTqvL7VTWkhNLu1jX24D+g==} engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0} dependencies: - '@babel/code-frame': 7.21.4 + '@babel/code-frame': 7.23.5 '@jest/types': 27.5.1 '@types/stack-utils': 2.0.1 chalk: 4.1.2 @@ -7945,7 +7934,7 @@ packages: resolution: {integrity: sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} dependencies: - '@babel/code-frame': 7.21.4 + '@babel/code-frame': 7.23.5 '@jest/types': 29.5.0 '@types/stack-utils': 2.0.1 chalk: 4.1.2 @@ -9298,7 +9287,7 @@ packages: resolution: {integrity: sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==} engines: {node: '>=8'} dependencies: - '@babel/code-frame': 7.21.4 + '@babel/code-frame': 7.23.5 error-ex: 1.3.2 json-parse-even-better-errors: 2.3.1 lines-and-columns: 1.2.4 -- GitLab