fix: Fix Playwright i18n collection by handling TypeScript declare fields in litegraph

- 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"
This commit is contained in:
snomiao
2025-09-01 23:21:01 +00:00
parent 481e3b593a
commit 5bc50500fd
9 changed files with 3663 additions and 438 deletions

View File

@@ -31,12 +31,16 @@
"knip": "knip --cache",
"knip:no-cache": "knip",
"locale": "lobe-i18n locale",
"collect-i18n": "npx playwright test --config=playwright.i18n.config.ts",
"prebuild:litegraph": "node scripts/prebuild-litegraph.js",
"restore:litegraph": "node scripts/restore-litegraph.js",
"collect-i18n": "pnpm prebuild:litegraph && npx playwright test --config=playwright.i18n.config.ts; pnpm restore:litegraph",
"json-schema": "tsx scripts/generate-json-schema.ts",
"storybook": "nx storybook -p 6006",
"build-storybook": "storybook build"
},
"devDependencies": {
"@babel/core": "^7.28.3",
"@babel/preset-typescript": "^7.27.1",
"@eslint/js": "^9.8.0",
"@executeautomation/playwright-mcp-server": "^1.0.6",
"@iconify/json": "^2.2.245",

View File

@@ -8,5 +8,8 @@ export default defineConfig({
},
reporter: 'list',
timeout: 60000,
testMatch: /collect-i18n-.*\.ts/
testMatch: /collect-i18n-.*\.ts/,
// Use the same global setup as regular tests to ensure proper environment
globalSetup: './browser_tests/globalSetup.ts',
globalTeardown: './browser_tests/globalTeardown.ts'
})

613
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
#!/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)

View File

@@ -0,0 +1,52 @@
#!/usr/bin/env node
/**
* Restore script for litegraph after Playwright tests
* This script restores the original TypeScript files from backups
*/
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 restoreLitegraph() {
console.log('Restoring original litegraph files...')
try {
const filesToRestore = [
'LGraphNode.ts',
'widgets/BaseWidget.ts',
'subgraph/SubgraphInput.ts',
'subgraph/SubgraphNode.ts',
'subgraph/SubgraphOutput.ts',
'subgraph/EmptySubgraphInput.ts',
'subgraph/EmptySubgraphOutput.ts'
]
let restoredCount = 0
for (const relativePath of filesToRestore) {
const filePath = path.join(litegraphSrcDir, relativePath)
const backupPath = filePath + '.backup'
if (await fs.pathExists(backupPath)) {
const backupContent = await fs.readFile(backupPath, 'utf-8')
await fs.writeFile(filePath, backupContent)
await fs.remove(backupPath)
restoredCount++
console.log(` ✓ Restored ${relativePath}`)
}
}
console.log(`✅ Restored ${restoredCount} files successfully`)
} catch (error) {
console.error('❌ Failed to restore litegraph:', error.message)
// eslint-disable-next-line no-undef
process.exit(1)
}
}
// Run the restore
restoreLitegraph().catch(console.error)

View File

