Skip to content

Commit a179d5c

Browse files
authored
Lint & refactor codebase (#539)
* Ignore shims script (hard forked) * Format scripts * Remove redundant code * [Refactor] Remove ternary statement * Add ESM top-level await * Add TS types, clean up * Ignore ESLint warnings in scripts * Remove redundant code * Lint tests * Remove stylistic ESLint rule !array.length is acceptable here. * Ignore ESLint errors on yaml parsing No easy solution here; this is already in the wild. Needs proper reimplementation at some point. * nit * [Refactor] if-else => switch * [Refactor] Remove redundant code * Remove unnecessary use of static class * Annotate remaining low-priority ESLint items * Lint configs * Lint playwright config * nit
1 parent 146a588 commit a179d5c

33 files changed

+345
-305
lines changed

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ out
33
dist
44
assets
55
.vite
6-
scripts
6+
scripts/shims
77
.env_*

eslint.config.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import eslintPluginUnicorn from 'eslint-plugin-unicorn';
66
export default tseslint.config(
77
// Baseline include / exclude
88
{ files: ['**/*.{js,cjs,mjs,ts,mts}'] },
9-
{ ignores: ['dist/**/*', 'jest.config.cjs'] },
9+
{ ignores: ['dist/**/*', 'jest.config.cjs', 'scripts/shims/**/*'] },
1010

1111
// Baseline
1212
eslint.configs.recommended,
@@ -51,6 +51,7 @@ export default tseslint.config(
5151
'unicorn/no-null': 'off',
5252
'unicorn/prevent-abbreviations': 'off',
5353
'unicorn/switch-case-braces': 'off',
54+
'unicorn/explicit-length-check': 'off',
5455
},
5556
},
5657

@@ -60,5 +61,14 @@ export default tseslint.config(
6061
rules: {
6162
'unicorn/no-process-exit': 'off',
6263
},
64+
},
65+
66+
// Tests
67+
{
68+
files: ['tests/**/*'],
69+
rules: {
70+
'unicorn/prefer-module': 'off',
71+
'@typescript-eslint/unbound-method': 'off',
72+
},
6373
}
6474
);

playwright.setup.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import { type FullConfig } from '@playwright/test';
2-
import { spawn } from 'child_process';
1+
import { spawn } from 'node:child_process';
32

