mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-04 15:10:06 +00:00
- Add prebuild script that temporarily removes 'declare' keyword from litegraph TypeScript files - Add restore script to revert files to original state after i18n collection - Update collect-i18n script to use prebuild/restore workflow - Add babel dependencies for TypeScript transformation - Update playwright.i18n.config.ts with global setup/teardown This fix addresses an issue where Playwright's Babel transformation couldn't handle TypeScript 'declare' fields in litegraph classes, causing the i18n collection to fail. Fixes the issue where 'pnpm collect-i18n' would fail with: "TypeScript 'declare' fields must first be transformed by @babel/plugin-transform-typescript"
70 lines
2.2 KiB
JavaScript
70 lines
2.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Prebuild script for litegraph to ensure compatibility with Playwright
|
|
* This script removes TypeScript 'declare' keyword that Playwright/Babel can't handle
|
|
* The files remain as TypeScript but with the problematic syntax removed
|
|
*/
|
|
import fs from 'fs-extra'
|
|
import path from 'path'
|
|
import { fileURLToPath } from 'url'
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const rootDir = path.resolve(__dirname, '..')
|
|
const litegraphSrcDir = path.join(rootDir, 'src/lib/litegraph/src')
|
|
|
|
async function prebuildLitegraph() {
|
|
console.log('Pre-processing litegraph for Playwright compatibility...')
|
|
|
|
try {
|
|
// Find all TypeScript files that use 'declare'
|
|
const filesToProcess = [
|
|
'LGraphNode.ts',
|
|
'widgets/BaseWidget.ts',
|
|
'subgraph/SubgraphInput.ts',
|
|
'subgraph/SubgraphNode.ts',
|
|
'subgraph/SubgraphOutput.ts',
|
|
'subgraph/EmptySubgraphInput.ts',
|
|
'subgraph/EmptySubgraphOutput.ts'
|
|
]
|
|
|
|
let processedCount = 0
|
|
|
|
for (const relativePath of filesToProcess) {
|
|
const filePath = path.join(litegraphSrcDir, relativePath)
|
|
|
|
if (await fs.pathExists(filePath)) {
|
|
const originalContent = await fs.readFile(filePath, 'utf-8')
|
|
|
|
// Remove 'declare' keyword from class properties
|
|
// This regex matches 'declare' at the start of a line (with optional whitespace)
|
|
const modifiedContent = originalContent.replace(
|
|
/^(\s*)declare\s+/gm,
|
|
'$1// @ts-ignore\n$1'
|
|
)
|
|
|
|
if (originalContent !== modifiedContent) {
|
|
// Create backup
|
|
const backupPath = filePath + '.backup'
|
|
if (!(await fs.pathExists(backupPath))) {
|
|
await fs.writeFile(backupPath, originalContent)
|
|
}
|
|
|
|
// Write modified content
|
|
await fs.writeFile(filePath, modifiedContent)
|
|
processedCount++
|
|
console.log(` ✓ Processed ${relativePath}`)
|
|
}
|
|
}
|
|
}
|
|
|
|
console.log(`✅ Pre-processed ${processedCount} files successfully`)
|
|
} catch (error) {
|
|
console.error('❌ Failed to pre-process litegraph:', error.message)
|
|
// eslint-disable-next-line no-undef
|
|
process.exit(1)
|
|
}
|
|
}
|
|
|
|
// Run the prebuild
|
|
prebuildLitegraph().catch(console.error)
|