Skip to content

Commit 146a588

Browse files
authored
Add ESLint & Update tooling (#536)
* Add ESLint & Unicorn * Update TypeScript * Update vite * Fix build process not type-checked * Update project to lint all files * Update tsconfig to match project use - Removes unnecessary jsx setting - Fix deprectated moduleResolution marker * Improve legibility of dense JSON files * Fix yarn start never stops * Allow JS scripts to be formatted * nit * Apply auto-fixes * Convert preMake to named export * Apply auto-fixes * Add top-level awaits to ESM scripts * Add types * Format launchdev.js * Remove workaround, clean up * Revert "Allow JS scripts to be formatted" This reverts commit 21cecd7. * Update test expectations * nit * Fix tests not linted
1 parent 579526b commit 146a588

22 files changed

+1100
-442
lines changed

.eslintrc.json

-18
This file was deleted.

.prettierrc

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,13 @@
44
"singleQuote": true,
55
"tabWidth": 2,
66
"trailingComma": "es5",
7-
"endOfLine": "auto"
7+
8+
"overrides": [
9+
{
10+
"files": "*.json",
11+
"options": {
12+
"printWidth": 80
13+
}
14+
}
15+
]
816
}

.vscode/launch.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
"cwd": "${workspaceFolder}",
1010
"outputCapture": "std",
1111
"sourceMaps": true,
12-
"resolveSourceMapLocations": ["${workspaceFolder}/src/**", "${workspaceFolder}/.vite/**", "!**/node_modules/**"],
12+
"resolveSourceMapLocations": [
13+
"${workspaceFolder}/src/**",
14+
"${workspaceFolder}/.vite/**",
15+
"!**/node_modules/**"
16+
],
1317
"preLaunchTask": "Start Vite Dev Server",
1418
"autoAttachChildProcesses": true,
1519
"env": {
1620
"ELECTRON_ENABLE_LOGGING": "true",
1721
"ELECTRON_ENABLE_STACK_DUMPING": "true",
1822
"NODE_DEBUG": "true"
1923
},
20-
"outFiles": ["${workspaceFolder}/.vite/**/*.js", "${workspaceFolder}/.vite/**/*.js.map"]
24+
"outFiles": [
25+
"${workspaceFolder}/.vite/**/*.js",
26+
"${workspaceFolder}/.vite/**/*.js.map"
27+
]
2128
}
2229
]
2330
}

eslint.config.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import globals from 'globals';
2+
import eslint from '@eslint/js';
3+
import tseslint from 'typescript-eslint';
4+
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
5+
6+
export default tseslint.config(
7+
// Baseline include / exclude
8+
{ files: ['**/*.{js,cjs,mjs,ts,mts}'] },
9+
{ ignores: ['dist/**/*', 'jest.config.cjs'] },
10+
11+
// Baseline
12+
eslint.configs.recommended,
13+
...tseslint.configs.recommendedTypeChecked,
14+
{
15+
languageOptions: {
16+
parserOptions: {
17+
projectService: true,
18+
tsconfigRootDir: import.meta.dirname,
19+
},
20+
},
21+
rules: {
22+
'no-empty-pattern': ['error', { allowObjectPatternsAsParameters: true }],
23+
'no-control-regex': 'off',
24+
25+
'@typescript-eslint/restrict-template-expressions': 'off',
26+
},
27+
},
28+
29+
// Baseline (except preload)
30+
{
31+
ignores: ['./src/preload.ts'],
32+
languageOptions: { globals: { ...globals.node } },
33+
},
34+
35+
// Preload
36+
{
37+
files: ['./src/preload.ts'],
38+
languageOptions: { globals: { ...globals.browser } },
39+
},
40+
41+
// Unicorn
42+
eslintPluginUnicorn.configs['flat/recommended'],
43+
{
44+
rules: {
45+
// Enable
46+
'unicorn/better-regex': 'warn',
47+
// Disable
48+
'unicorn/prefer-string-slice': 'off',
49+
'unicorn/no-negated-condition': 'off',
50+
'unicorn/filename-case': 'off',
51+
'unicorn/no-null': 'off',
52+
'unicorn/prevent-abbreviations': 'off',
53+
'unicorn/switch-case-braces': 'off',
54+
},
55+
},
56+
57+
// Scripts
58+
{
59+
files: ['scripts/**/*'],
60+
rules: {
61+
'unicorn/no-process-exit': 'off',
62+
},
63+
}
64+
);

package.json