4-
async function globalSetup(config: FullConfig) {
5-
console.log('globalSetup');
3+
async function globalSetup() {
4+
console.log('Playwright globalSetup called');
65

7-
return new Promise<void>(async (resolve, reject) => {
6+
return new Promise<void>((resolve, reject) => {
87
const electron = spawn('node', ['./scripts/launchdev.js']);
98

109
electron.on('close', () => {
11-
reject('process failed to start');
10+
reject(new Error('process failed to start'));
1211
});
1312

14-
electron.stdout.on('data', (data) => {
15-
if (data.indexOf('App ready') >= 0) {
13+
electron.stdout.on('data', (data: string | Buffer) => {
14+
if (data.includes('App ready')) {
1615
resolve();
1716
}
1817
});

scripts/downloadFrontend.js

+35-34
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,50 @@
1-
import axios from 'axios'
2-
import extract from 'extract-zip'
3-
import fs from 'node:fs/promises'
4-
import path from 'node:path'
1+
import axios from 'axios';
2+
import extract from 'extract-zip';
3+
import fs from 'node:fs/promises';
4+
import path from 'node:path';
55

6-
import packageJson from './getPackage.js'
6+
import packageJson from './getPackage.js';
77

88
// Example "v1.3.34"
99
const version = process.argv[2] || packageJson.config.frontendVersion;
1010
if (!version) {
11-
console.error('No version specified');
12-
process.exit(1);
11+
console.error('No version specified');
12+
process.exit(1);
1313
}
1414

1515
const url = `https://github.com/Comfy-Org/ComfyUI_frontend/releases/download/v${version}/dist.zip`;
1616
const downloadPath = 'temp_frontend.zip';
1717
const extractPath = 'assets/ComfyUI/web_custom_versions/desktop_app';
1818

1919
async function downloadAndExtractFrontend() {
20-
try {
21-
// Create directories if they don't exist
22-
await fs.mkdir(extractPath, { recursive: true });
23-
24-
// Download the file
25-
console.log('Downloading frontend...');
26-
const response = await axios({
27-
method: 'GET',
28-
url: url,
29-
responseType: 'arraybuffer'
30-
});
31-
32-
// Save to temporary file
33-
await fs.writeFile(downloadPath, response.data);
34-
35-
// Extract the zip file
36-
console.log('Extracting frontend...');
37-
await extract(downloadPath, { dir: path.resolve(extractPath) });
38-
39-
// Clean up temporary file
40-
await fs.unlink(downloadPath);
41-
42-
console.log('Frontend downloaded and extracted successfully!');
43-
} catch (error) {
44-
console.error('Error downloading frontend:', error.message);
45-
process.exit(1);
46-
}
20+
try {
21+
// Create directories if they don't exist
22+
await fs.mkdir(extractPath, { recursive: true });
23+
24+
// Download the file
25+
console.log('Downloading frontend...');
26+
const response = await axios({
27+
method: 'GET',
28+
url: url,
29+
responseType: 'arraybuffer',
30+
});
31+
32+
// Save to temporary file
33+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
34+
await fs.writeFile(downloadPath, response.data);
35+
36+
// Extract the zip file
37+
console.log('Extracting frontend...');
38+
await extract(downloadPath, { dir: path.resolve(extractPath) });
39+
40+
// Clean up temporary file
41+
await fs.unlink(downloadPath);
42+
43+
console.log('Frontend downloaded and extracted successfully!');
44+
} catch (error) {
45+
console.error('Error downloading frontend:', error.message);
46+
process.exit(1);
47+
}
4748
}
4849

4950
await downloadAndExtractFrontend();

scripts/downloadUV.js

+61-64
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,83 @@
1-
import path from "node:path"
2-
import os from 'node:os'
3-
import fs from 'fs-extra'
4-
import axios from 'axios'
5-
import * as tar from 'tar'
6-
import extractZip from 'extract-zip'
7-
import packageJson from './getPackage.js'
1+
import path from 'node:path';
2+
import os from 'node:os';
3+
import fs from 'fs-extra';
4+
import axios from 'axios';
5+
import * as tar from 'tar';
6+
import extractZip from 'extract-zip';
7+
import packageJson from './getPackage.js';
88

99
const uvVer = packageJson.config.uvVersion;
1010

1111
/** @typedef {{ [key]: { zipFile: string, uvOutputFolderName: string, zip: boolean } }} UvDownloadOptions */
1212
const options = {
13-
win32: {
14-
zipFile: 'uv-x86_64-pc-windows-msvc.zip',
15-
uvOutputFolderName: 'win',
16-
zip: true,
17-
},
18-
darwin: {
19-
zipFile: 'uv-aarch64-apple-darwin.tar.gz',
20-
uvOutputFolderName: 'macos',
21-
zip: false,
22-
},
23-
linux: {
24-
zipFile: 'uv-x86_64-unknown-linux-gnu.tar.gz',
25-
uvOutputFolderName: 'linux',
26-
zip: false,
27-
}
28-
}
13+
win32: {
14+
zipFile: 'uv-x86_64-pc-windows-msvc.zip',
15+
uvOutputFolderName: 'win',
16+
zip: true,
17+
},
18+
darwin: {
19+
zipFile: 'uv-aarch64-apple-darwin.tar.gz',
20+
uvOutputFolderName: 'macos',
21+
zip: false,
22+
},
23+
linux: {
24+
zipFile: 'uv-x86_64-unknown-linux-gnu.tar.gz',
25+
uvOutputFolderName: 'linux',
26+
zip: false,
27+
},
28+
};
2929

3030
async function downloadUV() {
31-
3231
const allFlag = process.argv[2];
3332
const baseDownloadURL = `https://github.com/astral-sh/uv/releases/download/${uvVer}/`;
34-
if (allFlag)
35-
{
36-
if (allFlag === 'all') {
37-
await downloadAndExtract(baseDownloadURL, options.win32);
38-
await downloadAndExtract(baseDownloadURL, options.darwin);
39-
await downloadAndExtract(baseDownloadURL, options.linux);
40-
return;
41-
}
42-
if (allFlag === 'none') {
43-
return;
44-
}
33+
if (allFlag) {
34+
if (allFlag === 'all') {
35+
await downloadAndExtract(baseDownloadURL, options.win32);
36+
await downloadAndExtract(baseDownloadURL, options.darwin);
37+
await downloadAndExtract(baseDownloadURL, options.linux);
38+
return;
39+
}
40+
if (allFlag === 'none') {
41+
return;
42+
}
4543
}
4644

4745
const uvDownloaded = fs.existsSync(path.join('./assets', 'uv'));
4846
if (!uvDownloaded) {
49-
await downloadAndExtract(baseDownloadURL, options[os.platform()]);
50-
return;
47+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
48+
await downloadAndExtract(baseDownloadURL, options[os.platform()]);
49+
return;
5150
}
5251
console.log('< UV Folder Exists, Skipping >');
53-
54-
};
52+
}
5553

5654
/** @param {UvDownloadOptions[any]} options */
5755
async function downloadAndExtract(baseURL, options) {
58-
const {
59-
zipFile,
60-
uvOutputFolderName,
61-
zip
62-
} = options;
63-
const zipFilePath = path.join('./assets', zipFile);
64-
const outputUVFolder = path.join('./assets', 'uv', uvOutputFolderName);
65-
await fs.mkdir(outputUVFolder, {
66-
recursive: true
56+
const { zipFile, uvOutputFolderName, zip } = options;
57+
const zipFilePath = path.join('./assets', zipFile);
58+
const outputUVFolder = path.join('./assets', 'uv', uvOutputFolderName);
59+
await fs.mkdir(outputUVFolder, {
60+
recursive: true,
61+
});
62+
const downloadedFile = await axios({
63+
method: 'GET',
64+
url: baseURL + zipFile,
65+
responseType: 'arraybuffer',
66+
});
67+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
68+
fs.writeFileSync(zipFilePath, downloadedFile.data);
69+
if (zip) {
70+
await extractZip(zipFilePath, { dir: path.resolve(outputUVFolder) });
71+
} else {
72+
tar.extract({
73+
sync: true,
74+
file: zipFilePath,
75+
C: outputUVFolder,
76+
'strip-components': 1,
6777
});
68-
const downloadedFile = await axios({
69-
method: 'GET',
70-
url: baseURL + zipFile,
71-
responseType: 'arraybuffer'
72-
});
73-
fs.writeFileSync(zipFilePath, downloadedFile.data);
74-
zip ? await extractZip(zipFilePath, {
75-
dir: path.resolve(outputUVFolder)
76-
}) : tar.extract({
77-
sync: true,
78-
file: zipFilePath,
79-
C: outputUVFolder,
80-
"strip-components": 1
81-
});
82-
await fs.unlink(zipFilePath);
83-
console.log(`FINISHED DOWNLOAD AND EXTRACT UV ${uvOutputFolderName}`);
78+
}
79+
await fs.unlink(zipFilePath);
80+
console.log(`FINISHED DOWNLOAD AND EXTRACT UV ${uvOutputFolderName}`);
8481
}
8582

8683
//** Download and Extract UV. Default uses OS.Platfrom. Add 'all' will download all. Add 'none' will skip */

scripts/getPackage.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Read the main package.json
2-
import { createRequire } from "node:module";
2+
import { createRequire } from 'node:module';
33

44
/** @type {import('../package.json')} */
5-
const packageJson = createRequire(import.meta.url)("../package.json");
5+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
6+
const packageJson = createRequire(import.meta.url)('../package.json');
67

78
export default packageJson;

scripts/launchdev.js

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function setupMainPackageWatcher() {
4343
: ['--inspect=9223'];
4444

4545
/** Spawn new electron process */
46+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
4647
electronApp = spawn(String(electronPath), [...args, '.'], {
4748
stdio: 'inherit',
4849
});

scripts/makeComfy.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as child_process from 'node:child_process'
2-
import pkg from './getPackage.js'
1+
import * as child_process from 'node:child_process';
2+
import pkg from './getPackage.js';
33

44
function makeAssets(gpuFlag) {
55
const baseCommand = [
@@ -12,7 +12,7 @@ function makeAssets(gpuFlag) {
1212
'--manager-url',
1313
'https://github.com/Comfy-Org/ComfyUI-Manager',
1414
'&&',
15-
'yarn run make:frontend'
15+
'yarn run make:frontend',
1616
].join(' ');
1717

1818
try {
@@ -29,7 +29,7 @@ const gpuFlags = {
2929
nvidia: '--nvidia',
3030
amd: '--amd',
3131
cpu: '--cpu',
32-
macos: '--m-series'
32+
macos: '--m-series',
3333
};
3434

3535
if (!arg || !gpuFlags[arg]) {

0 commit comments

Comments
 (0)