Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ESLint & Update tooling #536

Merged
merged 21 commits into from
Dec 19, 2024
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
18 changes: 0 additions & 18 deletions .eslintrc.json

This file was deleted.

10 changes: 9 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5",
"endOfLine": "auto"

"overrides": [
{
"files": "*.json",
"options": {
"printWidth": 80
}
}
]
}
11 changes: 9 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@
"cwd": "${workspaceFolder}",
"outputCapture": "std",
"sourceMaps": true,
"resolveSourceMapLocations": ["${workspaceFolder}/src/**", "${workspaceFolder}/.vite/**", "!**/node_modules/**"],
"resolveSourceMapLocations": [
"${workspaceFolder}/src/**",
"${workspaceFolder}/.vite/**",
"!**/node_modules/**"
],
"preLaunchTask": "Start Vite Dev Server",
"autoAttachChildProcesses": true,
"env": {
"ELECTRON_ENABLE_LOGGING": "true",
"ELECTRON_ENABLE_STACK_DUMPING": "true",
"NODE_DEBUG": "true"
},
"outFiles": ["${workspaceFolder}/.vite/**/*.js", "${workspaceFolder}/.vite/**/*.js.map"]
"outFiles": [
"${workspaceFolder}/.vite/**/*.js",
"${workspaceFolder}/.vite/**/*.js.map"
]
}
]
}
64 changes: 64 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import globals from 'globals';
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';

export default tseslint.config(
// Baseline include / exclude
{ files: ['**/*.{js,cjs,mjs,ts,mts}'] },
{ ignores: ['dist/**/*', 'jest.config.cjs'] },

// Baseline
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'no-empty-pattern': ['error', { allowObjectPatternsAsParameters: true }],
'no-control-regex': 'off',

'@typescript-eslint/restrict-template-expressions': 'off',
},
},

// Baseline (except preload)
{
ignores: ['./src/preload.ts'],
languageOptions: { globals: { ...globals.node } },
},

// Preload
{
files: ['./src/preload.ts'],
languageOptions: { globals: { ...globals.browser } },
},

// Unicorn
eslintPluginUnicorn.configs['flat/recommended'],
{
rules: {
// Enable
'unicorn/better-regex': 'warn',
// Disable
'unicorn/prefer-string-slice': 'off',
'unicorn/no-negated-condition': 'off',
'unicorn/filename-case': 'off',
'unicorn/no-null': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/switch-case-braces': 'off',
},
},

// Scripts
{
files: ['scripts/**/*'],
rules: {
'unicorn/no-process-exit': 'off',
},
}
);
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"test:update-snapshots": "npx playwright test --update-snapshots",
"todesktop:afterPack": "./scripts/todesktop/afterPack.cjs",
"todesktop:beforeInstall": "./scripts/todesktop/beforeInstall.cjs",
"typescript": "yarn run tsc",
"vite:compile": "vite build --config vite.main.config.ts && vite build --config vite.preload.config.ts",
"vite:types": "vite build --config vite.types.config.ts && node scripts/prepareTypes.js",
"typescript": "tsc -p tsconfig.build.json",
"vite:compile": "yarn run typescript && vite build --config vite.main.config.ts && vite build --config vite.preload.config.ts",
"vite:types": "yarn run typescript && vite build --config vite.types.config.ts && node scripts/prepareTypes.js",
"release:types": "node scripts/releaseTypes.js",
"update:frontend": "node scripts/updateFrontend.js"
},
Expand All @@ -58,11 +58,13 @@
"@electron/notarize": "^2.4.0",
"@electron/rebuild": "^3.7.1",
"@electron/windows-sign": "^1.1.3",
"@eslint/js": "^9.17.0",
"@playwright/test": "^1.47.2",
"@sentry/wizard": "^3.30.0",
"@todesktop/cli": "^1.9.7",
"@types/adm-zip": "^0.5.5",
"@types/electron-squirrel-startup": "^1.0.2",
"@types/eslint__js": "^8.42.3",
"@types/jest": "^29.5.14",
"@types/node": "^22.10.2",
"@types/tar": "6.1.13",
Expand All @@ -71,17 +73,20 @@
"@typescript-eslint/parser": "^5.0.0",
"electron": "31.3.1",
"electron-builder": "^25.1.8",
"eslint": "^8.0.1",
"eslint": "^9.17.0",
"eslint-plugin-import": "^2.25.0",
"eslint-plugin-unicorn": "^56.0.1",
"globals": "^15.13.0",
"husky": "^9.1.6",
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.0.0",
"typescript": "~5.5.4",
"vite": "^5.0.12",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.1",
"vite": "^6.0.3",
"vite-plugin-dts": "^4.3.0"
},
"keywords": [],
Expand Down
6 changes: 3 additions & 3 deletions scripts/downloadFrontend.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios'
import extract from 'extract-zip'
import fs from 'fs/promises'
import path from 'path'
import fs from 'node:fs/promises'
import path from 'node:path'

