From 66d02eeb6aff5c15b8c727d0eda4e9fc420fe09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=89=8B=E7=93=9C=E4=B8=80=E5=8D=81=E9=9B=AA?= Date: Fri, 14 Nov 2025 21:21:49 +0800 Subject: [PATCH] Enable source maps and improve debugging support This commit enables source maps in napcat-shell's Vite config for better debugging, adds source map path overrides to VSCode settings, and updates nodeTest.ps1 to launch with the Node.js inspector. The autoIncludeTSPlugin transform now returns a source map for improved breakpoint support in VSCode. Also adds a sources.txt file listing project and dependency sources. --- .vscode/settings.json | 7 +++++++ packages/napcat-develop/nodeTest.ps1 | 2 +- packages/napcat-shell/vite.config.ts | 4 ++-- packages/napcat-vite/vite-auto-include.js | 12 +++++++++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7a73a41b..a0a29010 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,2 +1,9 @@ { + "debug.node.sourceMapPathOverrides": { + "../../napcat-onebot/*": "${workspaceFolder}/packages/napcat-onebot/*", + "../../napcat-core/*": "${workspaceFolder}/packages/napcat-core/*", + "../../napcat-common/*": "${workspaceFolder}/packages/napcat-common/*", + "../../napcat-webui-backend/*": "${workspaceFolder}/packages/napcat-webui-backend/*", + "../../napcat-pty/*": "${workspaceFolder}/packages/napcat-pty/*" + } } \ No newline at end of file diff --git a/packages/napcat-develop/nodeTest.ps1 b/packages/napcat-develop/nodeTest.ps1 index 1118337a..9ae0b157 100644 --- a/packages/napcat-develop/nodeTest.ps1 +++ b/packages/napcat-develop/nodeTest.ps1 @@ -5,4 +5,4 @@ $uninstall = $uninstall.Trim('"') $qqPath = Split-Path $uninstall -Parent Write-Host "QQPath: $qqPath" -node.exe "./loadNapCat.cjs" "$qqPath" +node.exe --inspect "./loadNapCat.cjs" "$qqPath" diff --git a/packages/napcat-shell/vite.config.ts b/packages/napcat-shell/vite.config.ts index c9aac813..b956995d 100644 --- a/packages/napcat-shell/vite.config.ts +++ b/packages/napcat-shell/vite.config.ts @@ -48,7 +48,7 @@ const ShellBaseConfig = () => }, }, build: { - sourcemap: false, + sourcemap: true, target: 'esnext', minify: false, lib: { @@ -61,7 +61,7 @@ const ShellBaseConfig = () => fileName: (_, entryName) => `${entryName}.mjs`, }, rollupOptions: { - external: [...nodeModules, ...external], + external: [...nodeModules, ...external] }, }, }); diff --git a/packages/napcat-vite/vite-auto-include.js b/packages/napcat-vite/vite-auto-include.js index 4a0914d8..34402f67 100644 --- a/packages/napcat-vite/vite-auto-include.js +++ b/packages/napcat-vite/vite-auto-include.js @@ -35,7 +35,6 @@ export function autoIncludeTSPlugin(options) { transform(code, id) { for (const [entry, tsFiles] of Object.entries(tsFilesMap)) { - // 检查id是否匹配entry(支持完整路径或相对路径) const isMatch = id.endsWith(entry) || id.includes(entry); if (isMatch && tsFiles.length > 0) { const imports = tsFiles.map(filePath => { @@ -43,11 +42,18 @@ export function autoIncludeTSPlugin(options) { return `import './${relativePath}';`; }).join('\n'); - return imports + '\n' + code; + const transformedCode = imports + '\n' + code; + + return { + code: transformedCode, + map: { mappings: '' } // 空映射即可,VSCode 可以在 TS 上断点 + }; } } - return code; + + return null; }, + }; }