mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-03 22:59:14 +00:00
- 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 <noreply@anthropic.com>
30 lines
877 B
JavaScript
30 lines
877 B
JavaScript
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);
|
|
} |