style: Apply Prettier formatting

- Fix trailing whitespace
- Add missing newlines at end of files
This commit is contained in:
snomiao
2025-09-02 21:17:27 +00:00
parent 3700457462
commit f037567fc5
3 changed files with 20 additions and 20 deletions

View File

@@ -8,16 +8,16 @@ import { preprocessLitegraph } from './i18nSetup'
export default async function globalSetupWithI18n() { export default async function globalSetupWithI18n() {
// First preprocess litegraph files // First preprocess litegraph files
await preprocessLitegraph() await preprocessLitegraph()
// Then run regular global setup // Then run regular global setup
await globalSetup() await globalSetup()
// Register cleanup handlers // Register cleanup handlers
const cleanup = async () => { const cleanup = async () => {
const { restoreLitegraph } = await import('./i18nSetup') const { restoreLitegraph } = await import('./i18nSetup')
await restoreLitegraph() await restoreLitegraph()
} }
process.on('exit', cleanup) process.on('exit', cleanup)
process.on('SIGINT', async () => { process.on('SIGINT', async () => {
await cleanup() await cleanup()
@@ -27,4 +27,4 @@ export default async function globalSetupWithI18n() {
await cleanup() await cleanup()
process.exit(0) process.exit(0)
}) })
} }

View File

@@ -8,7 +8,7 @@ import { restoreLitegraph } from './i18nSetup'
export default async function globalTeardownWithI18n() { export default async function globalTeardownWithI18n() {
// First run regular teardown // First run regular teardown
await globalTeardown() await globalTeardown()
// Then restore litegraph files // Then restore litegraph files
await restoreLitegraph() await restoreLitegraph()
} }

View File

@@ -3,9 +3,9 @@
* Handles preprocessing of litegraph files that contain TypeScript 'declare' keywords * Handles preprocessing of litegraph files that contain TypeScript 'declare' keywords
*/ */
import { promises as fs } from 'fs' import { promises as fs } from 'fs'
import { glob } from 'glob'
import * as path from 'path' import * as path from 'path'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import { glob } from 'glob'
const __dirname = path.dirname(fileURLToPath(import.meta.url)) const __dirname = path.dirname(fileURLToPath(import.meta.url))
const rootDir = path.resolve(__dirname, '..') const rootDir = path.resolve(__dirname, '..')
@@ -22,7 +22,7 @@ async function findFilesWithDeclare(): Promise<string[]> {
const files = await glob(pattern, { const files = await glob(pattern, {
ignore: ['**/*.test.ts', '**/*.spec.ts', '**/node_modules/**'] ignore: ['**/*.test.ts', '**/*.spec.ts', '**/node_modules/**']
}) })
// Filter to only files that actually contain 'declare' keyword // Filter to only files that actually contain 'declare' keyword
const filesWithDeclare = await Promise.all( const filesWithDeclare = await Promise.all(
files.map(async (filePath) => { files.map(async (filePath) => {
@@ -36,35 +36,35 @@ async function findFilesWithDeclare(): Promise<string[]> {
} }
}) })
) )
return filesWithDeclare.filter((file): file is string => file !== null) return filesWithDeclare.filter((file): file is string => file !== null)
} }
export async function preprocessLitegraph() { export async function preprocessLitegraph() {
console.log('Preprocessing litegraph files for i18n collection...') console.log('Preprocessing litegraph files for i18n collection...')
const filesToProcess = await findFilesWithDeclare() const filesToProcess = await findFilesWithDeclare()
if (filesToProcess.length === 0) { if (filesToProcess.length === 0) {
console.log(' No files with declare keywords found') console.log(' No files with declare keywords found')
return return
} }
console.log(` Found ${filesToProcess.length} files with declare keywords`) console.log(` Found ${filesToProcess.length} files with declare keywords`)
await Promise.all( await Promise.all(
filesToProcess.map(async (filePath) => { filesToProcess.map(async (filePath) => {
const originalContent = await fs.readFile(filePath, 'utf-8') const originalContent = await fs.readFile(filePath, 'utf-8')
// Store original content in memory // Store original content in memory
backupMap.set(filePath, originalContent) backupMap.set(filePath, originalContent)
// Remove 'declare' keyword from class properties // Remove 'declare' keyword from class properties
const modifiedContent = originalContent.replace( const modifiedContent = originalContent.replace(
/^(\s*)declare\s+/gm, /^(\s*)declare\s+/gm,
'$1// @ts-ignore - removed declare for Playwright\n$1' '$1// @ts-ignore - removed declare for Playwright\n$1'
) )
// Write modified content // Write modified content
await fs.writeFile(filePath, modifiedContent) await fs.writeFile(filePath, modifiedContent)
console.log(` ✓ Processed ${path.relative(litegraphSrcDir, filePath)}`) console.log(` ✓ Processed ${path.relative(litegraphSrcDir, filePath)}`)
@@ -76,15 +76,15 @@ export async function restoreLitegraph() {
if (backupMap.size === 0) { if (backupMap.size === 0) {
return return
} }
console.log('Restoring original litegraph files...') console.log('Restoring original litegraph files...')
await Promise.all( await Promise.all(
Array.from(backupMap.entries()).map(async ([filePath, originalContent]) => { Array.from(backupMap.entries()).map(async ([filePath, originalContent]) => {
await fs.writeFile(filePath, originalContent) await fs.writeFile(filePath, originalContent)
console.log(` ✓ Restored ${path.relative(litegraphSrcDir, filePath)}`) console.log(` ✓ Restored ${path.relative(litegraphSrcDir, filePath)}`)
}) })
) )
backupMap.clear() backupMap.clear()
} }