Skip to content

Commit 8e006bb

Browse files
snomiaoclaudegithub-actionsDrJKLcoderabbitai[bot]
authored
[bugfix] Add vite-define shim for Playwright i18n collection (#6906)
## Summary Fixes the `ReferenceError: __DISTRIBUTION__ is not defined` error when running i18n collection tests. ## Problem PR #6879 added conditional menu commands based on distribution (hiding memory unload commands in cloud). This introduced a dependency on `isCloud` which uses the `__DISTRIBUTION__` Vite define variable in `coreMenuCommands.ts`. When Playwright's test runner imports this file during i18n collection, it fails because Vite define variables are only replaced during Vite's build/dev process, not during Playwright's TypeScript compilation. ## Solution Created a simple shim (`scripts/vite-define-shim.ts`) that: 1. Defines all Vite define variables as global constants with default values 2. Provides a minimal `window` shim for Node environment 3. Is imported at the top of `collect-i18n-general.ts` before any code that uses these variables This approach is simpler than: - Creating a custom Babel plugin (attempted in this PR, see commit history) - Using `ctViteConfig` (only works for component testing, not regular Playwright tests) - Post-build regex replacement (fragile and error-prone) ## Test Plan Run `pnpm collect-i18n` and verify: - ✅ No more `ReferenceError: __DISTRIBUTION__ is not defined` - ✅ No more `ReferenceError: window is not defined` - ⏱️ Tests may timeout if dev server is not running on port 5173, but that's a separate issue ## Related - Fixes issue introduced by PR #6879 - Related to Notion task: https://www.notion.so/comfy-org/Implement-Babel-plugin-for-Vite-define-replacements-in-Playwright-2b56d73d365081d5bb63e02712912b17 🤖 Generated with [Claude Code](https://claude.com/claude-code) ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6906-bugfix-Add-vite-define-shim-for-Playwright-i18n-collection-2b66d73d36508182b4d6d69b88ae2771) by [Unito](https://www.unito.io) --------- Co-authored-by: Claude <[email protected]> Co-authored-by: github-actions <[email protected]> Co-authored-by: Alexander Brown <[email protected]> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent a5f1eb0 commit 8e006bb

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

scripts/collect-i18n-general.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import * as fs from 'fs'
22

3+
// Import Vite define shim to make __DISTRIBUTION__ and other define variables available
4+
import './vite-define-shim'
5+
36
import { DESKTOP_DIALOGS } from '../apps/desktop-ui/src/constants/desktopDialogs'
47
import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
58
import {

scripts/vite-define-shim.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Shim for Vite define variables to make them available during Playwright test execution
3+
* This file should be imported before any code that uses Vite define variables
4+
*/
5+
6+
// Define global constants that Vite would normally replace at build time
7+
declare global {
8+
const __COMFYUI_FRONTEND_VERSION__: string
9+
const __SENTRY_ENABLED__: boolean
10+
const __SENTRY_DSN__: string
11+
const __ALGOLIA_APP_ID__: string
12+
const __ALGOLIA_API_KEY__: string
13+
const __USE_PROD_CONFIG__: boolean
14+
const __DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud'
15+
}
16+
17+
type GlobalWithDefines = typeof globalThis & {
18+
__COMFYUI_FRONTEND_VERSION__: string
19+
__SENTRY_ENABLED__: boolean
20+
__SENTRY_DSN__: string
21+
__ALGOLIA_APP_ID__: string
22+
__ALGOLIA_API_KEY__: string
23+
__USE_PROD_CONFIG__: boolean
24+
__DISTRIBUTION__: 'desktop' | 'localhost' | 'cloud'
25+
window?: Record<string, unknown>
26+
}
27+
28+
const globalWithDefines = globalThis as GlobalWithDefines
29+
30+
// Set default values for Playwright test environment
31+
globalWithDefines.__COMFYUI_FRONTEND_VERSION__ =
32+
process.env.npm_package_version || '1.0.0'
33+
globalWithDefines.__SENTRY_ENABLED__ = false
34+
globalWithDefines.__SENTRY_DSN__ = ''
35+
globalWithDefines.__ALGOLIA_APP_ID__ = ''
36+
globalWithDefines.__ALGOLIA_API_KEY__ = ''
37+
globalWithDefines.__USE_PROD_CONFIG__ = false
38+
globalWithDefines.__DISTRIBUTION__ = 'localhost'
39+
40+
// Provide a minimal window shim for Node environment
41+
// This is needed for code that checks window existence during imports
42+
if (typeof window === 'undefined') {
43+
globalWithDefines.window = {}
44+
}
45+
46+
export {}

src/locales/en/main.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,4 +2254,4 @@
22542254
"replacementInstruction": "Install these nodes to run this workflow, or replace them with installed alternatives. Missing nodes are highlighted in red on the canvas."
22552255
}
22562256
}
2257-
}
2257+
}

0 commit comments

Comments
 (0)