Skip to content

Commit

Permalink
shim
Browse files Browse the repository at this point in the history
  • Loading branch information
huchenlei committed Jun 15, 2024
1 parent 83d8679 commit 42238ce
Show file tree
Hide file tree
Showing 30 changed files with 14 additions and 4 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
SOFTWARE.
*/

import { $el } from "../ui";
import { $el } from "../ui.js";

$el("style", {
parent: document.head,
Expand Down
9 changes: 8 additions & 1 deletion src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import { defaultGraph } from "./defaultGraph.js";
import { getPngMetadata, getWebpMetadata, importA1111, getLatentMetadata } from "./pnginfo";
import { addDomClippingSetting } from "./domWidget";
import { createImageHost, calculateImageGrid } from "./ui/imagePreview"
import { applyTextReplacements, addStylesheet } from "./utils";
import type { ComfyExtension } from "/types/comfy";
import type { IWidget, LGraph, LGraphCanvas, LGraphNode } from "/types/litegraph";
import type { LGraph, LGraphCanvas, LGraphNode } from "/types/litegraph";

export const ANIM_PREVIEW_WIDGET = "$$comfy_animation_preview"

Expand Down Expand Up @@ -51,6 +52,12 @@ export class ComfyApp {
static open_maskeditor = null;
static clipspace_return_node = null;

// Force vite to import utils.ts as part of index.
static utils = {
applyTextReplacements,
addStylesheet,
};

ui: ComfyUI;
logging: ComfyLogging;
extensions: ComfyExtension[];
Expand Down
7 changes: 5 additions & 2 deletions vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ function transformExports(code: string, id: string): ShimResult {
let newCode = code;

// Regex to match different types of exports
const regex = /export\s+(const|let|var|function|class)\s+([a-zA-Z$_][a-zA-Z\d$_]*)(\s|\()/g;
const regex = /export\s+(const|let|var|function|class|async function)\s+([a-zA-Z$_][a-zA-Z\d$_]*)(\s|\()/g;
let match;

while ((match = regex.exec(code)) !== null) {
const name = match[2];
// All exports should be bind to the window object as new API endpoint.
newCode += `\nwindow.comfyAPI.${moduleName} = window.comfyAPI.${moduleName} || {};`;
if (exports.length == 0) {
newCode += `\nwindow.comfyAPI = window.comfyAPI || {};`;
newCode += `\nwindow.comfyAPI.${moduleName} = window.comfyAPI.${moduleName} || {};`;
}
newCode += `\nwindow.comfyAPI.${moduleName}.${name} = ${name};`;
exports.push(`export const ${name} = window.comfyAPI.${moduleName}.${name};\n`);
}
Expand Down

0 comments on commit 42238ce

Please sign in to comment.