import packageJson from './getPackage.js'

Expand Down Expand Up @@ -46,4 +46,4 @@ async function downloadAndExtractFrontend() {
}
}

downloadAndExtractFrontend();
await downloadAndExtractFrontend();
6 changes: 4 additions & 2 deletions scripts/downloadUV.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path"
import os from 'os'
import path from "node:path"
import os from 'node:os'
import fs from 'fs-extra'
import axios from 'axios'
import * as tar from 'tar'
Expand All @@ -8,6 +8,7 @@ import packageJson from './getPackage.js'

const uvVer = packageJson.config.uvVersion;

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

};

/** @param {UvDownloadOptions[any]} options */
async function downloadAndExtract(baseURL, options) {
const {
zipFile,
Expand Down
2 changes: 1 addition & 1 deletion scripts/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ const envContent = `# env vars picked up by the ComfyUI executable on startup
COMFYUI_CPU_ONLY=true
`;

fs.writeFile('ComfyUI/.env', envContent);
await fs.writeFile('ComfyUI/.env', envContent);
2 changes: 1 addition & 1 deletion scripts/getPackage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Read the main package.json
import { createRequire } from "module";
import { createRequire } from "node:module";

/** @type {import('../package.json')} */
const packageJson = createRequire(import.meta.url)("../package.json");
Expand Down
125 changes: 62 additions & 63 deletions scripts/launchdev.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,84 @@
import { build } from 'vite'
import electronPath from 'electron'
import { spawn } from 'child_process'
import { build } from 'vite';
import electronPath from 'electron';
import { spawn } from 'node:child_process';

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

/** @type {import('vite').LogLevel} */
const logLevel = 'warn'
const logLevel = 'warn';

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

return build({
mode,
logLevel,
configFile: 'vite.main.config.ts',
build: {
/**
* Set to {} to enable rollup watcher
* @see https://vitejs.dev/config/build-options.html#build-watch
*/
watch: {},
},
plugins: [
{
name: 'reload-app-on-main-package-change',
writeBundle() {
/** Kill electron if process already exist */
if (electronApp !== null) {
electronApp.removeListener('exit', process.exit);
electronApp.kill('SIGINT');
electronApp = null;
}
return build({
mode,
logLevel,
configFile: 'vite.main.config.ts',
build: {
/**
* Set to {} to enable rollup watcher
* @see https://vitejs.dev/config/build-options.html#build-watch
*/
watch: {},
},
plugins: [
{
name: 'reload-app-on-main-package-change-a',
writeBundle() {
/** Kill electron if process already exist */
if (electronApp !== null) {
electronApp.removeListener('exit', () => process.exit());
electronApp.kill('SIGINT');
electronApp = null;
}

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

/** Spawn new electron process */
electronApp = spawn(String(electronPath), [...args, '.'], {
stdio: 'inherit',
});
/** Spawn new electron process */
electronApp = spawn(String(electronPath), [...args, '.'], {
stdio: 'inherit',
});

electronApp.addListener('')
/** Stops the watch script when the application has been quit */
electronApp.addListener('exit', process.exit);
},
},
],
});
/** Stops the watch script when the application has been quit */
electronApp.addListener('exit', () => process.exit());
},
},
],
});
}

/**
* Setup watcher for `preload` package
* On file changed it reload web page.
*/
function setupPreloadPackageWatcher() {
return build({
mode,
logLevel,
configFile: 'vite.preload.config.ts',
build: {
/**
* Set to {} to enable rollup watcher
* @see https://vitejs.dev/config/build-options.html#build-watch
*/
watch: {},
},
plugins: [
{
name: 'reload-page-on-preload-package-change',
writeBundle() {},
},
],
});
return build({
mode,
logLevel,
configFile: 'vite.preload.config.ts',
build: {
/**
* Set to {} to enable rollup watcher
* @see https://vitejs.dev/config/build-options.html#build-watch
*/
watch: {},
},
plugins: [
{
name: 'reload-page-on-preload-package-change',
writeBundle() {},
},
],
});
}

(async () => {
await setupPreloadPackageWatcher();
await setupMainPackageWatcher();
})();
await setupPreloadPackageWatcher();
await setupMainPackageWatcher();
3 changes: 1 addition & 2 deletions scripts/makeComfy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as child_process from 'child_process'
import * as child_process from 'node:child_process'
import pkg from './getPackage.js'
import fs from 'fs'

function makeAssets(gpuFlag) {
const baseCommand = [
Expand Down
Loading
Loading