From 86bcd911a4b67bafd8d70522d0cf9890f7793e29 Mon Sep 17 00:00:00 2001 From: Andre Molnar Date: Fri, 1 Dec 2023 20:13:42 -0500 Subject: [PATCH] WIP idea of loading the files oddly --- web/index.html | 2 ++ web/scripts/app.js | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/web/index.html b/web/index.html index 41bc246c0..5fb0f4842 100644 --- a/web/index.html +++ b/web/index.html @@ -11,7 +11,9 @@ diff --git a/web/scripts/app.js b/web/scripts/app.js index b90d5b874..e21df2ef6 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -1283,10 +1283,43 @@ export class ComfyApp { async #loadExtensions() { const extensions = await api.getExtensions(); this.logging.addEntry("Comfy.App", "debug", { Extensions: extensions }); - const extensionPromises = extensions.map(async ext => { try { - await import(api.apiURL(ext)); + // Fetch the file as text + const response = await fetch(api.apiURL(ext)); + let text = await response.text(); + const lines = text.split('\n'); + for (const line of lines) { + // Process each line here + if (line.startsWith("import")) { + const match = line.match(/from "(.*)"/); + if (match) { + const importPath = match[1]; + if (importPath.startsWith("./")) { + let file = importPath.substring(2); + ext = ext.replace(/[^/]*$/, file) + text = text.replace(line, line.replace(importPath, `${api.apiURL(ext)}`)); + } + } + } + } + + // text = text.replace(/import { app } from "..\/..\/scripts\/app.js"/, ''); + // text = text.replace(/import { app } from "..\/..\/scripts\/api.js"/, ''); + + // Act on the text here... + + // Create a blob from the text + const blob = new Blob([text], { type: 'text/javascript' }); + + // Create a URL for the blob + const url = URL.createObjectURL(blob); + + // Import the module from the blob URL + await import(url); + + + // await import(api.apiURL(ext)); } catch (error) { console.error("Error loading extension", ext, error); }