+11-6
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"test:update-snapshots": "npx playwright test --update-snapshots",
4848
"todesktop:afterPack": "./scripts/todesktop/afterPack.cjs",
4949
"todesktop:beforeInstall": "./scripts/todesktop/beforeInstall.cjs",
50-
"typescript": "yarn run tsc",
51-
"vite:compile": "vite build --config vite.main.config.ts && vite build --config vite.preload.config.ts",
52-
"vite:types": "vite build --config vite.types.config.ts && node scripts/prepareTypes.js",
50+
"typescript": "tsc -p tsconfig.build.json",
51+
"vite:compile": "yarn run typescript && vite build --config vite.main.config.ts && vite build --config vite.preload.config.ts",
52+
"vite:types": "yarn run typescript && vite build --config vite.types.config.ts && node scripts/prepareTypes.js",
5353
"release:types": "node scripts/releaseTypes.js",
5454
"update:frontend": "node scripts/updateFrontend.js"
5555
},
@@ -58,11 +58,13 @@
5858
"@electron/notarize": "^2.4.0",
5959
"@electron/rebuild": "^3.7.1",
6060
"@electron/windows-sign": "^1.1.3",
61+
"@eslint/js": "^9.17.0",
6162
"@playwright/test": "^1.47.2",
6263
"@sentry/wizard": "^3.30.0",
6364
"@todesktop/cli": "^1.9.7",
6465
"@types/adm-zip": "^0.5.5",
6566
"@types/electron-squirrel-startup": "^1.0.2",
67+
"@types/eslint__js": "^8.42.3",
6668
"@types/jest": "^29.5.14",
6769
"@types/node": "^22.10.2",
6870
"@types/tar": "6.1.13",
@@ -71,17 +73,20 @@
7173
"@typescript-eslint/parser": "^5.0.0",
7274
"electron": "31.3.1",
7375
"electron-builder": "^25.1.8",
74-
"eslint": "^8.0.1",
76+
"eslint": "^9.17.0",
7577
"eslint-plugin-import": "^2.25.0",
78+
"eslint-plugin-unicorn": "^56.0.1",
79+
"globals": "^15.13.0",
7680
"husky": "^9.1.6",
7781
"jest": "^29.7.0",
7882
"lint-staged": "^15.2.10",
7983
"prettier": "^3.3.3",
8084
"rimraf": "^6.0.1",
8185
"ts-jest": "^29.2.5",
8286
"ts-node": "^10.0.0",
83-
"typescript": "~5.5.4",
84-
"vite": "^5.0.12",
87+
"typescript": "^5.7.2",
88+
"typescript-eslint": "^8.18.1",
89+
"vite": "^6.0.3",
8590
"vite-plugin-dts": "^4.3.0"
8691
},
8792
"keywords": [],

scripts/downloadFrontend.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import axios from 'axios'
22
import extract from 'extract-zip'
3-
import fs from 'fs/promises'
4-
import path from 'path'
3+
import fs from 'node:fs/promises'
4+
import path from 'node:path'
55

66
import packageJson from './getPackage.js'
77

@@ -46,4 +46,4 @@ async function downloadAndExtractFrontend() {
4646
}
4747
}
4848

49-
downloadAndExtractFrontend();
49+
await downloadAndExtractFrontend();

scripts/downloadUV.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import path from "path"
2-
import os from 'os'
1+
import path from "node:path"
2+
import os from 'node:os'
33
import fs from 'fs-extra'
44
import axios from 'axios'
55
import * as tar from 'tar'
@@ -8,6 +8,7 @@ import packageJson from './getPackage.js'
88

99
const uvVer = packageJson.config.uvVersion;
1010

