From e88817ea3604b1597372fa9f57782cdfb9f308e5 Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Mon, 30 Dec 2024 16:48:57 -0500 Subject: [PATCH] Lint/format vite.config.mts (#2103) --- lint-staged.config.js | 2 +- vite.config.mts | 43 +++++++++++++++++++++++-------------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lint-staged.config.js b/lint-staged.config.js index 6370b0929..a62f5669d 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,7 +1,7 @@ export default { './**/*.js': (stagedFiles) => formatAndEslint(stagedFiles), - './**/*.{ts,tsx,vue}': (stagedFiles) => [ + './**/*.{ts,tsx,vue,mts}': (stagedFiles) => [ ...formatAndEslint(stagedFiles), 'vue-tsc --noEmit', 'tsc --noEmit', diff --git a/vite.config.mts b/vite.config.mts index 9d94fe575..c6bda643d 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -2,7 +2,7 @@ import { defineConfig, Plugin } from 'vite' import type { UserConfigExport } from 'vitest/config' import vue from '@vitejs/plugin-vue' import path from 'path' -import dotenv from "dotenv" +import dotenv from 'dotenv' import Icons from 'unplugin-icons/vite' import IconsResolver from 'unplugin-icons/resolver' import Components from 'unplugin-vue-components/vite' @@ -20,9 +20,9 @@ interface ShimResult { } function isLegacyFile(id: string): boolean { - return id.endsWith('.ts') && ( - id.includes("src/extensions/core") || - id.includes("src/scripts") + return ( + id.endsWith('.ts') && + (id.includes('src/extensions/core') || id.includes('src/scripts')) ) } @@ -43,15 +43,15 @@ function comfyAPIPlugin(): Plugin { const shimComment = `// Shim for ${relativePath}\n` this.emitFile({ - type: "asset", + type: 'asset', fileName: shimFileName, - source: shimComment + result.exports.join("") + source: shimComment + result.exports.join('') }) } return { 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 // 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 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}.${name} = ${name};` - exports.push(`export const ${name} = window.comfyAPI.${moduleName}.${name};\n`) + exports.push( + `export const ${name} = window.comfyAPI.${moduleName}.${name};\n` + ) } return { @@ -88,10 +91,11 @@ function getModuleName(id: string): string { // Simple example to derive a module name from the file path const parts = id.split('/') 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({ base: '', @@ -99,7 +103,7 @@ export default defineConfig({ host: VITE_REMOTE_DEV ? '0.0.0.0' : undefined, proxy: { '/internal': { - target: DEV_SERVER_COMFYUI_URL, + target: DEV_SERVER_COMFYUI_URL }, '/api': { @@ -111,7 +115,7 @@ export default defineConfig({ res.end(JSON.stringify([])) } return null - }, + } }, '/ws': { @@ -135,7 +139,7 @@ export default defineConfig({ comfyAPIPlugin(), Icons({ - 'compiler': 'vue3' + compiler: 'vue3' }), Components({ @@ -172,7 +176,9 @@ export default defineConfig({ }, define: { - '__COMFYUI_FRONTEND_VERSION__': JSON.stringify(process.env.npm_package_version) + __COMFYUI_FRONTEND_VERSION__: JSON.stringify( + process.env.npm_package_version + ) }, resolve: { @@ -182,9 +188,6 @@ export default defineConfig({ }, optimizeDeps: { - exclude: [ - '@comfyorg/litegraph', - '@comfyorg/comfyui-electron-types' - ] + exclude: ['@comfyorg/litegraph', '@comfyorg/comfyui-electron-types'] } -}) as UserConfigExport \ No newline at end of file +}) as UserConfigExport