From a79d87d25af5016c30a25c2bc6866af246c7a156 Mon Sep 17 00:00:00 2001 From: snomiao Date: Fri, 12 Sep 2025 00:58:35 +0000 Subject: [PATCH] refactor(knip.config.ts): simplify and reorganize configuration for better clarity and maintainability feat(knip.config.ts): add support for vite and vitest configurations to enhance project structure and testing capabilities --- knip.config.ts | 113 ++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 71 deletions(-) diff --git a/knip.config.ts b/knip.config.ts index d7beb11eab..9df077d772 100644 --- a/knip.config.ts +++ b/knip.config.ts @@ -2,85 +2,56 @@ import type { KnipConfig } from 'knip' const config: KnipConfig = { entry: [ + '{build,scripts}/**/*.{js,ts}', + 'src/assets/css/style.css', 'src/main.ts', - 'vite.config.mts', - 'vite.electron.config.mts', - 'vite.types.config.mts', - 'eslint.config.js', - 'tailwind.config.js', - 'postcss.config.js', - 'playwright.config.ts', - 'playwright.i18n.config.ts', - 'vitest.config.ts', - 'scripts/**/*.{js,ts}' + 'src/scripts/ui/menu/index.ts', + 'src/types/index.ts' ], - project: [ - 'src/**/*.{js,ts,vue}', - 'tests-ui/**/*.{js,ts,vue}', - 'browser_tests/**/*.{js,ts}', - 'scripts/**/*.{js,ts}' + project: ['**/*.{js,ts,vue}', '*.{js,ts,mts}'], + ignoreBinaries: ['only-allow', 'openapi-typescript'], + ignoreDependencies: [ + // Weird importmap things + '@iconify/json', + '@primeuix/forms', + '@primeuix/styled', + '@primeuix/utils', + '@primevue/icons', + // Dev + '@trivago/prettier-plugin-sort-imports' ], ignore: [ - // Generated files - 'dist/**', - 'types/**', - 'node_modules/**', - // Config files that might not show direct usage - '.husky/**', - // Temporary or cache files - '.vite/**', - 'coverage/**', - // i18n config - '.i18nrc.cjs', - 'browser_tests/globalSetupWithI18n.ts', - 'browser_tests/globalTeardownWithI18n.ts', - 'browser_tests/i18nSetup.ts', - 'playwright.i18n.config.ts', - // Test setup files - 'browser_tests/globalSetup.ts', - 'browser_tests/globalTeardown.ts', - 'browser_tests/utils/**', - // Scripts - 'scripts/**', - // Vite config files - 'vite.electron.config.mts', - 'vite.types.config.mts', // Auto generated manager types 'src/types/generatedManagerTypes.ts', - // Design system components (may not be used immediately) - 'src/components/button/IconGroup.vue', - 'src/components/button/MoreButton.vue', - 'src/components/button/TextButton.vue', - 'src/components/card/CardTitle.vue', - 'src/components/card/CardDescription.vue', - 'src/components/input/SingleSelect.vue' + 'src/types/comfyRegistryTypes.ts', + // Used by a custom node (that should move off of this) + 'src/scripts/ui/components/splitButton.ts' ], - ignoreExportsUsedInFile: true, - // Vue-specific configuration - vue: true, - // Only check for unused files, disable all other rules - // TODO: Gradually enable other rules - see https://github.com/Comfy-Org/ComfyUI_frontend/issues/4888 - rules: { - binaries: 'off', - classMembers: 'off', - dependencies: 'off', - devDependencies: 'off', - duplicates: 'off', - enumMembers: 'off', - exports: 'off', - nsExports: 'off', - nsTypes: 'off', - types: 'off', - unlisted: 'off' + compilers: { + // https://github.com/webpro-nl/knip/issues/1008#issuecomment-3207756199 + css: (text: string) => + [ + ...text.replaceAll('plugin', 'import').matchAll(/(?<=@)import[^;]+/g) + ].join('\n') }, - // Include dependencies analysis - includeEntryExports: true, - // Workspace configuration for monorepo-like structure - workspaces: { - '.': { - entry: ['src/main.ts', 'playwright.i18n.config.ts'] - } - } + vite: { + config: ['vite?(.*).config.mts'] + }, + vitest: { + config: ['vitest?(.*).config.ts'], + entry: [ + '**/*.{bench,test,test-d,spec}.?(c|m)[jt]s?(x)', + '**/__mocks__/**/*.[jt]s?(x)' + ] + }, + playwright: { + config: ['playwright?(.*).config.ts'], + entry: ['**/*.@(spec|test).?(c|m)[jt]s?(x)', 'browser_tests/**/*.ts'] + }, + tags: [ + '-knipIgnoreUnusedButUsedByCustomNodes', + '-knipIgnoreUnusedButUsedByVueNodesBranch' + ] } export default config