@@ -1,40 +1,4 @@
{
"Comfy-Desktop_CheckForUpdates": {
"label": "Check for Updates"
},
"Comfy-Desktop_Folders_OpenCustomNodesFolder": {
"label": "Open Custom Nodes Folder"
},
"Comfy-Desktop_Folders_OpenInputsFolder": {
"label": "Open Inputs Folder"
},
"Comfy-Desktop_Folders_OpenLogsFolder": {
"label": "Open Logs Folder"
},
"Comfy-Desktop_Folders_OpenModelConfig": {
"label": "Open extra_model_paths.yaml"
},
"Comfy-Desktop_Folders_OpenModelsFolder": {
"label": "Open Models Folder"
},
"Comfy-Desktop_Folders_OpenOutputsFolder": {
"label": "Open Outputs Folder"
},
"Comfy-Desktop_OpenDevTools": {
"label": "Open DevTools"
},
"Comfy-Desktop_OpenUserGuide": {
"label": "Desktop User Guide"
},
"Comfy-Desktop_Quit": {
"label": "Quit"
},
"Comfy-Desktop_Reinstall": {
"label": "Reinstall"
},
"Comfy-Desktop_Restart": {
"label": "Restart"
},
"Comfy_3DViewer_Open3DViewer": {
"label": "Open 3D Viewer (Beta) for Selected Node"
},
@@ -173,6 +137,12 @@
"Comfy_Manager_CustomNodesManager": {
"label": "Toggle the Custom Nodes Manager"
},
"Comfy_Manager_CustomNodesManager_ToggleVisibility": {
"label": "Toggle Custom Nodes Manager Visibility"
},
"Comfy_Manager_Menu_ToggleVisibility": {
"label": "Toggle Manager Menu Visibility"
},
"Comfy_Manager_ToggleManagerProgressDialog": {
"label": "Toggle the Custom Nodes Manager Progress Bar"
},
@@ -257,9 +227,6 @@
"Workspace_ToggleBottomPanel_Shortcuts": {
"label": "Show Keybindings Dialog"
},
"Workspace_ToggleBottomPanelTab_command-terminal": {
"label": "Toggle Terminal Bottom Panel"
},
"Workspace_ToggleBottomPanelTab_logs-terminal": {
"label": "Toggle Logs Bottom Panel"
},

View File

@@ -958,18 +958,6 @@
"File": "File",
"Edit": "Edit",
"Help": "Help",
"Check for Updates": "Check for Updates",
"Open Custom Nodes Folder": "Open Custom Nodes Folder",
"Open Inputs Folder": "Open Inputs Folder",
"Open Logs Folder": "Open Logs Folder",
"Open extra_model_paths_yaml": "Open extra_model_paths.yaml",
"Open Models Folder": "Open Models Folder",
"Open Outputs Folder": "Open Outputs Folder",
"Open DevTools": "Open DevTools",
"Desktop User Guide": "Desktop User Guide",
"Quit": "Quit",
"Reinstall": "Reinstall",
"Restart": "Restart",
"Open 3D Viewer (Beta) for Selected Node": "Open 3D Viewer (Beta) for Selected Node",
"Browse Templates": "Browse Templates",
"Delete Selected Items": "Delete Selected Items",
@@ -1016,6 +1004,8 @@
"Interrupt": "Interrupt",
"Load Default Workflow": "Load Default Workflow",
"Toggle the Custom Nodes Manager": "Toggle the Custom Nodes Manager",
"Toggle Custom Nodes Manager Visibility": "Toggle Custom Nodes Manager Visibility",
"Toggle Manager Menu Visibility": "Toggle Manager Menu Visibility",
"Toggle the Custom Nodes Manager Progress Bar": "Toggle the Custom Nodes Manager Progress Bar",
"Decrease Brush Size in MaskEditor": "Decrease Brush Size in MaskEditor",
"Increase Brush Size in MaskEditor": "Increase Brush Size in MaskEditor",
@@ -1044,7 +1034,6 @@
"Toggle Search Box": "Toggle Search Box",
"Bottom Panel": "Bottom Panel",
"Show Keybindings Dialog": "Show Keybindings Dialog",
"Toggle Terminal Bottom Panel": "Toggle Terminal Bottom Panel",
"Toggle Logs Bottom Panel": "Toggle Logs Bottom Panel",
"Toggle Essential Bottom Panel": "Toggle Essential Bottom Panel",
"Toggle View Controls Bottom Panel": "Toggle View Controls Bottom Panel",
@@ -1112,7 +1101,10 @@
"Credits": "Credits",
"API Nodes": "API Nodes",
"Notification Preferences": "Notification Preferences",
"3DViewer": "3DViewer"
"3DViewer": "3DViewer",
"HotReload": "Hot Reload",
"config": "config",
"language": "language"
},
"serverConfigItems": {
"listen": {
@@ -1249,19 +1241,22 @@
"noise": "noise",
"sampling": "sampling",
"schedulers": "schedulers",
"conditioning": "conditioning",
"loaders": "loaders",
"guiders": "guiders",
"image": "image",
"preprocessors": "preprocessors",
"utils": "utils",
"string": "string",
"advanced": "advanced",
"guidance": "guidance",
"loaders": "loaders",
"model_merging": "model_merging",
"attention_experiments": "attention_experiments",
"conditioning": "conditioning",
"flux": "flux",
"hooks": "hooks",
"combine": "combine",
"cond single": "cond single",
"context": "context",
"controlnet": "controlnet",
"inpaint": "inpaint",
"scheduling": "scheduling",
@@ -1269,6 +1264,8 @@
"video": "video",
"mask": "mask",
"deprecated": "deprecated",
"debug": "debug",
"model": "model",
"latent": "latent",
"audio": "audio",
"3d": "3d",
@@ -1279,12 +1276,12 @@
"BFL": "BFL",
"model_patches": "model_patches",
"unet": "unet",
"Gemini": "Gemini",
"text": "text",
"gligen": "gligen",
"HotReload": "HotReload",
"video_models": "video_models",
"Ideogram": "Ideogram",
"v1": "v1",
"v2": "v2",
"v3": "v3",
"postprocessing": "postprocessing",
"transform": "transform",
"batch": "batch",
@@ -1294,34 +1291,44 @@
"Kling": "Kling",
"samplers": "samplers",
"operations": "operations",
"training": "training",
"lotus": "lotus",
"Luma": "Luma",
"MiniMax": "MiniMax",
"debug": "debug",
"model": "model",
"model_specific": "model_specific",
"Moonvalley Marey": "Moonvalley Marey",
"OpenAI": "OpenAI",
"cond pair": "cond pair",
"photomaker": "photomaker",
"Pika": "Pika",
"PixVerse": "PixVerse",
"utils": "utils",
"primitive": "primitive",
"qwen": "qwen",
"Recraft": "Recraft",
"edit_models": "edit_models",
"Rodin": "Rodin",
"Runway": "Runway",
"animation": "animation",
"api": "api",
"save": "save",
"upscale_diffusion": "upscale_diffusion",
"clip": "clip",
"Stability AI": "Stability AI",
"stable_cascade": "stable_cascade",
"3d_models": "3d_models",
"style_model": "style_model",
"sd": "sd",
"Veo": "Veo"
"Tripo": "Tripo",
"Veo": "Veo",
"processing": "processing",
"Vidu": "Vidu",
"camera": "camera"
},
"dataTypes": {
"*": "*",
"AUDIO": "AUDIO",
"AUDIO_ENCODER": "AUDIO_ENCODER",
"AUDIO_ENCODER_OUTPUT": "AUDIO_ENCODER_OUTPUT",
"AUDIO_RECORD": "AUDIO_RECORD",
"BOOLEAN": "BOOLEAN",
"CAMERA_CONTROL": "CAMERA_CONTROL",
"CLIP": "CLIP",
@@ -1332,6 +1339,7 @@
"CONTROL_NET": "CONTROL_NET",
"FLOAT": "FLOAT",
"FLOATS": "FLOATS",
"GEMINI_INPUT_FILES": "GEMINI_INPUT_FILES",
"GLIGEN": "GLIGEN",
"GUIDER": "GUIDER",
"HOOK_KEYFRAMES": "HOOK_KEYFRAMES",
@@ -1343,17 +1351,25 @@
"LOAD_3D": "LOAD_3D",
"LOAD_3D_ANIMATION": "LOAD_3D_ANIMATION",
"LOAD3D_CAMERA": "LOAD3D_CAMERA",
"LORA_MODEL": "LORA_MODEL",
"LOSS_MAP": "LOSS_MAP",
"LUMA_CONCEPTS": "LUMA_CONCEPTS",
"LUMA_REF": "LUMA_REF",
"MASK": "MASK",
"MESH": "MESH",
"MODEL": "MODEL",
"MODEL_PATCH": "MODEL_PATCH",
"MODEL_TASK_ID": "MODEL_TASK_ID",
"NOISE": "NOISE",
"OPENAI_CHAT_CONFIG": "OPENAI_CHAT_CONFIG",
"OPENAI_INPUT_FILES": "OPENAI_INPUT_FILES",
"PHOTOMAKER": "PHOTOMAKER",
"PIXVERSE_TEMPLATE": "PIXVERSE_TEMPLATE",
"RECRAFT_COLOR": "RECRAFT_COLOR",
"RECRAFT_CONTROLS": "RECRAFT_CONTROLS",
"RECRAFT_V3_STYLE": "RECRAFT_V3_STYLE",
"RETARGET_TASK_ID": "RETARGET_TASK_ID",
"RIG_TASK_ID": "RIG_TASK_ID",
"SAMPLER": "SAMPLER",
"SIGMAS": "SIGMAS",
"STRING": "STRING",
@@ -1364,6 +1380,7 @@
"VAE": "VAE",
"VIDEO": "VIDEO",
"VOXEL": "VOXEL",
"WAN_CAMERA_EMBEDDING": "WAN_CAMERA_EMBEDDING",
"WEBCAM": "WEBCAM"
},
"maintenance": {

File diff suppressed because it is too large Load Diff

View File

@@ -1,30 +1,4 @@
{
"Comfy-Desktop_AutoUpdate": {
"name": "Automatically check for updates"
},
"Comfy-Desktop_SendStatistics": {
"name": "Send anonymous usage metrics"
},
"Comfy-Desktop_UV_PypiInstallMirror": {
"name": "Pypi Install Mirror",
"tooltip": "Default pip install mirror"
},
"Comfy-Desktop_UV_PythonInstallMirror": {
"name": "Python Install Mirror",
"tooltip": "Managed Python installations are downloaded from the Astral python-build-standalone project. This variable can be set to a mirror URL to use a different source for Python installations. The provided URL will replace https://github.com/astral-sh/python-build-standalone/releases/download in, e.g., https://github.com/astral-sh/python-build-standalone/releases/download/20240713/cpython-3.12.4%2B20240713-aarch64-apple-darwin-install_only.tar.gz. Distributions can be read from a local directory by using the file:// URL scheme."
},
"Comfy-Desktop_UV_TorchInstallMirror": {
"name": "Torch Install Mirror",
"tooltip": "Pip install mirror for pytorch"
},
"Comfy-Desktop_WindowStyle": {
"name": "Window Style",
"tooltip": "Custom: Replace the system title bar with ComfyUI's Top menu",
"options": {
"default": "default",
"custom": "custom"
}
},
"Comfy_Canvas_BackgroundImage": {
"name": "Canvas background image",
"tooltip": "Image URL for the canvas background. You can right-click an image in the outputs panel and select \"Set as Background\" to use it, or upload your own image using the upload button."
@@ -388,6 +362,12 @@
"Topbar (2nd-row)": "Topbar (2nd-row)"
}
},
"HotReload_config": {
"name": "Hot Reload Configuration"
},
"HotReload_language": {
"name": "Language"
},
"LiteGraph_Canvas_LowQualityRenderingZoomThreshold": {
"name": "Low quality rendering zoom threshold",
"tooltip": "Zoom level threshold for performance mode. Lower values (0.1) = quality at all zoom levels. Higher values (1.0) = performance mode even when zoomed in. Performance mode simplifies rendering by hiding text labels, shadows, and details."