diff --git a/.github/actions/build/macos/comfy/action.yml b/.github/actions/build/macos/comfy/action.yml index 860fd6388..37b54b849 100644 --- a/.github/actions/build/macos/comfy/action.yml +++ b/.github/actions/build/macos/comfy/action.yml @@ -19,7 +19,6 @@ runs: run: | python -m pip install --upgrade pip yarn make:assets - yarn patch:core:frontend - name: Unzip Sign Lib/Bin Rezip if: ${{inputs.sign-and-publish == 'true'}} diff --git a/.github/actions/build/windows/app/action.yml b/.github/actions/build/windows/app/action.yml index 4395a9a0a..0c751bf08 100644 --- a/.github/actions/build/windows/app/action.yml +++ b/.github/actions/build/windows/app/action.yml @@ -47,7 +47,6 @@ runs: run: | set -x yarn make:assets - yarn patch:core:frontend shell: bash - name: Make app diff --git a/package.json b/package.json index e943bed22..bd23e8f83 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "make:nvidia": "yarn run make -- --nvidia", "notarize": "node debug/notarize.js", "package": "yarn run vite:compile && todesktop build --code-sign=false --async", - "patch:core:frontend": "node scripts/patchComfyUI.js", + "patch:core:frontend": "node scripts/patchComfyUI.js frontend requirements", "postinstall": "node .husky/install.mjs", "publish": "yarn run vite:compile && todesktop build", "publish:staging": "yarn run vite:compile && todesktop build --config=./todesktop.staging.json --async", diff --git a/scripts/makeComfy.js b/scripts/makeComfy.js index 9501857e1..8f2fefe52 100644 --- a/scripts/makeComfy.js +++ b/scripts/makeComfy.js @@ -16,3 +16,4 @@ execSync(`git clone ${managerRepo} assets/ComfyUI/custom_nodes/ComfyUI-Manager`) execSync(`cd assets/ComfyUI/custom_nodes/ComfyUI-Manager && git checkout ${pkg.config.managerCommit} && cd ../../..`); execSync(`yarn run make:frontend`); execSync(`yarn run download:uv all`); +execSync(`yarn run patch:core:frontend`); diff --git a/scripts/patchComfyUI.js b/scripts/patchComfyUI.js index 175562bed..d47d16842 100644 --- a/scripts/patchComfyUI.js +++ b/scripts/patchComfyUI.js @@ -2,32 +2,85 @@ import { applyPatch } from 'diff'; import fs from 'node:fs/promises'; /** - * @param {string} filePath - * @param {string} patchFilePath + * Patches files based on the {@link tasks} list. + * + * Each CLI argument is treated as a task name. + * + * Paths are relative to the project root. + * @example + * ```bash + * node scripts/patchComfyUI.js frontend requirements + * ``` */ -async function patchFile(filePath, patchFilePath) { +const tasks = new Map([ + [ + 'frontend', + { + target: './assets/ComfyUI/app/frontend_management.py', + patch: './scripts/core-remove-frontend.patch', + }, + ], + [ + 'requirements', + { + target: './assets/ComfyUI/requirements.txt', + patch: './scripts/core-requirements.patch', + }, + ], +]); + +// Main execution +const args = process.argv.slice(2); + +// Error if no args / any invalid args + +if (args.length === 0) { + console.error('No arguments provided'); + process.exit(15); +} + +const invalidArgs = args.filter((arg) => !tasks.has(arg)); + +if (invalidArgs.length > 0) { + console.error(`Invalid argument(s): ${invalidArgs.map((arg) => `"${arg}"`).join(', ')}`); + process.exit(255); +} + +// Apply patches +const promises = args.map((arg) => patchFile(tasks.get(arg).target, tasks.get(arg).patch)); +await Promise.all(promises); + +//#region Functions + +/** + * Applies a regular diff patch to a single file + * @param {string} targetPath Target file path + * @param {string} patchFilePath Patch file to apply to the target file + */ +async function patchFile(targetPath, patchFilePath) { try { // Read the original file and patch file const [originalContent, patchContent] = await Promise.all([ - fs.readFile(filePath, 'utf8'), + fs.readFile(targetPath, 'utf8'), fs.readFile(patchFilePath, 'utf8'), ]); // Apply the patch const patchedContent = applyPatch(originalContent, patchContent); - // If patch was successfully applied (not false or null) + // If patch was successfully applied (not falsy) if (patchedContent) { // Write the result to the output file - await fs.writeFile(filePath, patchedContent, 'utf8'); + await fs.writeFile(targetPath, patchedContent, 'utf8'); console.log('Patch applied successfully!'); } else { - console.error('Failed to apply patch - patch may be invalid or incompatible'); + throw new Error( + `ComfyUI core patching returned falsy value (${typeof patchedContent}) - .patch file probably requires update` + ); } } catch (error) { - console.error('Error applying patch:', error.message); + throw new Error(`Error applying core patch: ${error.message}`, { cause: error }); } } -await patchFile('./assets/ComfyUI/app/frontend_management.py', './scripts/core-remove-frontend.patch'); -await patchFile('./assets/ComfyUI/requirements.txt', './scripts/core-requirements.patch'); +//#endregion Functions