Lint/format vite.config.mts (#2103)

This commit is contained in:
Chenlei Hu
2024-12-30 16:48:57 -05:00
committed by GitHub
parent 4ae77e22d4
commit e88817ea36
2 changed files with 24 additions and 21 deletions

View File

@@ -1,7 +1,7 @@
export default { export default {
'./**/*.js': (stagedFiles) => formatAndEslint(stagedFiles), './**/*.js': (stagedFiles) => formatAndEslint(stagedFiles),
'./**/*.{ts,tsx,vue}': (stagedFiles) => [ './**/*.{ts,tsx,vue,mts}': (stagedFiles) => [
...formatAndEslint(stagedFiles), ...formatAndEslint(stagedFiles),
'vue-tsc --noEmit', 'vue-tsc --noEmit',
'tsc --noEmit', 'tsc --noEmit',

View File

@@ -2,7 +2,7 @@ import { defineConfig, Plugin } from 'vite'
import type { UserConfigExport } from 'vitest/config' import type { UserConfigExport } from 'vitest/config'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import path from 'path' import path from 'path'
import dotenv from "dotenv" import dotenv from 'dotenv'
import Icons from 'unplugin-icons/vite' import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver' import IconsResolver from 'unplugin-icons/resolver'
import Components from 'unplugin-vue-components/vite' import Components from 'unplugin-vue-components/vite'
@@ -20,9 +20,9 @@ interface ShimResult {
} }
function isLegacyFile(id: string): boolean { function isLegacyFile(id: string): boolean {
return id.endsWith('.ts') && ( return (
id.includes("src/extensions/core") || id.endsWith('.ts') &&
id.includes("src/scripts") (id.includes('src/extensions/core') || id.includes('src/scripts'))
) )
} }
@@ -43,15 +43,15 @@ function comfyAPIPlugin(): Plugin {
const shimComment = `// Shim for ${relativePath}\n` const shimComment = `// Shim for ${relativePath}\n`
this.emitFile({ this.emitFile({
type: "asset", type: 'asset',
fileName: shimFileName, fileName: shimFileName,
source: shimComment + result.exports.join("") source: shimComment + result.exports.join('')
}) })
} }
return { return {
code: result.code, code: result.code,
map: null // If you're not modifying the source map, return null map: null // If you're not modifying the source map, return null
} }
} }
} }
@@ -64,7 +64,8 @@ function transformExports(code: string, id: string): ShimResult {
let newCode = code let newCode = code
// Regex to match different types of exports // Regex to match different types of exports
const regex = /export\s+(const|let|var|function|class|async function)\s+([a-zA-Z$_][a-zA-Z\d$_]*)(\s|\()/g const regex =
/export\s+(const|let|var|function|class|async function)\s+([a-zA-Z$_][a-zA-Z\d$_]*)(\s|\()/g
let match let match
while ((match = regex.exec(code)) !== null) { while ((match = regex.exec(code)) !== null) {
@@ -75,7 +76,9 @@ function transformExports(code: string, id: string): ShimResult {
newCode += `\nwindow.comfyAPI.${moduleName} = window.comfyAPI.${moduleName} || {};` newCode += `\nwindow.comfyAPI.${moduleName} = window.comfyAPI.${moduleName} || {};`
} }
newCode += `\nwindow.comfyAPI.${moduleName}.${name} = ${name};` newCode += `\nwindow.comfyAPI.${moduleName}.${name} = ${name};`
exports.push(`export const ${name} = window.comfyAPI.${moduleName}.${name};\n`) exports.push(
`export const ${name} = window.comfyAPI.${moduleName}.${name};\n`
)
} }
return { return {
@@ -88,10 +91,11 @@ function getModuleName(id: string): string {
// Simple example to derive a module name from the file path // Simple example to derive a module name from the file path
const parts = id.split('/') const parts = id.split('/')
const fileName = parts[parts.length - 1] const fileName = parts[parts.length - 1]
return fileName.replace(/\.\w+$/, '') // Remove file extension return fileName.replace(/\.\w+$/, '') // Remove file extension
} }
const DEV_SERVER_COMFYUI_URL = process.env.DEV_SERVER_COMFYUI_URL || 'http://127.0.0.1:8188' const DEV_SERVER_COMFYUI_URL =
process.env.DEV_SERVER_COMFYUI_URL || 'http://127.0.0.1:8188'
export default defineConfig({ export default defineConfig({
base: '', base: '',
@@ -99,7 +103,7 @@ export default defineConfig({
host: VITE_REMOTE_DEV ? '0.0.0.0' : undefined, host: VITE_REMOTE_DEV ? '0.0.0.0' : undefined,
proxy: { proxy: {
'/internal': { '/internal': {
target: DEV_SERVER_COMFYUI_URL, target: DEV_SERVER_COMFYUI_URL
}, },
'/api': { '/api': {
@@ -111,7 +115,7 @@ export default defineConfig({
res.end(JSON.stringify([])) res.end(JSON.stringify([]))
} }
return null return null
}, }
}, },
'/ws': { '/ws': {
@@ -135,7 +139,7 @@ export default defineConfig({
comfyAPIPlugin(), comfyAPIPlugin(),
Icons({ Icons({
'compiler': 'vue3' compiler: 'vue3'
}), }),
Components({ Components({
@@ -172,7 +176,9 @@ export default defineConfig({
}, },
define: { define: {
'__COMFYUI_FRONTEND_VERSION__': JSON.stringify(process.env.npm_package_version) __COMFYUI_FRONTEND_VERSION__: JSON.stringify(
process.env.npm_package_version
)
}, },
resolve: { resolve: {
@@ -182,9 +188,6 @@ export default defineConfig({
}, },
optimizeDeps: { optimizeDeps: {
exclude: [ exclude: ['@comfyorg/litegraph', '@comfyorg/comfyui-electron-types']
'@comfyorg/litegraph',
'@comfyorg/comfyui-electron-types'
]
} }
}) as UserConfigExport }) as UserConfigExport