11+
/** @typedef {{ [key]: { zipFile: string, uvOutputFolderName: string, zip: boolean } }} UvDownloadOptions */
1112
const options = {
1213
win32: {
1314
zipFile: 'uv-x86_64-pc-windows-msvc.zip',
@@ -52,6 +53,7 @@ async function downloadUV() {
5253

5354
};
5455

56+
/** @param {UvDownloadOptions[any]} options */
5557
async function downloadAndExtract(baseURL, options) {
5658
const {
5759
zipFile,

scripts/env.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ const envContent = `# env vars picked up by the ComfyUI executable on startup
44
COMFYUI_CPU_ONLY=true
55
`;
66

7-
fs.writeFile('ComfyUI/.env', envContent);
7+
await fs.writeFile('ComfyUI/.env', envContent);

scripts/getPackage.js

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

44
/** @type {import('../package.json')} */
55
const packageJson = createRequire(import.meta.url)("../package.json");

scripts/launchdev.js

+62-63
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,84 @@
1-
import { build } from 'vite'
2-
import electronPath from 'electron'
3-
import { spawn } from 'child_process'
1+
import { build } from 'vite';
2+
import electronPath from 'electron';
3+
import { spawn } from 'node:child_process';
44

5-
/** @type 'production' | 'development'' */
6-
const mode = (process.env.MODE = process.env.MODE || 'development')
5+
/** @type {'production' | 'development'} */
6+
const mode = (process.env.MODE = process.env.MODE || 'development');
77

88
/** @type {import('vite').LogLevel} */
9-
const logLevel = 'warn'
9+
const logLevel = 'warn';
1010

1111
/**
1212
* Setup watcher for `main` package
1313
* On file changed it totally re-launch electron app.
1414
*/
1515
function setupMainPackageWatcher() {
16-
/** @type {ChildProcess | null} */
17-
let electronApp = null;
16+
/** @type {import('node:child_process').ChildProcess | null} */
17+
let electronApp = null;
1818

19-
return build({
20-
mode,
21-
logLevel,
22-
configFile: 'vite.main.config.ts',
23-
build: {
24-
/**
25-
* Set to {} to enable rollup watcher
26-
* @see https://vitejs.dev/config/build-options.html#build-watch
27-
*/
28-
watch: {},
29-
},
30-
plugins: [
31-
{
32-
name: 'reload-app-on-main-package-change',
33-
writeBundle() {
34-
/** Kill electron if process already exist */
35-
if (electronApp !== null) {
36-
electronApp.removeListener('exit', process.exit);
37-
electronApp.kill('SIGINT');
38-
electronApp = null;
39-
}
19+
return build({
20+
mode,
21+
logLevel,
22+
configFile: 'vite.main.config.ts',
23+
build: {
24+
/**
25+
* Set to {} to enable rollup watcher
26+
* @see https://vitejs.dev/config/build-options.html#build-watch
27+
*/
28+
watch: {},
29+
},
30+
plugins: [
31+
{
32+
name: 'reload-app-on-main-package-change-a',
33+
writeBundle() {
34+
/** Kill electron if process already exist */
35+
if (electronApp !== null) {
36+
electronApp.removeListener('exit', () => process.exit());
37+
electronApp.kill('SIGINT');
38+
electronApp = null;
39+
}
4040

41-
const args = process.env.CI ? ['--remote-debugging-port=9000', '--remote-allow-origins=http://127.0.0.1:9000' ] : ['--inspect=9223']
41+
const args = process.env.CI
42+
? ['--remote-debugging-port=9000', '--remote-allow-origins=http://127.0.0.1:9000']
43+
: ['--inspect=9223'];
4244

43-
/** Spawn new electron process */
44-
electronApp = spawn(String(electronPath), [...args, '.'], {
45-
stdio: 'inherit',
46-
});
45+
/** Spawn new electron process */
46+
electronApp = spawn(String(electronPath), [...args, '.'], {
47+
stdio: 'inherit',
48+
});
4749

48-
electronApp.addListener('')
49-
/** Stops the watch script when the application has been quit */
50-
electronApp.addListener('exit', process.exit);
51-
},
52-
},
53-
],
54-
});
50+
/** Stops the watch script when the application has been quit */
51+
electronApp.addListener('exit', () => process.exit());
52+
},
53+
},
54+
],
55+
});
5556
}
5657

5758
/**
5859
* Setup watcher for `preload` package
5960
* On file changed it reload web page.
6061
*/
6162
function setupPreloadPackageWatcher() {
62-
return build({
63-
mode,
64-
logLevel,
65-
configFile: 'vite.preload.config.ts',
66-
build: {
67-
/**
68-
* Set to {} to enable rollup watcher
69-
* @see https://vitejs.dev/config/build-options.html#build-watch
70-
*/
71-
watch: {},
72-
},
73-
plugins: [
74-
{
75-
name: 'reload-page-on-preload-package-change',
76-
writeBundle() {},
77-
},
78-
],
79-
});
63+
return build({
64+
mode,
65+
logLevel,
66+
configFile: 'vite.preload.config.ts',
67+
build: {
68+
/**
69+
* Set to {} to enable rollup watcher
70+
* @see https://vitejs.dev/config/build-options.html#build-watch
71+
*/
72+
watch: {},
73+
},
74+
plugins: [
75+
{
76+
name: 'reload-page-on-preload-package-change',
77+
writeBundle() {},
78+
},
79+
],
80+
});
8081
}
8182

82-
(async () => {
83-
await setupPreloadPackageWatcher();
84-
await setupMainPackageWatcher();
85-
})();
83+
await setupPreloadPackageWatcher();
84+
await setupMainPackageWatcher();

scripts/makeComfy.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as child_process from 'child_process'
1+
import * as child_process from 'node:child_process'
22
import pkg from './getPackage.js'
3-
import fs from 'fs'
43

54
function makeAssets(gpuFlag) {
65
const baseCommand = [

0 commit comments

Comments
 (0)