Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d8ff3df
reset branch
snomiao Sep 17, 2025
c5c54df
fix: remove unused dependencies and files flagged by knip
snomiao Sep 18, 2025
c66843e
fix: resolve knip issues - remove unused babel-plugin-module-resolver…
snomiao Sep 22, 2025
c4cb359
istall babel plugins
snomiao Sep 23, 2025
c3e2588
fix: resolve collect-i18n babel transformation issues
snomiao Sep 24, 2025
20e1cb0
fix: resolve TypeScript errors in collect-i18n-general.ts
snomiao Sep 24, 2025
66706f8
fix: remove scripts/collect-i18n-*.ts from tsconfig includes
snomiao Sep 24, 2025
14bc5ad
fix: revert unnecessary package.json version changes
snomiao Sep 24, 2025
1b87f29
fix: update pnpm-lock.yaml to match package.json
snomiao Sep 24, 2025
81314b6
Update locales [skip ci]
invalid-email-address Sep 24, 2025
7002a17
fix: add saveImmediately option to i18n configuration
snomiao Sep 24, 2025
1741677
Update locales [skip ci]
invalid-email-address Sep 24, 2025
7ec9f0b
Merge branch 'main' into sno-fix-playwright-babel-config
snomiao Sep 24, 2025
247937f
Update locales [skip ci]
invalid-email-address Sep 24, 2025
b98458d
fix: remove unused imports and streamline node definitions collection
snomiao Sep 24, 2025
23ba2fe
Merge branch 'sno-fix-playwright-babel-config' of github.com:Comfy-Or…
snomiao Sep 24, 2025
12a130b
Merge branch 'main' into sno-fix-playwright-babel-config
snomiao Sep 24, 2025
c785ccf
Update locales [skip ci]
invalid-email-address Sep 24, 2025
916170e
Update locales [skip ci]
invalid-email-address Sep 24, 2025
89465de
Revert "Update locales [skip ci]"
snomiao Sep 24, 2025
8560646
chore(babel-plugin-stub-vue-imports): remove unused Babel plugin for …
snomiao Sep 24, 2025
82c6f02
Merge branch 'main' into sno-fix-playwright-babel-config
snomiao Sep 24, 2025
8fdee1b
Merge branch 'main' into sno-fix-playwright-babel-config
snomiao Sep 25, 2025
7abda29
Update locales [skip ci]
invalid-email-address Sep 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: resolve collect-i18n babel transformation issues
- Created configurable babel-plugin-inject-globals to inject browser setup
- Added setup-browser-globals.mjs for browser environment mocking
- Moved babel plugin files to scripts directory for better organization
- Removed dependency on import order by using babel transformation
- Made plugin options configurable (filenamePattern, setupFile)
- Updated tsconfig.json to include playwright config and scripts

This fixes the ReferenceError: location is not defined issue that occurred
when running pnpm collect-i18n, ensuring the command works reliably
regardless of import auto-sorting.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
  • Loading branch information
