Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .github/actions/build/macos/comfy/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}
Expand Down
1 change: 0 additions & 1 deletion .github/actions/build/windows/app/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ runs:
run: |
set -x
yarn make:assets
yarn patch:core:frontend
shell: bash

- name: Make app
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions scripts/makeComfy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
73 changes: 63 additions & 10 deletions scripts/patchComfyUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading