Files
toor 01d9e301fc
Build / build (push) Canceled after 0s
Playwright / browser (push) Canceled after 0s
initialize Electron desktop app and remove unused files
2026-10-25 01:09:01 +08:00

46 lines
1.6 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig, type Plugin } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
/**
* Vite 的 SSR 变换用 `/^#!.*\n/` 识别 shebang,并把 import 声明提升到它前面。
* 这个正则只在 LF 工作区成立:`.` 不匹配 `\r`,所以 CRLF checkout(Windows 默认
* core.autocrlf=true)下 shebang 识别失败,import 被提升到 `#!/usr/bin/env node`
* 之前,shebang 落到文件中部,运行期直接抛 "Invalid or unexpected token"。
*
* 统一在 SSR 变换之前剥掉 shebang:它只对「直接执行」有意义,测试里不需要。
*/
function stripShebang(): Plugin {
return {
name: 'hermes:strip-shebang',
enforce: 'pre',
transform(code, id) {
if (!code.startsWith('#!')) return null
const newline = code.indexOf('\n')
return { code: newline === -1 ? '' : code.slice(newline + 1), map: null }
},
}
}
export default defineConfig({
plugins: [stripShebang(), vue()],
resolve: {
alias: {
'@': resolve(__dirname, 'packages/client/src'),
'/logo.png': resolve(__dirname, 'packages/client/public/logo.png'),
},
},
test: {
include: ['tests/**/*.test.ts'],
setupFiles: ['tests/setup.ts'],
coverage: {
// Without an explicit include, v8 coverage walks the whole project root.
// While the read-only reference_code/ checkout was present that pulled in
// ~570 of its files and diluted every percentage below.
provider: 'v8',
include: ['packages/*/src/**'],
exclude: ['**/vendor/**', '**/*.d.ts'],
},
},
})