snomiao and claude committed Sep 24, 2025
commit c3e2588ae04e4b8f0baf4c979f076b65b829c449
5 changes: 4 additions & 1 deletion knip.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ const config: KnipConfig = {
'@primeuix/utils',
'@primevue/icons',
// Dev
'@trivago/prettier-plugin-sort-imports'
'@trivago/prettier-plugin-sort-imports',
// Used by playwright.i18n.config.ts babel plugins
'@babel/plugin-transform-typescript',
'babel-plugin-module-resolver'
],
ignore: [
// Auto generated manager types
Expand Down
14 changes: 9 additions & 5 deletions playwright.i18n.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const config: any = defineConfig({
testDir: './scripts',
use: {
baseURL: 'http://localhost:5173',
headless: true
},
reporter: 'list',
timeout: 60000,
Expand All @@ -26,8 +25,8 @@ const config: any = defineConfig({
// Configure babel plugins for TypeScript with declare fields and module resolution
config['@playwright/test'] = {
babelPlugins: [
// Stub Vue and CSS imports first to prevent parsing errors
[path.join(__dirname, 'babel-plugin-stub-vue-imports.cjs')],
// Stub Vue and CSS imports to prevent parsing errors
[path.join(__dirname, 'scripts/babel-plugin-stub-vue-imports.cjs')],
// Module resolver to handle @ alias
[
'babel-plugin-module-resolver',
Expand All @@ -38,14 +37,19 @@ config['@playwright/test'] = {
}
}
],
// Then TypeScript transformation with declare field support
// TypeScript transformation with declare field support
[
'@babel/plugin-transform-typescript',
{
allowDeclareFields: true,
onlyRemoveTypeImports: true
}
]
],
// Inject browser globals AFTER TypeScript transformation
[path.join(__dirname, 'scripts/babel-plugin-inject-globals.cjs'), {
filenamePattern: 'collect-i18n-',
setupFile: './setup-browser-globals.mjs'
}]
]
}

Expand Down
30 changes: 30 additions & 0 deletions scripts/babel-plugin-inject-globals.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = function(babel) {
const { types: t } = babel;

return {
visitor: {
Program(path, state) {
// Get options from plugin configuration
const opts = state.opts || {};
const filenamePattern = opts.filenamePattern || DIE('filenamePattern option is required');
const setupFile = opts.setupFile || DIE('setupFile option is required');

// Only inject the setup for matching test files
if (state.filename?.match(filenamePattern)) {
// Create an import statement for the setup file
const importDeclaration = t.importDeclaration(
[],
t.stringLiteral(setupFile)
);

// Insert the import at the beginning of the file
path.node.body.unshift(importDeclaration);
}
}
}
};
};

function DIE(msg) {
throw new Error(msg);
}
1 change: 0 additions & 1 deletion scripts/collect-i18n-general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { SERVER_CONFIG_ITEMS } from '../src/constants/serverConfig'
import type { ComfyCommandImpl } from '../src/stores/commandStore'
import type { FormItem, SettingParams } from '../src/platform/settings/types'
import { formatCamelCase, normalizeI18nKey } from '../src/utils/formatUtil'
import './setup-browser-globals.js'

const localePath = './src/locales/en/main.json'
const commandsPath = './src/locales/en/commands.json'
Expand Down
2 changes: 0 additions & 2 deletions scripts/collect-i18n-node-defs.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Setup browser globals before any other imports that might use them
import * as fs from 'fs'

import { comfyPageFixture as test } from '../browser_tests/fixtures/ComfyPage'
import type { ComfyNodeDef } from '../src/schemas/nodeDefSchema'
import type { ComfyApi } from '../src/scripts/api'
import { ComfyNodeDefImpl } from '../src/stores/nodeDefStore'
import { normalizeI18nKey } from '../src/utils/formatUtil'
import './setup-browser-globals.js'

const localePath = './src/locales/en/main.json'
const nodeDefsPath = './src/locales/en/nodeDefs.json'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
// Setup browser-like globals for Node.js environment
import { Window } from 'happy-dom'
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const { Window } = require('happy-dom');

// Set build-time constants
global.__USE_PROD_CONFIG__ = false
global.__USE_LOCAL_SERVER__ = true
global.__RUN_TESTS__ = true
global.__USE_PROD_CONFIG__ = false;
global.__USE_LOCAL_SERVER__ = true;
global.__RUN_TESTS__ = true;

const window = new Window({
url: 'http://localhost:5173',
width: 1024,
height: 768
})
});

global.window = window
global.document = window.document
global.location = window.location
global.window = window;
global.document = window.document;
global.location = window.location;
// Don't set navigator if it's read-only
if (!global.navigator || Object.getOwnPropertyDescriptor(global, 'navigator')?.set) {
global.navigator = window.navigator
global.navigator = window.navigator;
}
global.HTMLElement = window.HTMLElement
global.Element = window.Element
global.CustomEvent = window.CustomEvent
global.requestAnimationFrame = window.requestAnimationFrame
global.HTMLElement = window.HTMLElement;
global.Element = window.Element;
global.CustomEvent = window.CustomEvent;
global.requestAnimationFrame = window.requestAnimationFrame;

// Use happy-dom's storage implementations
global.localStorage = window.localStorage
global.sessionStorage = window.sessionStorage
global.localStorage = window.localStorage;
global.sessionStorage = window.sessionStorage;

// Mock fetch if not available
if (!global.fetch) {
Expand All @@ -37,26 +39,26 @@ if (!global.fetch) {
blob: () => Promise.resolve(new Blob()),
arrayBuffer: () => Promise.resolve(new ArrayBuffer(0)),
headers: new Map()
})
});
}

// Mock ResizeObserver
global.ResizeObserver = class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
}
};

// Mock IntersectionObserver
global.IntersectionObserver = class IntersectionObserver {
constructor() {}
observe() {}
unobserve() {}
disconnect() {}
}
};

// Mock getComputedStyle
global.getComputedStyle = window.getComputedStyle
global.getComputedStyle = window.getComputedStyle;

// Mock createRange
global.document.createRange = () => ({
Expand All @@ -71,4 +73,4 @@ global.document.createRange = () => ({
height: 0
}),
getClientRects: () => []
})
});
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
"eslint.config.ts",
"global.d.ts",
"knip.config.ts",
"playwright.i18n.config.ts",
"scripts/collect-i18n-*.ts",
"src/**/*.vue",
"src/**/*",
"src/types/**/*.d.ts",
Expand Down